myjohndeere 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6f1396f290f034c7d9bc96100a798d5e3a653e7
4
- data.tar.gz: f0815526e2742dae974c1ed89745265e60a5a433
3
+ metadata.gz: 8b4556fe6533cae23c117ffd3d72d809f8c8bf2c
4
+ data.tar.gz: 86f46e02faf114baecf904059a1b333cedfb731e
5
5
  SHA512:
6
- metadata.gz: 6e09bf7d4e04d3a9d2b2093fdff043d5653c86d246fe5db098b6fc117db90f111cbf240b99a56f63ef41b81decae090338689843ec953a08ac66b34e283c4d05
7
- data.tar.gz: ae920d40bdcb973f0fa8ecfe7a5bf3c8185f212c80578a0ccb975f6e1e6925183a63501d4c16a01a71e512766fdd2a28223c744fdead6df105cfbf80dd5fba37
6
+ metadata.gz: f08775c36e5979e14558cb53feba7682c73aa0f43b6b7aec8054965891b7b224026559dfb1c44aba5aea5b2a8def4051aaf70ed1f81c132c5f9e79d9adae0f4f
7
+ data.tar.gz: efe276478ee3868e6c4a23509d01de0e2b8756f96b6671d272e1a90c18900f44708195c42a6f0507d936a3b734eebeba41ef558ad63adcd4c3e38a73c7cba788
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- myjohndeere (0.1.8)
4
+ myjohndeere (0.1.9)
5
5
  oauth (>= 0.5.3)
6
6
 
7
7
  GEM
@@ -14,7 +14,7 @@ GEM
14
14
  safe_yaml (~> 1.0.0)
15
15
  hashdiff (0.3.2)
16
16
  minitest (5.8.4)
17
- oauth (0.5.3)
17
+ oauth (0.5.4)
18
18
  public_suffix (2.0.5)
19
19
  rake (11.3.0)
20
20
  safe_yaml (1.0.4)
@@ -34,4 +34,4 @@ DEPENDENCIES
34
34
  webmock
35
35
 
36
36
  BUNDLED WITH
37
- 1.13.2
37
+ 1.16.1
data/lib/myjohndeere.rb CHANGED
@@ -81,13 +81,18 @@ module MyJohnDeere
81
81
 
82
82
  class Configuration
83
83
  attr_accessor :endpoint
84
- attr_writer :shared_secret, :app_id, :contribution_definition_id
84
+ attr_writer :shared_secret, :app_id, :contribution_definition_id, :use_last_active_boundary
85
85
  attr_reader :environment
86
86
 
87
87
  def log_level=(val)
88
88
  @log_level = val
89
89
  end
90
90
 
91
+ def use_last_active_boundary
92
+ @use_last_active_boundary ||= false
93
+ return @use_last_active_boundary
94
+ end
95
+
91
96
  def log_level
92
97
  @log_level ||= :fatal
93
98
  return @log_level
@@ -39,7 +39,12 @@ module MyJohnDeere
39
39
  active_boundaries = possible_boundaries.select { |b| b.active && !b.deleted }.
40
40
  uniq { |b| b.id }
41
41
  if active_boundaries.count > 1 then
42
- raise MyJohnDeereError.new("There was more than one boundary in the field ID: #{self.id}, this is currently unexpected")
42
+ if MyJohnDeere.configuration.use_last_active_boundary then
43
+ MyJohnDeere.logger.info("Multiple boundaries found for field ID: #{self.id}. Using last active")
44
+ return active_boundaries.last
45
+ else
46
+ raise MyJohnDeereError.new("There was more than one boundary in the field ID: #{self.id}, this is currently unexpected")
47
+ end
43
48
  elsif active_boundaries.count == 1 then
44
49
  return active_boundaries.first
45
50
  else
@@ -37,7 +37,7 @@ 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 !::File.exists?(file_path)
40
+ raise ArgumentError.new("You must pass an existing file") if !::File.exist?(file_path)
41
41
  raise ArgumentError.new("You must pass a valid file_resource_id") if file_resource_id.nil?
42
42
 
43
43
  ::File.open(file_path, "rb:UTF-8") do |f|
@@ -1,3 +1,3 @@
1
1
  module MyJohnDeere
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.9'
3
3
  end
data/spec/fixtures.json CHANGED
@@ -467,6 +467,262 @@
467
467
  }
468
468
  ]
469
469
  },
470
+ "field_with_multiple_active_boundaries_unique_ids" : {
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
+ },
470
726
  "field_with_multiple_active_boundaries" : {
471
727
  "@type":"Field",
472
728
  "name":"AndersonFarms",
data/test/test_field.rb CHANGED
@@ -42,6 +42,33 @@ class TestField < Minitest::Test
42
42
  assert !field.boundary_unset?
43
43
  end
44
44
 
45
+ def test_retrieval_with_multiple_active_boundaries_and_config_change
46
+ begin
47
+ fixture = API_FIXTURES["field_with_multiple_active_boundaries_unique_ids"]
48
+
49
+ stub_request(:get, /\/organizations\/#{ORGANIZATION_FIXTURE["id"]}\/fields\/#{fixture["id"]}/).
50
+ with(query: {embed: "boundaries"}).
51
+ to_return(status: 200, body: fixture.to_json)
52
+
53
+ MyJohnDeere.configuration.use_last_active_boundary = false
54
+
55
+ assert_raises MyJohnDeere::MyJohnDeereError do
56
+ MyJohnDeere::Field.retrieve(default_access_token,
57
+ fixture["id"], organization_id: ORGANIZATION_FIXTURE["id"],
58
+ body: {embed: "boundaries"})
59
+ end
60
+
61
+ MyJohnDeere.configuration.use_last_active_boundary = true
62
+
63
+ field = MyJohnDeere::Field.retrieve(default_access_token,
64
+ fixture["id"], organization_id: ORGANIZATION_FIXTURE["id"],
65
+ body: {embed: "boundaries"})
66
+ assert_equal fixture["boundaries"][1]["id"], field.boundary.id
67
+ ensure
68
+ MyJohnDeere.configuration.use_last_active_boundary = false
69
+ end
70
+ end
71
+
45
72
  def test_retrieval_with_multiple_boundaries
46
73
  fixture = API_FIXTURES["field_with_multiple_boundaries"]
47
74
 
metadata CHANGED
@@ -1,38 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myjohndeere
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Susmarski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-24 00:00:00.000000000 Z
11
+ date: 2018-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.5.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.5.3
27
- description: ' MyJohnDeere allows you to access your John Deere Financial account,
27
+ description: " MyJohnDeere allows you to access your John Deere Financial account,
28
28
  JDLink, Operations Center and many other applications from one convenient place.
29
- This Ruby Gem is provided as a convenient way to access their API.'
29
+ This Ruby Gem is provided as a convenient way to access their API."
30
30
  email: paul@susmarski.com
31
31
  executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - .gitignore
35
+ - ".gitignore"
36
36
  - Gemfile
37
37
  - Gemfile.lock
38
38
  - LICENSE
@@ -94,17 +94,17 @@ require_paths:
94
94
  - lib
95
95
  required_ruby_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - '>='
97
+ - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: 1.9.3
100
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - '>='
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
106
  rubyforge_project:
107
- rubygems_version: 2.0.14.1
107
+ rubygems_version: 2.5.1
108
108
  signing_key:
109
109
  specification_version: 4
110
110
  summary: Ruby bindings for the MyJohnDeere API