bigcommerce-oauth-api 1.2.0 → 1.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdf5b9ddfbfad7c95f914d01e772122c59363ebf
4
- data.tar.gz: 53309df2bcfad86dcb8f1ecafc88e22499314f89
3
+ metadata.gz: 8f37e6586189acbb81bc21f656d3f1b5a8e3e749
4
+ data.tar.gz: 53fff46f665e6862d78893f1f693087194389cdc
5
5
  SHA512:
6
- metadata.gz: 80a2d871dd59031976c08e65572705e583a0d552ebf02de3467f7fe333fe216904488ede52b947ee3760a2a5c592d031300e01e46c4b6ac0bf8882cb88e31986
7
- data.tar.gz: e5c66453f20d4ec5fc7e1a0cdb3ab675976d264ffd9c5b14b8e2ba69a2e9d757866b4d0bbf1804f2f747c0e7ded23b345edea319a1c9c00e5d7ad1d3ac13eacd
6
+ metadata.gz: 4154e91d65cc889f90a1bcbf757f54c61eb7e1e176dc2423808ec7a06cc43eb9223cdc237d3294714923e1e415c31d7a65fae2abbf48f170f2aa8fcf7f963f27
7
+ data.tar.gz: ed15ab36620add81872f55736405e0abaa5981ea15e6f5ff411cad34b335d9d056fc6e85fd52881240fa869cfda5a7bf0636335d9d80b88e7722a38e8332ccfa
@@ -1,3 +1,13 @@
1
+ ### 1.2.1 (2015-05-14)
2
+
3
+ Features:
4
+
5
+ - added support for 'If-Modified-Since' requests.
6
+
7
+ Bugfixes:
8
+
9
+ - PUT/POST as json with content-type headers.
10
+
1
11
  ### 1.2.0 (2015-04-19)
2
12
 
3
13
  Features:
data/README.md CHANGED
@@ -52,6 +52,8 @@ api = BigcommerceOAuthAPI::Client.new(
52
52
  )
53
53
  ```
54
54
 
55
+ Starting from v1.2.1 `bigcommerce-oauth-api` supports the `If-Modified-Since` header described on https://developer.bigcommerce.com/api/req-headers. As all other configurations, the header can be set with both module and instance configuration using the key `if_modified_since`.
56
+
55
57
  Using the API
56
58
  -------------
57
59
  It is recommended to use the Omniref documentation as a method reference in combination the official api documentation.
@@ -3,7 +3,7 @@ require File.expand_path('../lib/bigcommerce-oauth-api/version', __FILE__)
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'bigcommerce-oauth-api'
5
5
  s.version = BigcommerceOAuthAPI::VERSION.dup
6
- s.date = '2015-04-19'
6
+ s.date = '2015-05-14'
7
7
  s.summary = "Ruby client library for Bigcommerce APIs with OAuth and basic authentication support"
8
8
  s.description = "Connect Ruby applications to Bigcommerce APIs through OAuth or basic authentication"
9
9
  s.authors = ["Christian Orthmann"]
@@ -10,6 +10,7 @@ module BigcommerceOAuthAPI
10
10
  :client_id,
11
11
  :access_token,
12
12
  :format,
13
+ :if_modified_since,
13
14
  # legacy authentication
14
15
  :user_name,
15
16
  :api_key
@@ -21,6 +22,7 @@ module BigcommerceOAuthAPI
21
22
  DEFAULT_ACCESS_TOKEN = nil
22
23
  DEFAULT_FORMAT = :json
23
24
  DEFAULT_ADAPTER = Faraday.default_adapter
25
+ DEFAULT_IF_MODIFIED_SINCE = nil
24
26
  DEFAULT_USER_NAME = nil
25
27
  DEFAULT_API_KEY = nil
26
28
 
@@ -37,6 +39,7 @@ module BigcommerceOAuthAPI
37
39
  self.client_id = DEFAULT_CLIENT_ID
38
40
  self.access_token = DEFAULT_ACCESS_TOKEN
39
41
  self.adapter = DEFAULT_ADAPTER
42
+ self.if_modified_since = DEFAULT_IF_MODIFIED_SINCE
40
43
  self.user_name = DEFAULT_USER_NAME
41
44
  self.api_key = DEFAULT_API_KEY
42
45
  end
@@ -11,6 +11,11 @@ module BigcommerceOAuthAPI
11
11
  'Accept' => "application/#{format}; charset=utf-8"
12
12
  }
13
13
  }
14
+
15
+ if !if_modified_since.nil?
16
+ options[:headers]['If-Modified-Since'] = if_modified_since.to_s
17
+ end
18
+
14
19
  if is_legacy?
15
20
  options[:url] = "#{endpoint}/api/v2/"
16
21
  else
@@ -20,13 +25,14 @@ module BigcommerceOAuthAPI
20
25
  end
21
26
 
22
27
  Faraday::Connection.new(options) do |connection|
28
+ connection.request :json
23
29
  connection.use Faraday::Request::UrlEncoded
24
30
  if is_legacy?
25
31
  connection.use Faraday::Request::BasicAuthentication, user_name, api_key
26
32
  end
27
33
 
28
34
  case format.to_s.downcase
29
- when 'json' then connection.use Faraday::Response::ParseJson
35
+ when 'json' then connection.response :json, :content_type => /\bjson$/
30
36
  end
31
37
  connection.use FaradayMiddleware::RaiseHttpException
32
38
  connection.adapter(adapter)
@@ -24,14 +24,15 @@ module BigcommerceOAuthAPI
24
24
  def request(method, path, options)
25
25
  response = connection.send(method) do |request|
26
26
  case method
27
- when :get, :delete
28
- request.url(path, options)
29
- when :post, :put
30
- request.path = path
31
- request.body = options if !options.empty?
27
+ when :get, :delete
28
+ request.url(path, options)
29
+ when :post, :put
30
+ request.path = path
31
+ request.body = options if !options.empty?
32
32
  end
33
33
  end
34
- if response.status == 204
34
+
35
+ if response.status == 204 || response.status == 304
35
36
  nil
36
37
  elsif response.body.is_a?(Array)
37
38
  response.body.map { |resource| Resource.new(resource) }
@@ -1,3 +1,3 @@
1
1
  module BigcommerceOAuthAPI
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.2.1'.freeze
3
3
  end
@@ -36,6 +36,7 @@ module BigcommerceOAuthAPI
36
36
  :access_token => 'd',
37
37
  :adapter => 'e',
38
38
  :store_hash => 'f',
39
+ :if_modified_since => 'i',
39
40
  :user_name => 'g',
40
41
  :api_key => 'h',
41
42
  }
@@ -17,7 +17,8 @@ describe BigcommerceOAuthAPI::Request do
17
17
  path = '/awesome/1/path/1'
18
18
  options = { foo: 'bar', bar: { oof: 'rab' } }
19
19
  url = @client.send(:connection).build_url(path).to_s
20
- stub_request(:get, url).to_return(:status => 200, :body => options.to_json, :headers => {})
20
+ stub_request(:get, url).to_return(:status => 200, :body => options.to_json, :headers => {
21
+ content_type: 'application/json' })
21
22
 
22
23
  expect(@client.get(path, {})).to eql(BigcommerceOAuthAPI::Resource.new(options))
23
24
  expect(a_request(:get, url).
@@ -26,11 +27,25 @@ describe BigcommerceOAuthAPI::Request do
26
27
  end
27
28
  end
28
29
 
30
+ context 'given a request that returns an array' do
31
+ it 'should parse the response and into an array of resource objects' do
32
+ path = '/awesome/1/path/1'
33
+ options = [{ foo: 'bar', bar: { oof: 'rab' } }, { bar: 'bar', bar: { rab: 'rab' } }]
34
+ url = @client.send(:connection).build_url(path).to_s
35
+ stub_request(:get, url).to_return(:status => 200, :body => options.to_json, :headers => {
36
+ content_type: 'application/json' })
37
+ expect(@client.get(path, {})).to eql(options.map { |entry| BigcommerceOAuthAPI::Resource.new(entry) } )
38
+ expect(a_request(:get, url).
39
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
40
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
41
+ end
42
+ end
43
+
29
44
  context 'given a request that returns no content' do
30
45
  it 'returns nil' do
31
46
  path = '/awesome/1/path/1'
32
47
  url = @client.send(:connection).build_url(path).to_s
33
- stub_request(:get, url).to_return(:status => 204, :body => '', :headers => {})
48
+ stub_request(:get, url).to_return(:status => 204, :body => '', :headers => { content_type: 'application/json' })
34
49
 
35
50
  expect(@client.get(path, {})).to eql(nil)
36
51
  expect(a_request(:get, url).
@@ -40,5 +55,18 @@ describe BigcommerceOAuthAPI::Request do
40
55
  end
41
56
  end
42
57
 
58
+ context 'given a request that returns not modified' do
59
+ it 'returns nil' do
60
+ path = '/awesome/1/path/1'
61
+ url = @client.send(:connection).build_url(path).to_s
62
+ stub_request(:get, url).to_return(:status => 304, :body => '', :headers => { content_type: 'application/json' })
63
+
64
+ expect(@client.get(path, {})).to be_nil
65
+ expect(a_request(:get, url).
66
+ with(:headers => {'X-Auth-Client' => 'SECRET_ID',
67
+ 'X-Auth-Token' => 'SECRET_TOKEN'})).to have_been_made
68
+
69
+ end
70
+ end
43
71
  end
44
72
  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.0
4
+ version: 1.2.1
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-04-19 00:00:00.000000000 Z
11
+ date: 2015-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake