base-api-client 0.3.1.beta → 0.3.2.beta
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 +4 -4
- data/Gemfile +1 -0
- data/README.md +15 -13
- data/base-api-client.gemspec +3 -1
- data/config/client_secret.json +6 -6
- data/lib/base/api_client/client_secret.rb +13 -12
- data/lib/base/apis.rb +1 -0
- data/lib/base/apis/category.rb +7 -3
- data/lib/base/apis/delivery_company.rb +7 -3
- data/lib/base/apis/item.rb +7 -8
- data/lib/base/apis/item_category.rb +7 -3
- data/lib/base/apis/order.rb +7 -8
- data/lib/base/apis/saving.rb +7 -8
- data/lib/base/apis/search.rb +12 -19
- data/lib/base/apis/user.rb +7 -3
- data/lib/base/http.rb +4 -16
- data/spec/base/api_client/client_secret_spec.rb +65 -45
- data/spec/base/apis/category_spec.rb +2 -2
- data/spec/base/apis/delivery_company_spec.rb +2 -2
- data/spec/base/apis/{item_category.rb → item_category_spec.rb} +2 -2
- data/spec/base/apis/item_spec.rb +2 -2
- data/spec/base/apis/order_spec.rb +2 -2
- data/spec/base/apis/saving_spec.rb +2 -2
- data/spec/base/apis/search_spec.rb +38 -58
- data/spec/base/apis/user_spec.rb +2 -2
- data/spec/base/http_spec.rb +4 -52
- data/spec/fixtures/vcr_cassettes/category/index.yml +19 -21
- data/spec/fixtures/vcr_cassettes/client_secret/fetch_token_authorization_code.yml +40 -0
- data/spec/fixtures/vcr_cassettes/client_secret/fetch_token_refresh_token.yml +40 -0
- data/spec/fixtures/vcr_cassettes/delivery_company/index.yml +17 -19
- data/spec/fixtures/vcr_cassettes/item/index.yml +48 -12
- data/spec/fixtures/vcr_cassettes/item_category/detail.yml +19 -21
- data/spec/fixtures/vcr_cassettes/order/index.yml +17 -19
- data/spec/fixtures/vcr_cassettes/saving/index.yml +17 -19
- data/spec/fixtures/vcr_cassettes/search/request.yml +60 -67
- data/spec/fixtures/vcr_cassettes/user/me.yml +46 -9
- data/spec/spec_helper.rb +4 -2
- metadata +29 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2645f10be0a5d4ef6bd86d253f9a09463f0b4925
|
4
|
+
data.tar.gz: 70f3813b76248c2b5aa2b69a26e2ca39dc536963
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae41d730e14c568b63212cbed8711c832b7961dec8f5223aa8191ba46644da4b31322073e48c739b7d162ae58a3b98f620e9fd739d858d7ca999b14e18956172
|
7
|
+
data.tar.gz: beaf9d57274458b18470b9c5650fe99332099bfaadd76b534c3a561efbec03eea290fb11c11335925eea4cead58195ef2860ae24a88e4eb147259d7d2a24c1b1
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -58,42 +58,44 @@ client_secret.set_tokens!
|
|
58
58
|
|
59
59
|
### Retrieve my shop information
|
60
60
|
```ruby
|
61
|
-
client_secret
|
61
|
+
user = Base::Apis::User.new(client_secret)
|
62
|
+
user.me
|
62
63
|
```
|
63
64
|
|
64
65
|
### Retrieve my items
|
65
66
|
```ruby
|
66
|
-
client_secret
|
67
|
+
item = Base::Apis::Item.new(client_secret)
|
68
|
+
item.index
|
67
69
|
```
|
68
70
|
|
69
71
|
### Retrieve my orders
|
70
72
|
```ruby
|
71
|
-
|
72
|
-
|
73
|
+
order = Base::Apis::Order.new(client_secret)
|
74
|
+
order.index
|
73
75
|
```
|
74
76
|
|
75
77
|
### Retrieve savings
|
76
78
|
```ruby
|
77
|
-
|
78
|
-
|
79
|
+
saving = Base::Apis::Saving.new(client_secret)
|
80
|
+
saving.index
|
79
81
|
```
|
80
82
|
|
81
83
|
### Retrieve delivery companies
|
82
84
|
```ruby
|
83
|
-
|
84
|
-
|
85
|
+
dalivery_company = Base::Apis::DeliveryCompany.new(client_secret)
|
86
|
+
dalivery_company.index
|
85
87
|
```
|
86
88
|
|
87
|
-
### Retrieve
|
89
|
+
### Retrieve categories
|
88
90
|
```ruby
|
89
|
-
|
90
|
-
|
91
|
+
category = Base::Apis::Category.new(client_secret)
|
92
|
+
category.index
|
91
93
|
```
|
92
94
|
|
93
95
|
### Retrieve detailed item category
|
94
96
|
```ruby
|
95
|
-
|
96
|
-
|
97
|
+
item_category = Base::Apis::ItemCategory.new(client_secret)
|
98
|
+
item_category.detail(2_453_256)
|
97
99
|
```
|
98
100
|
|
99
101
|
### Search items
|
data/base-api-client.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'base-api-client'
|
3
|
-
spec.version = '0.3.
|
3
|
+
spec.version = '0.3.2.beta'
|
4
4
|
spec.author = 'ysksn'
|
5
5
|
spec.email = ['bluewhale1982@gmail.com']
|
6
6
|
spec.summary = 'Client for accessing BASE APIs'
|
@@ -13,4 +13,6 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.bindir = 'bin'
|
14
14
|
spec.post_install_message = 'base-api-client gem installed :)'
|
15
15
|
spec.required_ruby_version = ['> 2.2.2']
|
16
|
+
|
17
|
+
spec.add_runtime_dependency 'httpclient', '~> 2.7', '>= 2.7.1'
|
16
18
|
end
|
data/config/client_secret.json
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
|
-
"client_id": "",
|
3
|
-
"client_secret": "",
|
4
|
-
"code": "",
|
5
|
-
"redirect_uri": "",
|
6
|
-
"search_client_id": "",
|
7
|
-
"search_client_secret": ""
|
2
|
+
"client_id": "e0920d3fba627a5da4eaab4e8e9d43fc",
|
3
|
+
"client_secret": "ad493e7ada7eb96a6f71d1ccb100966b",
|
4
|
+
"code": "de4cf65f7c1908ca217e26edd71f43c7",
|
5
|
+
"redirect_uri": "https://pacific-thicket-66916.herokuapp.com/oauth2callback",
|
6
|
+
"search_client_id": "623f75000821c16163ec570ca6469539",
|
7
|
+
"search_client_secret": "214b4134022df8bf0230f5a077c772d9"
|
8
8
|
}
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Base
|
2
2
|
class APIClient
|
3
3
|
class ClientSecret
|
4
|
+
include HTTP
|
4
5
|
AUTH_URI = Apis::API_HOST / Apis::API_VERSION / 'oauth/authorize'
|
5
|
-
TOKEN_URI = Apis::API_HOST / Apis::API_VERSION / 'oauth/token'
|
6
6
|
SCOPES = %w(read_items read_orders read_savings read_users read_users_mail
|
7
7
|
write_items write_orders).join(' ').freeze
|
8
8
|
|
@@ -29,6 +29,7 @@ module Base
|
|
29
29
|
@refresh_token ||= opts['refresh_token']
|
30
30
|
@search_client_id ||= opts['search_client_id']
|
31
31
|
@search_client_secret ||= opts['search_client_secret']
|
32
|
+
set_tokens!
|
32
33
|
end
|
33
34
|
|
34
35
|
def update!(args)
|
@@ -57,16 +58,21 @@ module Base
|
|
57
58
|
end
|
58
59
|
|
59
60
|
def set_tokens!
|
60
|
-
response = fetch_token
|
61
|
+
response = JSON.parse(fetch_token.body)
|
61
62
|
@access_token = response['access_token']
|
62
63
|
@refresh_token = response['refresh_token']
|
63
64
|
@code = nil
|
64
|
-
send
|
65
|
+
send(:expires_at=, response['expires_in'])
|
65
66
|
to_hash
|
66
67
|
end
|
67
68
|
|
68
69
|
private
|
69
70
|
|
71
|
+
def expires_at=(expires_at = nil)
|
72
|
+
additional_second = expires_at || 3600
|
73
|
+
@expires_at = Time.now + additional_second
|
74
|
+
end
|
75
|
+
|
70
76
|
def load_file
|
71
77
|
file = Apis::CONFIG[:DEFAULT][:CLIENT_SECRET][:PATH]
|
72
78
|
MultiJson.load(File.open(file, 'r').read)
|
@@ -107,15 +113,10 @@ module Base
|
|
107
113
|
end
|
108
114
|
|
109
115
|
def fetch_token
|
110
|
-
|
111
|
-
uri
|
112
|
-
|
113
|
-
|
114
|
-
JSON.parse response.body
|
115
|
-
end
|
116
|
-
|
117
|
-
def expires_at=(expires_at = nil)
|
118
|
-
@expires_at = expires_at || Time.now + 3600
|
116
|
+
body = to_hash.merge(grant_type: grant_type)
|
117
|
+
uri = generate_uri('oauth/token')
|
118
|
+
clnt = HTTPClient.new
|
119
|
+
clnt.post(uri, body)
|
119
120
|
end
|
120
121
|
end
|
121
122
|
end
|
data/lib/base/apis.rb
CHANGED
data/lib/base/apis/category.rb
CHANGED
@@ -6,9 +6,13 @@ module Base
|
|
6
6
|
attr_reader :client_secret
|
7
7
|
|
8
8
|
def index
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
clnt = HTTPClient.new
|
10
|
+
uri = generate_uri('categories?')
|
11
|
+
|
12
|
+
clnt.get(
|
13
|
+
uri,
|
14
|
+
nil,
|
15
|
+
client_secret.header_parameter)
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
@@ -6,9 +6,13 @@ module Base
|
|
6
6
|
attr_reader :client_secret
|
7
7
|
|
8
8
|
def index
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
clnt = HTTPClient.new
|
10
|
+
uri = generate_uri('delivery_companies?')
|
11
|
+
|
12
|
+
clnt.get(
|
13
|
+
uri,
|
14
|
+
nil,
|
15
|
+
client_secret.header_parameter)
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
data/lib/base/apis/item.rb
CHANGED
@@ -12,16 +12,15 @@ module Base
|
|
12
12
|
# sort: 'asc or desc',
|
13
13
|
# limit: 1..100,
|
14
14
|
# offset: 0 }
|
15
|
-
request_parameters = block_given? ? yield : {}
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
"/#{Apis::API_VERSION}/items/?",
|
21
|
-
URI.encode_www_form(request_parameters)].join)
|
16
|
+
clnt = HTTPClient.new
|
17
|
+
uri = generate_uri('items')
|
18
|
+
body = block_given? ? yield : {}
|
22
19
|
|
23
|
-
|
24
|
-
|
20
|
+
clnt.get(
|
21
|
+
uri,
|
22
|
+
body,
|
23
|
+
client_secret.header_parameter)
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
@@ -6,9 +6,13 @@ module Base
|
|
6
6
|
attr_reader :client_secret
|
7
7
|
|
8
8
|
def detail(item_id)
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
clnt = HTTPClient.new
|
10
|
+
uri = generate_uri("item_categories/detail/#{item_id}")
|
11
|
+
|
12
|
+
clnt.get(
|
13
|
+
uri,
|
14
|
+
nil,
|
15
|
+
client_secret.header_parameter)
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
data/lib/base/apis/order.rb
CHANGED
@@ -12,16 +12,15 @@ module Base
|
|
12
12
|
# end_ordered: '2016-01-10',
|
13
13
|
# limit: 20,
|
14
14
|
# offset: 0 }
|
15
|
-
request_parameters = block_given? ? yield : {}
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
"/#{API_VERSION}/orders?",
|
21
|
-
URI.encode_www_form(request_parameters)].join)
|
16
|
+
clnt = HTTPClient.new
|
17
|
+
uri = generate_uri('orders')
|
18
|
+
body = block_given? ? yield : {}
|
22
19
|
|
23
|
-
|
24
|
-
|
20
|
+
clnt.get(
|
21
|
+
uri,
|
22
|
+
body,
|
23
|
+
client_secret.header_parameter)
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
data/lib/base/apis/saving.rb
CHANGED
@@ -12,16 +12,15 @@ module Base
|
|
12
12
|
# end_created: '2016-01-10',
|
13
13
|
# limit: 20,
|
14
14
|
# offset: 0 }
|
15
|
-
request_parameters = block_given? ? yield : {}
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
"/#{API_VERSION}/savings?",
|
21
|
-
URI.encode_www_form(request_parameters)].join)
|
16
|
+
clnt = HTTPClient.new
|
17
|
+
uri = generate_uri('savings')
|
18
|
+
body = block_given? ? yield : {}
|
22
19
|
|
23
|
-
|
24
|
-
|
20
|
+
clnt.get(
|
21
|
+
uri,
|
22
|
+
body,
|
23
|
+
client_secret.header_parameter)
|
25
24
|
end
|
26
25
|
end
|
27
26
|
end
|
data/lib/base/apis/search.rb
CHANGED
@@ -3,19 +3,20 @@ module Base
|
|
3
3
|
class Search
|
4
4
|
include HTTP
|
5
5
|
include Apis
|
6
|
-
attr_reader
|
7
|
-
attr_accessor :request_parameters, :uri
|
6
|
+
attr_reader :client_secret
|
8
7
|
|
9
8
|
def request(query, &block)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
start(request, uri)
|
14
|
-
end
|
9
|
+
clnt = HTTPClient.new
|
10
|
+
uri = generate_uri('search')
|
11
|
+
body = generate_body(query, &block)
|
15
12
|
|
16
|
-
|
13
|
+
clnt.get(
|
14
|
+
uri,
|
15
|
+
body,
|
16
|
+
client_secret.header_parameter)
|
17
|
+
end
|
17
18
|
|
18
|
-
def
|
19
|
+
def generate_body(query)
|
19
20
|
# https://github.com/baseinc/api-docs/blob/master/base_api_v1_search.md
|
20
21
|
#
|
21
22
|
# { client_id: 'client id for search',
|
@@ -26,21 +27,13 @@ module Base
|
|
26
27
|
# size: 10,
|
27
28
|
# fields: 'shop_name, title, detail',
|
28
29
|
# shop_id: '' }
|
30
|
+
|
29
31
|
given_parameters = block_given? ? yield : {}
|
30
32
|
default =
|
31
33
|
{ client_id: @client_secret.search_client_id,
|
32
34
|
client_secret: @client_secret.search_client_secret }
|
33
35
|
|
34
|
-
|
35
|
-
default.merge(given_parameters).merge(q: query)
|
36
|
-
end
|
37
|
-
|
38
|
-
def uri=(request_parameters)
|
39
|
-
@uri =
|
40
|
-
URI([
|
41
|
-
API_HOST,
|
42
|
-
"/#{API_VERSION}/search?",
|
43
|
-
URI.encode_www_form(request_parameters)].join)
|
36
|
+
default.merge(given_parameters).merge(q: query)
|
44
37
|
end
|
45
38
|
end
|
46
39
|
end
|
data/lib/base/apis/user.rb
CHANGED
@@ -6,9 +6,13 @@ module Base
|
|
6
6
|
attr_reader :client_secret
|
7
7
|
|
8
8
|
def me
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
clnt = HTTPClient.new
|
10
|
+
uri = generate_uri('users/me')
|
11
|
+
|
12
|
+
clnt.get(
|
13
|
+
uri,
|
14
|
+
nil,
|
15
|
+
client_secret.header_parameter)
|
12
16
|
end
|
13
17
|
end
|
14
18
|
end
|
data/lib/base/http.rb
CHANGED
@@ -1,22 +1,10 @@
|
|
1
1
|
module Base
|
2
2
|
module HTTP
|
3
3
|
def generate_uri(partial_path)
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
def generate_request(uri, header_parameter = nil)
|
10
|
-
Net::HTTP::Get.new(uri, header_parameter)
|
11
|
-
end
|
12
|
-
|
13
|
-
def start(request, uri)
|
14
|
-
Net::HTTP.start(
|
15
|
-
uri.hostname,
|
16
|
-
uri.port,
|
17
|
-
use_ssl: uri.scheme == 'https') do |http|
|
18
|
-
http.request(request)
|
19
|
-
end
|
4
|
+
[Apis::API_HOST.to_s,
|
5
|
+
Apis::API_VERSION,
|
6
|
+
partial_path]
|
7
|
+
.join('/')
|
20
8
|
end
|
21
9
|
end
|
22
10
|
end
|
@@ -7,12 +7,6 @@ RSpec.describe Base::APIClient::ClientSecret do
|
|
7
7
|
|
8
8
|
before(:each) do
|
9
9
|
allow(Time).to receive(:now) { Time.new(2016) }
|
10
|
-
allow_any_instance_of(Base::APIClient::ClientSecret)
|
11
|
-
.to receive(:fetch_token) do
|
12
|
-
{ access_token: 'fake_access_token',
|
13
|
-
refresh_token: 'fake_refresh_token',
|
14
|
-
expires_in: 3600 }
|
15
|
-
end
|
16
10
|
end
|
17
11
|
|
18
12
|
describe '#load_file' do
|
@@ -86,7 +80,7 @@ RSpec.describe Base::APIClient::ClientSecret do
|
|
86
80
|
it 'set the variable by given value' do
|
87
81
|
expect(subject.client_id).to eq 'optional_client_id'
|
88
82
|
expect(subject.client_secret).to eq 'optional_client_secret'
|
89
|
-
expect(subject.code).to eq
|
83
|
+
expect(subject.code).to eq nil
|
90
84
|
expect(subject.redirect_uri).to eq 'optional_redirect_uri'
|
91
85
|
expect(subject.search_client_id).to eq 'optional_search_client_id'
|
92
86
|
expect(subject.search_client_secret).to eq \
|
@@ -132,7 +126,7 @@ RSpec.describe Base::APIClient::ClientSecret do
|
|
132
126
|
client_id: 'fake_client_id',
|
133
127
|
client_secret: 'fake_client_secret',
|
134
128
|
code: nil,
|
135
|
-
expires_at:
|
129
|
+
expires_at: Date.parse(Time.new(2016).to_s).to_time + 3600,
|
136
130
|
redirect_uri: 'http://fake_redirect_uri.com',
|
137
131
|
access_token: nil,
|
138
132
|
refresh_token: nil,
|
@@ -144,7 +138,7 @@ RSpec.describe Base::APIClient::ClientSecret do
|
|
144
138
|
describe '#to_json' do
|
145
139
|
it 'returns values of instance variables in json' do
|
146
140
|
expect(subject.send(:to_json)).to eq \
|
147
|
-
<<"EOS""{\"client_id\":\"fake_client_id\",\"client_secret\":\"fake_client_secret\",\"code\":null,\"expires_at\":
|
141
|
+
<<"EOS""{\"client_id\":\"fake_client_id\",\"client_secret\":\"fake_client_secret\",\"code\":null,\"expires_at\":\"2016-01-01 01:00:00 +0900\",\"redirect_uri\":\"http://fake_redirect_uri.com\",\"access_token\":null,\"refresh_token\":null,\"search_client_id\":\"fake_search_client_id\",\"search_client_secret\":\"fake_search_client_secret\"}"
|
148
142
|
EOS
|
149
143
|
end
|
150
144
|
end
|
@@ -201,36 +195,54 @@ EOS
|
|
201
195
|
|
202
196
|
describe '#fetch_token' do
|
203
197
|
context 'grant_type is "authorization_code"' do
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
198
|
+
let(:response) do
|
199
|
+
subject.grant_type = 'authorization_code'
|
200
|
+
VCR.use_cassette('client_secret/fetch_token_authorization_code') do
|
201
|
+
subject.send(:fetch_token)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'status is 200' do
|
206
|
+
expect(response.status).to eq 200
|
207
|
+
end
|
208
|
+
|
209
|
+
it 'returns access_token, token_type, expires_in, and refresh_token' do
|
210
|
+
expect(JSON.parse(response.body).keys).to eq \
|
211
|
+
%w(access_token token_type expires_in refresh_token)
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'token_type is bearer' do
|
215
|
+
expect(JSON.parse(response.body)['token_type']).to eq 'bearer'
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'expires_in is 3600' do
|
219
|
+
expect(JSON.parse(response.body)['expires_in']).to eq 3600
|
217
220
|
end
|
218
221
|
end
|
219
222
|
|
220
223
|
context 'grant_type is "refresh_token"' do
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
224
|
+
let(:response) do
|
225
|
+
subject.grant_type = 'refresh_token'
|
226
|
+
VCR.use_cassette('client_secret/fetch_token_refresh_token') do
|
227
|
+
subject.send(:fetch_token)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'status is 200' do
|
232
|
+
expect(response.status).to eq 200
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'returns access_token, token_type, expires_in, and refresh_token' do
|
236
|
+
expect(JSON.parse(response.body).keys).to eq \
|
237
|
+
%w(access_token token_type expires_in refresh_token)
|
238
|
+
end
|
239
|
+
|
240
|
+
it 'token_type is bearer' do
|
241
|
+
expect(JSON.parse(response.body)['token_type']).to eq 'bearer'
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'expires_in is 3600' do
|
245
|
+
expect(JSON.parse(response.body)['expires_in']).to eq 3600
|
234
246
|
end
|
235
247
|
end
|
236
248
|
end
|
@@ -241,10 +253,11 @@ EOS
|
|
241
253
|
end
|
242
254
|
|
243
255
|
before do
|
244
|
-
|
256
|
+
allow_any_instance_of(Base::APIClient::ClientSecret)
|
257
|
+
.to receive_message_chain(:fetch_token, :body) do
|
245
258
|
{ 'access_token' => 'stubbed_access_token',
|
246
259
|
'refresh_token' => 'stubbed_refresh_token',
|
247
|
-
'expires_in' => 3600 }
|
260
|
+
'expires_in' => 3600 }.to_json
|
248
261
|
end
|
249
262
|
end
|
250
263
|
|
@@ -307,23 +320,30 @@ EOS
|
|
307
320
|
end
|
308
321
|
|
309
322
|
describe '#expires_at=' do
|
310
|
-
let(:
|
323
|
+
let(:additional_second) { 3600 }
|
324
|
+
before do
|
325
|
+
allow(Time).to receive(:now) do
|
326
|
+
Date.parse(Time.new(2016).to_s).to_time
|
327
|
+
end
|
328
|
+
end
|
311
329
|
|
312
330
|
context 'an arg given' do
|
313
331
|
it 'returns expires_at' do
|
314
|
-
subject.send(:expires_at=,
|
315
|
-
expect(subject.expires_at).to eq
|
332
|
+
subject.send(:expires_at=, additional_second)
|
333
|
+
expect(subject.expires_at).to eq expected_expires_at
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'returns expires_at' do
|
337
|
+
seconds = 99_999
|
338
|
+
subject.send(:expires_at=, seconds)
|
339
|
+
expect(subject.expires_at).to eq Time.now + seconds
|
316
340
|
end
|
317
341
|
end
|
318
342
|
|
319
343
|
context 'none is given' do
|
320
344
|
it 'returns expires_at' do
|
321
|
-
allow(Time).to receive(:now) do
|
322
|
-
Date.parse(Time.new(2016).to_s).to_time
|
323
|
-
end
|
324
|
-
|
325
345
|
subject.send(:expires_at=)
|
326
|
-
expect(subject.expires_at).to eq
|
346
|
+
expect(subject.expires_at).to eq Time.now + 3600
|
327
347
|
end
|
328
348
|
end
|
329
349
|
end
|