class Dugway::Store
Public Class Methods
new(subdomain)
click to toggle source
# File lib/dugway/store.rb, line 11 def initialize(subdomain) self.class.base_uri "https://api.bigcartel.com/#{ subdomain }" end
Public Instance Methods
account()
click to toggle source
# File lib/dugway/store.rb, line 15 def account @account ||= get('/store.json') end
artist(permalink)
click to toggle source
# File lib/dugway/store.rb, line 65 def artist(permalink) lookup(permalink, artists) end
artist_products(permalink)
click to toggle source
# File lib/dugway/store.rb, line 69 def artist_products(permalink) lookup_products(permalink, 'artists') end
artists()
click to toggle source
# File lib/dugway/store.rb, line 61 def artists account.has_key?('artists') ? account['artists'] : [] end
categories()
click to toggle source
# File lib/dugway/store.rb, line 49 def categories account.has_key?('categories') ? account['categories'] : [] end
category(permalink)
click to toggle source
# File lib/dugway/store.rb, line 53 def category(permalink) lookup(permalink, categories) end
category_products(permalink)
click to toggle source
# File lib/dugway/store.rb, line 57 def category_products(permalink) lookup_products(permalink, 'categories') end
country()
click to toggle source
# File lib/dugway/store.rb, line 118 def country account['country'] end
currency()
click to toggle source
# File lib/dugway/store.rb, line 122 def currency account['currency'] end
custom_pages()
click to toggle source
# File lib/dugway/store.rb, line 30 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
locale()
click to toggle source
# File lib/dugway/store.rb, line 126 def locale currency['locale'] end
next_product(permalink)
click to toggle source
# File lib/dugway/store.rb, line 104 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)
click to toggle source
# File lib/dugway/store.rb, line 41 def page(permalink) if permalink != 'checkout' lookup(permalink, pages) else { 'name' => 'Checkout', 'permalink' => 'checkout', 'url' => '/checkout', 'category' => 'other' } end end
pages()
click to toggle source
# File lib/dugway/store.rb, line 37 def pages @pages ||= theme_pages + custom_pages end
previous_product(permalink)
click to toggle source
# File lib/dugway/store.rb, line 94 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
product(permalink)
click to toggle source
# File lib/dugway/store.rb, line 78 def product(permalink) lookup(permalink, products) end
product_and_option(option_id)
click to toggle source
# File lib/dugway/store.rb, line 82 def product_and_option(option_id) products.each do |product| product['options'].each do |option| if option['id'] == option_id return product, option end end end nil end
products()
click to toggle source
# File lib/dugway/store.rb, line 73 def products @products ||= get('/products.json') Marshal.load(Marshal.dump(@products)) # Hack to avoid data munging elsewhere? end
search_products(search_terms)
click to toggle source
# File lib/dugway/store.rb, line 114 def search_products(search_terms) products.select { |p| p['name'].downcase.include?(search_terms.downcase) || p['description'].downcase.include?(search_terms.downcase) } end
theme_pages()
click to toggle source
# 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' => 'Contact', 'permalink' => 'contact', 'url' => '/contact', 'category' => 'theme' }, { 'name' => 'Maintenance', 'permalink' => 'maintenance', 'url' => '/maintenance', 'category' => 'theme' } ] end
Private Instance Methods
get(path)
click to toggle source
# File lib/dugway/store.rb, line 132 def get(path) self.class.get(path).parsed_response end
lookup(permalink, array)
click to toggle source
# File lib/dugway/store.rb, line 136 def lookup(permalink, array) array.find { |item| item['permalink'] == permalink } end
lookup_products(permalink, type)
click to toggle source
# File lib/dugway/store.rb, line 140 def lookup_products(permalink, type) products.select { |p| p[type].any? { |c| c['permalink'] == permalink }} end