plenty_client 0.1.1 → 0.1.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: 468471d1063a081184202e28692e3b8f6f2a8f99011cbcd52ad11dcc57a2dff3
4
- data.tar.gz: 8b3dfd65b46808a089ec788576d9d1d0db196148d032d6c977e3f53d27f03ffb
3
+ metadata.gz: 3b1ce1f9899a6d120944ae078627fe676c3af95c773c3aa2c0a9d347a4727b33
4
+ data.tar.gz: c96480546c1ce74d997439685960918f9ceed35d2ad78fa403b105d3be0dfa99
5
5
  SHA512:
6
- metadata.gz: 40c8107ab4b4e6d46f5fff6bcaa008e7c587f875955e8cd42977d8e8f313d833791a57d48f4dcf0c04d509eabebed3221ce9acdb0cffd52804a7fab31118f6ce
7
- data.tar.gz: d13f2f3ac98937ade8439d9fac70374869c831f4675cbc1b51cd86b98edfe90c8e20e9c158199be84207a4963dede77cb39efb16abf968ec29b9fe4afb567941
6
+ metadata.gz: 63da84709428e75cc89b05079e5fcc81e8b083f5be250fe62c398232e4e073fb73b14f6c5cf122a1ebb7a5e2d8b61bedda96d53c6bd9e5b7a962e6e16951806e
7
+ data.tar.gz: f2bdee10c09c20eae6b332045b327db9fe22632931f5c6340396f7f956d889cdedcb6a6c49cff03c93b203b98eb6de3f41341008d3b6644e388d80365d7494bb
@@ -1,8 +1,11 @@
1
1
  require 'json'
2
2
 
3
3
  module PlentyClient
4
- class ResponseError < StandardError; end
5
- class AttemptsExceeded < StandardError; end
4
+ class ConnectionError < StandardError; end
5
+ class ClientError < ConnectionError; end
6
+ class RedirectionError < ConnectionError; end
7
+ class ServerError < ConnectionError; end
8
+ class ResponseError < ConnectionError; end
6
9
  class NotFound < ResponseError; end
7
10
 
8
11
  autoload :Config, 'plenty_client/config'
@@ -21,12 +21,12 @@ module PlentyClient
21
21
  get(build_endpoint(DOWNLOAD_ORDER_DOCUMENTS_BY_TYPE, type_string: type_string), headers, &block)
22
22
  end
23
23
 
24
- def list(order_id, type_sting = nil, headers = {}, &block)
25
- get(build_endpoint(LIST_ORDER_DOCUMENTS, order: order_id, type_sting: type_sting), headers, &block)
24
+ def list(order_id, type_string = nil, headers = {}, &block)
25
+ get(build_endpoint(LIST_ORDER_DOCUMENTS, order: order_id, type_string: type_string), headers, &block)
26
26
  end
27
27
 
28
- def list_by_type(order_id, type_sting = nil, headers = {}, &block)
29
- get(build_endpoint(LIST_ORDER_DOCUMENTS_BY_TYPE, order: order_id, type_sting: type_sting), headers, &block)
28
+ def list_by_type(type_string = nil, headers = {}, &block)
29
+ get(build_endpoint(LIST_ORDER_DOCUMENTS_BY_TYPE, type_string: type_string), headers, &block)
30
30
  end
31
31
 
32
32
  def upload(order_id, type_string, body = {})
@@ -5,22 +5,16 @@ module PlentyClient
5
5
  module Request
6
6
  module ClassMethods
7
7
  def request(http_method, path, params = {})
8
- return false if http_method.nil? || path.nil?
9
- return false unless %w[post put patch delete get].include?(http_method.to_s)
8
+ raise ArgumentError, "http_method or path is missing" if http_method.nil? || path.nil?
9
+ unless %w[post put patch delete get].include?(http_method.to_s)
10
+ raise ArgumentError, "unsupported http_method: #{http_method}"
11
+ end
10
12
 
11
13
  login_check unless PlentyClient::Config.tokens_valid?
12
14
 
13
15
  params = stringify_symbol_keys(params) if params.is_a?(Hash)
14
16
 
15
- attempts = PlentyClient::Config.attempt_count
16
- attempts.times do
17
- begin
18
- response = perform(http_method, path, params)
19
- return response if response
20
- rescue Faraday::ConnectionFailed => e
21
- end
22
- end
23
- raise PlentyClient::AttemptsExceeded, "unable to get valid response after #{attempts} attempts"
17
+ perform(http_method, path, params)
24
18
  end
25
19
 
26
20
  def post(path, body = {})
@@ -84,11 +78,13 @@ module PlentyClient
84
78
  logger.filter(/password=([^&]+)/, 'password=[FILTERED]')
85
79
  end
86
80
  end
81
+ faraday.request :retry, max: PlentyClient::Config.attempt_count
87
82
  end
88
83
  conn.adapter :typhoeus
89
84
  verb = http_method.to_s.downcase
90
85
  params = params.to_json unless %w[get delete].include?(verb)
91
86
  response = conn.send(verb, base_url(path), params)
87
+ assert_success_status_code(response)
92
88
  parse_body(response)
93
89
  end
94
90
 
@@ -119,6 +115,7 @@ module PlentyClient
119
115
  end
120
116
 
121
117
  def parse_body(response)
118
+ return nil if response.body.strip == ""
122
119
  content_type = response.env.response_headers['Content-Type']
123
120
  case content_type
124
121
  when %r{(?:application|text)/json}
@@ -129,6 +126,8 @@ module PlentyClient
129
126
  json
130
127
  when %r{application/pdf}
131
128
  response.body
129
+ else
130
+ raise PlentyClient::ResponseError, "unsupported response Content-Type: #{content_type}"
132
131
  end
133
132
  rescue JSON::ParserError
134
133
  raise PlentyClient::ResponseError, 'invalid response'
@@ -156,6 +155,17 @@ module PlentyClient
156
155
  response.dig('error', 'message')
157
156
  end
158
157
  end
158
+
159
+ def assert_success_status_code(response)
160
+ case response.status
161
+ when 300..399
162
+ raise RedirectionError, "Invalid response: HTTP status: #{response.status}"
163
+ when 400..499
164
+ raise ClientError, "Invalid response: HTTP status: #{response.status}"
165
+ when 500..599
166
+ raise ServerError, "Invalid response: HTTP status: #{response.status}"
167
+ end
168
+ end
159
169
  end
160
170
 
161
171
  def self.included(base)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PlentyClient
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'
5
5
  end
@@ -20,14 +20,15 @@ Gem::Specification.new do |spec|
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ['lib']
22
22
 
23
- spec.add_development_dependency 'bundler', '~> 1.13'
24
- spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'rake', '~> 12.0'
25
25
  spec.add_development_dependency 'rspec', '~> 3.0'
26
26
  spec.add_development_dependency 'webmock', '~> 3.0'
27
27
  spec.add_development_dependency 'guard-rspec', '~> 4.7'
28
28
  spec.add_development_dependency 'pry', '~> 0.11'
29
+ spec.add_development_dependency 'byebug'
29
30
 
30
- spec.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.0'
31
- spec.add_runtime_dependency 'faraday', '~> 0.9'
32
- spec.add_runtime_dependency 'typhoeus', '~> 1.3', '>= 1.3.0'
31
+ spec.add_runtime_dependency 'json', '>= 1.8.0'
32
+ spec.add_runtime_dependency 'faraday', '>= 0.9'
33
+ spec.add_runtime_dependency 'typhoeus', '>= 1.3.0'
33
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plenty_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dariusch Ochlast
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-26 00:00:00.000000000 Z
11
+ date: 2019-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.13'
19
+ version: '1.16'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.13'
26
+ version: '1.16'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '12.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '12.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -95,12 +95,23 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0.11'
97
97
  - !ruby/object:Gem::Dependency
98
- name: json
98
+ name: byebug
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '1.8'
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: json
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
104
115
  - - ">="
105
116
  - !ruby/object:Gem::Version
106
117
  version: 1.8.0
@@ -108,9 +119,6 @@ dependencies:
108
119
  prerelease: false
109
120
  version_requirements: !ruby/object:Gem::Requirement
110
121
  requirements:
111
- - - "~>"
112
- - !ruby/object:Gem::Version
113
- version: '1.8'
114
122
  - - ">="
115
123
  - !ruby/object:Gem::Version
116
124
  version: 1.8.0
@@ -118,23 +126,20 @@ dependencies:
118
126
  name: faraday
119
127
  requirement: !ruby/object:Gem::Requirement
120
128
  requirements:
121
- - - "~>"
129
+ - - ">="
122
130
  - !ruby/object:Gem::Version
123
131
  version: '0.9'
124
132
  type: :runtime
125
133
  prerelease: false
126
134
  version_requirements: !ruby/object:Gem::Requirement
127
135
  requirements:
128
- - - "~>"
136
+ - - ">="
129
137
  - !ruby/object:Gem::Version
130
138
  version: '0.9'
131
139
  - !ruby/object:Gem::Dependency
132
140
  name: typhoeus
133
141
  requirement: !ruby/object:Gem::Requirement
134
142
  requirements:
135
- - - "~>"
136
- - !ruby/object:Gem::Version
137
- version: '1.3'
138
143
  - - ">="
139
144
  - !ruby/object:Gem::Version
140
145
  version: 1.3.0
@@ -142,9 +147,6 @@ dependencies:
142
147
  prerelease: false
143
148
  version_requirements: !ruby/object:Gem::Requirement
144
149
  requirements:
145
- - - "~>"
146
- - !ruby/object:Gem::Version
147
- version: '1.3'
148
150
  - - ">="
149
151
  - !ruby/object:Gem::Version
150
152
  version: 1.3.0
@@ -317,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
317
319
  version: '0'
318
320
  requirements: []
319
321
  rubyforge_project:
320
- rubygems_version: 2.7.3
322
+ rubygems_version: 2.7.7
321
323
  signing_key:
322
324
  specification_version: 4
323
325
  summary: This the first draft of a PlentyMarkets Rest Client for Ruby.