Class: Dugway::Store

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/dugway/store.rb

Instance Method Summary collapse

Constructor Details

#initialize(subdomain) ⇒ Store

Returns a new instance of Store.



11
12
13
# File 'lib/dugway/store.rb', line 11

def initialize(subdomain)
  self.class.base_uri "http://api.bigcartel.com/#{ subdomain }"
end

Instance Method Details

#accountObject



15
16
17
# File 'lib/dugway/store.rb', line 15

def 
  @account ||= get('/store.json')
end

#artist(permalink) ⇒ Object



63
64
65
# File 'lib/dugway/store.rb', line 63

def artist(permalink)
  lookup(permalink, artists)
end

#artist_products(permalink) ⇒ Object



67
68
69
# File 'lib/dugway/store.rb', line 67

def artist_products(permalink)
  lookup_products(permalink, 'artists')
end

#artistsObject



59
60
61
# File 'lib/dugway/store.rb', line 59

def artists
  .has_key?('artists') ? ['artists'] : []
end

#categoriesObject



47
48
49
# File 'lib/dugway/store.rb', line 47

def categories
  .has_key?('categories') ? ['categories'] : []
end

#category(permalink) ⇒ Object



51
52
53
# File 'lib/dugway/store.rb', line 51

def category(permalink)
  lookup(permalink, categories)
end

#category_products(permalink) ⇒ Object



55
56
57
# File 'lib/dugway/store.rb', line 55

def category_products(permalink)
  lookup_products(permalink, 'categories')
end

#countryObject



115
116
117
# File 'lib/dugway/store.rb', line 115

def country
  ['country']
end

#currencyObject



119
120
121
# File 'lib/dugway/store.rb', line 119

def currency
  ['currency']
end

#custom_pagesObject



32
33
34
35
36
37
# File 'lib/dugway/store.rb', line 32

def custom_pages
  @custom_pages ||= begin
    custom_pages = .has_key?('pages') ? ['pages'] : []
    custom_pages = custom_pages.map { |page| get("/page/#{ page['permalink'] }.json") }
  end
end

#localeObject



123
124
125
# File 'lib/dugway/store.rb', line 123

def locale
  currency['locale']
end

#next_product(permalink) ⇒ Object



101
102
103
104
105
106
107
108
109
# File 'lib/dugway/store.rb', line 101

def next_product(permalink)
  products.each_with_index { |product, index|
    if product['permalink'] == permalink && (index + 1) < products.size && next_product = products[index + 1]
      return next_product
    end
  }

  nil
end

#page(permalink) ⇒ Object



43
44
45
# File 'lib/dugway/store.rb', line 43

def page(permalink)
  lookup(permalink, pages)
end

#pagesObject



39
40
41
# File 'lib/dugway/store.rb', line 39

def pages
  @pages ||= theme_pages + custom_pages
end

#previous_product(permalink) ⇒ Object



91
92
93
94
95
96
97
98
99
# File 'lib/dugway/store.rb', line 91

def previous_product(permalink)
  products.each_with_index { |product, index|
    if product['permalink'] == permalink && index > 0 && previous_product = products[index - 1]
      return previous_product
    end
  }

  nil
end

#product(permalink) ⇒ Object



75
76
77
# File 'lib/dugway/store.rb', line 75

def product(permalink)
  lookup(permalink, products)
end

#product_and_option(option_id) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/dugway/store.rb', line 79

def product_and_option(option_id)
  products.each { |product|
    product['options'].each { |option|
      if option['id'] == option_id
        return product, option
      end
    }
  }

  nil
end

#productsObject



71
72
73
# File 'lib/dugway/store.rb', line 71

def products
  @products ||= get('/products.json')
end

#search_products(search_terms) ⇒ Object



111
112
113
# File 'lib/dugway/store.rb', line 111

def search_products(search_terms)
  products.select { |p| p['name'].downcase.include?(search_terms.downcase) || p['description'].downcase.include?(search_terms.downcase) }
end

#theme_pagesObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/dugway/store.rb', line 19

def theme_pages
  [
    { 'name' => 'Home', 'permalink' => 'home', 'url' => '/', 'category' => 'theme' },
    { 'name' => 'Products', 'permalink' => 'products', 'url' => '/products', 'category' => 'theme' },
    { 'name' => 'Product', 'permalink' => 'product', 'url' => '/product', 'category' => 'theme' },
    { 'name' => 'Cart', 'permalink' => 'cart', 'url' => '/cart', 'category' => 'theme' },
    { 'name' => 'Checkout', 'permalink' => 'checkout', 'url' => '/checkout', 'category' => 'theme' },
    { 'name' => 'Success', 'permalink' => 'success', 'url' => '/success', 'category' => 'theme' },
    { 'name' => 'Contact', 'permalink' => 'contact', 'url' => '/contact', 'category' => 'theme' },
    { 'name' => 'Maintenance', 'permalink' => 'maintenance', 'url' => '/maintenance', 'category' => 'theme' }
  ]
end