lucid_shopify 0.16.0 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/lib/lucid_shopify/config.rb +18 -1
- data/lib/lucid_shopify/request.rb +3 -3
- data/lib/lucid_shopify/response.rb +1 -1
- data/lib/lucid_shopify/send_request.rb +40 -4
- data/lib/lucid_shopify/version.rb +1 -1
- data/lib/lucid_shopify/webhook.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6f55b3ddbd880a63fa9b5afdd2d41ef31ba8a3e1d9cac38cda26c4247cac0f2
|
4
|
+
data.tar.gz: 40361daabb00f6bc9f8269cc97c06d68b748f2271d8d802f9eb763b89c3e9390
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11bb3dd84382f4d700ab0714d8b9c84c80222b2dac28870e68a26df97832a11c499d07c1a30f2c22b3c938b98893918cd7e5ee1f87fa83f7897a9019c27a6c15
|
7
|
+
data.tar.gz: bd289c3cdac7201be678821547363dadd135c16dd0b50696a248c326be68fba84f5432763e1a1dc375e52daa2d06feeae4a6759d2746b86d541e44fb5de42fda
|
data/README.md
CHANGED
@@ -129,6 +129,10 @@ charge:
|
|
129
129
|
client.get(credentials, 'orders', since_id: since_id)['orders']
|
130
130
|
client.post_json(credentials, 'orders', new_order)
|
131
131
|
|
132
|
+
Request logging is disabled by default. To enable it:
|
133
|
+
|
134
|
+
LucidShopify.config.logger = Logger.new(STDOUT)
|
135
|
+
|
132
136
|
|
133
137
|
### Make throttled API requests
|
134
138
|
|
data/lib/lucid_shopify/config.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'forwardable'
|
4
|
+
require 'logger'
|
4
5
|
|
5
6
|
require 'lucid_shopify'
|
6
7
|
|
@@ -11,7 +12,7 @@ module LucidShopify
|
|
11
12
|
extend Forwardable
|
12
13
|
|
13
14
|
# TODO: *Config.dry_initializer.attributes (version 2.0.0+)
|
14
|
-
def_delegators :config, :api_key, :shared_secret, :scope, :billing_callback_uri, :webhook_uri
|
15
|
+
def_delegators :config, :api_key, :shared_secret, :scope, :billing_callback_uri, :webhook_uri, :logger
|
15
16
|
|
16
17
|
# @param config [Config]
|
17
18
|
attr_writer :config
|
@@ -43,5 +44,21 @@ module LucidShopify
|
|
43
44
|
param :billing_callback_uri
|
44
45
|
# @return [String]
|
45
46
|
param :webhook_uri
|
47
|
+
|
48
|
+
#
|
49
|
+
# @return [Logger]
|
50
|
+
#
|
51
|
+
def logger
|
52
|
+
@logger ||= Logger.new(File::NULL)
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# @param new_logger [Logger]
|
57
|
+
#
|
58
|
+
def logger=(new_logger)
|
59
|
+
raise ArgumentError, 'not a Logger' unless new_logger.is_a?(Logger)
|
60
|
+
|
61
|
+
@logger = new_logger
|
62
|
+
end
|
46
63
|
end
|
47
64
|
end
|
@@ -16,12 +16,12 @@ module LucidShopify
|
|
16
16
|
# @return [String] the endpoint relative to the base URL
|
17
17
|
param :path, reader: :private
|
18
18
|
# @return [Hash]
|
19
|
-
param :options, default:
|
19
|
+
param :options, default: -> { {} }
|
20
20
|
|
21
21
|
# @return [Hash]
|
22
|
-
param :http_headers, default:
|
22
|
+
param :http_headers, default: -> { build_headers }
|
23
23
|
# @return [String]
|
24
|
-
param :url, default:
|
24
|
+
param :url, default: -> { build_url }
|
25
25
|
|
26
26
|
#
|
27
27
|
# @return [String]
|
@@ -32,19 +32,25 @@ module LucidShopify
|
|
32
32
|
# @raise [Response::ServerError] for status 5xx
|
33
33
|
#
|
34
34
|
def call(request, attempts: default_attempts)
|
35
|
-
|
36
|
-
|
35
|
+
req = request
|
36
|
+
|
37
|
+
log_request(req)
|
38
|
+
|
39
|
+
res = @strategy.(req) do
|
40
|
+
res = send(req)
|
37
41
|
|
38
|
-
Response.new(
|
42
|
+
Response.new(req, res.code, res.headers.to_h, res.to_s)
|
39
43
|
end
|
40
44
|
|
45
|
+
log_response(req, res)
|
46
|
+
|
41
47
|
res.assert!.data_hash
|
42
48
|
rescue HTTP::ConnectionError,
|
43
49
|
HTTP::ResponseError,
|
44
50
|
HTTP::TimeoutError => e
|
45
51
|
raise NetworkError.new(e), e.message if attempts.zero?
|
46
52
|
|
47
|
-
call(
|
53
|
+
call(req, attempts: attempts - 1)
|
48
54
|
end
|
49
55
|
|
50
56
|
#
|
@@ -58,6 +64,36 @@ module LucidShopify
|
|
58
64
|
@http.headers(req.http_headers).__send__(req.http_method, req.url, req.options)
|
59
65
|
end
|
60
66
|
|
67
|
+
#
|
68
|
+
# @param request [Request]
|
69
|
+
#
|
70
|
+
def log_request(request)
|
71
|
+
req = request
|
72
|
+
|
73
|
+
LucidShopify.config.logger.info('<%s> [%i] %s %s %s' % [
|
74
|
+
self.class.to_s,
|
75
|
+
req.object_id,
|
76
|
+
req.http_method.to_s.upcase,
|
77
|
+
req.url,
|
78
|
+
req.options[:params]&.to_json || '{}'
|
79
|
+
])
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# @param request [Request]
|
84
|
+
# @param response [Response]
|
85
|
+
#
|
86
|
+
def log_response(request, response)
|
87
|
+
req = request
|
88
|
+
res = response
|
89
|
+
|
90
|
+
LucidShopify.config.logger.info('<%s> [%i] %i' % [
|
91
|
+
self.class.to_s,
|
92
|
+
req.object_id,
|
93
|
+
res.status_code
|
94
|
+
])
|
95
|
+
end
|
96
|
+
|
61
97
|
#
|
62
98
|
# @return [Integer]
|
63
99
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lucid_shopify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelsey Judson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|