myjohndeere 0.0.10 → 0.0.11
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.rb +1 -0
- data/lib/myjohndeere/file.rb +32 -0
- data/lib/myjohndeere/file_resource.rb +2 -2
- data/lib/myjohndeere/json_attributes.rb +3 -1
- data/lib/myjohndeere/version.rb +1 -1
- data/spec/fixtures.json +73 -0
- data/test/test_contribution_product.rb +1 -1
- data/test/test_file.rb +71 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1831ed7f9d5597914571ae4a25fd71625b9f99e
|
4
|
+
data.tar.gz: 4197edf1ab0d1da49e9701a068acd99c429f12a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56e08d24d21555aa5172a6f375c7c94afc29270fbffa5365ec487fbb3dc49aa34ab919687f6d052986f5965166fa6795350c2c5fbae3d85401cc56e513da670f
|
7
|
+
data.tar.gz: a13f520f6b07bf56efc54be842b00008ae033c0d076e5ff589739be54f363688be1eada9f2d9a383bc2d75a4b1025cb2f4d0acdf27ef4a396d3c8c9426f6faed
|
data/Gemfile.lock
CHANGED
data/lib/myjohndeere.rb
CHANGED
@@ -28,6 +28,7 @@ require 'myjohndeere/organization_owned_resource'
|
|
28
28
|
require 'myjohndeere/api_support_item'
|
29
29
|
require 'myjohndeere/contribution_activation'
|
30
30
|
require 'myjohndeere/contribution_product'
|
31
|
+
require 'myjohndeere/file'
|
31
32
|
|
32
33
|
# API Sub-classes
|
33
34
|
require 'myjohndeere/map_legend_item'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module MyJohnDeere
|
2
|
+
class File < OrganizationOwnedResource
|
3
|
+
self.base_jd_resource = "files"
|
4
|
+
self.list_resource_path = "organizations/%{organization_id}/#{self.base_jd_resource}"
|
5
|
+
self.retrieve_resource_path = self.base_jd_resource
|
6
|
+
attributes_to_pull_from_json(:id, :name, :type, :createdTime, :modifiedTime, :nativeSize, :source, :transferPending, :visibleViaShare, :shared, :status, :archived, :new)
|
7
|
+
|
8
|
+
def initialize(json_object, access_token = nil)
|
9
|
+
super(json_object, access_token)
|
10
|
+
end
|
11
|
+
|
12
|
+
def upload_url()
|
13
|
+
"#{MyJohnDeere.configuration.endpoint}/#{self.class.build_resource_base_path!("#{self.class.retrieve_resource_path}/#{self.id}")}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.create(access_token, organization_id, name: nil)
|
17
|
+
raise ArgumentError.new("You must pass a name for the file") if name.nil?
|
18
|
+
|
19
|
+
body = {
|
20
|
+
name: name
|
21
|
+
}
|
22
|
+
|
23
|
+
response = send_create(access_token, body, {organization_id: organization_id})
|
24
|
+
|
25
|
+
return nil if response.nil?
|
26
|
+
response.organization_id = organization_id
|
27
|
+
return response
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO: Support upload_file
|
31
|
+
end
|
32
|
+
end
|
@@ -37,10 +37,10 @@ module MyJohnDeere
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def self.upload_file(access_token, file_resource_id, file_path)
|
40
|
-
raise ArgumentError.new("You must pass an existing file") if
|
40
|
+
raise ArgumentError.new("You must pass an existing file") if !::File.exists?(file_path)
|
41
41
|
raise ArgumentError.new("You must pass a valid file_resource_id") if file_resource_id.nil?
|
42
42
|
|
43
|
-
File.open(file_path, "rb:UTF-8") do |f|
|
43
|
+
::File.open(file_path, "rb:UTF-8") do |f|
|
44
44
|
body = f.read()
|
45
45
|
response = access_token.execute_request(:put,
|
46
46
|
"#{self.base_jd_resource}/#{file_resource_id}",
|
@@ -22,7 +22,9 @@ module MyJohnDeere
|
|
22
22
|
self.class.json_attributes.each do |attrib|
|
23
23
|
attrib = attrib.to_s
|
24
24
|
val = json_data[attrib]
|
25
|
-
if
|
25
|
+
if val =~ /\A(true)|(false)\z/i then
|
26
|
+
val = /true/i.match(val) ? true : false
|
27
|
+
elsif /(date)|(timestamp)|(time\Z)/i.match(attrib) then
|
26
28
|
# try to parse it
|
27
29
|
val = Time.parse(val) rescue val
|
28
30
|
end
|
data/lib/myjohndeere/version.rb
CHANGED
data/spec/fixtures.json
CHANGED
@@ -1,4 +1,77 @@
|
|
1
1
|
{
|
2
|
+
"files" : {
|
3
|
+
"links": [
|
4
|
+
{
|
5
|
+
"rel": "self",
|
6
|
+
"uri": "https://sandboxapi.deere.com/platform/files"
|
7
|
+
},
|
8
|
+
{
|
9
|
+
"rel": "nextPage",
|
10
|
+
"uri": "https://sandboxapi.deere.com/platform/files;start=10;count=10"
|
11
|
+
}
|
12
|
+
],
|
13
|
+
"total": 1534,
|
14
|
+
"values": [
|
15
|
+
{
|
16
|
+
"links": [
|
17
|
+
{
|
18
|
+
"rel": "owningOrganization",
|
19
|
+
"uri": "https://sandboxapi.deere.com/platform/organizations/1234"
|
20
|
+
},
|
21
|
+
{
|
22
|
+
"rel": "partnerships",
|
23
|
+
"uri": "https://sandboxapi.deere.com/platform/files/466578633/partnerships"
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"rel": "self",
|
27
|
+
"uri": "https://sandboxapi.deere.com/platform/files/466578633"
|
28
|
+
}
|
29
|
+
],
|
30
|
+
"id": "577499742",
|
31
|
+
"name": "back40.zip",
|
32
|
+
"type": "SETUP",
|
33
|
+
"createdTime": "2013-01-04T14:08:51.104Z",
|
34
|
+
"modifiedTime": "2013-01-04T14:08:51.104Z",
|
35
|
+
"nativeSize": "72946",
|
36
|
+
"source": "JohnDoe",
|
37
|
+
"transferPending": "false",
|
38
|
+
"visibleViaShare": "owned",
|
39
|
+
"shared": "false",
|
40
|
+
"status": "UPLOAD_PENDING",
|
41
|
+
"archived": "false",
|
42
|
+
"new": "true"
|
43
|
+
}
|
44
|
+
]
|
45
|
+
},
|
46
|
+
"file" : {
|
47
|
+
"links": [
|
48
|
+
{
|
49
|
+
"rel": "owningOrganization",
|
50
|
+
"uri": "https://sandboxapi.deere.com/platform/organizations/1234"
|
51
|
+
},
|
52
|
+
{
|
53
|
+
"rel": "partnerships",
|
54
|
+
"uri": "https://sandboxapi.deere.com/platform/files/466578633/partnerships"
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"rel": "self",
|
58
|
+
"uri": "https://sandboxapi.deere.com/platform/files/577499742"
|
59
|
+
}
|
60
|
+
],
|
61
|
+
"id": "577499742",
|
62
|
+
"name": "back40.zip",
|
63
|
+
"type": "SETUP",
|
64
|
+
"createdTime": "2015-02-03T10:42:24.282Z",
|
65
|
+
"modifiedTime": "2015-02-03T10:42:24.282Z",
|
66
|
+
"nativeSize": "72946",
|
67
|
+
"source": "JohnDoe",
|
68
|
+
"transferPending": "false",
|
69
|
+
"visibleViaShare": "owned",
|
70
|
+
"shared": "false",
|
71
|
+
"status": "UPLOAD_PENDING",
|
72
|
+
"archived": "false",
|
73
|
+
"new": "true"
|
74
|
+
},
|
2
75
|
"contribution_products" : {
|
3
76
|
"links": [
|
4
77
|
{
|
data/test/test_file.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class TestFile < Minitest::Test
|
4
|
+
FIXTURE = API_FIXTURES.fetch("file")
|
5
|
+
FIXTURE_FOR_LIST = API_FIXTURES.fetch("files")
|
6
|
+
FILE_ID = "577499742"
|
7
|
+
ORGANIZATION_ID = "1234"
|
8
|
+
|
9
|
+
def test_retrieve()
|
10
|
+
stub_request(:get, /\/files\/#{FILE_ID}/).
|
11
|
+
to_return(status: 200, body: FIXTURE.to_json)
|
12
|
+
|
13
|
+
file = MyJohnDeere::File.retrieve(default_access_token, FILE_ID)
|
14
|
+
assert_equal "577499742", file.id
|
15
|
+
assert_equal "back40.zip", file.name
|
16
|
+
assert_equal "SETUP", file.type
|
17
|
+
assert_equal Time.parse("2015-02-03T10:42:24.282Z"), file.created_time
|
18
|
+
assert_equal Time.parse("2015-02-03T10:42:24.282Z"), file.modified_time
|
19
|
+
assert_equal "72946", file.native_size
|
20
|
+
assert_equal "JohnDoe", file.source
|
21
|
+
assert_equal false, file.transfer_pending
|
22
|
+
assert_equal "owned", file.visible_via_share
|
23
|
+
assert_equal false, file.shared
|
24
|
+
assert_equal "UPLOAD_PENDING", file.status
|
25
|
+
assert_equal false, file.archived
|
26
|
+
assert_equal true, file.new
|
27
|
+
assert_equal ORGANIZATION_ID, file.organization_id
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_list
|
31
|
+
stub_request(:get, /organizations\/#{ORGANIZATION_ID}\/files/).
|
32
|
+
to_return(status: 200, body: FIXTURE_FOR_LIST.to_json)
|
33
|
+
|
34
|
+
files = MyJohnDeere::File.list(default_access_token,
|
35
|
+
organization_id: ORGANIZATION_ID)
|
36
|
+
|
37
|
+
assert_equal 1, files.data.length
|
38
|
+
assert_equal MyJohnDeere::File, files.data[0].class
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_created_argument_checking
|
42
|
+
assert_raises ArgumentError do
|
43
|
+
MyJohnDeere::File.create(default_access_token,
|
44
|
+
ORGANIZATION_ID,
|
45
|
+
name: nil
|
46
|
+
)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_upload_url
|
51
|
+
assert_equal "https://sandboxapi.deere.com/platform/files/1234", MyJohnDeere::File.new("id" => "1234").upload_url
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_create
|
55
|
+
expected_name = "blah"
|
56
|
+
expected_body = {
|
57
|
+
name: expected_name
|
58
|
+
}.to_json
|
59
|
+
stub_request(:post, /organizations\/#{ORGANIZATION_ID}\/files/).
|
60
|
+
with(body: expected_body,
|
61
|
+
headers: {'Accept'=>'application/vnd.deere.axiom.v3+json', 'Content-Length'=>expected_body.length, 'Content-Type'=>'application/vnd.deere.axiom.v3+json'}).
|
62
|
+
to_return(status: 201, headers: {"Location"=>"https://sandboxapi.deere.com/platform/files/#{FILE_ID}"})
|
63
|
+
response = MyJohnDeere::File.create(default_access_token,
|
64
|
+
ORGANIZATION_ID,
|
65
|
+
name: expected_name
|
66
|
+
)
|
67
|
+
assert_equal FILE_ID, response.id
|
68
|
+
assert_equal ORGANIZATION_ID, response.organization_id
|
69
|
+
assert_equal "blah", response.name
|
70
|
+
end
|
71
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Susmarski
|
@@ -47,6 +47,7 @@ files:
|
|
47
47
|
- lib/myjohndeere/core_ext/string.rb
|
48
48
|
- lib/myjohndeere/errors.rb
|
49
49
|
- lib/myjohndeere/field.rb
|
50
|
+
- lib/myjohndeere/file.rb
|
50
51
|
- lib/myjohndeere/file_resource.rb
|
51
52
|
- lib/myjohndeere/hash_utils.rb
|
52
53
|
- lib/myjohndeere/json_attributes.rb
|
@@ -72,6 +73,7 @@ files:
|
|
72
73
|
- test/test_contribution_activation.rb
|
73
74
|
- test/test_contribution_product.rb
|
74
75
|
- test/test_field.rb
|
76
|
+
- test/test_file.rb
|
75
77
|
- test/test_file_resource.rb
|
76
78
|
- test/test_helper.rb
|
77
79
|
- test/test_list_object.rb
|
@@ -113,6 +115,7 @@ test_files:
|
|
113
115
|
- test/test_contribution_activation.rb
|
114
116
|
- test/test_contribution_product.rb
|
115
117
|
- test/test_field.rb
|
118
|
+
- test/test_file.rb
|
116
119
|
- test/test_file_resource.rb
|
117
120
|
- test/test_helper.rb
|
118
121
|
- test/test_list_object.rb
|