my_john_deere_api 0.4.0 → 0.4.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
  SHA256:
3
- metadata.gz: 5005d82b1ef3ac1363022c0a4344000cd823bef860301bc9a067f3d5ac200cbc
4
- data.tar.gz: df32f8ea65db2bb668f23fa1a9c7e48db055abf6fc85dbeb84b51d97db777050
3
+ metadata.gz: 308f6c3b51f2e879f9df9bb1b616947867acd261363aa72e98458f5e6234aa37
4
+ data.tar.gz: '09257f1b9559a3a5b631f724bf4767151d49b0c6a9ddbc6ded2b024c3063bb8b'
5
5
  SHA512:
6
- metadata.gz: 85b45d83f40727e26a7259c4237abe4d876a4eb6edb9c73eca3764ceb3253d5220729ac4fa52ab7b03e3e9fad4fbf2efbc3d97c91a80f7f57e17704b69cc89fe
7
- data.tar.gz: 6511158e47fc47504f0143569ad435f00e45cd9cfa24a52be526bfd20f22d9f606bed14d22246fa1f0308865bebb92ad8b449dd41476fe269511011bb7ea5318
6
+ metadata.gz: 6a9f7d5b8303090de1101531ae6b9be02534c1c8d71179117ee5714238ae1ce4d067987a4a324e3a59316a95d7a613ab532c85989c4451109dc6236946be4195
7
+ data.tar.gz: 369e58fbca78c338cf6e79935037cb154ba1fd5a44385e2623d62ef8a213bb9f60a3c74035efbad066b6a6b414a06e95828702844460890d757b4b6c51fa97d7
@@ -34,5 +34,27 @@ module MyJohnDeereApi
34
34
  def archived?
35
35
  @archived
36
36
  end
37
+
38
+ ##
39
+ # flags associated with this organization
40
+
41
+ def flags
42
+ raise AccessTokenError unless accessor
43
+
44
+ return @flags if defined?(@flags)
45
+ @flags = Request::Collection::Flags.new(accessor, organization: organization_id, field: id).all
46
+ end
47
+
48
+ private
49
+
50
+ ##
51
+ # Infer the organization_id from the 'self' link
52
+
53
+ def organization_id
54
+ return @organization_id if defined?(@organization_id)
55
+
56
+ parts = links['self'].split('/')
57
+ @organization_id = parts[parts.index('organizations') + 1]
58
+ end
37
59
  end
38
60
  end
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeereApi
2
- VERSION='0.4.0'
2
+ VERSION='0.4.1'
3
3
  end
@@ -15,6 +15,9 @@ describe 'MyJohnDeereApi::Model::Field' do
15
15
  }
16
16
  end
17
17
 
18
+ let(:client) { JD::Client.new(API_KEY, API_SECRET, environment: :sandbox, access: [ACCESS_TOKEN, ACCESS_SECRET]) }
19
+ let(:accessor) { VCR.use_cassette('catalog') { client.send(:accessor) } }
20
+
18
21
  describe '#initialize' do
19
22
  def link_for label
20
23
  record['links'].detect{|link| link['rel'] == label}['uri'].gsub('https://sandboxapi.deere.com/platform', '')
@@ -45,4 +48,27 @@ describe 'MyJohnDeereApi::Model::Field' do
45
48
  assert_equal accessor, field.accessor
46
49
  end
47
50
  end
51
+
52
+ describe '#flags' do
53
+ it 'returns a collection of flags for this organization' do
54
+ accessor
55
+ organization = VCR.use_cassette('get_organizations') { client.organizations.first }
56
+ field = VCR.use_cassette('get_fields') { organization.fields.first }
57
+ flags = VCR.use_cassette('get_flags') { field.flags }
58
+
59
+ assert_kind_of Array, flags
60
+
61
+ flags.each do |flag|
62
+ assert_kind_of JD::Model::Flag, flag
63
+ end
64
+ end
65
+
66
+ it 'raises an exception if an accessor is not available' do
67
+ field = JD::Model::Field.new(record)
68
+
69
+ exception = assert_raises(JD::AccessTokenError) { field.flags }
70
+
71
+ assert_includes exception.message, 'Access Token must be supplied'
72
+ end
73
+ end
48
74
  end
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.4.0
4
+ version: 0.4.1
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-09 00:00:00.000000000 Z
11
+ date: 2020-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: vcr