myjohndeere 0.0.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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +52 -0
  3. data/Gemfile +16 -0
  4. data/Gemfile.lock +37 -0
  5. data/LICENSE +21 -0
  6. data/README.md +109 -0
  7. data/Rakefile +8 -0
  8. data/lib/myjohndeere.rb +132 -0
  9. data/lib/myjohndeere/access_token.rb +79 -0
  10. data/lib/myjohndeere/api_support_item.rb +27 -0
  11. data/lib/myjohndeere/boundary.rb +18 -0
  12. data/lib/myjohndeere/core_ext/string.rb +9 -0
  13. data/lib/myjohndeere/errors.rb +10 -0
  14. data/lib/myjohndeere/field.rb +28 -0
  15. data/lib/myjohndeere/file_resource.rb +61 -0
  16. data/lib/myjohndeere/hash_utils.rb +33 -0
  17. data/lib/myjohndeere/json_attributes.rb +39 -0
  18. data/lib/myjohndeere/list_object.rb +94 -0
  19. data/lib/myjohndeere/map_layer.rb +41 -0
  20. data/lib/myjohndeere/map_layer_summary.rb +40 -0
  21. data/lib/myjohndeere/map_legend_item.rb +10 -0
  22. data/lib/myjohndeere/metadata_item.rb +8 -0
  23. data/lib/myjohndeere/organization.rb +16 -0
  24. data/lib/myjohndeere/organization_owned_resource.rb +17 -0
  25. data/lib/myjohndeere/requestable.rb +36 -0
  26. data/lib/myjohndeere/response.rb +31 -0
  27. data/lib/myjohndeere/rest_methods.rb +64 -0
  28. data/lib/myjohndeere/single_resource.rb +13 -0
  29. data/lib/myjohndeere/util.rb +54 -0
  30. data/lib/myjohndeere/version.rb +3 -0
  31. data/myjohndeere.gemspec +23 -0
  32. data/spec/fixtures.json +778 -0
  33. data/test/api_fixtures.rb +29 -0
  34. data/test/test_access_token.rb +60 -0
  35. data/test/test_boundary.rb +37 -0
  36. data/test/test_field.rb +47 -0
  37. data/test/test_file_resource.rb +48 -0
  38. data/test/test_helper.rb +36 -0
  39. data/test/test_list_object.rb +74 -0
  40. data/test/test_map_layer.rb +52 -0
  41. data/test/test_map_layer_summary.rb +52 -0
  42. data/test/test_myjohndeere.rb +56 -0
  43. data/test/test_organization.rb +42 -0
  44. data/test/test_requestable.rb +15 -0
  45. data/test/test_rest_methods.rb +34 -0
  46. data/test/test_util.rb +86 -0
  47. metadata +118 -0
@@ -0,0 +1,56 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class TestMyJohnDeere < Minitest::Test
4
+ def test_uninitialized_configuration
5
+ MyJohnDeere.configuration = MyJohnDeere::Configuration.new
6
+ assert_raises MyJohnDeere::ConfigurationError do
7
+ MyJohnDeere.configuration.app_id
8
+ end
9
+ MyJohnDeere.configuration.app_id = "blah"
10
+ assert_equal "blah", MyJohnDeere.configuration.app_id
11
+
12
+ assert_raises MyJohnDeere::ConfigurationError do
13
+ MyJohnDeere.configuration.shared_secret
14
+ end
15
+
16
+ MyJohnDeere.configuration.shared_secret = "blah"
17
+ assert_equal "blah", MyJohnDeere.configuration.shared_secret
18
+
19
+ MyJohnDeere.configuration.contribution_definition_id = nil
20
+ assert_raises MyJohnDeere::ConfigurationError do
21
+ MyJohnDeere.configuration.contribution_definition_id
22
+ end
23
+
24
+ MyJohnDeere.configuration.contribution_definition_id = "something"
25
+ assert_equal "something", MyJohnDeere.configuration.contribution_definition_id
26
+ end
27
+
28
+ def test_endpoint_setting
29
+ MyJohnDeere.configuration = MyJohnDeere::Configuration.new
30
+ assert_equal :sandbox, MyJohnDeere.configuration.environment
31
+ assert_equal MyJohnDeere::ENDPOINTS[:sandbox], MyJohnDeere.configuration.endpoint
32
+
33
+ assert_raises MyJohnDeere::ConfigurationError do
34
+ MyJohnDeere.configuration.environment = :bar
35
+ end
36
+
37
+ MyJohnDeere.configuration.environment = "sandbox"
38
+ assert_equal :sandbox, MyJohnDeere.configuration.environment
39
+ assert_equal MyJohnDeere::ENDPOINTS[:sandbox], MyJohnDeere.configuration.endpoint
40
+
41
+ MyJohnDeere.configuration.environment = :production
42
+ assert_equal :production, MyJohnDeere.configuration.environment
43
+ assert_equal MyJohnDeere::ENDPOINTS[:production], MyJohnDeere.configuration.endpoint
44
+ end
45
+
46
+ def test_logger_setup
47
+ assert MyJohnDeere.logger.is_a?(Logger)
48
+ assert_equal Logger::FATAL, MyJohnDeere.logger.level
49
+
50
+ MyJohnDeere.configure do |config|
51
+ config.log_level = :warn
52
+ end
53
+
54
+ assert_equal Logger::WARN, MyJohnDeere.logger.level
55
+ end
56
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class TestOrganization < Minitest::Test
4
+ FIXTURE = API_FIXTURES.fetch("organization")
5
+ FIXTURE_FOR_LIST = API_FIXTURES.fetch("organizations")
6
+
7
+ def test_retrieve()
8
+ stub_request(:get, /organizations/).
9
+ to_return(status: 200, body: FIXTURE.to_json)
10
+
11
+ organization = MyJohnDeere::Organization.retrieve(default_access_token, FIXTURE[:id])
12
+
13
+ assert_equal "1234", organization.id
14
+ assert_equal "Smith Farms", organization.name
15
+ assert_equal "customer", organization.type
16
+ assert_equal true, organization.member
17
+ assert_equal FIXTURE["links"].length, organization.links.length
18
+ assert organization.access_token
19
+ end
20
+
21
+ def test_list()
22
+ stub_request(:get, /organizations;start=0;count=1/).
23
+ to_return(status: 200, body: FIXTURE_FOR_LIST.to_json)
24
+
25
+ organizations = MyJohnDeere::Organization.list(default_access_token, count: 1)
26
+
27
+ assert_equal 1, organizations.data.length
28
+ assert_equal MyJohnDeere::Organization, organizations.data[0].class
29
+ assert_equal 2, organizations.links.length
30
+ end
31
+
32
+ def test_fields()
33
+ organization = MyJohnDeere::Organization.new(FIXTURE, default_access_token)
34
+
35
+ stub_request(:get, /organizations\/#{organization.id}\/fields/).
36
+ to_return(status: 200, body: API_FIXTURES["fields"].to_json)
37
+ fields = organization.fields
38
+
39
+ assert_equal MyJohnDeere::ListObject, fields.class
40
+ assert_equal MyJohnDeere::Field, fields.data[0].class
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class TestAccessToken < Minitest::Test
4
+ def test_initialization
5
+ assert MyJohnDeere::Requestable.new()
6
+
7
+ expected_object = default_access_token()
8
+ requestable = MyJohnDeere::Requestable.new({}, expected_object)
9
+ assert_equal expected_object, requestable.access_token
10
+
11
+ assert_raises ArgumentError do
12
+ MyJohnDeere::Requestable.new({}, "something")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class TestRestMethods < Minitest::Test
4
+ LIST_FIXTURE = API_FIXTURES["organizations"]
5
+ def test_argument_validation_on_list()
6
+ assert_raises ArgumentError do
7
+ MyJohnDeere::Organization.list(nil, count: 1)
8
+ end
9
+ end
10
+
11
+ def test_argument_validation_on_retrieve
12
+ assert_raises ArgumentError do
13
+ MyJohnDeere::Organization.retrieve(nil, 1234)
14
+ end
15
+ end
16
+
17
+ def test_list_with_etag
18
+ stub_request(:get, /organizations/).
19
+ with(headers: {MyJohnDeere::ETAG_HEADER_KEY => ""}).
20
+ to_return(status: 200, body: LIST_FIXTURE.to_json(), headers: {MyJohnDeere::ETAG_HEADER_KEY=>"something"})
21
+
22
+ organizations = MyJohnDeere::Organization.list(default_access_token, count: 1, etag: "")
23
+
24
+ assert_equal "something", organizations.etag
25
+ end
26
+
27
+ def test_list_with_body
28
+ stub_request(:get, /organizations;start=0;count=1/).
29
+ with(query: {embed: "boundaries"}).
30
+ to_return(status: 200, body: LIST_FIXTURE.to_json())
31
+ organizations = MyJohnDeere::Organization.list(default_access_token, count: 1, etag: "", body: {embed: "boundaries"})
32
+ assert_equal({:embed=>"boundaries"}, organizations.options[:body])
33
+ end
34
+ end
data/test/test_util.rb ADDED
@@ -0,0 +1,86 @@
1
+ require File.expand_path('../test_helper', __FILE__)
2
+
3
+ class TestUtil < Minitest::Test
4
+ def test_build_url_get_method_behavior
5
+ expected_path = "/organizations?something=1"
6
+ expected_headers = {"accept"=>"application/vnd.deere.axiom.v3+json", "blah"=>"1"}
7
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:get, "organizations",
8
+ headers: {"blah" => "1"}, body: {"something" => 1},
9
+ etag: nil)
10
+
11
+ assert_equal expected_path, path,
12
+ "Should have put the body in the path and a leading slash"
13
+ assert_equal expected_headers, headers,
14
+ "Should have put our header in and the default request header"
15
+
16
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:get, "/organizations",
17
+ headers: {"blah" => "1"}, body: {"something" => 1},
18
+ etag: nil)
19
+
20
+ expected_headers["X-Deere-Signature"] = ""
21
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:get, "/organizations",
22
+ headers: {"blah" => "1"}, body: {"something" => 1},
23
+ etag: "")
24
+ assert_equal expected_path, path
25
+ assert_equal expected_headers, headers,
26
+ "We used a blank string for the etag indicating we want the behavior"
27
+
28
+ expected_path = "/organizations;start=10;count=10?something=1"
29
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:get, "/organizations",
30
+ headers: {"blah" => "1"}, body: {"something" => 1, count: 10, start: 10},
31
+ etag: "")
32
+ assert_equal expected_path, path, "Should put the start and count in the path"
33
+
34
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:get, "/organizations;start=10",
35
+ headers: {"blah" => "1"}, body: {"something" => 1, start: 10, count: 10},
36
+ etag: "")
37
+ assert_equal expected_path, path, "Shouldn't add extra start since we have it already"
38
+ end
39
+
40
+ def test_etag_with_blank_body
41
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:get, "test", etag: "", body: "")
42
+ assert path
43
+ assert body
44
+ assert_equal({"accept"=>"application/vnd.deere.axiom.v3+json", "X-Deere-Signature"=>""}, headers)
45
+ end
46
+
47
+ def test_url_cleanup
48
+ expected_path = "/organizations"
49
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:get, expected_path)
50
+ assert_equal expected_path, path, "Shouldn't care about the leading slash"
51
+ assert_equal({"accept"=>"application/vnd.deere.axiom.v3+json"}, headers,
52
+ "Headers should just be the default request headers")
53
+
54
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:get, "platform/organizations")
55
+ assert_equal expected_path, path, "Shouldn't care about the leading platform"
56
+
57
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:get, "#{MyJohnDeere.configuration.endpoint}/organizations")
58
+ assert_equal expected_path, path, "Should remove the extra uri at the front since we probably pulled from a link object in the json"
59
+ end
60
+
61
+ def test_post_setup
62
+ expected_headers = {"accept"=>"application/vnd.deere.axiom.v3+json", "Content-Type"=>"application/vnd.deere.axiom.v3+json", "blah"=>"1"}
63
+ input_header = {"blah" => "1"}
64
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:post, "/organizations",
65
+ headers: input_header)
66
+ assert_equal "/organizations", path, "Shouldn't do anything to the path"
67
+ assert_equal expected_headers, headers, "Shouldn't have anything about content_length"
68
+ assert_equal "", body, "Should be an empty body"
69
+
70
+ expected_body = {"something" => 1}
71
+ expected_headers["Content-Length"] = expected_body.to_json.length.to_s
72
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:post, "/organizations",
73
+ headers: input_header, body: expected_body)
74
+ assert_equal "/organizations", path, "Shouldn't do anything to the path"
75
+ assert_equal expected_headers, headers, "should now include the content_length"
76
+ assert JSON.parse(body), "The body should be JSON parsable"
77
+
78
+ expected_body = {"something" => 1}.to_json
79
+ expected_headers["Content-Length"] = expected_body.length.to_s
80
+ path, headers, body = MyJohnDeere::Util.build_path_headers_and_body(:post, "/organizations",
81
+ headers: input_header, body: expected_body)
82
+ assert_equal "/organizations", path, "Shouldn't do anything to the path"
83
+ assert_equal expected_headers, headers, "Shouldn't have anything about content_length"
84
+ assert JSON.parse(body), "The body should be JSON parsable and should be ready to go since we did the json conversion"
85
+ end
86
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: myjohndeere
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Susmarski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.3
27
+ description: ' MyJohnDeere is used to make data-driven decisions to maximize your
28
+ return on every acre. This Ruby Gem is provided as a convenient way to access their
29
+ API.'
30
+ email: paul@susmarski.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - Gemfile
37
+ - Gemfile.lock
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - lib/myjohndeere.rb
42
+ - lib/myjohndeere/access_token.rb
43
+ - lib/myjohndeere/api_support_item.rb
44
+ - lib/myjohndeere/boundary.rb
45
+ - lib/myjohndeere/core_ext/string.rb
46
+ - lib/myjohndeere/errors.rb
47
+ - lib/myjohndeere/field.rb
48
+ - lib/myjohndeere/file_resource.rb
49
+ - lib/myjohndeere/hash_utils.rb
50
+ - lib/myjohndeere/json_attributes.rb
51
+ - lib/myjohndeere/list_object.rb
52
+ - lib/myjohndeere/map_layer.rb
53
+ - lib/myjohndeere/map_layer_summary.rb
54
+ - lib/myjohndeere/map_legend_item.rb
55
+ - lib/myjohndeere/metadata_item.rb
56
+ - lib/myjohndeere/organization.rb
57
+ - lib/myjohndeere/organization_owned_resource.rb
58
+ - lib/myjohndeere/requestable.rb
59
+ - lib/myjohndeere/response.rb
60
+ - lib/myjohndeere/rest_methods.rb
61
+ - lib/myjohndeere/single_resource.rb
62
+ - lib/myjohndeere/util.rb
63
+ - lib/myjohndeere/version.rb
64
+ - myjohndeere.gemspec
65
+ - spec/fixtures.json
66
+ - test/api_fixtures.rb
67
+ - test/test_access_token.rb
68
+ - test/test_boundary.rb
69
+ - test/test_field.rb
70
+ - test/test_file_resource.rb
71
+ - test/test_helper.rb
72
+ - test/test_list_object.rb
73
+ - test/test_map_layer.rb
74
+ - test/test_map_layer_summary.rb
75
+ - test/test_myjohndeere.rb
76
+ - test/test_organization.rb
77
+ - test/test_requestable.rb
78
+ - test/test_rest_methods.rb
79
+ - test/test_util.rb
80
+ homepage: http://rubygems.org/gems/myjohndeere
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: 1.9.3
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.0.14.1
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Ruby bindings for the MyJohnDeere API
104
+ test_files:
105
+ - test/api_fixtures.rb
106
+ - test/test_access_token.rb
107
+ - test/test_boundary.rb
108
+ - test/test_field.rb
109
+ - test/test_file_resource.rb
110
+ - test/test_helper.rb
111
+ - test/test_list_object.rb
112
+ - test/test_map_layer.rb
113
+ - test/test_map_layer_summary.rb
114
+ - test/test_myjohndeere.rb
115
+ - test/test_organization.rb
116
+ - test/test_requestable.rb
117
+ - test/test_rest_methods.rb
118
+ - test/test_util.rb