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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa7a124e765e51f59294a364b97b006e5898b96cf2613745c66ac35051ec46ab
4
- data.tar.gz: deb41acf5b31b21a7eee70bf644b8daff3badf6e716653076df2760940545145
3
+ metadata.gz: f6f55b3ddbd880a63fa9b5afdd2d41ef31ba8a3e1d9cac38cda26c4247cac0f2
4
+ data.tar.gz: 40361daabb00f6bc9f8269cc97c06d68b748f2271d8d802f9eb763b89c3e9390
5
5
  SHA512:
6
- metadata.gz: d86eb37763f25cdbc7fd686a9bd0fe31e5139db86d33a87a11cf27bd8ce05c7617f3b02a978a4f4194f67f6fad44f86ee299ad69e25cea2ca2843980a5761183
7
- data.tar.gz: bfd6ace749c04766bd6270350fdcce7ac4593f0881c561091ce2b70fca3caeae25a78bc41efb0b7cf12b19033ccbbcd2cf834da8e99dd9d249fa356ed857b56d
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
 
@@ -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: proc { {} }
19
+ param :options, default: -> { {} }
20
20
 
21
21
  # @return [Hash]
22
- param :http_headers, default: proc { build_headers }
22
+ param :http_headers, default: -> { build_headers }
23
23
  # @return [String]
24
- param :url, default: proc { build_url }
24
+ param :url, default: -> { build_url }
25
25
 
26
26
  #
27
27
  # @return [String]
@@ -39,7 +39,7 @@ module LucidShopify
39
39
  # @return [String]
40
40
  param :data
41
41
  # @return [Hash] the parsed response body
42
- param :data_hash, default: proc { parse_data }
42
+ param :data_hash, default: -> { parse_data }
43
43
 
44
44
  #
45
45
  # @return [Hash]
@@ -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
- res = @strategy.(request) do
36
- res = send(request)
35
+ req = request
36
+
37
+ log_request(req)
38
+
39
+ res = @strategy.(req) do
40
+ res = send(req)
37
41
 
38
- Response.new(request, res.code, res.headers.to_h, res.to_s)
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(request, attempts: attempts - 1)
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
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucidShopify
4
- VERSION = '0.16.0'
4
+ VERSION = '0.17.0'
5
5
  end
@@ -15,7 +15,7 @@ module LucidShopify
15
15
  # @return [String]
16
16
  param :data
17
17
  # @return [Hash] the parsed request body
18
- param :data_hash, default: proc { parse_data }
18
+ param :data_hash, default: -> { parse_data }
19
19
 
20
20
  #
21
21
  # @return [Hash]
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.16.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-10-23 00:00:00.000000000 Z
11
+ date: 2018-11-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dotenv