cropio-ruby 0.16 → 0.30

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
  SHA256:
3
- metadata.gz: c683d6641c3ac442f0ee38bff30617d43017eb3164662262382631578b1fed03
4
- data.tar.gz: 7b9f418f5798fd0312f10b6d7a0dc580efe4071d84fbada4140a3c169e5461ff
3
+ metadata.gz: 77758f23f2c5d9cdcf0400363600bc364672fd822fd2ba06db2c2db9fd43723e
4
+ data.tar.gz: 134dbc4b77839a712ced82a2374b931a65a0620dd54414a216290c077aefeead
5
5
  SHA512:
6
- metadata.gz: d44f8a9dec5b88545a4024544fa730171a2132e90d6cc9cf95950dd17d3f66adf785c31fcbc035e71249ba13d0e9720f57493be9b69fefa90883c6fd7c3b56ff
7
- data.tar.gz: 919218f9db0cdf2fd5797420c76da265a11033ad68732065d3935424ec54764b3aba2a94bf5cc184293dd9bdc529e83141b6f44d4103402c2bf5f3d83a898987
6
+ metadata.gz: c839106f25b44657f26c4f2f1d7ca21924975c43a6ada212e04f067b510e0d8577d9f07bfbeb89a24ca387f208d6630756f8ddd8e2f67049675d42bc3578a214
7
+ data.tar.gz: cc592d5711cad983f2df110aebee664ec92c7d53e1d34a9bc0169a1ecbb7cfbd7412f1e998b146e3b7006d55bb22545071ac74d9e459f114045e7e79f635b75c
data/README.md CHANGED
@@ -56,6 +56,11 @@ Currently supported API methods is:
56
56
  Crop.all
57
57
  ```
58
58
 
59
+ - get record by id
60
+ ```ruby
61
+ Crop.find(1)
62
+ ```
63
+
59
64
  - create
60
65
 
61
66
  ```ruby
@@ -27,7 +27,7 @@ STR
27
27
  spec.license = 'MIT'
28
28
 
29
29
  spec.add_dependency 'json'
30
- spec.add_dependency 'rest-client'
30
+ spec.add_dependency 'rest-client', '~>2.1.0rc1'
31
31
 
32
32
  spec.add_development_dependency 'bundler', '~> 1.9'
33
33
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -7,7 +7,9 @@ module Cropio
7
7
  # Accepts reources name and params to perform HTTPS GET request.
8
8
  def get(resource, query = {})
9
9
  rmethod = extract_resource_method!(query)
10
- proxy(method: :get, url: url_for(resource, rmethod),
10
+ id = extract_record_id!(query)
11
+
12
+ proxy(method: :get, url: url_for(resource, rmethod, id),
11
13
  headers: { params: query })
12
14
  end
13
15
 
@@ -28,17 +30,25 @@ module Cropio
28
30
 
29
31
  protected
30
32
 
31
- def url_for(resource, resource_method = nil)
33
+ def url_for(resource, resource_method = nil, id = nil)
32
34
  url = "#{Cropio::Connection::Configurable::BASE_URL}/#{resource}"
33
35
  url += "/#{resource_method}" if resource_method
36
+ url += "/#{id}" if id
34
37
  url
35
38
  end
36
39
 
37
40
  def extract_resource_method!(query)
38
- fail(ArgumentError) unless query.is_a?(Hash)
41
+ raise ArgumentError unless query.is_a?(Hash)
42
+
39
43
  query.delete(:resource_method)
40
44
  end
41
45
 
46
+ def extract_record_id!(query)
47
+ raise ArgumentError unless query.is_a?(Hash)
48
+
49
+ query.delete(:id)
50
+ end
51
+
42
52
  def proxy(options)
43
53
  options[:headers] ||= {}
44
54
  options[:headers].merge!(headers)
@@ -48,10 +58,13 @@ module Cropio
48
58
  rescue RestClient::UnprocessableEntity => e
49
59
  puts JSON.parse(e.http_body)
50
60
  raise e
61
+ rescue RestClient::NotFound
62
+ {}
51
63
  end
52
64
 
53
65
  def clear_params_in_options!(options)
54
66
  return if options[:headers][:params].nil?
67
+
55
68
  options[:headers][:params].reject! { |_k, v| v.nil? }
56
69
  end
57
70
 
@@ -42,6 +42,13 @@ module Cropio
42
42
  to_instances(get_all_changes(from_time, to_time))
43
43
  end
44
44
 
45
+ def self.find(id)
46
+ obj = PROXY.get(resources_name, id: id).fetch('data', nil)
47
+ return if obj.nil?
48
+
49
+ to_instance(obj)
50
+ end
51
+
45
52
  # Returns persistance of the resource.
46
53
  # Resource is persisted if it is saved
47
54
  # and not deleted, if this resource exists
@@ -61,7 +61,10 @@ require_relative './resources/land_document'
61
61
  require_relative './resources/land_document_land_parcel_mapping_item'
62
62
  require_relative './resources/land_parcel'
63
63
  require_relative './resources/protected_document'
64
-
64
+ require_relative './resources/productivity_estimate_history'
65
+ require_relative './resources/fuel_hourly_data_item'
66
+ require_relative './resources/productivity_estimate'
67
+ require_relative './resources/productivity_estimate_peer'
65
68
 
66
69
  module Cropio
67
70
  module Resources
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cropio
4
+ module Resources
5
+ class FuelHourlyDataItem < Cropio::Resource::Base
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cropio
4
+ module Resources
5
+ class ProductivityEstimate < Cropio::Resource::Base
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cropio
4
+ module Resources
5
+ class ProductivityEstimateHistory < Cropio::Resource::Base
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cropio
4
+ module Resources
5
+ class ProductivityEstimatePeer < Cropio::Resource::Base
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Cropio
2
- VERSION = '0.16'.freeze
2
+ VERSION = '0.30'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cropio-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.16'
4
+ version: '0.30'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Vernidub
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-18 00:00:00.000000000 Z
11
+ date: 2020-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rest-client
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2.1.0rc1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.1.0rc1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -145,6 +145,7 @@ files:
145
145
  - lib/cropio/resources/field_scout_report_threat_mapping_item.rb
146
146
  - lib/cropio/resources/field_shape.rb
147
147
  - lib/cropio/resources/field_shape_land_parcel_mapping_item.rb
148
+ - lib/cropio/resources/fuel_hourly_data_item.rb
148
149
  - lib/cropio/resources/group_folder.rb
149
150
  - lib/cropio/resources/harvest_weighing.rb
150
151
  - lib/cropio/resources/historical_value.rb
@@ -173,6 +174,9 @@ files:
173
174
  - lib/cropio/resources/note.rb
174
175
  - lib/cropio/resources/photo.rb
175
176
  - lib/cropio/resources/plant_threat.rb
177
+ - lib/cropio/resources/productivity_estimate.rb
178
+ - lib/cropio/resources/productivity_estimate_history.rb
179
+ - lib/cropio/resources/productivity_estimate_peer.rb
176
180
  - lib/cropio/resources/protected_document.rb
177
181
  - lib/cropio/resources/satellite_image.rb
178
182
  - lib/cropio/resources/seed.rb