sendle_api 0.1.9 → 0.2.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/lib/sendle_api/errors.rb +8 -53
- data/lib/sendle_api/version.rb +1 -1
- data/sendle_api.gemspec +5 -4
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a6d36701b1b8fa5816f7e19a6e4e19da3d169c2b1e3001310e7480a6f1c87a0
|
4
|
+
data.tar.gz: 0fd6ab34c7f2d65ef57b6c0a6a2b12d329055a3b2601d39247f2c825741d4a2e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e27eaf700d38a76b4db7437109013328bbeaa0c3d1dbb44aff6eaa4cece40e12b83c9c5af87f9538e4bd4d4695a65cfc2b66be70c9f126639beb80230f6f555
|
7
|
+
data.tar.gz: 8a0de62d7bf13843cf38e55549bf2858711dcf9275a1be9a46d8416928c7b09443856d9c9e761079abe9cc5391a098c93bea46a912ee3f7fd1cdf0ed069b211a
|
data/lib/sendle_api/errors.rb
CHANGED
@@ -1,71 +1,26 @@
|
|
1
|
-
|
2
1
|
require "active_support/core_ext/array/wrap"
|
3
2
|
require "active_support/core_ext/object/blank"
|
4
3
|
|
5
4
|
module SendleAPI
|
6
|
-
class Errors <
|
7
|
-
# Grabs errors from an array of messages (like ActiveRecord::Validations).
|
8
|
-
# The second parameter directs the errors cache to be cleared (default)
|
9
|
-
# or not (by passing true).
|
10
|
-
def from_array(messages, save_cache = false)
|
11
|
-
clear unless save_cache
|
12
|
-
humanized_attributes = Hash[@base.known_attributes.map { |attr_name| [attr_name.humanize, attr_name] }]
|
13
|
-
messages.each do |message|
|
14
|
-
attr_message = humanized_attributes.keys.sort_by { |a| -a.length }.detect do |attr_name|
|
15
|
-
if message[0, attr_name.size + 1] == "#{attr_name} "
|
16
|
-
add humanized_attributes[attr_name], message[(attr_name.size + 1)..-1]
|
17
|
-
end
|
18
|
-
end
|
19
|
-
self[:base] << message if attr_message.nil?
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Grabs errors from a hash of attribute => array of errors elements
|
24
|
-
# The second parameter directs the errors cache to be cleared (default)
|
25
|
-
# or not (by passing true)
|
26
|
-
#
|
27
|
-
# Unrecognized attribute names will be humanized and added to the record's
|
28
|
-
# base errors.
|
5
|
+
class Errors < ActiveResource::Errors
|
29
6
|
def from_hash(messages, save_cache = false)
|
30
7
|
clear unless save_cache
|
31
8
|
|
32
|
-
|
33
|
-
|
34
|
-
messages.
|
35
|
-
|
36
|
-
messages.each do |(key, errors)|
|
9
|
+
add(:base, messages["error_description"]) if messages["error_description"]
|
10
|
+
|
11
|
+
messages["messages"].each do |(key, errors)|
|
37
12
|
errors.each do |error|
|
38
13
|
if @base.known_attributes.include?(key)
|
39
|
-
add
|
14
|
+
add(key, error)
|
40
15
|
elsif key == "base"
|
41
|
-
|
16
|
+
add(:base, error)
|
42
17
|
else
|
43
18
|
# reporting an error on an attribute not in attributes
|
44
19
|
# format and add them to base
|
45
|
-
|
20
|
+
add(:base, "#{key.humanize} #{error}")
|
46
21
|
end
|
47
22
|
end
|
48
23
|
end
|
49
24
|
end
|
50
|
-
|
51
|
-
# Grabs errors from a json response.
|
52
|
-
def from_json(json, save_cache = false)
|
53
|
-
decoded = ActiveSupport::JSON.decode(json) || {} rescue {}
|
54
|
-
if decoded.kind_of?(Hash) && (decoded.has_key?("errors") || decoded.empty?)
|
55
|
-
errors = decoded["errors"] || {}
|
56
|
-
if errors.kind_of?(Array)
|
57
|
-
# 3.2.1-style with array of strings
|
58
|
-
ActiveSupport::Deprecation.warn("Returning errors as an array of strings is deprecated.")
|
59
|
-
from_array errors, save_cache
|
60
|
-
else
|
61
|
-
# 3.2.2+ style
|
62
|
-
from_hash errors, save_cache
|
63
|
-
end
|
64
|
-
else
|
65
|
-
# <3.2-style respond_with - lacks 'errors' key
|
66
|
-
ActiveSupport::Deprecation.warn('Returning errors as a hash without a root "errors" key is deprecated.')
|
67
|
-
from_hash decoded, save_cache
|
68
|
-
end
|
69
|
-
end
|
70
25
|
end
|
71
|
-
end
|
26
|
+
end
|
data/lib/sendle_api/version.rb
CHANGED
data/sendle_api.gemspec
CHANGED
@@ -21,14 +21,15 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
# Specify which files should be added to the gem when it is released.
|
23
23
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
-
spec.files =
|
25
|
-
|
26
|
-
|
24
|
+
spec.files =
|
25
|
+
Dir.chdir(File.expand_path("..", __FILE__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
|
+
end
|
27
28
|
spec.bindir = "exe"
|
28
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
30
|
spec.require_paths = ["lib"]
|
30
31
|
|
31
|
-
spec.add_dependency("activeresource", ">=
|
32
|
+
spec.add_dependency("activeresource", ">= 6.1.0")
|
32
33
|
|
33
34
|
spec.add_development_dependency("dotenv")
|
34
35
|
spec.add_development_dependency("guard-rspec")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sendle_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Chong
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activeresource
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.1.0
|
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
|
-
version:
|
26
|
+
version: 6.1.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dotenv
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -203,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
203
|
- !ruby/object:Gem::Version
|
204
204
|
version: '0'
|
205
205
|
requirements: []
|
206
|
-
rubygems_version: 3.
|
206
|
+
rubygems_version: 3.5.23
|
207
207
|
signing_key:
|
208
208
|
specification_version: 4
|
209
209
|
summary: Ruby object based Sendle API wrapper.
|