my_john_deere_api 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/my_john_deere_api/authorize.rb +19 -82
- data/lib/my_john_deere_api/client.rb +51 -0
- data/lib/my_john_deere_api/consumer.rb +85 -0
- data/lib/my_john_deere_api/version.rb +1 -1
- data/lib/my_john_deere_api.rb +2 -0
- data/test/lib/test_authorize.rb +25 -78
- data/test/lib/test_client.rb +63 -0
- data/test/lib/test_consumer.rb +74 -0
- data/test/support/helper.rb +9 -0
- data/test/test_my_john_deere_api.rb +8 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1972b07d8f4e72723a8984e459a5fc97e7587914b06415dcd2ce181d6db3c43b
|
4
|
+
data.tar.gz: 6ecea1bd5fef0c60e04c510674c54adae3dd80967f3132fbba68e54d199a57e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 905162ea13bdb92ef6a7a1c0d86db73e351c0edf8f3b8420a8cb93193eb6e0e4e717436ca535b705636c0fe01256ee2797e9ae20f9e020b515cc15ad0e649c3b
|
7
|
+
data.tar.gz: 28a612aab3944a40bf19e23bc3640db8cdcff1e78faed99e374320df64ceb7441df5b92171e5aa2c0beb56ef90c26aa3dd2bae3cd5a061d4c3ba96277142f837
|
@@ -1,34 +1,25 @@
|
|
1
1
|
class MyJohnDeereApi::Authorize
|
2
|
-
attr_reader :api_key, :api_secret,
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
sandbox: 'https://sandboxapi.deere.com',
|
7
|
-
production: 'https://api.soa-proxy.deere.com',
|
8
|
-
}
|
2
|
+
attr_reader :api_key, :api_secret,
|
3
|
+
:request_token, :request_secret,
|
4
|
+
:access_token, :access_secret,
|
5
|
+
:environment
|
9
6
|
|
10
7
|
DEFAULTS = {
|
11
|
-
environment: :production
|
8
|
+
environment: :production
|
12
9
|
}
|
13
10
|
|
14
11
|
##
|
15
|
-
# Create an Authorize object
|
16
|
-
#
|
17
|
-
# Options:
|
18
|
-
#
|
19
|
-
# [:environment] *:production* or *:sandbox*, determines the base url
|
20
|
-
# used to make oauth requests.
|
12
|
+
# Create an Authorize object.
|
21
13
|
#
|
22
|
-
#
|
23
|
-
#
|
14
|
+
# This is used to obtain authentication an access key/secret
|
15
|
+
# on behalf of a user.
|
24
16
|
|
25
|
-
def initialize(api_key, api_secret, options={})
|
17
|
+
def initialize(api_key, api_secret, options = {})
|
26
18
|
options = DEFAULTS.merge(options)
|
27
19
|
|
28
20
|
@api_key = api_key
|
29
21
|
@api_secret = api_secret
|
30
22
|
@environment = options[:environment]
|
31
|
-
@base_url = options[:base_url] || URLS[@environment]
|
32
23
|
end
|
33
24
|
|
34
25
|
##
|
@@ -38,13 +29,21 @@ class MyJohnDeereApi::Authorize
|
|
38
29
|
def authorize_url
|
39
30
|
return @authorize_url if defined?(@authorize_url)
|
40
31
|
|
41
|
-
requester =
|
32
|
+
requester = consumer.get_request_token
|
42
33
|
@request_token = requester.token
|
43
34
|
@request_secret = requester.secret
|
44
35
|
|
45
36
|
@authorize_url = requester.authorize_url
|
46
37
|
end
|
47
38
|
|
39
|
+
##
|
40
|
+
# API consumer that makes non-user-specific GET requests
|
41
|
+
|
42
|
+
def consumer
|
43
|
+
return @consumer if defined?(@consumer)
|
44
|
+
@consumer = MyJohnDeereApi::Consumer.new(@api_key, @api_secret, environment: environment).app_get
|
45
|
+
end
|
46
|
+
|
48
47
|
##
|
49
48
|
# Turn a verification code into access tokens. If this is
|
50
49
|
# run from a separate process than the one that created
|
@@ -55,72 +54,10 @@ class MyJohnDeereApi::Authorize
|
|
55
54
|
token ||= request_token
|
56
55
|
secret ||= request_secret
|
57
56
|
|
58
|
-
requester = OAuth::RequestToken.new(
|
57
|
+
requester = OAuth::RequestToken.new(consumer, token, secret)
|
59
58
|
access_object = requester.get_access_token(oauth_verifier: code)
|
60
59
|
@access_token = access_object.token
|
61
60
|
@access_secret = access_object.secret
|
62
61
|
nil
|
63
62
|
end
|
64
|
-
|
65
|
-
##
|
66
|
-
# oAuth Consumer which uses just the base url, for
|
67
|
-
# app-wide, non user-specific requests.
|
68
|
-
|
69
|
-
def app_consumer
|
70
|
-
@app_consumer ||= consumer(base_url)
|
71
|
-
end
|
72
|
-
|
73
|
-
##
|
74
|
-
# oAuth Consumer which uses the proper url for user-specific requests.
|
75
|
-
|
76
|
-
def user_consumer
|
77
|
-
@user_consumer ||= consumer("#{base_url}/platform")
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def consumer(site)
|
83
|
-
OAuth::Consumer.new(
|
84
|
-
api_key,
|
85
|
-
api_secret,
|
86
|
-
site: site,
|
87
|
-
header: header,
|
88
|
-
http_method: :get,
|
89
|
-
request_token_url: links[:request_token],
|
90
|
-
access_token_url: links[:access_token],
|
91
|
-
authorize_url: links[:authorize_request_token]
|
92
|
-
)
|
93
|
-
end
|
94
|
-
|
95
|
-
def links
|
96
|
-
return @links if defined?(@links)
|
97
|
-
|
98
|
-
catalog = OAuth::Consumer.new(api_key, api_secret)
|
99
|
-
.request(
|
100
|
-
:get,
|
101
|
-
"#{base_url}/platform/",
|
102
|
-
nil,
|
103
|
-
{},
|
104
|
-
header
|
105
|
-
).body
|
106
|
-
|
107
|
-
@links = {}
|
108
|
-
|
109
|
-
JSON.parse(catalog)['links'].each do |link|
|
110
|
-
uri = URI.parse(link['uri'])
|
111
|
-
uri.query = nil
|
112
|
-
|
113
|
-
@links[keyify(link['rel'])] = uri.to_s
|
114
|
-
end
|
115
|
-
|
116
|
-
@links
|
117
|
-
end
|
118
|
-
|
119
|
-
def header
|
120
|
-
{accept: 'application/vnd.deere.axiom.v3+json'}
|
121
|
-
end
|
122
|
-
|
123
|
-
def keyify key_name
|
124
|
-
key_name.gsub(/^oauth/, '').gsub(/([a-z])([A-Z])/, '\1_\2').downcase.to_sym
|
125
|
-
end
|
126
63
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class MyJohnDeereApi::Client
|
2
|
+
attr_reader :api_key, :api_secret, :access_token, :access_secret, :environment
|
3
|
+
|
4
|
+
DEFAULTS = {
|
5
|
+
environment: :production
|
6
|
+
}
|
7
|
+
|
8
|
+
##
|
9
|
+
# Creates the client with everthing it needs to perform API requests.
|
10
|
+
# User-specific credentials are optional, but user-specific API
|
11
|
+
# requests are only possible if they are supplied.
|
12
|
+
#
|
13
|
+
# options:
|
14
|
+
#
|
15
|
+
# [:environment] :sandbox or :production
|
16
|
+
#
|
17
|
+
# [:access] an array with two elements, the access_token
|
18
|
+
# and the access_secret of the given user
|
19
|
+
|
20
|
+
def initialize(api_key, api_secret, options = {})
|
21
|
+
options = DEFAULTS.merge(options)
|
22
|
+
|
23
|
+
@api_key = api_key
|
24
|
+
@api_secret = api_secret
|
25
|
+
|
26
|
+
if options.has_key?(:access) && options[:access].is_a?(Array)
|
27
|
+
@access_token, @access_secret = options[:access]
|
28
|
+
end
|
29
|
+
|
30
|
+
@environment = options[:environment]
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
##
|
36
|
+
# Returns an oAuth consumer which can be used to build requests
|
37
|
+
|
38
|
+
def consumer
|
39
|
+
return @consumer if defined?(@consumer)
|
40
|
+
@consumer = MyJohnDeereApi::Consumer.new(@api_key, @api_secret, environment: environment)
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Returns an oAuth AccessToken object which can be used to make
|
45
|
+
# user-specific API requests
|
46
|
+
|
47
|
+
def accessor
|
48
|
+
return @accessor if defined?(@accessor)
|
49
|
+
@accessor = OAuth::AccessToken.new(consumer.user_get, access_token, access_secret)
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
class MyJohnDeereApi::Consumer
|
2
|
+
attr_reader :api_key, :api_secret, :environment, :base_url
|
3
|
+
|
4
|
+
# valid API urls
|
5
|
+
URLS = {
|
6
|
+
sandbox: 'https://sandboxapi.deere.com',
|
7
|
+
production: 'https://api.soa-proxy.deere.com',
|
8
|
+
}
|
9
|
+
|
10
|
+
DEFAULTS = {
|
11
|
+
environment: :production
|
12
|
+
}
|
13
|
+
|
14
|
+
def initialize(api_key, api_secret, options={})
|
15
|
+
options = DEFAULTS.merge(options)
|
16
|
+
|
17
|
+
@api_key = api_key
|
18
|
+
@api_secret = api_secret
|
19
|
+
|
20
|
+
@environment = options[:environment]
|
21
|
+
@base_url = options[:base_url] || URLS[@environment]
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# oAuth Consumer which uses just the base url, for
|
26
|
+
# app-wide, non user-specific GET requests.
|
27
|
+
|
28
|
+
def app_get
|
29
|
+
@app_get ||= consumer(base_url)
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# oAuth Consumer which uses the proper url for user-specific GET requests.
|
34
|
+
|
35
|
+
def user_get
|
36
|
+
@user_get ||= consumer("#{base_url}/platform")
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def consumer(site)
|
42
|
+
OAuth::Consumer.new(
|
43
|
+
api_key,
|
44
|
+
api_secret,
|
45
|
+
site: site,
|
46
|
+
header: header,
|
47
|
+
http_method: :get,
|
48
|
+
request_token_url: links[:request_token],
|
49
|
+
access_token_url: links[:access_token],
|
50
|
+
authorize_url: links[:authorize_request_token]
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
def links
|
55
|
+
return @links if defined?(@links)
|
56
|
+
|
57
|
+
catalog = OAuth::Consumer.new(api_key, api_secret)
|
58
|
+
.request(
|
59
|
+
:get,
|
60
|
+
"#{base_url}/platform/",
|
61
|
+
nil,
|
62
|
+
{},
|
63
|
+
header
|
64
|
+
).body
|
65
|
+
|
66
|
+
@links = {}
|
67
|
+
|
68
|
+
JSON.parse(catalog)['links'].each do |link|
|
69
|
+
uri = URI.parse(link['uri'])
|
70
|
+
uri.query = nil
|
71
|
+
|
72
|
+
@links[keyify(link['rel'])] = uri.to_s
|
73
|
+
end
|
74
|
+
|
75
|
+
@links
|
76
|
+
end
|
77
|
+
|
78
|
+
def header
|
79
|
+
@header ||= {accept: 'application/vnd.deere.axiom.v3+json'}
|
80
|
+
end
|
81
|
+
|
82
|
+
def keyify key_name
|
83
|
+
key_name.gsub(/^oauth/, '').gsub(/([a-z])([A-Z])/, '\1_\2').downcase.to_sym
|
84
|
+
end
|
85
|
+
end
|
data/lib/my_john_deere_api.rb
CHANGED
data/test/lib/test_authorize.rb
CHANGED
@@ -2,50 +2,49 @@ require 'uri'
|
|
2
2
|
require 'cgi'
|
3
3
|
require 'support/helper'
|
4
4
|
|
5
|
-
TOKEN_PATTERN = /^[0-9a-z\-]+$/
|
6
|
-
SECRET_PATTERN = /^[0-9A-Za-z\-+=\/]+$/
|
7
|
-
API_KEY = ENV['API_KEY']
|
8
|
-
API_SECRET = ENV['API_SECRET']
|
9
|
-
|
10
5
|
def contains_parameters?(uri)
|
11
6
|
!URI.parse(uri).query.nil?
|
12
7
|
end
|
13
8
|
|
14
9
|
def create_authorize
|
15
|
-
JD::Authorize.new(API_KEY, API_SECRET, environment: :sandbox)
|
10
|
+
VCR.use_cassette('catalog'){ JD::Authorize.new(API_KEY, API_SECRET, environment: :sandbox) }
|
16
11
|
end
|
17
12
|
|
18
13
|
def fancy_url
|
19
14
|
'https://example.com/turtles'
|
20
15
|
end
|
21
16
|
|
22
|
-
|
17
|
+
describe 'MyJohnDeereApi::Authorize' do
|
23
18
|
describe 'initialization' do
|
24
|
-
it
|
25
|
-
authorize = JD::Authorize.new(
|
19
|
+
it 'sets the api key/secret' do
|
20
|
+
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(API_KEY, API_SECRET) }
|
26
21
|
|
27
|
-
assert_equal
|
28
|
-
assert_equal
|
22
|
+
assert_equal API_KEY, authorize.api_key
|
23
|
+
assert_equal API_SECRET, authorize.api_secret
|
29
24
|
end
|
30
25
|
|
31
|
-
it '
|
32
|
-
|
33
|
-
assert_equal :production, authorize.environment
|
34
|
-
end
|
26
|
+
it 'sets the environment' do
|
27
|
+
environment = :sandbox
|
35
28
|
|
36
|
-
|
37
|
-
|
38
|
-
assert_equal 'https://api.soa-proxy.deere.com', authorize.base_url
|
29
|
+
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(API_KEY, API_SECRET, environment: environment) }
|
30
|
+
assert_equal environment, authorize.environment
|
39
31
|
end
|
40
32
|
|
41
|
-
it
|
42
|
-
|
43
|
-
|
33
|
+
it 'defaults the environment to production' do
|
34
|
+
environment = :production
|
35
|
+
|
36
|
+
authorize = VCR.use_cassette('catalog') { JD::Authorize.new(API_KEY, API_SECRET) }
|
37
|
+
assert_equal environment, authorize.environment
|
44
38
|
end
|
39
|
+
end
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
describe '#consumer' do
|
42
|
+
it "returns a non-user-specific consumer configured for GET requests" do
|
43
|
+
authorize = create_authorize
|
44
|
+
consumer = VCR.use_cassette('catalog') { authorize.consumer }
|
45
|
+
|
46
|
+
assert_kind_of OAuth::Consumer, consumer
|
47
|
+
assert_equal :get, consumer.http_method
|
49
48
|
end
|
50
49
|
end
|
51
50
|
|
@@ -54,8 +53,9 @@ class AuthorizeTest < MiniTest::Test
|
|
54
53
|
authorize = create_authorize
|
55
54
|
|
56
55
|
url = VCR.use_cassette('get_request_token') { authorize.authorize_url }
|
56
|
+
links = VCR.use_cassette('catalog') { JD::Consumer.new(API_KEY, API_SECRET, environment: :sandbox).send(:links) }
|
57
57
|
|
58
|
-
assert_includes url, "#{
|
58
|
+
assert_includes url, "#{links[:authorize_request_token]}?oauth_token="
|
59
59
|
|
60
60
|
query = URI.parse(url).query
|
61
61
|
params = CGI::parse(query)
|
@@ -85,57 +85,4 @@ class AuthorizeTest < MiniTest::Test
|
|
85
85
|
assert_match SECRET_PATTERN, authorize.access_secret
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
89
|
-
describe '#links' do
|
90
|
-
it "returns a list of catalog urls" do
|
91
|
-
authorize = create_authorize
|
92
|
-
|
93
|
-
links = VCR.use_cassette("catalog"){ authorize.send(:links) }
|
94
|
-
|
95
|
-
assert_kind_of Hash, links
|
96
|
-
|
97
|
-
[:request_token, :authorize_request_token, :access_token].each do |link|
|
98
|
-
assert links.has_key?(link)
|
99
|
-
refute contains_parameters?(links[link])
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe '#base_url' do
|
105
|
-
it 'defaults to production deere url' do
|
106
|
-
authorize = JD::Authorize.new('key', 'secret')
|
107
|
-
assert_equal 'https://api.soa-proxy.deere.com', authorize.base_url
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'can be set via accessor' do
|
111
|
-
authorize = create_authorize
|
112
|
-
authorize.base_url = fancy_url
|
113
|
-
|
114
|
-
assert_equal fancy_url, authorize.base_url
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe '#app_consumer' do
|
119
|
-
it 'creates a working oAuth consumer for non-user-specific requests' do
|
120
|
-
auth = create_authorize
|
121
|
-
app_consumer = VCR.use_cassette('app_consumer') { auth.app_consumer }
|
122
|
-
|
123
|
-
assert_kind_of OAuth::Consumer, app_consumer
|
124
|
-
assert_equal API_KEY, app_consumer.key
|
125
|
-
assert_equal API_SECRET, app_consumer.secret
|
126
|
-
assert_equal auth.base_url, app_consumer.site
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe '#user_consumer' do
|
131
|
-
it 'creates a working oAuth consumer for user-specific requests' do
|
132
|
-
auth = create_authorize
|
133
|
-
user_consumer = VCR.use_cassette('app_consumer') { auth.user_consumer }
|
134
|
-
|
135
|
-
assert_kind_of OAuth::Consumer, user_consumer
|
136
|
-
assert_equal API_KEY, user_consumer.key
|
137
|
-
assert_equal API_SECRET, user_consumer.secret
|
138
|
-
assert_equal "#{auth.base_url}/platform", user_consumer.site
|
139
|
-
end
|
140
|
-
end
|
141
88
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'MyJohnDeereApi::Client' do
|
4
|
+
describe '#initialize(api_key, api_secret)' do
|
5
|
+
it 'sets the api key/secret' do
|
6
|
+
client = JD::Client.new(API_KEY, API_SECRET)
|
7
|
+
|
8
|
+
assert_equal API_KEY, client.api_key
|
9
|
+
assert_equal API_SECRET, client.api_secret
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'accepts access token/secret' do
|
13
|
+
access_token = 'token'
|
14
|
+
access_secret = 'secret'
|
15
|
+
|
16
|
+
client = JD::Client.new(API_KEY, API_SECRET, access: [access_token, access_secret])
|
17
|
+
|
18
|
+
assert_equal access_token, client.access_token
|
19
|
+
assert_equal access_secret, client.access_secret
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'accepts environment' do
|
23
|
+
environment = :sandbox
|
24
|
+
|
25
|
+
client = JD::Client.new(API_KEY, API_SECRET, environment: environment)
|
26
|
+
assert_equal environment, client.environment
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'defaults the environment to production' do
|
30
|
+
environment = :production
|
31
|
+
|
32
|
+
client = JD::Client.new(API_KEY, API_SECRET)
|
33
|
+
assert_equal environment, client.environment
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#consumer' do
|
38
|
+
it 'receives the api key/secret and environment of the client' do
|
39
|
+
environment = :sandbox
|
40
|
+
|
41
|
+
client = JD::Client.new(API_KEY, API_SECRET, environment: environment)
|
42
|
+
consumer = client.send :consumer
|
43
|
+
|
44
|
+
assert_kind_of JD::Consumer, consumer
|
45
|
+
assert_equal API_KEY, consumer.api_key
|
46
|
+
assert_equal API_SECRET, consumer.api_secret
|
47
|
+
assert_equal environment, consumer.environment
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#accessor' do
|
52
|
+
it 'returns an object that can make user-specific requests' do
|
53
|
+
client = JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET])
|
54
|
+
consumer = client.send(:consumer)
|
55
|
+
accessor = VCR.use_cassette('catalog') { client.send :accessor }
|
56
|
+
|
57
|
+
assert_kind_of OAuth::AccessToken, accessor
|
58
|
+
assert_kind_of OAuth::Consumer, accessor.consumer
|
59
|
+
assert_equal ACCESS_TOKEN, accessor.token
|
60
|
+
assert_equal ACCESS_SECRET, accessor.secret
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'support/helper'
|
2
|
+
|
3
|
+
describe 'JD::Consumer' do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'requires an api key and secret' do
|
6
|
+
consumer = JD::Consumer.new(API_KEY, API_SECRET)
|
7
|
+
|
8
|
+
assert_equal API_KEY, consumer.api_key
|
9
|
+
assert_equal API_SECRET, consumer.api_secret
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'accepts sandbox environment' do
|
13
|
+
environment = :sandbox
|
14
|
+
consumer = JD::Consumer.new(API_KEY, API_SECRET, environment: environment)
|
15
|
+
|
16
|
+
assert_equal environment, consumer.environment
|
17
|
+
assert_equal JD::Consumer::URLS[environment], consumer.base_url
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'accepts production environment' do
|
21
|
+
environment = :production
|
22
|
+
consumer = JD::Consumer.new(API_KEY, API_SECRET, environment: environment)
|
23
|
+
|
24
|
+
assert_equal environment, consumer.environment
|
25
|
+
assert_equal JD::Consumer::URLS[environment], consumer.base_url
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'defaults to production environment' do
|
29
|
+
default_environment = :production
|
30
|
+
consumer = JD::Consumer.new(API_KEY, API_SECRET)
|
31
|
+
|
32
|
+
assert_equal default_environment, consumer.environment
|
33
|
+
assert_equal JD::Consumer::URLS[default_environment], consumer.base_url
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'accepts an arbitrary base_url' do
|
37
|
+
base_url = 'https://example.com'
|
38
|
+
consumer = JD::Consumer.new(API_KEY, API_SECRET, base_url: base_url)
|
39
|
+
|
40
|
+
assert_equal base_url, consumer.base_url
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'uses specified base_url regardless of specified environment' do
|
44
|
+
base_url = 'https://example.com'
|
45
|
+
consumer = JD::Consumer.new(API_KEY, API_SECRET, base_url: base_url, environment: :sandbox)
|
46
|
+
|
47
|
+
assert_equal base_url, consumer.base_url
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#app_get' do
|
52
|
+
it 'creates a working oAuth consumer for non-user-specific GET requests' do
|
53
|
+
consumer = JD::Consumer.new(API_KEY, API_SECRET, environment: :sandbox)
|
54
|
+
app_get = VCR.use_cassette('app_consumer') { consumer.app_get }
|
55
|
+
|
56
|
+
assert_kind_of OAuth::Consumer, app_get
|
57
|
+
assert_equal API_KEY, app_get.key
|
58
|
+
assert_equal API_SECRET, app_get.secret
|
59
|
+
assert_equal JD::Consumer::URLS[:sandbox], app_get.site
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '#user_get' do
|
64
|
+
it 'creates a working oAuth consumer for user-specific GET requests' do
|
65
|
+
consumer = JD::Consumer.new(API_KEY, API_SECRET, environment: :sandbox)
|
66
|
+
user_get = VCR.use_cassette('app_consumer') { consumer.user_get }
|
67
|
+
|
68
|
+
assert_kind_of OAuth::Consumer, user_get
|
69
|
+
assert_equal API_KEY, user_get.key
|
70
|
+
assert_equal API_SECRET, user_get.secret
|
71
|
+
assert_equal "#{JD::Consumer::URLS[:sandbox]}/platform", user_get.site
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/test/support/helper.rb
CHANGED
@@ -8,6 +8,15 @@ require 'my_john_deere_api'
|
|
8
8
|
# shortcut for long module name
|
9
9
|
JD = MyJohnDeereApi
|
10
10
|
|
11
|
+
API_KEY = ENV['API_KEY']
|
12
|
+
API_SECRET = ENV['API_SECRET']
|
13
|
+
|
14
|
+
ACCESS_TOKEN = ENV['ACCESS_TOKEN']
|
15
|
+
ACCESS_SECRET = ENV['ACCESS_SECRET']
|
16
|
+
|
17
|
+
TOKEN_PATTERN = /^[0-9a-z\-]+$/
|
18
|
+
SECRET_PATTERN = /^[0-9A-Za-z\-+=\/]+$/
|
19
|
+
|
11
20
|
VCR.configure do |config|
|
12
21
|
config.cassette_library_dir = 'test/support/vcr'
|
13
22
|
config.hook_into :webmock
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: my_john_deere_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jaime. Bellmyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: vcr
|
@@ -97,8 +97,12 @@ files:
|
|
97
97
|
- Rakefile
|
98
98
|
- lib/my_john_deere_api.rb
|
99
99
|
- lib/my_john_deere_api/authorize.rb
|
100
|
+
- lib/my_john_deere_api/client.rb
|
101
|
+
- lib/my_john_deere_api/consumer.rb
|
100
102
|
- lib/my_john_deere_api/version.rb
|
101
103
|
- test/lib/test_authorize.rb
|
104
|
+
- test/lib/test_client.rb
|
105
|
+
- test/lib/test_consumer.rb
|
102
106
|
- test/lib/test_version.rb
|
103
107
|
- test/support/helper.rb
|
104
108
|
- test/support/vcr/app_consumer.yml
|