ncore 3.14.0 → 3.15.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/CHANGELOG.md +6 -0
- data/LICENSE +1 -1
- data/README.md +0 -3
- data/lib/ncore/attributes.rb +23 -1
- data/lib/ncore/client.rb +32 -22
- data/lib/ncore/version.rb +1 -1
- data/ncore.gemspec +1 -0
- metadata +15 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ac9447e7da05e0e5822bc1f853d60054fdcbf4ed383c7faa5e3454a791ea7b9a
|
|
4
|
+
data.tar.gz: 253422e826a1009929f1d8fe565aaeb9e9f36d142125b258dbe7523cb1aea6bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0416aa8b47c956fa4f982aee4071c5ef3ecf64d08fb0916b234d051bacf2d6c13f882a396b2bd75c0b502debc0ea36248fa8bacb80580ab95366112a132a8751
|
|
7
|
+
data.tar.gz: 8a43de4843cd2363a1b250b1b89486de0b422aa0aa12cbc3746a775d8145d0cf25f504628fa761fedae76de451eef6a902f70747ceb7a79e0bae531a14381c0d
|
data/CHANGELOG.md
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -5,9 +5,6 @@ client by itself, but provides several useful building blocks to build one.
|
|
|
5
5
|
|
|
6
6
|
It relies on `excon` for HTTP handling and `activemodel`.
|
|
7
7
|
|
|
8
|
-
If present, uses `multi_json`. Otherwise, the stdlib 'json' is used.
|
|
9
|
-
'multi_json' with an accelerated json gem is recommended.
|
|
10
|
-
|
|
11
8
|
See `example/` for the beginning of an actual api client.
|
|
12
9
|
|
|
13
10
|
|
data/lib/ncore/attributes.rb
CHANGED
|
@@ -48,9 +48,29 @@ module NCore
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
# attr_decimal(:amount, ...)
|
|
51
|
-
# adds: obj.amount =>
|
|
51
|
+
# adds: obj.amount => BigDecimal if String, else raw json type
|
|
52
52
|
# obj.amount? => bool
|
|
53
53
|
def attr_decimal(*attrs, predicate: true)
|
|
54
|
+
attrs.each do |attr|
|
|
55
|
+
check_existing_method(attr)
|
|
56
|
+
class_eval <<-AD, __FILE__, __LINE__+1
|
|
57
|
+
def #{attr}
|
|
58
|
+
case self[:#{attr}]
|
|
59
|
+
when String
|
|
60
|
+
BigDecimal(self[:#{attr}])
|
|
61
|
+
else
|
|
62
|
+
self[:#{attr}]
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
AD
|
|
66
|
+
attr_boolean :"#{attr}?" if predicate
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# attr_money(:amount, ...)
|
|
71
|
+
# adds: obj.amount => BigMoney if String or BigDecimal, else raw json type
|
|
72
|
+
# obj.amount? => bool
|
|
73
|
+
def attr_money(*attrs, predicate: true)
|
|
54
74
|
attrs.each do |attr|
|
|
55
75
|
check_existing_method(attr)
|
|
56
76
|
class_eval <<-AD, __FILE__, __LINE__+1
|
|
@@ -58,6 +78,8 @@ module NCore
|
|
|
58
78
|
case self[:#{attr}]
|
|
59
79
|
when String
|
|
60
80
|
BigMoney.new(self[:#{attr}])
|
|
81
|
+
when BigDecimal
|
|
82
|
+
BigMoney.new(self[:#{attr}].to_s)
|
|
61
83
|
else
|
|
62
84
|
self[:#{attr}]
|
|
63
85
|
end
|
data/lib/ncore/client.rb
CHANGED
|
@@ -31,11 +31,7 @@ module NCore
|
|
|
31
31
|
path += qs
|
|
32
32
|
payload = nil
|
|
33
33
|
else
|
|
34
|
-
|
|
35
|
-
payload = MultiJson.encode params.as_json
|
|
36
|
-
else
|
|
37
|
-
payload = params.to_json
|
|
38
|
-
end
|
|
34
|
+
payload = json_coder.generate params
|
|
39
35
|
end
|
|
40
36
|
|
|
41
37
|
rest_opts = {
|
|
@@ -252,22 +248,40 @@ module NCore
|
|
|
252
248
|
response
|
|
253
249
|
end
|
|
254
250
|
|
|
251
|
+
|
|
252
|
+
def json_opts
|
|
253
|
+
{ allow_duplicate_key: false,
|
|
254
|
+
create_additions: false,
|
|
255
|
+
decimal_class: BigDecimal,
|
|
256
|
+
symbolize_names: false,
|
|
257
|
+
}
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
def json_coder
|
|
261
|
+
@json_coder ||= ::JSON::Coder.new(json_opts) do |value, is_key|
|
|
262
|
+
case value
|
|
263
|
+
when BigDecimal
|
|
264
|
+
::JSON::Fragment.new value.to_s
|
|
265
|
+
when DateTime, Time
|
|
266
|
+
value.iso8601(3)
|
|
267
|
+
else
|
|
268
|
+
if is_key
|
|
269
|
+
value.as_json.to_s
|
|
270
|
+
else
|
|
271
|
+
value.as_json
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
end
|
|
276
|
+
|
|
255
277
|
def parse_response(response)
|
|
256
278
|
if response.body.blank?
|
|
257
279
|
json = {}
|
|
258
280
|
else
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
raise module_parent::Error, "Unable to parse API response; HTTP status: #{response.status}; body: #{response.body.inspect}"
|
|
264
|
-
end
|
|
265
|
-
else
|
|
266
|
-
begin
|
|
267
|
-
json = JSON.parse(response.body, symbolize_names: false) || {}
|
|
268
|
-
rescue JSON::ParserError
|
|
269
|
-
raise module_parent::Error, "Unable to parse API response; HTTP status: #{response.status}; body: #{response.body.inspect}"
|
|
270
|
-
end
|
|
281
|
+
begin
|
|
282
|
+
json = json_coder.parse response.body
|
|
283
|
+
rescue JSON::ParserError
|
|
284
|
+
raise module_parent::Error, "Unable to parse API response; HTTP status: #{response.status}; body: #{response.body.inspect}"
|
|
271
285
|
end
|
|
272
286
|
end
|
|
273
287
|
json = json.with_indifferent_access
|
|
@@ -339,11 +353,7 @@ module NCore
|
|
|
339
353
|
def debug_response(response)
|
|
340
354
|
return unless logger.debug?
|
|
341
355
|
headers = response.headers.transform_keys(&:downcase)
|
|
342
|
-
|
|
343
|
-
json = MultiJson.load(response.body||'', symbolize_keys: false) rescue response.body
|
|
344
|
-
else
|
|
345
|
-
json = JSON.parse(response.body||'', symbolize_names: false) rescue response.body
|
|
346
|
-
end
|
|
356
|
+
json = json_coder.parse(response.body) rescue response.body
|
|
347
357
|
logger << <<~DBG
|
|
348
358
|
RESPONSE:
|
|
349
359
|
#{response.status} | #{headers['content-type']} | #{response.body.size} bytes
|
data/lib/ncore/version.rb
CHANGED
data/ncore.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ncore
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.15.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Notioneer Team
|
|
@@ -43,6 +43,20 @@ dependencies:
|
|
|
43
43
|
- - "<"
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
45
|
version: '2'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: json
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '2.17'
|
|
53
|
+
type: :runtime
|
|
54
|
+
prerelease: false
|
|
55
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
56
|
+
requirements:
|
|
57
|
+
- - ">="
|
|
58
|
+
- !ruby/object:Gem::Version
|
|
59
|
+
version: '2.17'
|
|
46
60
|
- !ruby/object:Gem::Dependency
|
|
47
61
|
name: bundler
|
|
48
62
|
requirement: !ruby/object:Gem::Requirement
|