my_john_deere_api 2.2.2 → 2.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/my_john_deere_api/request/create/base.rb +2 -44
- data/lib/my_john_deere_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b21ab5fade7543a53cfb56a48d2cc251d397ad66ce5fc7642921084683b6a767
|
4
|
+
data.tar.gz: f6cac8a2d165caa91171d8f495faaa1013867c50402fb327fcd0ac272806ed93
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d09890868c851fa39c64a7934d1060e167d980d05a058e84b699c0916642d2b485f996efea49ad20210d9d61173870a301e42a81891695a04bd0616feba0cbf0
|
7
|
+
data.tar.gz: 6fdd6b0bee46bb7a6e375259ae21c1ddf2c9113d7b2343f518e6716bf06d1c0811b4d7e3de75aa02cc90c05a76564e50d872d05e5078ec676b2b4d0d20ae49b2
|
data/README.md
CHANGED
@@ -490,6 +490,24 @@ client.delete('/assets/123123')
|
|
490
490
|
|
491
491
|
John Deere's standard response is a 204 HTTP status code, with the message "No Content". This method returns the full Net::HTTP response.
|
492
492
|
|
493
|
+
|
494
|
+
### Errors
|
495
|
+
|
496
|
+
Custom errors help clearly identify problems when using the client:
|
497
|
+
|
498
|
+
* **UnsupportedEnvironmentError** is raised when you attempt to instantiate a client with an
|
499
|
+
unrecognized environment. Valid environments are `:sandbox` or `:production`.
|
500
|
+
* **InvalidRecordError** is raised when bad input has been given, in an attempt to create or update
|
501
|
+
a record on the John Deere platform.
|
502
|
+
* **TypeMismatchError** is raised when a model is instantiated, typically when a record is received
|
503
|
+
from John Deere and is being converted into a Ruby object. Model instantiation is normally handled
|
504
|
+
by request objects, but this error is helpful if you're instantiating your own models for advanced
|
505
|
+
usage.
|
506
|
+
* **NotYetImplementedError** is raised when you attempt to use a feature that is earmarked for future
|
507
|
+
development, but hasn't been implemented in this client yet. These are a great chance to contribute
|
508
|
+
to this gem!
|
509
|
+
|
510
|
+
|
493
511
|
### Contributing to This Gem
|
494
512
|
|
495
513
|
The easiest way to contribute is:
|
@@ -2,6 +2,8 @@ require 'json'
|
|
2
2
|
|
3
3
|
module MyJohnDeereApi
|
4
4
|
class Request::Create::Base
|
5
|
+
include Validators::Base
|
6
|
+
|
5
7
|
attr_reader :client, :attributes, :response
|
6
8
|
|
7
9
|
##
|
@@ -42,36 +44,8 @@ module MyJohnDeereApi
|
|
42
44
|
@object = model.new(client, fetch_record)
|
43
45
|
end
|
44
46
|
|
45
|
-
##
|
46
|
-
# Runs validations, adding to the errors hash as needed. Returns true
|
47
|
-
# if the errors hash is still empty after all validations have been run.
|
48
|
-
|
49
|
-
def valid?
|
50
|
-
return @is_valid if defined?(@is_valid)
|
51
|
-
|
52
|
-
validate_required
|
53
|
-
validate_attributes
|
54
|
-
|
55
|
-
@is_valid = errors.empty?
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
# Raises an error if the record is invalid. Passes the errors hash
|
60
|
-
# to the error, in order to build a useful message string.
|
61
|
-
|
62
|
-
def validate!
|
63
|
-
raise(InvalidRecordError, errors) unless valid?
|
64
|
-
end
|
65
|
-
|
66
47
|
private
|
67
48
|
|
68
|
-
##
|
69
|
-
# Run validations unique to a given model. This should be overridden
|
70
|
-
# by children where needed.
|
71
|
-
|
72
|
-
def validate_attributes
|
73
|
-
end
|
74
|
-
|
75
49
|
##
|
76
50
|
# Convert inputs into working attributes. This allows us to auto-create
|
77
51
|
# some attributes from others, or set defaults, on a class-by-class basis.
|
@@ -80,22 +54,6 @@ module MyJohnDeereApi
|
|
80
54
|
def process_attributes
|
81
55
|
end
|
82
56
|
|
83
|
-
##
|
84
|
-
# Attributes that must be specified, override in child class
|
85
|
-
|
86
|
-
def required_attributes
|
87
|
-
[]
|
88
|
-
end
|
89
|
-
|
90
|
-
##
|
91
|
-
# Validates required attributes
|
92
|
-
|
93
|
-
def validate_required
|
94
|
-
required_attributes.each do |attr|
|
95
|
-
errors[attr] = 'is required' unless attributes[attr]
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
57
|
##
|
100
58
|
# Headers for POST request
|
101
59
|
|