myjohndeere 0.0.11 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +13 -3
- data/lib/myjohndeere/boundary.rb +0 -1
- data/lib/myjohndeere/rest_methods.rb +5 -0
- data/lib/myjohndeere/version.rb +1 -1
- data/test/test_rest_methods.rb +17 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e6813bb496ffe2d2a5d24c26c9255d554675184
|
4
|
+
data.tar.gz: 9da19d2acb3e3fdad3b8d08c138e333ee5019f69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c0d1f7ffd65f2b0c3f1b806d1282f2df3c84c807a4d2ab2c6689af54eaecab6c3cb901d5d5826f227e730bd812bbb2885a73c54fe369eb5ef5d4c73c5f09a35
|
7
|
+
data.tar.gz: 39b995dbdcbfa0af60fd5a2d0cc3b9ce6d6a97c1a7c616f4b79f15ed5d3e38a474a7c2ebf39b09cb5087b3f1b149134a6171a59c68c3aebe5e22e5605e397a40
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
The MyJohnDeere Ruby library provides convenient access to the MyJohnDeere API from applications written in the Ruby language. It includes a pre-defined set of classes for API resources that are available currently from the API. You will need to get access by going to the [JohnDeere Developer page](https://developer.deere.com/#!welcome). The interface utilizes OAUTH 1.0.
|
4
4
|
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
You don't need this source code unless you want to modify the gem. If you just want to use the package, just run:
|
8
|
+
|
9
|
+
`gem install myjohndeere`
|
10
|
+
|
11
|
+
If you want to build the gem from source:
|
12
|
+
|
13
|
+
`gem build myjohndeere.gemspec`
|
14
|
+
|
5
15
|
## Usage
|
6
16
|
|
7
17
|
### Configuration
|
@@ -82,13 +92,13 @@ end
|
|
82
92
|
|
83
93
|
## Listable Objects
|
84
94
|
|
85
|
-
MyJohnDeere returns either pages of objects that will automatically be iterated through 10 at a time *or* you'll receive the entirety of the resource if you specify an
|
95
|
+
MyJohnDeere returns either pages of objects that will automatically be iterated through 10 at a time *or* you'll receive the entirety of the resource if you specify an ETAG token. **The default behavior is for pagination.**
|
86
96
|
|
87
97
|
**If using the paginated approach**: Use `more_pages?` on the listable object to see if there are more pages to be acquired by using `next_page!`. This will modify the `.start` and `.count` values on the list object. These automatically increase with each `next_page`.
|
88
98
|
|
89
|
-
**If using the
|
99
|
+
**If using the ETAG approach**: The entirety of the data set will be returned to you and on the list object you'll want to call `list.etag` and store this locally. You can then use this on future requests to see if anything has changed from the original request. To use it: `MyJohnDeere::Organization.list(access_token, etag: '')`
|
90
100
|
|
91
|
-
If you for some reason specify both, the
|
101
|
+
If you for some reason specify both, the ETAG will be the assumed behavior.
|
92
102
|
|
93
103
|
The raw data can be acquired by using `.data` on a listable object.
|
94
104
|
|
data/lib/myjohndeere/boundary.rb
CHANGED
@@ -10,7 +10,6 @@ module MyJohnDeere
|
|
10
10
|
super(json_object, access_token)
|
11
11
|
self.field_id = field_id
|
12
12
|
self.active = self.active.to_s.downcase == "true"
|
13
|
-
self.multipolygons = json_object["multipolygons"]
|
14
13
|
# This doesn't exist currently, not sure why
|
15
14
|
self.field_id ||= extract_link_with_rel_from_list("fields", /\/(\d+)\/(.+?)\/fields\Z/)
|
16
15
|
end
|
@@ -10,9 +10,14 @@ module MyJohnDeere
|
|
10
10
|
def list(access_token, options = {})
|
11
11
|
validate_access_token(access_token)
|
12
12
|
options = {count: 10, start: 0, etag: nil}.merge(options)
|
13
|
+
if !options[:etag].nil? then
|
14
|
+
options.delete(:count)
|
15
|
+
options.delete(:start)
|
16
|
+
end
|
13
17
|
options[:body] ||= {}
|
14
18
|
# The count and start are in this list,so move them into the body
|
15
19
|
SPECIAL_BODY_PARAMETERS.each do |sbp|
|
20
|
+
next if options[sbp].nil?
|
16
21
|
options[:body][sbp] = options[sbp]
|
17
22
|
end
|
18
23
|
|
data/lib/myjohndeere/version.rb
CHANGED
data/test/test_rest_methods.rb
CHANGED
@@ -25,6 +25,20 @@ class TestRestMethods < Minitest::Test
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
+
def test_deleted_object_with_etag
|
29
|
+
etag_val = "something"
|
30
|
+
new_etag = "something2"
|
31
|
+
stub_request(:get, /organizations\Z/).
|
32
|
+
with(headers: {MyJohnDeere::ETAG_HEADER_KEY => etag_val}).
|
33
|
+
to_return(status: 200, body: API_FIXTURES["deleted_organization"].to_json(),
|
34
|
+
headers: {MyJohnDeere::ETAG_HEADER_KEY=>new_etag})
|
35
|
+
|
36
|
+
organizations = MyJohnDeere::Organization.list(default_access_token, etag: etag_val)
|
37
|
+
|
38
|
+
assert organizations.data.first.deleted
|
39
|
+
assert_equal new_etag, organizations.etag
|
40
|
+
end
|
41
|
+
|
28
42
|
def test_list_with_etag
|
29
43
|
stub_request(:get, /organizations/).
|
30
44
|
with(headers: {MyJohnDeere::ETAG_HEADER_KEY => ""}).
|
@@ -49,8 +63,9 @@ class TestRestMethods < Minitest::Test
|
|
49
63
|
end
|
50
64
|
|
51
65
|
def test_list_with_body
|
52
|
-
stub_request(:get, /organizations
|
53
|
-
with(query: {embed: "boundaries"}
|
66
|
+
stub_request(:get, /organizations/).
|
67
|
+
with(query: {embed: "boundaries"},
|
68
|
+
headers: {MyJohnDeere::ETAG_HEADER_KEY=>""}).
|
54
69
|
to_return(status: 200, body: LIST_FIXTURE.to_json())
|
55
70
|
organizations = MyJohnDeere::Organization.list(default_access_token, count: 1, etag: "", body: {embed: "boundaries"})
|
56
71
|
assert_equal({:embed=>"boundaries"}, organizations.options[:body])
|