Class: Futureshop::Inventory
- Inherits:
-
Object
- Object
- Futureshop::Inventory
- Defined in:
- lib/futureshop/inventory.rb
Class Method Summary collapse
- .all(**args) ⇒ Object
- .each(**args) ⇒ Object
- .each_batch(types: [:regular], create_date_start: nil, create_date_end: nil, product_no: [], jan_code: []) {|| ... } ⇒ Object
Class Method Details
.all(**args) ⇒ Object
35 36 37 |
# File 'lib/futureshop/inventory.rb', line 35 def all(**args) return each.to_a end |
.each(**args) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/futureshop/inventory.rb', line 25 def each(**args) return enum_for(__method__, **args) unless block_given? each_batch **args do |inventories| inventories.each do |inventory| yield inventory end end end |
.each_batch(types: [:regular], create_date_start: nil, create_date_end: nil, product_no: [], jan_code: []) {|| ... } ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/futureshop/inventory.rb', line 4 def each_batch(types: [:regular], create_date_start: nil, create_date_end: nil, product_no: [], jan_code: []) params = { types: types, product_no: product_no, jan_code: jan_code } params[:create_date_start] = create_date_start.strftime("%FT%T") if create_date_start params[:create_date_end] = create_date_end.strftime("%FT%T") if create_date_end res = client.get("/admin-api/v1/inventory", params: params) yield res["productList"] next_url = res["nextUrl"] while next_url sleep Client::INTERVAL url = URI.parse(next_url) res = client.request_by_uri(:get, url) yield res["productList"] next_url = res["nextUrl"] end end |