shopify_api_bruv 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38efd46bd4364767f9f3ab83f500fc9a7dd4361e80023eaf2587fd66d5dff380
|
4
|
+
data.tar.gz: a2f7d1f2e9a218dff3b96e123040ba8e06333f828b74a25b46decf27d791c025
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56d43835d001e36aea5beec0d02f5d3c9f0ecb47808167a0b48a2050905e1bd187cb0532b9e84d239d769e035f7254a599cdf18b802be3abca930abb90c40666
|
7
|
+
data.tar.gz: 06076ae61c40e87ec4802f89ebe8c9196c347e5c5d4f3ce3a6dface969badf10aa489ebf579f69da1bfb6db987d666f1d50019d0efc361bfff9a534b1c2d16be
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.2.2] - 2023-12-09
|
4
|
+
|
5
|
+
- Adds page info to http response
|
6
|
+
|
7
|
+
## [0.2.1] - 2023-12-09
|
8
|
+
|
9
|
+
- Adds feature to automatically fetch the mutation object name to pre-select data
|
10
|
+
|
3
11
|
## [0.2.0] - 2023-12-09
|
4
12
|
|
5
13
|
- Merges [PR #1](https://github.com/Idjent/shopify_api_bruv/pull/1) Fixes resource not being re-usable for mutations
|
data/Gemfile.lock
CHANGED
@@ -3,12 +3,13 @@
|
|
3
3
|
module ShopifyApiBruv
|
4
4
|
module Clients
|
5
5
|
class HttpResponse
|
6
|
-
attr_reader :code, :headers, :body
|
6
|
+
attr_reader :code, :headers, :body, :page_info
|
7
7
|
|
8
8
|
def initialize(code:, headers:, body:)
|
9
9
|
@code = code
|
10
10
|
@headers = headers
|
11
11
|
@body = body
|
12
|
+
@page_info = parse_page_info
|
12
13
|
|
13
14
|
ShopifyApiBruv.logger(
|
14
15
|
method: :info,
|
@@ -20,6 +21,26 @@ module ShopifyApiBruv
|
|
20
21
|
|
21
22
|
private
|
22
23
|
|
24
|
+
def parse_page_info
|
25
|
+
return { previous: nil, next: nil } if headers['link'].nil?
|
26
|
+
|
27
|
+
page_info = {}
|
28
|
+
|
29
|
+
headers['link'].split(',').each do |link|
|
30
|
+
rel = link.match(/rel="(.*?)"/).captures.first
|
31
|
+
url = link.match(/<(.*?)>/).captures.first
|
32
|
+
|
33
|
+
URI.parse(url).query.split('&').each do |param|
|
34
|
+
if param.split('=').first == 'page_info'
|
35
|
+
page_info[rel] = param.split('=').last
|
36
|
+
break
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
{ previous: page_info['previous'], next: page_info['next'] }
|
42
|
+
end
|
43
|
+
|
23
44
|
def ok?
|
24
45
|
(200..299).cover?(code)
|
25
46
|
end
|
@@ -9,26 +9,28 @@ module ShopifyApiBruv
|
|
9
9
|
|
10
10
|
MAX_TRIES = ENV.fetch('SHOPIFY_API_BRUV_REQUEST_MAX_TRIES', 3).to_i
|
11
11
|
SLEEP_TIMER = ENV.fetch('SHOPIFY_API_BRUV_REQUEST_SLEEP_TIMER', 4).to_i
|
12
|
+
MUTATION_OBJECT_NAME_PATTERN = /mutation\s+(\w+)\s*\(.*/
|
12
13
|
|
13
14
|
def initialize(config:)
|
14
15
|
@client = Clients::Graphql::Client.new(config:)
|
15
16
|
end
|
16
17
|
|
17
|
-
def request(variables: nil,
|
18
|
+
def request(variables: nil, tries: 0)
|
18
19
|
raise NotImplementedError, 'Please set a query in the derived class' if query.nil?
|
19
20
|
|
20
21
|
response = client.request(query:, variables:)
|
21
22
|
|
22
|
-
handle_response(response:, query:, variables:,
|
23
|
+
handle_response(response:, query:, variables:, tries:)
|
23
24
|
end
|
24
25
|
|
25
26
|
private
|
26
27
|
|
27
|
-
def handle_response(response:, query:, variables:,
|
28
|
+
def handle_response(response:, query:, variables:, tries:)
|
28
29
|
body = response.body
|
29
30
|
|
30
31
|
handle_response_errors(body:, query:, variables:, tries:)
|
31
32
|
|
33
|
+
mutation_object_name = query.match(MUTATION_OBJECT_NAME_PATTERN)&.captures&.first
|
32
34
|
mutation_object_name.nil? ? body['data'] : body.dig('data', mutation_object_name)
|
33
35
|
end
|
34
36
|
|