myjohndeere 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/myjohndeere/field.rb +16 -2
- data/lib/myjohndeere/list_object.rb +8 -5
- data/lib/myjohndeere/organization.rb +2 -2
- data/lib/myjohndeere/requestable.rb +4 -0
- data/lib/myjohndeere/rest_methods.rb +8 -4
- data/lib/myjohndeere/version.rb +1 -1
- data/spec/fixtures.json +513 -1
- data/test/test_field.rb +35 -1
- data/test/test_list_object.rb +6 -5
- data/test/test_requestable.rb +11 -0
- data/test/test_rest_methods.rb +6 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0600e03c73fe1849281e0eaa4da74c376f4e9e31
|
4
|
+
data.tar.gz: 35ef8400afccb26a497be17bed63fd9c20365a78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df107d11f531cdf8fa5c8fc6be1ab8d47177c9a4d9545db6fe3afe75a2c5282d5847ce1dd209ae77b6301e285024f771cef59bd9553fc7553aa53244473e137a
|
7
|
+
data.tar.gz: 5628ca820a9388f451afc569d5fe46795f904b3c962ae4c1adbc1bce85f599342b8860e47e1709f1dcfadf17865db37c4d6d978f7d32a6f8b979f53d4dbd6ee2
|
data/lib/myjohndeere/field.rb
CHANGED
@@ -11,7 +11,8 @@ module MyJohnDeere
|
|
11
11
|
boundaries = json_object["boundaries"]
|
12
12
|
if boundaries && boundaries.length > 0 then
|
13
13
|
# If we embed, then we'll need to pass our id
|
14
|
-
|
14
|
+
possible_boundaries = boundaries.map { |b_json| Boundary.new(b_json, access_token, self.id) }
|
15
|
+
self.boundary = find_first_active_boundary(possible_boundaries)
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
@@ -23,7 +24,8 @@ module MyJohnDeere
|
|
23
24
|
|
24
25
|
def boundary
|
25
26
|
if self.boundary_unset? then
|
26
|
-
|
27
|
+
boundaries = Boundary.list(self.access_token, field_id: self.id, organization_id: self.organization_id)
|
28
|
+
@boundary = find_first_active_boundary(boundaries.data)
|
27
29
|
end
|
28
30
|
return @boundary
|
29
31
|
end
|
@@ -31,5 +33,17 @@ module MyJohnDeere
|
|
31
33
|
def boundary=(val)
|
32
34
|
@boundary = val
|
33
35
|
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def find_first_active_boundary(possible_boundaries)
|
39
|
+
active_boundaries = possible_boundaries.select { |b| b.active && !b.deleted }
|
40
|
+
if active_boundaries.count > 1 then
|
41
|
+
raise MyJohnDeereError.new("There was more than one boundary in the field, this is currently unexpected")
|
42
|
+
elsif active_boundaries.count == 1 then
|
43
|
+
return active_boundaries.first
|
44
|
+
else
|
45
|
+
return possible_boundaries.first
|
46
|
+
end
|
47
|
+
end
|
34
48
|
end
|
35
49
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module MyJohnDeere
|
2
2
|
class ListObject < Requestable
|
3
3
|
OPTION_ATTRIBUTES = [:count, :start, :etag]
|
4
|
-
attr_reader :data, :listable, :total, :options, :last_response_code
|
4
|
+
attr_reader :data, :listable, :total, :options, :last_response_code, :base_resources
|
5
5
|
include Enumerable
|
6
6
|
|
7
7
|
OPTION_ATTRIBUTES.each do |attribute|
|
@@ -13,8 +13,9 @@ module MyJohnDeere
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def initialize(listable, access_token, json_data, last_response_code,
|
16
|
+
def initialize(listable, access_token, json_data, last_response_code, base_resources,
|
17
17
|
options: {})
|
18
|
+
@base_resources = base_resources
|
18
19
|
@last_response_code = last_response_code
|
19
20
|
@options = options
|
20
21
|
# Confirm object is listable?
|
@@ -40,11 +41,13 @@ module MyJohnDeere
|
|
40
41
|
end
|
41
42
|
|
42
43
|
def next_page!()
|
43
|
-
|
44
|
-
new_list = @listable.list(self.access_token,
|
44
|
+
list_options = base_resources.merge({
|
45
45
|
count: self.count,
|
46
46
|
start: self.start + self.count,
|
47
|
-
etag: self.etag
|
47
|
+
etag: self.etag
|
48
|
+
})
|
49
|
+
return if !self.has_more?()
|
50
|
+
new_list = @listable.list(self.access_token, list_options)
|
48
51
|
new_list.instance_variables.each do |iv|
|
49
52
|
self.instance_variable_set(iv, new_list.instance_variable_get(iv))
|
50
53
|
end
|
@@ -10,11 +10,11 @@ module MyJohnDeere
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def has_access_to_boundaries?
|
13
|
-
self.
|
13
|
+
self.has_access_to?("boundaries")
|
14
14
|
end
|
15
15
|
|
16
16
|
def has_access_to_fields?
|
17
|
-
self.
|
17
|
+
self.has_access_to?("fields")
|
18
18
|
end
|
19
19
|
|
20
20
|
def fields
|
@@ -11,6 +11,10 @@ module MyJohnDeere
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
+
def has_access_to?(rel_link_name)
|
15
|
+
self.links.any? {|i| i["rel"] == rel_link_name}
|
16
|
+
end
|
17
|
+
|
14
18
|
def extract_link_with_rel_from_list(rel_target, regex_to_capture_item)
|
15
19
|
link = self.links.detect { |l| l["rel"] == rel_target }
|
16
20
|
if link then
|
@@ -21,7 +21,8 @@ module MyJohnDeere
|
|
21
21
|
options[:body][sbp] = options[sbp]
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
path, base_resources = build_resource_base_path!(self.list_resource_path, options)
|
25
|
+
response = access_token.execute_request(:get, path,
|
25
26
|
options
|
26
27
|
)
|
27
28
|
return ListObject.new(
|
@@ -29,6 +30,7 @@ module MyJohnDeere
|
|
29
30
|
access_token,
|
30
31
|
response.data,
|
31
32
|
response.code,
|
33
|
+
base_resources,
|
32
34
|
options: options.merge(
|
33
35
|
etag: response.http_headers[MyJohnDeere::ETAG_HEADER_KEY]
|
34
36
|
)
|
@@ -37,8 +39,9 @@ module MyJohnDeere
|
|
37
39
|
|
38
40
|
def retrieve(access_token, id, options={})
|
39
41
|
validate_access_token(access_token)
|
42
|
+
path, = build_resource_base_path!(self.retrieve_resource_path, options)
|
40
43
|
response = access_token.execute_request(:get,
|
41
|
-
"#{
|
44
|
+
"#{path}/#{id}",
|
42
45
|
options)
|
43
46
|
|
44
47
|
return new(response.data, access_token)
|
@@ -60,7 +63,7 @@ module MyJohnDeere
|
|
60
63
|
end
|
61
64
|
MyJohnDeere.logger.info("Building resource path: #{resource_path}, with ids: #{base_resources}")
|
62
65
|
begin
|
63
|
-
return resource_path % base_resources
|
66
|
+
return resource_path % base_resources, base_resources
|
64
67
|
rescue KeyError
|
65
68
|
raise ArgumentError.new("You must specify #{expected_definitions.join(", ")} as part of this request path")
|
66
69
|
end
|
@@ -71,8 +74,9 @@ module MyJohnDeere
|
|
71
74
|
end
|
72
75
|
|
73
76
|
def send_create(access_token, body, path_builder_options = {})
|
77
|
+
path, = build_resource_base_path!(self.list_resource_path, path_builder_options)
|
74
78
|
response = access_token.execute_request(:post,
|
75
|
-
|
79
|
+
path,
|
76
80
|
body: body
|
77
81
|
)
|
78
82
|
#{"Content-Type"=>"text/plain", "X-Deere-Handling-Server"=>"ldxtc3", "X-Frame-Options"=>"SAMEORIGIN", "Location"=>"https://sandboxapi.deere.com/platform/mapLayers/e2711205-c5df-445e-aad5-81eaf9090e6c", "X-Deere-Elapsed-Ms"=>"162", "Vary"=>"Accept-Encoding", "Expires"=>"Thu, 14 Sep 2017 15:52:24 GMT", "Cache-Control"=>"max-age=0, no-cache", "Pragma"=>"no-cache", "Date"=>"Thu, 14 Sep 2017 15:52:24 GMT", "Transfer-Encoding"=>"chunked", "Connection"=>"close, Transfer-Encoding"}
|
data/lib/myjohndeere/version.rb
CHANGED
data/spec/fixtures.json
CHANGED
@@ -467,6 +467,518 @@
|
|
467
467
|
}
|
468
468
|
]
|
469
469
|
},
|
470
|
+
"field_with_multiple_active_boundaries" : {
|
471
|
+
"@type":"Field",
|
472
|
+
"name":"AndersonFarms",
|
473
|
+
"boundaries":[
|
474
|
+
{
|
475
|
+
"@type":"Boundary",
|
476
|
+
"name":"a",
|
477
|
+
"modifiedTime":"2017-08-04T21:45:51.469Z",
|
478
|
+
"area":{
|
479
|
+
"@type":"MeasurementAsDouble",
|
480
|
+
"valueAsDouble":15.892707870809991,
|
481
|
+
"unit":"ha"
|
482
|
+
},
|
483
|
+
"multipolygons":[
|
484
|
+
{
|
485
|
+
"@type":"Polygon",
|
486
|
+
"rings":[
|
487
|
+
{
|
488
|
+
"@type":"Ring",
|
489
|
+
"points":[
|
490
|
+
{
|
491
|
+
"@type":"Point",
|
492
|
+
"lat":40.095079098,
|
493
|
+
"lon":-105.032172203
|
494
|
+
},
|
495
|
+
{
|
496
|
+
"@type":"Point",
|
497
|
+
"lat":40.095111927,
|
498
|
+
"lon":-105.023052692
|
499
|
+
},
|
500
|
+
{
|
501
|
+
"@type":"Point",
|
502
|
+
"lat":40.096425084,
|
503
|
+
"lon":-105.023825169
|
504
|
+
},
|
505
|
+
{
|
506
|
+
"@type":"Point",
|
507
|
+
"lat":40.096802611,
|
508
|
+
"lon":-105.024554729
|
509
|
+
},
|
510
|
+
{
|
511
|
+
"@type":"Point",
|
512
|
+
"lat":40.096457912,
|
513
|
+
"lon":-105.025134087
|
514
|
+
},
|
515
|
+
{
|
516
|
+
"@type":"Point",
|
517
|
+
"lat":40.097245793,
|
518
|
+
"lon":-105.029489994
|
519
|
+
},
|
520
|
+
{
|
521
|
+
"@type":"Point",
|
522
|
+
"lat":40.097492004,
|
523
|
+
"lon":-105.030562878
|
524
|
+
},
|
525
|
+
{
|
526
|
+
"@type":"Point",
|
527
|
+
"lat":40.097787456,
|
528
|
+
"lon":-105.031678677
|
529
|
+
},
|
530
|
+
{
|
531
|
+
"@type":"Point",
|
532
|
+
"lat":40.097771042,
|
533
|
+
"lon":-105.032193661
|
534
|
+
},
|
535
|
+
{
|
536
|
+
"@type":"Point",
|
537
|
+
"lat":40.095079098,
|
538
|
+
"lon":-105.032172203
|
539
|
+
}
|
540
|
+
],
|
541
|
+
"type":"exterior",
|
542
|
+
"passable":true
|
543
|
+
}
|
544
|
+
]
|
545
|
+
}
|
546
|
+
],
|
547
|
+
"extent":{
|
548
|
+
"@type":"Extent",
|
549
|
+
"topLeft":{
|
550
|
+
"@type":"Point",
|
551
|
+
"lat":40.097787456,
|
552
|
+
"lon":-105.032193661
|
553
|
+
},
|
554
|
+
"bottomRight":{
|
555
|
+
"@type":"Point",
|
556
|
+
"lat":40.095079098,
|
557
|
+
"lon":-105.023052692
|
558
|
+
}
|
559
|
+
},
|
560
|
+
"id":"f4828b25-2a92-12a4-bf3e-a107c39ecb84",
|
561
|
+
"links":[
|
562
|
+
{
|
563
|
+
"@type":"Link",
|
564
|
+
"rel":"self",
|
565
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/boundaries/f4828b25-2a92-4f2d-bf3e-a107c39ecb84"
|
566
|
+
},
|
567
|
+
{
|
568
|
+
"@type":"Link",
|
569
|
+
"rel":"owningOrganization",
|
570
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234"
|
571
|
+
}
|
572
|
+
],
|
573
|
+
"active":true
|
574
|
+
},
|
575
|
+
{
|
576
|
+
"@type":"Boundary",
|
577
|
+
"name":"b",
|
578
|
+
"modifiedTime":"2017-08-04T21:45:51.469Z",
|
579
|
+
"area":{
|
580
|
+
"@type":"MeasurementAsDouble",
|
581
|
+
"valueAsDouble":15.892707870809991,
|
582
|
+
"unit":"ha"
|
583
|
+
},
|
584
|
+
"multipolygons":[
|
585
|
+
{
|
586
|
+
"@type":"Polygon",
|
587
|
+
"rings":[
|
588
|
+
{
|
589
|
+
"@type":"Ring",
|
590
|
+
"points":[
|
591
|
+
{
|
592
|
+
"@type":"Point",
|
593
|
+
"lat":40.095079098,
|
594
|
+
"lon":-105.032172203
|
595
|
+
},
|
596
|
+
{
|
597
|
+
"@type":"Point",
|
598
|
+
"lat":40.095111927,
|
599
|
+
"lon":-105.023052692
|
600
|
+
},
|
601
|
+
{
|
602
|
+
"@type":"Point",
|
603
|
+
"lat":40.096425084,
|
604
|
+
"lon":-105.023825169
|
605
|
+
},
|
606
|
+
{
|
607
|
+
"@type":"Point",
|
608
|
+
"lat":40.096802611,
|
609
|
+
"lon":-105.024554729
|
610
|
+
},
|
611
|
+
{
|
612
|
+
"@type":"Point",
|
613
|
+
"lat":40.096457912,
|
614
|
+
"lon":-105.025134087
|
615
|
+
},
|
616
|
+
{
|
617
|
+
"@type":"Point",
|
618
|
+
"lat":40.097245793,
|
619
|
+
"lon":-105.029489994
|
620
|
+
},
|
621
|
+
{
|
622
|
+
"@type":"Point",
|
623
|
+
"lat":40.097492004,
|
624
|
+
"lon":-105.030562878
|
625
|
+
},
|
626
|
+
{
|
627
|
+
"@type":"Point",
|
628
|
+
"lat":40.097787456,
|
629
|
+
"lon":-105.031678677
|
630
|
+
},
|
631
|
+
{
|
632
|
+
"@type":"Point",
|
633
|
+
"lat":40.097771042,
|
634
|
+
"lon":-105.032193661
|
635
|
+
},
|
636
|
+
{
|
637
|
+
"@type":"Point",
|
638
|
+
"lat":40.095079098,
|
639
|
+
"lon":-105.032172203
|
640
|
+
}
|
641
|
+
],
|
642
|
+
"type":"exterior",
|
643
|
+
"passable":true
|
644
|
+
}
|
645
|
+
]
|
646
|
+
}
|
647
|
+
],
|
648
|
+
"extent":{
|
649
|
+
"@type":"Extent",
|
650
|
+
"topLeft":{
|
651
|
+
"@type":"Point",
|
652
|
+
"lat":40.097787456,
|
653
|
+
"lon":-105.032193661
|
654
|
+
},
|
655
|
+
"bottomRight":{
|
656
|
+
"@type":"Point",
|
657
|
+
"lat":40.095079098,
|
658
|
+
"lon":-105.023052692
|
659
|
+
}
|
660
|
+
},
|
661
|
+
"id":"f4828b25-2a92-12a4-bf3e-a107c39ecb85",
|
662
|
+
"links":[
|
663
|
+
{
|
664
|
+
"@type":"Link",
|
665
|
+
"rel":"self",
|
666
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/boundaries/f4828b25-2a92-4f2d-bf3e-a107c39ecb84"
|
667
|
+
},
|
668
|
+
{
|
669
|
+
"@type":"Link",
|
670
|
+
"rel":"owningOrganization",
|
671
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234"
|
672
|
+
}
|
673
|
+
],
|
674
|
+
"active":true
|
675
|
+
}
|
676
|
+
],
|
677
|
+
"id":"2516aa2c-2c0d-4dae-ba63-5c64fd172d01",
|
678
|
+
"links":[
|
679
|
+
{
|
680
|
+
"@type":"Link",
|
681
|
+
"rel":"self",
|
682
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01"
|
683
|
+
},
|
684
|
+
{
|
685
|
+
"@type":"Link",
|
686
|
+
"rel":"clients",
|
687
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/clients"
|
688
|
+
},
|
689
|
+
{
|
690
|
+
"@type":"Link",
|
691
|
+
"rel":"notes",
|
692
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/notes"
|
693
|
+
},
|
694
|
+
{
|
695
|
+
"@type":"Link",
|
696
|
+
"rel":"farms",
|
697
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/farms"
|
698
|
+
},
|
699
|
+
{
|
700
|
+
"@type":"Link",
|
701
|
+
"rel":"owningOrganization",
|
702
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234"
|
703
|
+
},
|
704
|
+
{
|
705
|
+
"@type":"Link",
|
706
|
+
"rel":"simplifiedBoundaries",
|
707
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/boundaries?simple=true"
|
708
|
+
},
|
709
|
+
{
|
710
|
+
"@type":"Link",
|
711
|
+
"rel":"addBoundary",
|
712
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/boundaries"
|
713
|
+
},
|
714
|
+
{
|
715
|
+
"@type":"Link",
|
716
|
+
"rel":"activeBoundary",
|
717
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/boundaries/f4828b25-2a92-4f2d-bf3e-a107c39ecb84"
|
718
|
+
},
|
719
|
+
{
|
720
|
+
"@type":"Link",
|
721
|
+
"rel":"fieldOperation",
|
722
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/fieldOperations"
|
723
|
+
}
|
724
|
+
]
|
725
|
+
},
|
726
|
+
"field_with_multiple_boundaries" : {
|
727
|
+
"@type":"Field",
|
728
|
+
"name":"AndersonFarms",
|
729
|
+
"boundaries":[
|
730
|
+
{
|
731
|
+
"@type":"Boundary",
|
732
|
+
"name":"a",
|
733
|
+
"modifiedTime":"2017-08-04T21:45:51.469Z",
|
734
|
+
"area":{
|
735
|
+
"@type":"MeasurementAsDouble",
|
736
|
+
"valueAsDouble":15.892707870809991,
|
737
|
+
"unit":"ha"
|
738
|
+
},
|
739
|
+
"multipolygons":[
|
740
|
+
{
|
741
|
+
"@type":"Polygon",
|
742
|
+
"rings":[
|
743
|
+
{
|
744
|
+
"@type":"Ring",
|
745
|
+
"points":[
|
746
|
+
{
|
747
|
+
"@type":"Point",
|
748
|
+
"lat":40.095079098,
|
749
|
+
"lon":-105.032172203
|
750
|
+
},
|
751
|
+
{
|
752
|
+
"@type":"Point",
|
753
|
+
"lat":40.095111927,
|
754
|
+
"lon":-105.023052692
|
755
|
+
},
|
756
|
+
{
|
757
|
+
"@type":"Point",
|
758
|
+
"lat":40.096425084,
|
759
|
+
"lon":-105.023825169
|
760
|
+
},
|
761
|
+
{
|
762
|
+
"@type":"Point",
|
763
|
+
"lat":40.096802611,
|
764
|
+
"lon":-105.024554729
|
765
|
+
},
|
766
|
+
{
|
767
|
+
"@type":"Point",
|
768
|
+
"lat":40.096457912,
|
769
|
+
"lon":-105.025134087
|
770
|
+
},
|
771
|
+
{
|
772
|
+
"@type":"Point",
|
773
|
+
"lat":40.097245793,
|
774
|
+
"lon":-105.029489994
|
775
|
+
},
|
776
|
+
{
|
777
|
+
"@type":"Point",
|
778
|
+
"lat":40.097492004,
|
779
|
+
"lon":-105.030562878
|
780
|
+
},
|
781
|
+
{
|
782
|
+
"@type":"Point",
|
783
|
+
"lat":40.097787456,
|
784
|
+
"lon":-105.031678677
|
785
|
+
},
|
786
|
+
{
|
787
|
+
"@type":"Point",
|
788
|
+
"lat":40.097771042,
|
789
|
+
"lon":-105.032193661
|
790
|
+
},
|
791
|
+
{
|
792
|
+
"@type":"Point",
|
793
|
+
"lat":40.095079098,
|
794
|
+
"lon":-105.032172203
|
795
|
+
}
|
796
|
+
],
|
797
|
+
"type":"exterior",
|
798
|
+
"passable":true
|
799
|
+
}
|
800
|
+
]
|
801
|
+
}
|
802
|
+
],
|
803
|
+
"extent":{
|
804
|
+
"@type":"Extent",
|
805
|
+
"topLeft":{
|
806
|
+
"@type":"Point",
|
807
|
+
"lat":40.097787456,
|
808
|
+
"lon":-105.032193661
|
809
|
+
},
|
810
|
+
"bottomRight":{
|
811
|
+
"@type":"Point",
|
812
|
+
"lat":40.095079098,
|
813
|
+
"lon":-105.023052692
|
814
|
+
}
|
815
|
+
},
|
816
|
+
"id":"f4828b25-2a92-12a4-bf3e-a107c39ecb84",
|
817
|
+
"links":[
|
818
|
+
{
|
819
|
+
"@type":"Link",
|
820
|
+
"rel":"self",
|
821
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/boundaries/f4828b25-2a92-4f2d-bf3e-a107c39ecb84"
|
822
|
+
},
|
823
|
+
{
|
824
|
+
"@type":"Link",
|
825
|
+
"rel":"owningOrganization",
|
826
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234"
|
827
|
+
}
|
828
|
+
],
|
829
|
+
"active":false
|
830
|
+
},
|
831
|
+
{
|
832
|
+
"@type":"Boundary",
|
833
|
+
"name":"b",
|
834
|
+
"modifiedTime":"2017-08-04T21:45:51.469Z",
|
835
|
+
"area":{
|
836
|
+
"@type":"MeasurementAsDouble",
|
837
|
+
"valueAsDouble":15.892707870809991,
|
838
|
+
"unit":"ha"
|
839
|
+
},
|
840
|
+
"multipolygons":[
|
841
|
+
{
|
842
|
+
"@type":"Polygon",
|
843
|
+
"rings":[
|
844
|
+
{
|
845
|
+
"@type":"Ring",
|
846
|
+
"points":[
|
847
|
+
{
|
848
|
+
"@type":"Point",
|
849
|
+
"lat":40.095079098,
|
850
|
+
"lon":-105.032172203
|
851
|
+
},
|
852
|
+
{
|
853
|
+
"@type":"Point",
|
854
|
+
"lat":40.095111927,
|
855
|
+
"lon":-105.023052692
|
856
|
+
},
|
857
|
+
{
|
858
|
+
"@type":"Point",
|
859
|
+
"lat":40.096425084,
|
860
|
+
"lon":-105.023825169
|
861
|
+
},
|
862
|
+
{
|
863
|
+
"@type":"Point",
|
864
|
+
"lat":40.096802611,
|
865
|
+
"lon":-105.024554729
|
866
|
+
},
|
867
|
+
{
|
868
|
+
"@type":"Point",
|
869
|
+
"lat":40.096457912,
|
870
|
+
"lon":-105.025134087
|
871
|
+
},
|
872
|
+
{
|
873
|
+
"@type":"Point",
|
874
|
+
"lat":40.097245793,
|
875
|
+
"lon":-105.029489994
|
876
|
+
},
|
877
|
+
{
|
878
|
+
"@type":"Point",
|
879
|
+
"lat":40.097492004,
|
880
|
+
"lon":-105.030562878
|
881
|
+
},
|
882
|
+
{
|
883
|
+
"@type":"Point",
|
884
|
+
"lat":40.097787456,
|
885
|
+
"lon":-105.031678677
|
886
|
+
},
|
887
|
+
{
|
888
|
+
"@type":"Point",
|
889
|
+
"lat":40.097771042,
|
890
|
+
"lon":-105.032193661
|
891
|
+
},
|
892
|
+
{
|
893
|
+
"@type":"Point",
|
894
|
+
"lat":40.095079098,
|
895
|
+
"lon":-105.032172203
|
896
|
+
}
|
897
|
+
],
|
898
|
+
"type":"exterior",
|
899
|
+
"passable":true
|
900
|
+
}
|
901
|
+
]
|
902
|
+
}
|
903
|
+
],
|
904
|
+
"extent":{
|
905
|
+
"@type":"Extent",
|
906
|
+
"topLeft":{
|
907
|
+
"@type":"Point",
|
908
|
+
"lat":40.097787456,
|
909
|
+
"lon":-105.032193661
|
910
|
+
},
|
911
|
+
"bottomRight":{
|
912
|
+
"@type":"Point",
|
913
|
+
"lat":40.095079098,
|
914
|
+
"lon":-105.023052692
|
915
|
+
}
|
916
|
+
},
|
917
|
+
"id":"f4828b25-2a92-12a4-bf3e-a107c39ecb85",
|
918
|
+
"links":[
|
919
|
+
{
|
920
|
+
"@type":"Link",
|
921
|
+
"rel":"self",
|
922
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/boundaries/f4828b25-2a92-4f2d-bf3e-a107c39ecb84"
|
923
|
+
},
|
924
|
+
{
|
925
|
+
"@type":"Link",
|
926
|
+
"rel":"owningOrganization",
|
927
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234"
|
928
|
+
}
|
929
|
+
],
|
930
|
+
"active":true
|
931
|
+
}
|
932
|
+
],
|
933
|
+
"id":"2516aa2c-2c0d-4dae-ba63-5c64fd172d01",
|
934
|
+
"links":[
|
935
|
+
{
|
936
|
+
"@type":"Link",
|
937
|
+
"rel":"self",
|
938
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01"
|
939
|
+
},
|
940
|
+
{
|
941
|
+
"@type":"Link",
|
942
|
+
"rel":"clients",
|
943
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/clients"
|
944
|
+
},
|
945
|
+
{
|
946
|
+
"@type":"Link",
|
947
|
+
"rel":"notes",
|
948
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/notes"
|
949
|
+
},
|
950
|
+
{
|
951
|
+
"@type":"Link",
|
952
|
+
"rel":"farms",
|
953
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/farms"
|
954
|
+
},
|
955
|
+
{
|
956
|
+
"@type":"Link",
|
957
|
+
"rel":"owningOrganization",
|
958
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234"
|
959
|
+
},
|
960
|
+
{
|
961
|
+
"@type":"Link",
|
962
|
+
"rel":"simplifiedBoundaries",
|
963
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/boundaries?simple=true"
|
964
|
+
},
|
965
|
+
{
|
966
|
+
"@type":"Link",
|
967
|
+
"rel":"addBoundary",
|
968
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/boundaries"
|
969
|
+
},
|
970
|
+
{
|
971
|
+
"@type":"Link",
|
972
|
+
"rel":"activeBoundary",
|
973
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/boundaries/f4828b25-2a92-4f2d-bf3e-a107c39ecb84"
|
974
|
+
},
|
975
|
+
{
|
976
|
+
"@type":"Link",
|
977
|
+
"rel":"fieldOperation",
|
978
|
+
"uri":"https://sandboxapi.deere.com/platform/organizations/1234/fields/2516aa2c-2c0d-4dae-ba63-5c64fd172d01/fieldOperations"
|
979
|
+
}
|
980
|
+
]
|
981
|
+
},
|
470
982
|
"field_with_embedded_boundary" : {
|
471
983
|
"@type":"Field",
|
472
984
|
"name":"AndersonFarms",
|
@@ -802,7 +1314,7 @@
|
|
802
1314
|
"uri": "https://sandboxapi.deere.com/platform/organizations/1234/fields"
|
803
1315
|
}
|
804
1316
|
],
|
805
|
-
"total":
|
1317
|
+
"total": 2,
|
806
1318
|
"values": [
|
807
1319
|
{
|
808
1320
|
"name": "Nautilus",
|
data/test/test_field.rb
CHANGED
@@ -42,13 +42,47 @@ class TestField < Minitest::Test
|
|
42
42
|
assert !field.boundary_unset?
|
43
43
|
end
|
44
44
|
|
45
|
+
def test_retrieval_with_multiple_boundaries
|
46
|
+
fixture = API_FIXTURES["field_with_multiple_boundaries"]
|
47
|
+
|
48
|
+
stub_request(:get, /\/organizations\/#{ORGANIZATION_FIXTURE["id"]}\/fields\/#{fixture["id"]}/).
|
49
|
+
with(query: {embed: "boundaries"}).
|
50
|
+
to_return(status: 200, body: fixture.to_json)
|
51
|
+
|
52
|
+
field = MyJohnDeere::Field.retrieve(default_access_token,
|
53
|
+
fixture["id"], organization_id: ORGANIZATION_FIXTURE["id"],
|
54
|
+
body: {embed: "boundaries"})
|
55
|
+
|
56
|
+
assert_equal fixture["boundaries"][1]["id"], field.boundary.id
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_retrieval_with_multiple_active_boundaries
|
60
|
+
fixture = API_FIXTURES["field_with_multiple_active_boundaries"]
|
61
|
+
|
62
|
+
stub_request(:get, /\/organizations\/#{ORGANIZATION_FIXTURE["id"]}\/fields\/#{fixture["id"]}/).
|
63
|
+
with(query: {embed: "boundaries"}).
|
64
|
+
to_return(status: 200, body: fixture.to_json)
|
65
|
+
|
66
|
+
assert_raises MyJohnDeere::MyJohnDeereError, "At the moment I don't have a use case where this would happen" do
|
67
|
+
field = MyJohnDeere::Field.retrieve(default_access_token,
|
68
|
+
fixture["id"], organization_id: ORGANIZATION_FIXTURE["id"],
|
69
|
+
body: {embed: "boundaries"})
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
45
73
|
def test_list()
|
46
74
|
stub_request(:get, /organizations\/#{ORGANIZATION_FIXTURE["id"]}\/fields/).
|
47
75
|
to_return(status: 200, body: FIXTURE_FOR_LIST.to_json)
|
48
76
|
|
49
|
-
fields = MyJohnDeere::Field.list(default_access_token,
|
77
|
+
fields = MyJohnDeere::Field.list(default_access_token,
|
78
|
+
count: 1, organization_id: ORGANIZATION_FIXTURE["id"])
|
50
79
|
|
51
80
|
assert_equal 1, fields.data.length
|
81
|
+
assert fields.has_more?
|
52
82
|
assert_equal MyJohnDeere::Field, fields.data[0].class
|
83
|
+
|
84
|
+
fields.next_page!
|
85
|
+
|
86
|
+
assert_equal 1, fields.data
|
53
87
|
end
|
54
88
|
end
|
data/test/test_list_object.rb
CHANGED
@@ -6,7 +6,8 @@ class TestListObject < Minitest::Test
|
|
6
6
|
list = MyJohnDeere::ListObject.new(MyJohnDeere::Organization,
|
7
7
|
default_access_token,
|
8
8
|
{"values" => data},
|
9
|
-
200
|
9
|
+
200,
|
10
|
+
{})
|
10
11
|
|
11
12
|
list.each_with_index do |x, i|
|
12
13
|
assert_equal data[i]["id"], x.id
|
@@ -21,14 +22,14 @@ class TestListObject < Minitest::Test
|
|
21
22
|
default_access_token, {
|
22
23
|
"total" => expected_total,
|
23
24
|
"values" => Array.new(1, API_FIXTURES["organization"])
|
24
|
-
}, options: {start: 0})
|
25
|
+
}, {}, options: {start: 0})
|
25
26
|
assert list.has_more?
|
26
27
|
|
27
28
|
list.start = expected_total
|
28
29
|
assert !list.has_more?
|
29
30
|
|
30
31
|
list = MyJohnDeere::ListObject.new(MyJohnDeere::Organization,
|
31
|
-
default_access_token, {"values" =>[]}, options: {start: 0})
|
32
|
+
default_access_token, {"values" =>[]}, {}, options: {start: 0})
|
32
33
|
assert !list.has_more?, "The data is equal to the total"
|
33
34
|
end
|
34
35
|
|
@@ -50,7 +51,7 @@ class TestListObject < Minitest::Test
|
|
50
51
|
test_json = API_FIXTURES["organizations"]
|
51
52
|
existing_data = Array.new(test_json["total"]-1, test_json["values"][0])
|
52
53
|
list = MyJohnDeere::ListObject.new(MyJohnDeere::Organization, default_access_token,
|
53
|
-
{"values" => existing_data}, 200, options: {
|
54
|
+
{"values" => existing_data}, 200, {}, options: {
|
54
55
|
start: 0, count: existing_data.length, etag: ""})
|
55
56
|
assert list.using_etag?
|
56
57
|
assert !list.has_more?
|
@@ -68,7 +69,7 @@ class TestListObject < Minitest::Test
|
|
68
69
|
test_json = API_FIXTURES["organizations"]
|
69
70
|
existing_data = (1..(test_json["total"]-1)).to_a
|
70
71
|
list = MyJohnDeere::ListObject.new(MyJohnDeere::Organization, default_access_token,
|
71
|
-
test_json, 200, options: {start: 0,
|
72
|
+
test_json, 200, {}, options: {start: 0,
|
72
73
|
count: existing_data.length})
|
73
74
|
assert list.has_more?
|
74
75
|
assert !list.using_etag?
|
data/test/test_requestable.rb
CHANGED
@@ -12,4 +12,15 @@ class TestAccessToken < Minitest::Test
|
|
12
12
|
MyJohnDeere::Requestable.new({}, "something")
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
16
|
+
def test_has_access_to
|
17
|
+
r = MyJohnDeere::Requestable.new({"links" => [
|
18
|
+
{
|
19
|
+
"rel" => "addresses",
|
20
|
+
"uri" => "https://sandboxapi.deere.com/platform/organizations/1234/addresses"
|
21
|
+
}]})
|
22
|
+
|
23
|
+
assert r.has_access_to?("addresses")
|
24
|
+
assert !r.has_access_to?("something_else")
|
25
|
+
end
|
15
26
|
end
|
data/test/test_rest_methods.rb
CHANGED
@@ -51,11 +51,15 @@ class TestRestMethods < Minitest::Test
|
|
51
51
|
|
52
52
|
def test_build_resource_base_path
|
53
53
|
resource_path = "blah"
|
54
|
-
|
54
|
+
path, base_resources = MyJohnDeere::Organization.build_resource_base_path!("blah", {})
|
55
|
+
assert_equal "blah", path
|
56
|
+
assert_nil base_resources
|
55
57
|
resource_path = "blah%{x_id}"
|
56
58
|
options = {x: 5, x_id: 1}
|
57
|
-
|
59
|
+
path, base_resources = MyJohnDeere::Organization.build_resource_base_path!(resource_path, options)
|
60
|
+
assert_equal "blah1", path
|
58
61
|
assert_equal({x: 5}, options)
|
62
|
+
assert_equal({x_id: 1}, base_resources)
|
59
63
|
|
60
64
|
assert_raises ArgumentError do
|
61
65
|
MyJohnDeere::Organization.build_resource_base_path!(resource_path, {})
|
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Susmarski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.6.13
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
110
|
summary: Ruby bindings for the MyJohnDeere API
|