artemis_api 0.3.0 → 0.4.0
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/README.md +9 -1
- data/lib/artemis_api/batch.rb +2 -2
- data/lib/artemis_api/client.rb +8 -1
- data/lib/artemis_api/subscription.rb +2 -2
- data/lib/artemis_api/version.rb +1 -1
- data/test/batch_test.rb +37 -0
- data/test/completion_test.rb +8 -0
- data/test/discard_test.rb +8 -0
- data/test/zone_test.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ddb2f3f02a23e8af40bb40ac71a3ce9a5a6c37e
|
4
|
+
data.tar.gz: 1e63ef8698d8bed206674ff165a82f7fe404a64d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a50bcb4e50699bd837c933bbea113b33454ec61a00233c6ae5e204bf7a5f4cbd00cb4d1225537da8df8d65a382d1704c73fb9ac4571763f1c9e8314a4b29d7d1
|
7
|
+
data.tar.gz: 3a1d56165f91ac90ed852f39e5e355efc946e18d8f22ce8a1032560bdd9fb4d54570bbd518bcdfa25e017ae30d79ac7edcb6e913c059013b021dd6ebd9ae9261
|
data/README.md
CHANGED
@@ -166,8 +166,10 @@ ArtemisApi::Batch.find(id: 22, facility_id: 2, client: client, include: "complet
|
|
166
166
|
We also support filtering on several models: Batch, Completion, Discard, Harvest, Zone, Item. It is another optional param and it expects a hash. Here's what that should look like.
|
167
167
|
|
168
168
|
```ruby
|
169
|
-
ArtemisApi::Batch.find_all(facility_id: 2, client: client, filters: {
|
169
|
+
ArtemisApi::Batch.find_all(facility_id: 2, client: client, filters: {search: 'genovese basil'})
|
170
170
|
ArtemisApi::Batch.find_all(facility_id: 2, client: client, filters: {ids: [2, 4, 6, 11]})
|
171
|
+
ArtemisApi::Batch.find_all(facility_id: 2, client: client, filters: {date_type: 'seeded_at', date_window: "2019-10-31 17:06:42 -0400,2019-11-15 17:06:42 -0500"})
|
172
|
+
|
171
173
|
ArtemisApi::Completion.find_all(facility_id: 2, client: client, filters: {crop_batch_ids: [5]})
|
172
174
|
ArtemisApi::Harvest.find_all(facility_id: 2, client: client, filters: {crop_batch_ids: [5, 7]})
|
173
175
|
ArtemisApi::Discard.find_all(facility_id: 2, client: client, filters: {crop_batch_ids: [6, 7, 9]})
|
@@ -177,6 +179,12 @@ ArtemisApi::Item.find_all(facility_id: 2, batch_id: 22, client: client, filters:
|
|
177
179
|
|
178
180
|
Note that when you filter by ids or crop_batch_ids, you must pass in an array even if it only has one element.
|
179
181
|
|
182
|
+
Pagination is also supported on batches, and is also an optional param that expects a hash. We use the limit/offset method of pagination.
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
ArtemisApi::Batch.find_all(facility_id: 2, client: client, page: {limit: 10, offset: 60})
|
186
|
+
```
|
187
|
+
|
180
188
|
The Artemis API is currently mainly read only, but we do support the creation of Subscriptions. These are used to set up webhooks that will make a callback to you whenever a Completion or Batch gets created or updated in the given facility. They require a `subject`, which can currently be either `completions` or `batches`, and a `destination`, which is the url that you want the callback to hit. There are two ways to make that call:
|
181
189
|
|
182
190
|
```ruby
|
data/lib/artemis_api/batch.rb
CHANGED
@@ -9,8 +9,8 @@ module ArtemisApi
|
|
9
9
|
client.find_one(self.json_type, id, facility_id: facility_id, include: include, force: force)
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.find_all(client:, facility_id:, include: nil, filters: nil)
|
13
|
-
client.find_all(self.json_type, facility_id: facility_id, include: include, filters: filters)
|
12
|
+
def self.find_all(client:, facility_id:, include: nil, filters: nil, page: nil)
|
13
|
+
client.find_all(self.json_type, facility_id: facility_id, include: include, filters: filters, page: page)
|
14
14
|
end
|
15
15
|
|
16
16
|
def completions(include: nil)
|
data/lib/artemis_api/client.rb
CHANGED
@@ -60,7 +60,7 @@ module ArtemisApi
|
|
60
60
|
obj
|
61
61
|
end
|
62
62
|
|
63
|
-
def find_all(type, facility_id: nil, batch_id: nil, include: nil, filters: nil)
|
63
|
+
def find_all(type, facility_id: nil, batch_id: nil, include: nil, filters: nil, page: nil)
|
64
64
|
records = []
|
65
65
|
refresh if @oauth_token.expired?
|
66
66
|
|
@@ -75,6 +75,7 @@ module ArtemisApi
|
|
75
75
|
query = {}
|
76
76
|
query[:include] = include if include
|
77
77
|
format_filters(filters, query) if filters
|
78
|
+
format_pagination(page, query) if page
|
78
79
|
|
79
80
|
url = build_url(path: path, query: URI.encode_www_form(query))
|
80
81
|
|
@@ -163,5 +164,11 @@ module ArtemisApi
|
|
163
164
|
end
|
164
165
|
end
|
165
166
|
end
|
167
|
+
|
168
|
+
def format_pagination(page_hash, query_hash)
|
169
|
+
page_hash.each do |k, v|
|
170
|
+
query_hash[:"page[#{k}]"] = v
|
171
|
+
end
|
172
|
+
end
|
166
173
|
end
|
167
174
|
end
|
@@ -6,8 +6,8 @@ module ArtemisApi
|
|
6
6
|
client.find_one(self.json_type, id, facility_id: facility_id, include: include, force: force)
|
7
7
|
end
|
8
8
|
|
9
|
-
def self.find_all(facility_id:, client:, include: nil
|
10
|
-
client.find_all(self.json_type, facility_id: facility_id, include: include
|
9
|
+
def self.find_all(facility_id:, client:, include: nil)
|
10
|
+
client.find_all(self.json_type, facility_id: facility_id, include: include)
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.create(facility_id:, subject:, destination:, client:)
|
data/lib/artemis_api/version.rb
CHANGED
data/test/batch_test.rb
CHANGED
@@ -19,6 +19,15 @@ class BatchTest < Minitest::Test
|
|
19
19
|
relationships: {zone: {data: {id: 1, type: 'zones'}}}
|
20
20
|
},
|
21
21
|
included: [{id: '1', type: 'zones', attributes: {id: 1, name: 'Germination'}}]}.to_json)
|
22
|
+
|
23
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/batches?filter[search]=oct")
|
24
|
+
.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)
|
25
|
+
|
26
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/batches?filter[ids][]=2&filter[ids][]=3")
|
27
|
+
.to_return(body: {data: [{id: '2', type: 'batches', attributes: {id: 2, name: 'Oct19-Bok-Cho'}}]}.to_json)
|
28
|
+
|
29
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/batches?page[limit]=1&page[offset]=4")
|
30
|
+
.to_return(body: {data: [{id: '2', type: 'batches', attributes: {id: 2, name: 'Oct19-Bok-Cho'}}]}.to_json)
|
22
31
|
end
|
23
32
|
|
24
33
|
def test_finding_all_batches
|
@@ -55,4 +64,32 @@ class BatchTest < Minitest::Test
|
|
55
64
|
zone = batch.zone
|
56
65
|
assert_equal zone.name, 'Germination'
|
57
66
|
end
|
67
|
+
|
68
|
+
def test_filtering_by_search_term
|
69
|
+
batches = ArtemisApi::Batch.find_all(facility_id: @facility.id, client: @client, filters: {search: "oct"})
|
70
|
+
assert_equal 2, batches.count
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_filtering_by_ids
|
74
|
+
batches = ArtemisApi::Batch.find_all(facility_id: @facility.id, client: @client, filters: {ids: [2, 3]})
|
75
|
+
assert_equal 1, batches.count
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_filtering_by_date_window
|
79
|
+
ending = Time.now + 2.day
|
80
|
+
beginning = ending - 15.days
|
81
|
+
date_window = [beginning, ending].join(',')
|
82
|
+
|
83
|
+
# TODO: Figure out how the filtering syntax goes.
|
84
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/batches?filter[date_type]=seeded_at&filter[date_window]=#{date_window}")
|
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)
|
86
|
+
|
87
|
+
batches = ArtemisApi::Batch.find_all(facility_id: @facility.id, client: @client, filters: {date_type: "seeded_at", date_window: date_window})
|
88
|
+
assert_equal 2, batches.count
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_pagination
|
92
|
+
batches = ArtemisApi::Batch.find_all(facility_id: @facility.id, client: @client, page: {limit: 1, offset: 4})
|
93
|
+
assert_equal 1, batches.count
|
94
|
+
end
|
58
95
|
end
|
data/test/completion_test.rb
CHANGED
@@ -10,6 +10,9 @@ class CompletionTest < Minitest::Test
|
|
10
10
|
|
11
11
|
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/completions/2")
|
12
12
|
.to_return(body: {data: {id: '2', type: 'completions', attributes: {id: 2, action_type: 'move'}}}.to_json)
|
13
|
+
|
14
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/completions?filter[crop_batch_ids][]=2&filter[crop_batch_ids][]=3")
|
15
|
+
.to_return(body: {data: [{id: '1', type: 'completions', attributes: {id: 1, action_type: 'start'}}]}.to_json)
|
13
16
|
end
|
14
17
|
|
15
18
|
def test_finding_all_completions
|
@@ -21,4 +24,9 @@ class CompletionTest < Minitest::Test
|
|
21
24
|
completion = ArtemisApi::Completion.find(id: 2, facility_id: @facility.id, client: @client)
|
22
25
|
assert_equal 'move', completion.action_type
|
23
26
|
end
|
27
|
+
|
28
|
+
def test_filtering_completion_by_crop_batch_ids
|
29
|
+
completions = ArtemisApi::Completion.find_all(facility_id: @facility.id, client: @client, filters: {crop_batch_ids: [2, 3]})
|
30
|
+
assert_equal 1, completions.count
|
31
|
+
end
|
24
32
|
end
|
data/test/discard_test.rb
CHANGED
@@ -60,6 +60,9 @@ class DiscardTest < Minitest::Test
|
|
60
60
|
|
61
61
|
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/discards")
|
62
62
|
.to_return(body: {data: [{id: '1', type: 'discards', attributes: {id: 1, reason_type: 'disease', quantity: 20}}, {id: '2', type: 'discards', attributes: {id: 2, reason_type: 'pests', quantity: 5}}]}.to_json)
|
63
|
+
|
64
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/discards?filter[crop_batch_ids][]=2&filter[crop_batch_ids][]=3")
|
65
|
+
.to_return(body: {data: [{id: '1', type: 'discards', attributes: {id: 1, quantity: 4, reason_type: 'pests'}}]}.to_json)
|
63
66
|
end
|
64
67
|
|
65
68
|
def test_finding_a_specific_discard
|
@@ -82,4 +85,9 @@ class DiscardTest < Minitest::Test
|
|
82
85
|
discards = ArtemisApi::Discard.find_all(facility_id: @facility.id, client: @client)
|
83
86
|
assert_equal 2, discards.count
|
84
87
|
end
|
88
|
+
|
89
|
+
def test_filtering_discard_by_crop_batch_ids
|
90
|
+
discards = ArtemisApi::Discard.find_all(facility_id: @facility.id, client: @client, filters: {crop_batch_ids: [2, 3]})
|
91
|
+
assert_equal 1, discards.count
|
92
|
+
end
|
85
93
|
end
|
data/test/zone_test.rb
CHANGED
@@ -10,6 +10,9 @@ class ZoneTest < Minitest::Test
|
|
10
10
|
|
11
11
|
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/zones/2")
|
12
12
|
.to_return(body: {data: {id: '2', type: 'zones', attributes: {id: 2, name: 'Propagation'}}}.to_json)
|
13
|
+
|
14
|
+
stub_request(:get, "http://localhost:3000/api/v3/facilities/#{@facility.id}/zones?filter[seeding_unit_id]=100")
|
15
|
+
.to_return(body: {data: [{id: '2', type: 'zones', attributes: {id: 2, name: 'Propagation'}}]}.to_json)
|
13
16
|
end
|
14
17
|
|
15
18
|
def test_finding_all_zones
|
@@ -31,4 +34,9 @@ class ZoneTest < Minitest::Test
|
|
31
34
|
zone = @facility.zone(2)
|
32
35
|
assert_equal 'Propagation', zone.name
|
33
36
|
end
|
37
|
+
|
38
|
+
def test_filtering_zones_by_seeding_unit_id
|
39
|
+
zones = ArtemisApi::Zone.find_all(facility_id: @facility.id, client: @client, filters: {seeding_unit_id: 100})
|
40
|
+
assert_equal 1, zones.count
|
41
|
+
end
|
34
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artemis_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamey Hampton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|