Class: Economic::ProductRepo

Inherits:
BaseRepo show all
Defined in:
lib/economic/product_repo.rb

Direct Known Subclasses

PricingRepo

Constant Summary

Constants inherited from BaseRepo

BaseRepo::URL

Class Method Summary collapse

Methods inherited from BaseRepo

all, destroy, endpoint_url, filter, find, id_to_url_formatted_id, save, send_request, updated_after

Class Method Details

.in_group(product_group_or_product_group_number) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/economic/product_repo.rb', line 3

def self.in_group(product_group_or_product_group_number)
  id = product_group_or_product_group_number.product_group_number if product_group_or_product_group_number.respond_to? :product_group_number
  id ||= product_group_or_product_group_number

  end_point = [ProductGroupRepo.endpoint_url, id, "products"].join("/")
  response = send_request(method: :get, url: end_point)
  entry_hash = JSON.parse(response.body)
  products = []

  entry_hash["collection"].each do |product|
    products.push Product.new(product)
  end
  products
end