my_john_deere_api 0.15.4 → 0.15.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +129 -111
- data/lib/my_john_deere_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50683e3b5739e473385b52c3ff9e7bcdabb74410c004fa13e9349de03c7eca43
|
4
|
+
data.tar.gz: f7b612049d14d825bbf78831e2a2f4b19370df18ddde3a114b277494d4ba45c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 506973aa4c9aaaf172e6767b4dfb6668002a65754ee798fa86039d65b45c90e52a93c41a392fa3dac6d0d782bf124bcfef38538ae43bc559349874b0c6105ac3
|
7
|
+
data.tar.gz: adff5451e37aeb001d4b2fd309ee9f8363944e96f887b884f9fcd44b2492136bed4e2148da8033b21a261e078a38ad7e8b62c041efb421082fecf26174fa3508
|
data/README.md
CHANGED
@@ -13,75 +13,84 @@ This client allows you to connect the MyJohnDeere API without having to code you
|
|
13
13
|
We provide RDoc documentation, but here is a helpful guide for getting started. Because the gem name is long, all examples are going
|
14
14
|
to assume this shortcut:
|
15
15
|
|
16
|
-
|
16
|
+
```ruby
|
17
|
+
JD = MyJohnDeereApi
|
18
|
+
```
|
17
19
|
|
18
20
|
So that when you see:
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
```ruby
|
23
|
+
JD::Authorize
|
24
|
+
```
|
22
25
|
It really means:
|
23
26
|
|
24
|
-
|
25
|
-
|
27
|
+
```ruby
|
28
|
+
MyJohnDeereApi::Authorize
|
29
|
+
```
|
26
30
|
|
27
31
|
### Authorizing with John Deere via Auth 1.0
|
28
32
|
|
29
33
|
This is the simplest path to authorization, though your user has to jump through an extra hoop of giving you the verification code:
|
30
34
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
```ruby
|
36
|
+
# Create an authorize object, using your app's API key and secret. You can
|
37
|
+
# pass an environment (`:live` or `:sandbox`), which default to `:live`.
|
38
|
+
authorize = JD::Authorize.new(API_KEY, API_SECRET, environment: :sandbox)
|
39
|
+
|
40
|
+
# Retrieve a valid authorization url from John Deere, where you can send
|
41
|
+
# your user for authorizing your app to the JD platform.
|
42
|
+
url = authorize.authorize_url
|
43
|
+
|
44
|
+
# Verify the code given to the user during the authorization process, and
|
45
|
+
# turn this into access credentials for your user.
|
46
|
+
authorize.verify(code)
|
47
|
+
```
|
42
48
|
|
43
49
|
In reality, you will likely need to re-instantiate the authorize object when the user returns, and that works without issue:
|
44
50
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
```ruby
|
52
|
+
# Create an authorize object, using your app's API key and secret.
|
53
|
+
authorize = JD::Authorize.new(API_KEY, API_SECRET, environment: :sandbox)
|
54
|
+
|
55
|
+
# Retrieve a valid authorization url from John Deere.
|
56
|
+
url = authorize.authorize_url
|
57
|
+
|
58
|
+
# Queue elevator music while your app serves other users...
|
59
|
+
|
60
|
+
# Re-create the authorize instance in a different process
|
61
|
+
authorize = JD::Authorize.new(API_KEY, API_SECRET, environment: :sandbox)
|
62
|
+
|
63
|
+
# Proceed as normal
|
64
|
+
authorize.verify(code)
|
65
|
+
```
|
58
66
|
|
59
67
|
In a web app, you're prefer that your user doesn't have to copy/paste verification codes. So you can pass in an :oauth_callback url.
|
60
68
|
When the user authorizes your app with John Deere, they are redirected to the url you provide, with the paraameter 'oauth_verifier'
|
61
69
|
that contains the verification code so the user doesn't have to provide it.
|
62
70
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
# Retrieve a valid authorization url from John Deere.
|
72
|
-
# This will contain the callback url encoded into the
|
73
|
-
# query string for you.
|
74
|
-
url = authorize.authorize_url
|
75
|
-
|
76
|
-
# Queue elevator music while your app serves other users...
|
77
|
-
|
78
|
-
# Re-create the authorize instance in a different process.
|
79
|
-
# It's not necessary to re-initialize with the callback url.
|
80
|
-
authorize = JD::Authorize.new(API_KEY, API_SECRET, environment: :sandbox)
|
81
|
-
|
82
|
-
# Inside a Rails controller, you might do this:
|
83
|
-
authorize.verify(params[:oauth_verifier])
|
71
|
+
```ruby
|
72
|
+
# Create an authorize object, using your app's API key and secret.
|
73
|
+
authorize = JD::Authorize.new(
|
74
|
+
API_KEY,
|
75
|
+
API_SECRET,
|
76
|
+
environment: :sandbox,
|
77
|
+
oauth_callback: 'https://example.com'
|
78
|
+
)
|
84
79
|
|
80
|
+
# Retrieve a valid authorization url from John Deere.
|
81
|
+
# This will contain the callback url encoded into the
|
82
|
+
# query string for you.
|
83
|
+
url = authorize.authorize_url
|
84
|
+
|
85
|
+
# Queue elevator music while your app serves other users...
|
86
|
+
|
87
|
+
# Re-create the authorize instance in a different process.
|
88
|
+
# It's not necessary to re-initialize with the callback url.
|
89
|
+
authorize = JD::Authorize.new(API_KEY, API_SECRET, environment: :sandbox)
|
90
|
+
|
91
|
+
# Inside a Rails controller, you might do this:
|
92
|
+
authorize.verify(params[:oauth_verifier])
|
93
|
+
```
|
85
94
|
|
86
95
|
### Interacting with the user's John Deere account
|
87
96
|
|
@@ -89,20 +98,21 @@ After authorization is complete, the `Client` object will provide most of the in
|
|
89
98
|
be used with or without user credentials, because some API calls are specific to your application's relationship
|
90
99
|
with John Deere, not your user's. But most interactions will involve user data. Here's how to instantiate a client:
|
91
100
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
101
|
+
```ruby
|
102
|
+
client = JD::Client.new(
|
103
|
+
# the application's API key
|
104
|
+
API_KEY,
|
105
|
+
|
106
|
+
# the application's API secret
|
107
|
+
API_SECRET,
|
108
|
+
|
109
|
+
# the chosen environment (:sandbox or :live)
|
110
|
+
environment: :sandbox,
|
111
|
+
|
112
|
+
# the user's access credentials
|
113
|
+
access: [ACCESS_TOKEN, ACCESS_SECRET]
|
114
|
+
)
|
115
|
+
```
|
106
116
|
|
107
117
|
### Direct API Requests
|
108
118
|
|
@@ -115,23 +125,25 @@ to be able to make calls that are not yet fully supported by the client. Or some
|
|
115
125
|
|
116
126
|
GET requests require only a resource path.
|
117
127
|
|
118
|
-
|
119
|
-
|
120
|
-
|
128
|
+
```ruby
|
129
|
+
client.get('/organizations')
|
130
|
+
|
131
|
+
# Abbreviated sample response:
|
132
|
+
{
|
133
|
+
"links": [...],
|
134
|
+
"total": 1,
|
135
|
+
"values": [
|
121
136
|
{
|
122
|
-
"
|
123
|
-
"
|
124
|
-
"
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
},
|
133
|
-
]
|
134
|
-
}
|
137
|
+
"@type": "Organization",
|
138
|
+
"name": "ABC Farms",
|
139
|
+
"type": "customer",
|
140
|
+
"member": true,
|
141
|
+
"id": "123123",
|
142
|
+
"links": [...]
|
143
|
+
},
|
144
|
+
]
|
145
|
+
}
|
146
|
+
```
|
135
147
|
|
136
148
|
This won't provide any client goodies like pagination or validation, but it does parse the returned JSON.
|
137
149
|
|
@@ -140,22 +152,24 @@ This won't provide any client goodies like pagination or validation, but it does
|
|
140
152
|
|
141
153
|
POST requests require a resource path, and a hash for the request body. The client will camelize the keys, and convert to JSON.
|
142
154
|
|
143
|
-
|
144
|
-
|
155
|
+
```ruby
|
156
|
+
client.post(
|
157
|
+
'/organizations/123123/assets',
|
158
|
+
{
|
159
|
+
"title"=>"i like turtles",
|
160
|
+
"assetCategory"=>"DEVICE",
|
161
|
+
"assetType"=>"SENSOR",
|
162
|
+
"assetSubType"=>"ENVIRONMENTAL",
|
163
|
+
"links"=>[
|
145
164
|
{
|
146
|
-
"
|
147
|
-
"
|
148
|
-
"
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
"uri"=>"https://sandboxapi.deere.com/platform/contributionDefinitions/CONTRIBUTION_DEFINITION_ID"
|
155
|
-
}
|
156
|
-
]
|
157
|
-
}
|
158
|
-
)
|
165
|
+
"@type"=>"Link",
|
166
|
+
"rel"=>"contributionDefinition",
|
167
|
+
"uri"=>"https://sandboxapi.deere.com/platform/contributionDefinitions/CONTRIBUTION_DEFINITION_ID"
|
168
|
+
}
|
169
|
+
]
|
170
|
+
}
|
171
|
+
)
|
172
|
+
```
|
159
173
|
|
160
174
|
John Deere's standard response is a 201 HTTP status code, with the message "Created". This method returns the full Net::HTTP response.
|
161
175
|
|
@@ -164,22 +178,24 @@ John Deere's standard response is a 201 HTTP status code, with the message "Crea
|
|
164
178
|
|
165
179
|
PUT requests require a resource path, and a hash for the request body. The client will camelize the keys, and convert to JSON.
|
166
180
|
|
167
|
-
|
168
|
-
|
181
|
+
```ruby
|
182
|
+
client.put(
|
183
|
+
'/assets/123123',
|
184
|
+
{
|
185
|
+
"title"=>"i REALLY like turtles",
|
186
|
+
"assetCategory"=>"DEVICE",
|
187
|
+
"assetType"=>"SENSOR",
|
188
|
+
"assetSubType"=>"ENVIRONMENTAL",
|
189
|
+
"links"=>[
|
169
190
|
{
|
170
|
-
"
|
171
|
-
"
|
172
|
-
"
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
"uri"=>"https://sandboxapi.deere.com/platform/contributionDefinitions/CONTRIBUTION_DEFINITION_ID"
|
179
|
-
}
|
180
|
-
]
|
181
|
-
}
|
182
|
-
)
|
191
|
+
"@type"=>"Link",
|
192
|
+
"rel"=>"contributionDefinition",
|
193
|
+
"uri"=>"https://sandboxapi.deere.com/platform/contributionDefinitions/CONTRIBUTION_DEFINITION_ID"
|
194
|
+
}
|
195
|
+
]
|
196
|
+
}
|
197
|
+
)
|
198
|
+
```
|
183
199
|
|
184
200
|
John Deere's standard response is a 204 HTTP status code, with the message "No Content". This method returns the full Net::HTTP response.
|
185
201
|
|
@@ -188,7 +204,9 @@ John Deere's standard response is a 204 HTTP status code, with the message "No C
|
|
188
204
|
|
189
205
|
DELETE requests require only a resource path.
|
190
206
|
|
191
|
-
|
207
|
+
```ruby
|
208
|
+
client.delete('/assets/123123')
|
209
|
+
```
|
192
210
|
|
193
211
|
John Deere's standard response is a 204 HTTP status code, with the message "No Content". This method returns the full Net::HTTP response.
|
194
212
|
|