huginn_bigcommerce_order_agent 1.2.0 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/client/order.rb +27 -7
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 195499f3e19f046ab4677c77b50cdc95ba33d63165421767cb33d319a2fb6def
4
- data.tar.gz: 7c0563eef15b00675f32058fa0fb8a6bff2fa2759fffebec710188f0889b81bb
3
+ metadata.gz: 06fd79e1a3fdeedd873c6ddb41a3ea16b1d694904a594d0db765af3e877255d8
4
+ data.tar.gz: 87d6429a9828866ac2d6e5502c2e88bd81f9c2dbb981f28eae89555f856e6fa3
5
5
  SHA512:
6
- metadata.gz: 8b4f70f7d4ed41d6770c53504bdb5616ab2df4a806552591fdce9570401b837cfa0f2b76862967590f3812527f619a4ce2c8d2d3c030ced56d9c46154ff7c62a
7
- data.tar.gz: 89b8c27736a5cbdfbc15f6fd444bfbbe9cb913d86e23e04c74ead07dd7a8cb80dda235b95d14a79d6682388d018990fd26bb93fd582fa713a5a8cf7f64c2dcff
6
+ metadata.gz: 5c9053f29d026783d5a24783d2ed49367d33a82d9efd6cb361ebff54a5dfa94e7397834f2cb6365e485b063c747b079f39596bdf799c6ff811a8ac589e278b0c
7
+ data.tar.gz: abb7aa29f262fc4b89b47d7121d9ea4d301e0b1eacf379d8458afd5224ae49c0c430486d3b8f8c2fb0a7048fd70428fd26b56f0c838c333496fc6e26bf2a7f04
data/lib/client/order.rb CHANGED
@@ -43,11 +43,27 @@ module BigcommerceOrderAgent
43
43
 
44
44
  #---------- Sub Record Queries ----------#
45
45
 
46
- # Returns the order's line items
47
- def get_products(order_id, params = {})
46
+ # Returns the order's line items.
47
+ # NOTE: BigCommerce silently paginates this resource. The dfault is 50 items per page,
48
+ # but orders with more than 50 items won't return anything to indicate that there are
49
+ # more items to fetch, so we effectively have to call this recursively until the API
50
+ # returns an empty array. Super fun.
51
+ def get_products(order_id, page_number = 1, page_size = 50)
48
52
  begin
49
- response = client.get(uri({ order_id: order_id }, 'products'), params)
50
- return response.body
53
+ response = client.get(uri({ order_id: order_id }, 'products'), { limit: page_size, page: page_number })
54
+ data = response.body
55
+
56
+ if (data.present? && data.length == page_size)
57
+ # If the number of items is the same as the max page size, check for another page
58
+ next_page = get_products(order_id, page_number + 1, page_size)
59
+ # If there are items on the next page, merge them into the current list
60
+ if (next_page.present? && next_page.length > 0)
61
+ data.concat(next_page)
62
+ end
63
+ end
64
+
65
+ # return the full list of items for the order
66
+ return data
51
67
  rescue Faraday::Error => e
52
68
  raise BigcommerceApiError.new(
53
69
  e.response[:status],
@@ -55,7 +71,9 @@ module BigcommerceOrderAgent
55
71
  "Failed to get order products #{order_id}",
56
72
  order_id,
57
73
  {
58
- errors: JSON.parse(e.response[:body])['errors']
74
+ errors: JSON.parse(e.response[:body])['errors'],
75
+ product_page_number: page_number,
76
+ page_size: page_size
59
77
  },
60
78
  e
61
79
  )
@@ -150,9 +168,11 @@ module BigcommerceOrderAgent
150
168
  # Returns the region (state) code for the provided address
151
169
  def get_region_code(address)
152
170
  country = Country.named(address['country'])
153
- state = country.subregions.named(address['state'])
171
+ state = country.nil? ? nil : country.subregions.named(address['state'])
154
172
 
155
- return state.code
173
+ # For cases where a matching state is not found, default to the `state`
174
+ # value on the address. (This is not uncommon for international addresses)
175
+ return state.nil? ? address['state'] : state.code
156
176
  end
157
177
  end
158
178
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: huginn_bigcommerce_order_agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - 5 Stones
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-17 00:00:00.000000000 Z
11
+ date: 2022-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler