Class: Zanox::Shop

Inherits:
Item
  • Object
show all
Defined in:
lib/zanox/resources/shop.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hashable

#to_hash

Constructor Details

#initialize(data) ⇒ Shop

  • pid (Integer) Shop ID

  • name (String) The name of the product

  • rank (Float) The rank of the shop

  • description (HTML) The description of the shop

  • excerpt (String) A short description of the shop

  • products_count (Integer) The number of products in stock

  • regions (String[]) A collection of regions where the shop is located

  • categories (String[]) A collection of the main categories of products

  • url (String) The direct link to the shop

  • image (String) An image representing the shop

  • currency (String) The currency used inside the shop

  • terms (HTML) The terms applied by the shop

  • policies (String[]) A collection of the policies followed by the shop



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/zanox/resources/shop.rb', line 45

def initialize(data)
  @pid            = data['@id'].to_i
  @name           = data['name']
  @rank           = data['adrank'].to_f
  @description    = strip_cdata(data['descriptionLocal'])
  @excerpt        = data['description']
  @products_count = data['products'].to_i
  @regions        = [data['regions'].try { |r| r.map(&:values) }].flatten.compact
  @categories     = [].tap do |categories|
    [data['categories'].try { |p| p[0]['category'] }].flatten.each do |category|
      categories << {
        id:   category['@id'],
        name: category['$'],
      }
    end
  end
  @url            = data['url']
  @image          = data['image']
  @currency       = data['currency']
  @terms          = strip_cdata(data['terms'])
  @policies       = [].tap do |policies|
    [data['policies'].try { |p| p['policy'] }].flatten.each do |policy|
      policies << {
        id:   policy['@id'],
        name: policy['$'],
      } if policy
    end
  end
end

Instance Attribute Details

#availableObject (readonly)

Returns the value of attribute available.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def available
  @available
end

#categoriesObject (readonly)

Returns the value of attribute categories.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def categories
  @categories
end

#currencyObject (readonly)

Returns the value of attribute currency.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def currency
  @currency
end

#descriptionObject (readonly)

Returns the value of attribute description.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def description
  @description
end

#excerptObject (readonly)

Returns the value of attribute excerpt.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def excerpt
  @excerpt
end

#imageObject (readonly)

Returns the value of attribute image.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def image
  @image
end

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def name
  @name
end

#pidObject (readonly)

Returns the value of attribute pid.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def pid
  @pid
end

#policiesObject (readonly)

Returns the value of attribute policies.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def policies
  @policies
end

#products_countObject (readonly)

Returns the value of attribute products_count.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def products_count
  @products_count
end

#rankObject (readonly)

Returns the value of attribute rank.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def rank
  @rank
end

#regionsObject (readonly)

Returns the value of attribute regions.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def regions
  @regions
end

#termsObject (readonly)

Returns the value of attribute terms.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def terms
  @terms
end

#urlObject (readonly)

Returns the value of attribute url.



27
28
29
# File 'lib/zanox/resources/shop.rb', line 27

def url
  @url
end

Class Method Details

.confirmed_shopsObject

TODO: we could cache these results



92
93
94
# File 'lib/zanox/resources/shop.rb', line 92

def confirmed_shops
  confirmed_ids.map { |id| find(id) }.flatten
end

.find(param, args = {}) ⇒ Object



76
77
78
# File 'lib/zanox/resources/shop.rb', line 76

def find(param, args = {})
  param.is_a?(Numeric) ? find_by_id(param) : find_by_keyword(param)
end

.find_by_id(id, args = {}) ⇒ Object



80
81
82
83
# File 'lib/zanox/resources/shop.rb', line 80

def find_by_id(id, args = {})
  response = API.request("programs/program/#{id}", args)
  response.program_item.map { |program| new(program) }
end

.find_by_keyword(keyword, args = {}) ⇒ Object



85
86
87
88
89
# File 'lib/zanox/resources/shop.rb', line 85

def find_by_keyword(keyword, args = {})
  args.merge!({ q: keyword })
  response = API.request(:programs, args)
  response.program_items.map { |program| new(program) }
end