artemis_api 0.4.0 → 0.5.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 +5 -5
- data/Gemfile.lock +9 -9
- data/History.txt +6 -0
- data/README.md +6 -4
- data/artemis_api.gemspec +3 -2
- data/lib/artemis_api.rb +1 -0
- data/lib/artemis_api/batch.rb +2 -2
- data/lib/artemis_api/facility.rb +8 -0
- data/lib/artemis_api/resource_unit.rb +13 -0
- data/lib/artemis_api/version.rb +1 -1
- data/test/batch_test.rb +2 -3
- data/test/completion_test.rb +7 -1
- data/test/resource_unit_test.rb +24 -0
- metadata +21 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d26e2f48257f9de7ae7ce3d4b23ea245fdc7d3408a1467bd09b279275240523d
|
4
|
+
data.tar.gz: 673cd71c200ec4f0bdf793b70df3e5075b16a0b37e1ad8f3d008ba3d6deed0a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 914e649b5638e024bff44c404daf3c19c0fe4b02e17ec2829b9bbe2057c8e396f48c2a4923af5774cdaacd5473e3c85f16cb88414f6e5fa8ed9a543089d16598
|
7
|
+
data.tar.gz: 78e811dc747f089a520f6cf39b4c8fe080a035fcb285e9b048538b614bbbce3a9099fd98763694f8946b7318896a6ade38408ab171da34a1323cbf2424f6c399
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
artemis_api (0.
|
4
|
+
artemis_api (0.5.1)
|
5
|
+
oauth2
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -16,25 +17,25 @@ GEM
|
|
16
17
|
concurrent-ruby (1.1.5)
|
17
18
|
crack (0.4.3)
|
18
19
|
safe_yaml (~> 1.0.0)
|
19
|
-
faraday (0.
|
20
|
+
faraday (1.0.1)
|
20
21
|
multipart-post (>= 1.2, < 3)
|
21
22
|
hashdiff (0.4.0)
|
22
23
|
i18n (1.6.0)
|
23
24
|
concurrent-ruby (~> 1.0)
|
24
25
|
jwt (2.2.1)
|
25
26
|
minitest (5.11.3)
|
26
|
-
multi_json (1.
|
27
|
+
multi_json (1.14.1)
|
27
28
|
multi_xml (0.6.0)
|
28
29
|
multipart-post (2.1.1)
|
29
|
-
oauth2 (1.4.
|
30
|
-
faraday (>= 0.8, <
|
30
|
+
oauth2 (1.4.4)
|
31
|
+
faraday (>= 0.8, < 2.0)
|
31
32
|
jwt (>= 1.0, < 3.0)
|
32
33
|
multi_json (~> 1.3)
|
33
34
|
multi_xml (~> 0.5)
|
34
35
|
rack (>= 1.2, < 3)
|
35
36
|
public_suffix (3.1.1)
|
36
|
-
rack (2.
|
37
|
-
rake (
|
37
|
+
rack (2.2.2)
|
38
|
+
rake (13.0.1)
|
38
39
|
safe_yaml (1.0.5)
|
39
40
|
thread_safe (0.3.6)
|
40
41
|
tzinfo (1.2.5)
|
@@ -52,8 +53,7 @@ DEPENDENCIES
|
|
52
53
|
artemis_api!
|
53
54
|
bundler (~> 1.16)
|
54
55
|
minitest (~> 5.0)
|
55
|
-
|
56
|
-
rake (~> 10.0)
|
56
|
+
rake (~> 13.0)
|
57
57
|
webmock
|
58
58
|
|
59
59
|
BUNDLED WITH
|
data/History.txt
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# coding: UTF-8
|
2
2
|
|
3
|
+
=== 0.4.0 / 2019-11-14
|
4
|
+
|
5
|
+
* Added pagination functionality to Batch queries
|
6
|
+
* Cleaned up filtering and added tests
|
7
|
+
* Documentation updates
|
8
|
+
|
3
9
|
=== 0.3.0 / 2019-11-04
|
4
10
|
|
5
11
|
* Added an alternative OAuth flow that can accept an authorization code
|
data/README.md
CHANGED
@@ -56,15 +56,17 @@ client = ArtemisApi::Client.new(access_token: 'your_access_token',
|
|
56
56
|
expires_at: token_expires_at)
|
57
57
|
```
|
58
58
|
|
59
|
-
Alternatively, if you're working on a command line tool or otherwise not intending to implement a full OAuth flow, you can generate an authorization code directly and
|
59
|
+
Alternatively, if you're working on a command line tool or otherwise not intending to implement a full OAuth flow, you can generate an authorization code directly and use this code to obtain an access token and a refresh token.
|
60
|
+
Do this by creating an OAuth application in your Artemis settings with `urn:ietf:wg:oauth:2.0:oob` as the callback url. Then, clicking the Authorize button directly on Artemis Portal beside it on your application show page will
|
61
|
+
provide you directly with an authorization code. Pass it into the Client instantiator like this. (The same rules apply about either passing in options or setting your ENV variables.)
|
60
62
|
|
61
63
|
```ruby
|
62
64
|
client = ArtemisApi::Client.new(auth_code: 'your_generated_authorization_code')
|
63
65
|
```
|
64
66
|
|
65
|
-
This
|
66
|
-
|
67
|
-
|
67
|
+
This authorization code is only valid for one use. If you want to keep connecting using the same authorization grant, you
|
68
|
+
need to save the values of `client.access_token`, `client.refresh_token` and `client.expires_at` and use them when
|
69
|
+
reinstantiating `client` in the future.
|
68
70
|
|
69
71
|
#### Requesting data from Artemis
|
70
72
|
|
data/artemis_api.gemspec
CHANGED
@@ -21,10 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
+
spec.add_dependency "oauth2"
|
25
|
+
|
24
26
|
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
-
spec.add_development_dependency "rake", "~>
|
27
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
26
28
|
spec.add_development_dependency "minitest", "~> 5.0"
|
27
|
-
spec.add_development_dependency "oauth2"
|
28
29
|
spec.add_development_dependency "webmock"
|
29
30
|
spec.add_development_dependency "activesupport"
|
30
31
|
end
|
data/lib/artemis_api.rb
CHANGED
data/lib/artemis_api/batch.rb
CHANGED
@@ -13,11 +13,11 @@ module ArtemisApi
|
|
13
13
|
client.find_all(self.json_type, facility_id: facility_id, include: include, filters: filters, page: page)
|
14
14
|
end
|
15
15
|
|
16
|
-
def completions(include: nil)
|
16
|
+
def completions(include: nil, filters: {})
|
17
17
|
ArtemisApi::Completion.find_all(facility_id: facility_id,
|
18
18
|
client: client,
|
19
19
|
include: include,
|
20
|
-
filters: {crop_batch_ids: [id]})
|
20
|
+
filters: {crop_batch_ids: [id]}.with_indifferent_access.merge(filters))
|
21
21
|
end
|
22
22
|
|
23
23
|
def completion(completion_id, include: nil)
|
data/lib/artemis_api/facility.rb
CHANGED
@@ -42,6 +42,14 @@ module ArtemisApi
|
|
42
42
|
ArtemisApi::SeedingUnit.find(id: unit_id, facility_id: id, client: client, include: include)
|
43
43
|
end
|
44
44
|
|
45
|
+
def resource_units(include: nil)
|
46
|
+
ArtemisApi::ResourceUnit.find_all(facility_id: id, client: client, include: include)
|
47
|
+
end
|
48
|
+
|
49
|
+
def resource_unit(unit_id, include: nil)
|
50
|
+
ArtemisApi::ResourceUnit.find(id: unit_id, facility_id: id, client: client, include: include)
|
51
|
+
end
|
52
|
+
|
45
53
|
def harvest_units(include: nil)
|
46
54
|
ArtemisApi::HarvestUnit.find_all(facility_id: id, client: client, include: include)
|
47
55
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ArtemisApi
|
2
|
+
class ResourceUnit < ArtemisApi::Model
|
3
|
+
json_type 'resource_units'
|
4
|
+
|
5
|
+
def self.find(id:, facility_id:, client:, include: nil, force: false)
|
6
|
+
client.find_one(self.json_type, id, facility_id: facility_id, include: include, force: force)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.find_all(facility_id:, client:, include: nil)
|
10
|
+
client.find_all(self.json_type, facility_id: facility_id, include: include)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/artemis_api/version.rb
CHANGED
data/test/batch_test.rb
CHANGED
@@ -80,9 +80,8 @@ class BatchTest < Minitest::Test
|
|
80
80
|
beginning = ending - 15.days
|
81
81
|
date_window = [beginning, ending].join(',')
|
82
82
|
|
83
|
-
|
84
|
-
|
85
|
-
.to_return(body: {data: [{id: '1', type: 'batches', attributes: {id: 1, arbitrary_id: 'Oct16-Gem-Let'}}, {id: '2', type: 'batches', attributes: {id: 2, name: 'Oct19-Bok-Cho'}}]}.to_json)
|
83
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/batches?filter[date_type]=seeded_at&filter[date_window]=#{CGI.escape(date_window)}")
|
84
|
+
.to_return(body: {data: [{id: 'd1', type: 'batches', attributes: {id: 1, arbitrary_id: 'Oct16-Gem-Let'}}, {id: '2', type: 'batches', attributes: {id: 2, name: 'Oct19-Bok-Cho'}}]}.to_json)
|
86
85
|
|
87
86
|
batches = ArtemisApi::Batch.find_all(facility_id: @facility.id, client: @client, filters: {date_type: "seeded_at", date_window: date_window})
|
88
87
|
assert_equal 2, batches.count
|
data/test/completion_test.rb
CHANGED
@@ -9,10 +9,16 @@ class CompletionTest < Minitest::Test
|
|
9
9
|
.to_return(body: {data: [{id: '1', type: 'completions', attributes: {id: 1, action_type: 'start'}}, {id: '2', type: 'completions', attributes: {id: 2, action_type: 'move'}}]}.to_json)
|
10
10
|
|
11
11
|
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/completions/2")
|
12
|
-
.to_return(body: {data: {id: '2', type: 'completions', attributes: {id: 2, action_type: 'move'}}}.to_json)
|
12
|
+
.to_return(body: {data: {id: '2', type: 'completions', attributes: {id: 2, action_type: 'move'}, relationships: { batch: { data: { id: 1, type: 'batches' }}}}}.to_json)
|
13
|
+
|
14
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/completions/2")
|
15
|
+
.to_return(body: {data: {id: '2', type: 'completions', attributes: {id: 2, action_type: 'move'}, relationships: { batch: { data: { id: 1, type: 'batches' }}}}}.to_json)
|
13
16
|
|
14
17
|
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/completions?filter[crop_batch_ids][]=2&filter[crop_batch_ids][]=3")
|
15
18
|
.to_return(body: {data: [{id: '1', type: 'completions', attributes: {id: 1, action_type: 'start'}}]}.to_json)
|
19
|
+
|
20
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/completions?filter[parent_id]=2")
|
21
|
+
.to_return(body: {data: [{id: '3', type: 'completions', attributes: {id: 3, action_type: 'process'}}, {id: '4', type: 'completions', attributes: {id: 4, action_type: 'process'}}]}.to_json)
|
16
22
|
end
|
17
23
|
|
18
24
|
def test_finding_all_completions
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class ResourceUnitTest < Minitest::Test
|
4
|
+
def setup
|
5
|
+
get_client
|
6
|
+
get_facility
|
7
|
+
|
8
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/resource_units")
|
9
|
+
.to_return(body: {data: [{id: '1', type: 'resource_units', attributes: {id: 1, name: 'Bunch', kind: 'count', conversion_si: 1.0}}, {id: '2', type: 'resource_units', attributes: {id: 2, name: 'grams', kind: 'weight', conversion_si: 1.0}}]}.to_json)
|
10
|
+
|
11
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/resource_units/2")
|
12
|
+
.to_return(body: {data: {id: '2', type: 'resource_units', attributes: {id: 2, name: 'grams', kind: 'weight', conversion_is: 1.0}}}.to_json)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_finding_all_resource_units
|
16
|
+
resource_units = ArtemisApi::ResourceUnit.find_all(facility_id: @facility.id, client: @client)
|
17
|
+
assert_equal 2, resource_units.count
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_finding_a_specific_resource_unit
|
21
|
+
resource_unit = ArtemisApi::ResourceUnit.find(id: 2, facility_id: @facility.id, client: @client)
|
22
|
+
assert_equal 'grams', resource_unit.name
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artemis_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamey Hampton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oauth2
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,14 +44,14 @@ dependencies:
|
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '13.0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '13.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: minitest
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,20 +66,6 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '5.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: oauth2
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: webmock
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/artemis_api/item.rb
|
125
125
|
- lib/artemis_api/model.rb
|
126
126
|
- lib/artemis_api/organization.rb
|
127
|
+
- lib/artemis_api/resource_unit.rb
|
127
128
|
- lib/artemis_api/seeding_unit.rb
|
128
129
|
- lib/artemis_api/subscription.rb
|
129
130
|
- lib/artemis_api/user.rb
|
@@ -139,6 +140,7 @@ files:
|
|
139
140
|
- test/harvest_unit_test.rb
|
140
141
|
- test/item_test.rb
|
141
142
|
- test/organization_test.rb
|
143
|
+
- test/resource_unit_test.rb
|
142
144
|
- test/seeding_unit_test.rb
|
143
145
|
- test/subscription_test.rb
|
144
146
|
- test/test_helper.rb
|
@@ -163,8 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
165
|
- !ruby/object:Gem::Version
|
164
166
|
version: '0'
|
165
167
|
requirements: []
|
166
|
-
|
167
|
-
rubygems_version: 2.5.1
|
168
|
+
rubygems_version: 3.0.3
|
168
169
|
signing_key:
|
169
170
|
specification_version: 4
|
170
171
|
summary: An API wrapper for the ArtemisAg API
|