myjohndeere 0.0.6 → 0.0.7
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/myjohndeere/errors.rb +4 -0
- data/lib/myjohndeere/file_resource.rb +4 -0
- data/lib/myjohndeere/map_layer.rb +1 -0
- data/lib/myjohndeere/map_layer_summary.rb +2 -1
- data/lib/myjohndeere/rest_methods.rb +8 -0
- data/lib/myjohndeere/version.rb +1 -1
- data/spec/colored.png +0 -0
- data/test/test_file_resource.rb +11 -0
- data/test/test_map_layer_summary.rb +10 -1
- data/test/test_rest_methods.rb +11 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02a777b7787f90d5e37dc4e4b74953e95381d92d
|
4
|
+
data.tar.gz: 378a2721904af871dbd3a824cbd2bafa68589131
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53ab4da655908df5b9fba3fa956bda2485aa4e30be6a10a4793b7adf271e70449935607afa9ac82e4b8f0ce2ae70eb585e00de436e981d021f81fb144c52282b
|
7
|
+
data.tar.gz: ef1643bf28600368f5ba3abbf26411e45585813abbb0ad4ebf5284e29722c347f8caaf5a3bec309d0a79dd80c0d989c1622f31130e79d395bbc6fd2658fc7a66
|
data/Gemfile.lock
CHANGED
data/lib/myjohndeere/errors.rb
CHANGED
@@ -33,6 +33,10 @@ module MyJohnDeere
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
# You're attempting to perform a request against a resource that is unsupported
|
37
|
+
class UnsupportedRequestError < MyJohnDeereError
|
38
|
+
end
|
39
|
+
|
36
40
|
# Configuration error is raised when configuration hasn't been properly done
|
37
41
|
class ConfigurationError < MyJohnDeereError
|
38
42
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module MyJohnDeere
|
2
2
|
class FileResource < OrganizationOwnedResource
|
3
|
+
self.supports_delete = true
|
3
4
|
self.base_jd_resource = "fileResources"
|
4
5
|
self.list_resource_path = "mapLayers/%{map_layer_id}/#{self.base_jd_resource}"
|
5
6
|
self.retrieve_resource_path = self.base_jd_resource
|
@@ -36,6 +37,9 @@ module MyJohnDeere
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def self.upload_file(access_token, file_resource_id, file_path)
|
40
|
+
raise ArgumentError.new("You must pass an existing file") if !File.exists?(file_path)
|
41
|
+
raise ArgumentError.new("You must pass a valid file_resource_id") if file_resource_id.nil?
|
42
|
+
|
39
43
|
File.open(file_path, "rb:UTF-8") do |f|
|
40
44
|
body = f.read()
|
41
45
|
response = access_token.execute_request(:put,
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module MyJohnDeere
|
2
2
|
class MapLayer < OrganizationOwnedResource
|
3
|
+
self.supports_delete = true
|
3
4
|
self.base_jd_resource = "mapLayers"
|
4
5
|
self.list_resource_path = "mapLayerSummaries/%{map_layer_summary_id}/#{self.base_jd_resource}"
|
5
6
|
self.retrieve_resource_path = self.base_jd_resource
|
@@ -1,5 +1,6 @@
|
|
1
1
|
module MyJohnDeere
|
2
2
|
class MapLayerSummary < OrganizationOwnedResource
|
3
|
+
self.supports_delete = true
|
3
4
|
self.base_jd_resource = "mapLayerSummaries"
|
4
5
|
self.list_resource_path = "organizations/%{organization_id}/fields/%{field_id}/#{self.base_jd_resource}"
|
5
6
|
self.retrieve_resource_path = self.base_jd_resource
|
@@ -18,7 +19,7 @@ module MyJohnDeere
|
|
18
19
|
owning_organization_link_item(organization_id),
|
19
20
|
{
|
20
21
|
rel: "contributionDefinition",
|
21
|
-
uri: "#{MyJohnDeere.configuration.endpoint}/#{MyJohnDeere.configuration.contribution_definition_id}"
|
22
|
+
uri: "#{MyJohnDeere.configuration.endpoint}/contributionDefinitions/#{MyJohnDeere.configuration.contribution_definition_id}"
|
22
23
|
}
|
23
24
|
],
|
24
25
|
metadata: metadata.map { |md| md.to_hash },
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module MyJohnDeere
|
2
2
|
module RESTMethods
|
3
3
|
module ClassMethods
|
4
|
+
attr_accessor :supports_delete
|
4
5
|
attr_accessor :base_jd_resource
|
5
6
|
attr_accessor :retrieve_resource_path
|
6
7
|
attr_accessor :list_resource_path
|
@@ -37,6 +38,13 @@ module MyJohnDeere
|
|
37
38
|
return new(response.data, access_token)
|
38
39
|
end
|
39
40
|
|
41
|
+
def delete(access_token, id)
|
42
|
+
raise UnsupportedRequestError.new("Delete is not supported by this resource") if !self.supports_delete
|
43
|
+
|
44
|
+
response = access_token.execute_request(:delete, "#{self.base_jd_resource}/#{id}")
|
45
|
+
return response.code == 204
|
46
|
+
end
|
47
|
+
|
40
48
|
def build_resource_base_path!(resource_path, options = {})
|
41
49
|
expected_definitions = resource_path.scan(/%{(.+?)}/)
|
42
50
|
return resource_path if expected_definitions.empty?
|
data/lib/myjohndeere/version.rb
CHANGED
data/spec/colored.png
ADDED
Binary file
|
data/test/test_file_resource.rb
CHANGED
@@ -74,4 +74,15 @@ class TestFileResource < Minitest::Test
|
|
74
74
|
assert_equal FILE_RESOURCE_ID, response.id
|
75
75
|
assert_equal ORGANIZATION_ID, response.organization_id
|
76
76
|
end
|
77
|
+
|
78
|
+
def test_upload_file
|
79
|
+
stub_request(:put, /fileResources\/#{FILE_RESOURCE_ID}/).
|
80
|
+
with(headers: {'Content-Length'=>'4407', 'Content-Type'=>'application/octet-stream'}).
|
81
|
+
to_return(status: 204)
|
82
|
+
|
83
|
+
success = MyJohnDeere::FileResource.upload_file(default_access_token, FILE_RESOURCE_ID,
|
84
|
+
"#{PROJECT_ROOT}/spec/colored.png")
|
85
|
+
|
86
|
+
assert success
|
87
|
+
end
|
77
88
|
end
|
@@ -33,7 +33,16 @@ class TestMapLayerSummary < Minitest::Test
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_create
|
36
|
-
expected_body =
|
36
|
+
expected_body = {"title"=>"Test number 2",
|
37
|
+
"text"=>"Hello from farm lens again",
|
38
|
+
"links"=>
|
39
|
+
[{"rel"=>"owningOrganization",
|
40
|
+
"uri"=>"https://sandboxapi.deere.com/platform/organizations/1234"},
|
41
|
+
{"rel"=>"contributionDefinition",
|
42
|
+
"uri"=>
|
43
|
+
"https://sandboxapi.deere.com/platform/contributionDefinitions/foobar"}],
|
44
|
+
"metadata"=>[{"key"=>"key", "value"=>"val"}],
|
45
|
+
"dateCreated"=>"2016-01-02T16:14:23.421Z"}.to_json
|
37
46
|
stub_request(:post, /\/organizations\/#{ORGANIZATION_ID}\/fields\/#{FIELD_ID}\/mapLayerSummaries/).
|
38
47
|
with(body: expected_body,
|
39
48
|
headers: {'Accept'=>'application/vnd.deere.axiom.v3+json', 'Content-Length'=>expected_body.length, 'Content-Type'=>'application/vnd.deere.axiom.v3+json'}).
|
data/test/test_rest_methods.rb
CHANGED
@@ -14,6 +14,17 @@ class TestRestMethods < Minitest::Test
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
def test_delete
|
18
|
+
stub_request(:delete, /mapLayerSummaries/).
|
19
|
+
to_return(status: 204)
|
20
|
+
|
21
|
+
assert MyJohnDeere::MapLayerSummary.delete(default_access_token, "foobar")
|
22
|
+
|
23
|
+
assert_raises MyJohnDeere::UnsupportedRequestError do
|
24
|
+
MyJohnDeere::Organization.delete(default_access_token, "foobar")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
17
28
|
def test_list_with_etag
|
18
29
|
stub_request(:get, /organizations/).
|
19
30
|
with(headers: {MyJohnDeere::ETAG_HEADER_KEY => ""}).
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myjohndeere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Susmarski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/myjohndeere/util.rb
|
63
63
|
- lib/myjohndeere/version.rb
|
64
64
|
- myjohndeere.gemspec
|
65
|
+
- spec/colored.png
|
65
66
|
- spec/fixtures.json
|
66
67
|
- test/api_fixtures.rb
|
67
68
|
- test/test_access_token.rb
|