apimatic_core 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/apimatic-core/utilities/api_helper.rb +1 -2
- data/lib/apimatic-core/utilities/json_pointer_helper.rb +134 -0
- data/lib/apimatic_core.rb +1 -1
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 748bf7df87d6f81d0b5d593d893451ea2f1a38d4baa0f5a8034d12a9287bf11f
|
4
|
+
data.tar.gz: 5fbf6484cb560e4c0fbd9cf41b18dfdb65c1efb52a66de4d559916ca417d3eca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bfbdc11191f658ac7e3dc9dd5dcc57b6854bcd3690ebeba1a6c77122a543c92f39e486aae6106bd191bf25bed3c599d073be0e49844445b40d61a45f29840ba
|
7
|
+
data.tar.gz: 4bf096df545db3b501d85c7a22e945dff7c4f2ef287c88af9b7a782293435a8063373209acddcfd309fc3ba6330b535cb6d4b14509dfcfc0f25802c82205fc7a
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'erb'
|
2
|
-
require 'json-pointer'
|
3
2
|
|
4
3
|
module CoreLibrary
|
5
4
|
# API utility class involved in executing an API
|
@@ -469,7 +468,7 @@ module CoreLibrary
|
|
469
468
|
if placeholder.include? '#'
|
470
469
|
# pick the 2nd chunk then remove the last character (i.e. `}`) of the string value
|
471
470
|
node_pointer = placeholder.split('#')[1].delete_suffix('}')
|
472
|
-
value_pointer =
|
471
|
+
value_pointer = JsonPointerHelper.new(value, node_pointer, symbolize_keys: true)
|
473
472
|
extracted_value = json_serialize(value_pointer.value) if value_pointer.exists?
|
474
473
|
elsif !value.nil?
|
475
474
|
extracted_value = json_serialize(value)
|
@@ -0,0 +1,134 @@
|
|
1
|
+
module CoreLibrary
|
2
|
+
# A utility for json specific operations.
|
3
|
+
class JsonPointerHelper
|
4
|
+
NotFound = Class.new
|
5
|
+
WILDCARD = '~'.freeze
|
6
|
+
ARRAY_PUSH_KEY = '-'.freeze
|
7
|
+
|
8
|
+
def self.escape_fragment(fragment)
|
9
|
+
return fragment if fragment == WILDCARD
|
10
|
+
|
11
|
+
fragment.gsub(/~/, '~0').gsub(%r{/}, '~1')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.unescape_fragment(fragment)
|
15
|
+
fragment.gsub(/~1/, '/').gsub(/~0/, '~')
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(hash, path, options = {})
|
19
|
+
@hash = hash
|
20
|
+
@path = path
|
21
|
+
@options = options
|
22
|
+
end
|
23
|
+
|
24
|
+
def value
|
25
|
+
get_member_value
|
26
|
+
end
|
27
|
+
|
28
|
+
def exists?
|
29
|
+
_exists = false
|
30
|
+
get_target_member(@hash, path_fragments.dup) do |target, options = {}|
|
31
|
+
if options[:wildcard]
|
32
|
+
_exists = target.any? { |t| !t.nil? && !t.is_a?(NotFound) }
|
33
|
+
else
|
34
|
+
_exists = true unless target.is_a?(NotFound)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
_exists
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def get_member_value(obj = @hash, fragments = path_fragments.dup)
|
43
|
+
return obj if fragments.empty?
|
44
|
+
|
45
|
+
fragment = fragments.shift
|
46
|
+
case obj
|
47
|
+
when Hash
|
48
|
+
get_member_value(obj[fragment_to_key(fragment)], fragments)
|
49
|
+
when Array
|
50
|
+
if fragment == WILDCARD
|
51
|
+
obj.map { |i| get_member_value(i, fragments.dup) }
|
52
|
+
else
|
53
|
+
get_member_value(obj[fragment_to_index(fragment)], fragments)
|
54
|
+
end
|
55
|
+
else
|
56
|
+
NotFound.new
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_target_member(obj, fragments, options = {}, &block)
|
61
|
+
return yield(obj, {}) if fragments.empty?
|
62
|
+
|
63
|
+
case obj
|
64
|
+
when Hash
|
65
|
+
get_target_member_if_hash(obj, fragments, options, &block)
|
66
|
+
when Array
|
67
|
+
get_target_member_if_array(obj, fragments, options, &block)
|
68
|
+
else
|
69
|
+
NotFound.new
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_target_member_if_hash(obj, fragments, options = {}, &block)
|
74
|
+
fragment = fragments.shift
|
75
|
+
key = fragment_to_key(fragment)
|
76
|
+
obj = if options[:create_missing]
|
77
|
+
obj[key] ||= {}
|
78
|
+
else
|
79
|
+
obj.key?(key) ? obj[key] : NotFound.new
|
80
|
+
end
|
81
|
+
|
82
|
+
get_target_member(obj, fragments, options, &block)
|
83
|
+
end
|
84
|
+
|
85
|
+
def get_target_member_if_array(obj, fragments, options = {}, &block)
|
86
|
+
fragment = fragments.shift
|
87
|
+
if fragment == WILDCARD
|
88
|
+
if obj.any?
|
89
|
+
targets = obj.map do |i|
|
90
|
+
get_target_member(i || {}, fragments.dup, options) do |t|
|
91
|
+
t
|
92
|
+
end
|
93
|
+
end
|
94
|
+
yield(targets, wildcard: true)
|
95
|
+
else
|
96
|
+
NotFound.new
|
97
|
+
end
|
98
|
+
else
|
99
|
+
index = fragment_to_index(fragment)
|
100
|
+
obj = if options[:create_missing]
|
101
|
+
obj[index] ||= {}
|
102
|
+
else
|
103
|
+
index >= obj.size ? NotFound.new : obj[index]
|
104
|
+
end
|
105
|
+
|
106
|
+
get_target_member(obj, fragments, &block)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def path_fragments
|
111
|
+
@path_fragments ||= @path.sub(%r{\A/}, '').split('/').map { |fragment| unescape_fragment(fragment) }
|
112
|
+
end
|
113
|
+
|
114
|
+
def escape_fragment(fragment)
|
115
|
+
JsonPointerHelper.escape_fragment(fragment)
|
116
|
+
end
|
117
|
+
|
118
|
+
def unescape_fragment(fragment)
|
119
|
+
JsonPointerHelper.unescape_fragment(fragment)
|
120
|
+
end
|
121
|
+
|
122
|
+
def fragment_to_key(fragment)
|
123
|
+
if @options[:symbolize_keys]
|
124
|
+
fragment.to_sym
|
125
|
+
else
|
126
|
+
fragment
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def fragment_to_index(fragment)
|
131
|
+
fragment.to_i
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
data/lib/apimatic_core.rb
CHANGED
@@ -3,7 +3,6 @@ require 'json'
|
|
3
3
|
require 'certifi'
|
4
4
|
require 'apimatic_core_interfaces'
|
5
5
|
require 'cgi'
|
6
|
-
require 'json-pointer'
|
7
6
|
|
8
7
|
require_relative 'apimatic-core/request_builder'
|
9
8
|
require_relative 'apimatic-core/response_handler'
|
@@ -44,6 +43,7 @@ require_relative 'apimatic-core/utilities/file_helper'
|
|
44
43
|
require_relative 'apimatic-core/utilities/xml_helper'
|
45
44
|
require_relative 'apimatic-core/utilities/auth_helper'
|
46
45
|
require_relative 'apimatic-core/utilities/union_type_helper'
|
46
|
+
require_relative 'apimatic-core/utilities/json_pointer_helper'
|
47
47
|
|
48
48
|
require_relative 'apimatic-core/authentication/header_auth'
|
49
49
|
require_relative 'apimatic-core/authentication/query_auth'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apimatic_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- APIMatic Ltd.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: apimatic_core_interfaces
|
@@ -78,20 +78,6 @@ dependencies:
|
|
78
78
|
- - "~>"
|
79
79
|
- !ruby/object:Gem::Version
|
80
80
|
version: '1.0'
|
81
|
-
- !ruby/object:Gem::Dependency
|
82
|
-
name: json-pointer
|
83
|
-
requirement: !ruby/object:Gem::Requirement
|
84
|
-
requirements:
|
85
|
-
- - ">="
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
version: '0'
|
88
|
-
type: :runtime
|
89
|
-
prerelease: false
|
90
|
-
version_requirements: !ruby/object:Gem::Requirement
|
91
|
-
requirements:
|
92
|
-
- - ">="
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: '0'
|
95
81
|
- !ruby/object:Gem::Dependency
|
96
82
|
name: faraday
|
97
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,6 +192,7 @@ files:
|
|
206
192
|
- lib/apimatic-core/utilities/comparison_helper.rb
|
207
193
|
- lib/apimatic-core/utilities/date_time_helper.rb
|
208
194
|
- lib/apimatic-core/utilities/file_helper.rb
|
195
|
+
- lib/apimatic-core/utilities/json_pointer_helper.rb
|
209
196
|
- lib/apimatic-core/utilities/union_type_helper.rb
|
210
197
|
- lib/apimatic-core/utilities/xml_helper.rb
|
211
198
|
- lib/apimatic_core.rb
|
@@ -228,7 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
228
215
|
- !ruby/object:Gem::Version
|
229
216
|
version: '0'
|
230
217
|
requirements: []
|
231
|
-
rubygems_version: 3.4.
|
218
|
+
rubygems_version: 3.4.19
|
232
219
|
signing_key:
|
233
220
|
specification_version: 4
|
234
221
|
summary: A library that contains apimatic-apimatic-core logic and utilities for consuming
|