bigcommerce-oauth-api 1.2.1 → 1.3.0

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.
@@ -6,14 +6,19 @@ module BigcommerceOAuthAPI
6
6
  VALID_OPTIONS_KEYS = [
7
7
  :store_hash,
8
8
  :endpoint,
9
- :adapter,
10
9
  :client_id,
11
10
  :access_token,
12
11
  :format,
13
12
  :if_modified_since,
14
13
  # legacy authentication
15
14
  :user_name,
16
- :api_key
15
+ :api_key,
16
+ # connection / faraday
17
+ :adapter,
18
+ :timeout,
19
+ :open_timeout,
20
+ # library
21
+ :typecast_to_resource
17
22
  ].freeze
18
23
 
19
24
  DEFAULT_STORE_HASH = nil
@@ -23,8 +28,11 @@ module BigcommerceOAuthAPI
23
28
  DEFAULT_FORMAT = :json
24
29
  DEFAULT_ADAPTER = Faraday.default_adapter
25
30
  DEFAULT_IF_MODIFIED_SINCE = nil
31
+ DEFAULT_TYPECAST_TO_RESOURCE = true # if set to false then response-objects with be of type Hash.
26
32
  DEFAULT_USER_NAME = nil
27
33
  DEFAULT_API_KEY = nil
34
+ DEFAULT_TIMEOUT = 5
35
+ DEFAULT_OPEN_TIMEOUT = 2
28
36
 
29
37
  attr_accessor *VALID_OPTIONS_KEYS
30
38
 
@@ -40,8 +48,11 @@ module BigcommerceOAuthAPI
40
48
  self.access_token = DEFAULT_ACCESS_TOKEN
41
49
  self.adapter = DEFAULT_ADAPTER
42
50
  self.if_modified_since = DEFAULT_IF_MODIFIED_SINCE
51
+ self.typecast_to_resource = DEFAULT_TYPECAST_TO_RESOURCE
43
52
  self.user_name = DEFAULT_USER_NAME
44
53
  self.api_key = DEFAULT_API_KEY
54
+ self.timeout = DEFAULT_TIMEOUT
55
+ self.open_timeout = DEFAULT_OPEN_TIMEOUT
45
56
  end
46
57
 
47
58
  def configure
@@ -53,4 +64,4 @@ module BigcommerceOAuthAPI
53
64
  Hash[ * VALID_OPTIONS_KEYS.map { |key| [key, send(key)] }.flatten ]
54
65
  end
55
66
  end
56
- end
67
+ end
@@ -27,6 +27,9 @@ module BigcommerceOAuthAPI
27
27
  Faraday::Connection.new(options) do |connection|
28
28
  connection.request :json
29
29
  connection.use Faraday::Request::UrlEncoded
30
+ connection.options.timeout = timeout # open/read timeout in seconds
31
+ connection.options.open_timeout = open_timeout # connection open timeout in seconds
32
+
30
33
  if is_legacy?
31
34
  connection.use Faraday::Request::BasicAuthentication, user_name, api_key
32
35
  end
@@ -39,4 +42,4 @@ module BigcommerceOAuthAPI
39
42
  end
40
43
  end
41
44
  end
42
- end
45
+ end
@@ -50,6 +50,10 @@ module BigcommerceOAuthAPI
50
50
  # 507 HTTP
51
51
  class InsufficientStorage < Error; end
52
52
 
53
+ # 509 HTTP (deprecated)
54
+ # Returned to apps using Basic Authentication that have exceeded their rate limits.
55
+ class BandwidthLimitExceeded < Error; end
56
+
53
57
  # Raised if the client attempts to define an api method that already is defined elsewhere.
54
58
  # Specs will catch this type of error since it will be thrown upon initialization.
55
59
  class MethodAlreadyDefinedError < Error; end
@@ -57,4 +61,3 @@ module BigcommerceOAuthAPI
57
61
  # Raised if the client attempts to use a non-legacy api with a legacy configuration.
58
62
  class NonLegacyApi < Error; end
59
63
  end
60
-
@@ -32,13 +32,17 @@ module BigcommerceOAuthAPI
32
32
  end
33
33
  end
34
34
 
35
- if response.status == 204 || response.status == 304
36
- nil
37
- elsif response.body.is_a?(Array)
38
- response.body.map { |resource| Resource.new(resource) }
35
+ if typecast_to_resource
36
+ if response.status == 204 || response.status == 304
37
+ nil
38
+ elsif response.body.is_a?(Array)
39
+ response.body.map! { |resource| Resource.new(resource) }
40
+ else
41
+ Resource.new(response.body)
42
+ end
39
43
  else
40
- Resource.new(response.body)
44
+ response.body
41
45
  end
42
46
  end
43
47
  end
44
- end
48
+ end
@@ -31,9 +31,8 @@ module BigcommerceOAuthAPI
31
31
  end
32
32
 
33
33
  def method_missing(method_sym, *arguments)
34
- method_name = method_sym.to_s
35
- attribute_name = method_name.gsub(/(\?$)|(=$)/, '')
36
- if @attributes.include?(method_name.to_sym)
34
+ if @attributes.include?(method_sym)
35
+ attribute_name = method_sym.to_s.gsub(/(\?$)|(=$)/, '')
37
36
  self.instance_eval build_attribute_getter(attribute_name)
38
37
  send(method_sym, *arguments)
39
38
  else
@@ -65,4 +64,4 @@ module BigcommerceOAuthAPI
65
64
  var
66
65
  end
67
66
  end
68
- end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module BigcommerceOAuthAPI
2
- VERSION = '1.2.1'.freeze
3
- end
2
+ VERSION = '1.3.0'.freeze
3
+ end
@@ -20,6 +20,7 @@ module FaradayMiddleware
20
20
  when 502 then raise BigcommerceOAuthAPI::BadGateway, response[:body]
21
21
  when 503 then raise BigcommerceOAuthAPI::ServiceUnavailable, response[:body]
22
22
  when 507 then raise BigcommerceOAuthAPI::InsufficientStorage, response[:body]
23
+ when 509 then raise BigcommerceOAuthAPI::BandwidthLimitExceeded, response[:body]
23
24
  end
24
25
  end
25
26
  end
@@ -37,8 +37,11 @@ module BigcommerceOAuthAPI
37
37
  :adapter => 'e',
38
38
  :store_hash => 'f',
39
39
  :if_modified_since => 'i',
40
+ :typecast_to_resource => 'j',
40
41
  :user_name => 'g',
41
42
  :api_key => 'h',
43
+ :timeout => 'k',
44
+ :open_timeout => 'l'
42
45
  }
43
46
  end
44
47
 
@@ -112,4 +115,4 @@ module BigcommerceOAuthAPI
112
115
  end
113
116
  end
114
117
  end
115
- end
118
+ end
@@ -208,4 +208,4 @@ describe BigcommerceOAuthAPI::Client do
208
208
  end
209
209
  end
210
210
  end
211
- end
211
+ end
@@ -231,4 +231,4 @@ describe BigcommerceOAuthAPI::Client do
231
231
  end
232
232
  end
233
233
  end
234
- end
234
+ end
@@ -65,4 +65,4 @@ module BigcommerceOAuthAPI
65
65
  end
66
66
 
67
67
  end
68
- end
68
+ end
@@ -26,4 +26,4 @@ module BigcommerceOAuthAPI
26
26
  end
27
27
  end
28
28
  end
29
- end
29
+ end
@@ -69,4 +69,4 @@ describe BigcommerceOAuthAPI::Request do
69
69
  end
70
70
  end
71
71
  end
72
- end
72
+ end
@@ -40,4 +40,4 @@ module BigcommerceOAuthAPI
40
40
  end
41
41
  end
42
42
  end
43
- end
43
+ end
@@ -23,7 +23,8 @@ describe Faraday::Response do
23
23
  501 => BigcommerceOAuthAPI::NotImplemented,
24
24
  502 => BigcommerceOAuthAPI::BadGateway,
25
25
  503 => BigcommerceOAuthAPI::ServiceUnavailable,
26
- 507 => BigcommerceOAuthAPI::InsufficientStorage
26
+ 507 => BigcommerceOAuthAPI::InsufficientStorage,
27
+ 509 => BigcommerceOAuthAPI::BandwidthLimitExceeded
27
28
  }.each do |status, exception|
28
29
  context "when HTTP status is #{status}" do
29
30
  before do
@@ -62,4 +62,4 @@ end
62
62
 
63
63
  def a_delete(client, path)
64
64
  a_request(:delete, client_request_url(client, path))
65
- end
65
+ end
@@ -4,4 +4,4 @@ require 'bigcommerce-oauth-api/api'
4
4
  class DuplicateApiDefinitionClient < BigcommerceOAuthAPI::API
5
5
  with_api_methods :state => { api_module: :state, scope: :self, methods: [:all, :select]},
6
6
  :geography_state => { api_module: :state, scope: :self, methods: [:all, :select]}
7
- end
7
+ end
@@ -3,4 +3,4 @@ require 'bigcommerce-oauth-api/api'
3
3
 
4
4
  class MethodAlreadyDefinedClient < BigcommerceOAuthAPI::API
5
5
  with_api_methods :post => { api_module: :post, scope: :self, methods: [:select]}
6
- end
6
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigcommerce-oauth-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Orthmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-14 00:00:00.000000000 Z
11
+ date: 2015-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ~>
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: faraday
85
99
  requirement: !ruby/object:Gem::Requirement