Class: Dugway::Store
Instance Method Summary collapse
- #account ⇒ Object
- #artist(permalink) ⇒ Object
- #artist_products(permalink) ⇒ Object
- #artists ⇒ Object
- #categories ⇒ Object
- #category(permalink) ⇒ Object
- #category_products(permalink) ⇒ Object
- #country ⇒ Object
- #currency ⇒ Object
- #custom_pages ⇒ Object
- #external_pages ⇒ Object
-
#initialize(subdomain, store_options = {}) ⇒ Store
constructor
A new instance of Store.
- #instant_checkout? ⇒ Boolean
- #locale ⇒ Object
- #next_product(permalink) ⇒ Object
- #page(permalink) ⇒ Object
- #pages ⇒ Object
- #previous_product(permalink) ⇒ Object
- #price_suffix ⇒ Object
- #product(permalink) ⇒ Object
- #product_and_option(option_id) ⇒ Object
- #products ⇒ Object
- #required_pages ⇒ Object
- #search_products(search_terms) ⇒ Object
- #subscribe_url ⇒ Object
- #theme_pages ⇒ Object
- #website ⇒ Object
Constructor Details
#initialize(subdomain, store_options = {}) ⇒ Store
Returns a new instance of Store.
11 12 13 14 |
# File 'lib/dugway/store.rb', line 11 def initialize(subdomain, = {}) self.class.base_uri "https://api.bigcartel.com/#{ subdomain }" @store_options = || {} end |
Instance Method Details
#account ⇒ Object
16 17 18 |
# File 'lib/dugway/store.rb', line 16 def account @account ||= get('/store.json') end |
#artist(permalink) ⇒ Object
66 67 68 |
# File 'lib/dugway/store.rb', line 66 def artist(permalink) lookup(permalink, artists) end |
#artist_products(permalink) ⇒ Object
70 71 72 |
# File 'lib/dugway/store.rb', line 70 def artist_products(permalink) lookup_products(permalink, 'artists') end |
#artists ⇒ Object
62 63 64 |
# File 'lib/dugway/store.rb', line 62 def artists account.has_key?('artists') ? account['artists'] : [] end |
#categories ⇒ Object
50 51 52 |
# File 'lib/dugway/store.rb', line 50 def categories account.has_key?('categories') ? account['categories'] : [] end |
#category(permalink) ⇒ Object
54 55 56 |
# File 'lib/dugway/store.rb', line 54 def category(permalink) lookup(permalink, categories) end |
#category_products(permalink) ⇒ Object
58 59 60 |
# File 'lib/dugway/store.rb', line 58 def category_products(permalink) lookup_products(permalink, 'categories') end |
#country ⇒ Object
124 125 126 |
# File 'lib/dugway/store.rb', line 124 def country account['country'] end |
#currency ⇒ Object
128 129 130 |
# File 'lib/dugway/store.rb', line 128 def currency account['currency'] end |
#custom_pages ⇒ Object
31 32 33 34 35 36 |
# File 'lib/dugway/store.rb', line 31 def custom_pages @custom_pages ||= begin custom_pages = account.has_key?('pages') ? account['pages'] : [] custom_pages = custom_pages.map { |page| get("/page/#{ page['permalink'] }.json") } end end |
#external_pages ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/dugway/store.rb', line 152 def external_pages @external_pages ||= begin pages = [] if subscribe_url && !subscribe_url.empty? pages << { 'name' => 'Subscribe', 'permalink' => 'subscribe', 'url' => subscribe_url, 'category' => 'external' } end pages end end |
#instant_checkout? ⇒ Boolean
140 141 142 |
# File 'lib/dugway/store.rb', line 140 def instant_checkout? Dugway..dig(:store, :instant_checkout) || false end |
#locale ⇒ Object
132 133 134 |
# File 'lib/dugway/store.rb', line 132 def locale @store_options[:locale] || currency['locale'] end |
#next_product(permalink) ⇒ Object
106 107 108 109 110 111 112 113 114 |
# File 'lib/dugway/store.rb', line 106 def next_product(permalink) products.each_with_index do |product, index| if product['permalink'] == permalink && (index + 1) < products.size && next_product = products[index + 1] return next_product end end nil end |
#page(permalink) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/dugway/store.rb', line 42 def page(permalink) if permalink != 'checkout' lookup(permalink, pages) else { 'name' => 'Checkout', 'permalink' => 'checkout', 'url' => '/checkout', 'category' => 'other' } end end |
#pages ⇒ Object
38 39 40 |
# File 'lib/dugway/store.rb', line 38 def pages @pages ||= theme_pages + custom_pages + external_pages + required_pages end |
#previous_product(permalink) ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/dugway/store.rb', line 96 def previous_product(permalink) products.each_with_index do |product, index| if product['permalink'] == permalink && index > 0 && previous_product = products[index - 1] return previous_product end end nil end |
#price_suffix ⇒ Object
148 149 150 |
# File 'lib/dugway/store.rb', line 148 def price_suffix @store_options[:price_suffix] end |
#product(permalink) ⇒ Object
79 80 81 |
# File 'lib/dugway/store.rb', line 79 def product(permalink) lookup(permalink, products) end |
#product_and_option(option_id) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/dugway/store.rb', line 83 def product_and_option(option_id) products.each do |product| next unless product['options'] product['options'].each do |option| if option['id'] == option_id return product, option end end end nil end |
#products ⇒ Object
74 75 76 77 |
# File 'lib/dugway/store.rb', line 74 def products @products ||= get('/products.json') Marshal.load(Marshal.dump(@products)) # Hack to avoid data munging elsewhere? end |
#required_pages ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/dugway/store.rb', line 167 def required_pages @required_pages ||= begin required_pages_config = @store_options[:required_pages] || account['required_pages'] || [] required_pages_config.map do |page_config| { 'name' => page_config['name'], 'permalink' => page_config['permalink'], 'url' => page_config['url'], 'category' => page_config['category'] || 'custom', 'required' => true } end end end |
#search_products(search_terms) ⇒ Object
116 117 118 119 120 121 122 |
# File 'lib/dugway/store.rb', line 116 def search_products(search_terms) return [] unless search_terms products.select { |p| (p['name'] && p['name'].downcase.include?(search_terms.downcase)) || (p['description'] && p['description'].downcase.include?(search_terms.downcase)) } end |
#subscribe_url ⇒ Object
144 145 146 |
# File 'lib/dugway/store.rb', line 144 def subscribe_url @store_options[:subscribe_url] || account['subscribe_url'] end |
#theme_pages ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dugway/store.rb', line 20 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' => 'Contact', 'permalink' => 'contact', 'url' => '/contact', 'category' => 'theme' }, { 'name' => 'Maintenance', 'permalink' => 'maintenance', 'url' => '/maintenance', 'category' => 'theme' } ] end |
#website ⇒ Object
136 137 138 |
# File 'lib/dugway/store.rb', line 136 def website @store_options[:website] || account['website'] end |