dtk-common-core 0.5.12 → 0.5.13
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 +8 -8
- data/lib/dtk-common-core/version.rb +1 -1
- data/lib/response.rb +35 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTQxZWIxMWFhNzdiOTFmOGYyZGRjNGM2OWI0NjZkM2Q5ZTZiMTQyNw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzMwZTg5YmI5MzY5ZTY2ZWUzNDQ0MTQxYzEzY2Q3Y2NjNWE5N2M3OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTI4ZjhiNzY0MTY2OTU2ZDdkYjM0ODNhNDM4NmQ2NmEyZmY1MmRjYzYyMGIy
|
10
|
+
OWQ1ZmExMWVmYjQ2OTUzZjA4YmFiNTI3YjU3NTlkNjI0OWFlODZhMzRlNGVj
|
11
|
+
OGY1ZTlkMjQ0NjExZWMyNjM1ZmEyMjMyOWIwNzhkMTc5MDgxNmM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NGZlNGU1NzlkNzNjZWM3MTNhNGM2ZjhjM2ZiMGFiMTFhM2FmNjc0ZjBkNzQy
|
14
|
+
ZTZhOThhNWQ3MzBiNGNlMjliMDQ4ZGNiYzEyODIwYzA2NzZkOTFmZmVlZDEw
|
15
|
+
MDYxYzk0Mjk4ZWY3NmU3MGM5MGFlMGQ1MmI0ZWZkY2I1NDNiOTg=
|
data/lib/response.rb
CHANGED
@@ -15,8 +15,31 @@ module DTK
|
|
15
15
|
GenericError = "error"
|
16
16
|
end
|
17
17
|
|
18
|
+
module ResponseConstants
|
19
|
+
# these trems dont get properly marshalled
|
20
|
+
NilTerm = '***NIL***'
|
21
|
+
BooleanTrue = '***TRUE***'
|
22
|
+
BooleanFalse = '***FALSE***'
|
23
|
+
end
|
24
|
+
|
18
25
|
class Response < Hash
|
19
26
|
include ResponseTokens
|
27
|
+
|
28
|
+
module Term
|
29
|
+
include ResponseConstants
|
30
|
+
def self.nil()
|
31
|
+
NilTerm
|
32
|
+
end
|
33
|
+
module Boolean
|
34
|
+
def self.true()
|
35
|
+
Term::BooleanTrue
|
36
|
+
end
|
37
|
+
def self.false()
|
38
|
+
Term::BooleanFalse
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
20
43
|
def initialize(hash={})
|
21
44
|
super()
|
22
45
|
replace(hash)
|
@@ -72,6 +95,10 @@ module DTK
|
|
72
95
|
self[DataField]=data_values
|
73
96
|
end
|
74
97
|
|
98
|
+
def set_data_hash(data_hash)
|
99
|
+
self[DataField]=data_hash
|
100
|
+
end
|
101
|
+
|
75
102
|
def data_ret_and_remove!(*data_keys)
|
76
103
|
data = data()
|
77
104
|
data_keys.map{|key|data.delete(internal_key_form(key))}
|
@@ -85,7 +112,7 @@ module DTK
|
|
85
112
|
def internal_key_form(key)
|
86
113
|
key.to_s
|
87
114
|
end
|
88
|
-
def external_key_form(key)
|
115
|
+
def external_key_form(key)
|
89
116
|
key.to_sym
|
90
117
|
end
|
91
118
|
private :internal_key_form,:external_key_form
|
@@ -103,7 +130,7 @@ module DTK
|
|
103
130
|
end
|
104
131
|
end
|
105
132
|
|
106
|
-
class RestClientWrapper
|
133
|
+
class RestClientWrapper
|
107
134
|
class << self
|
108
135
|
include ResponseTokens
|
109
136
|
def get_raw(url,body={},opts={},&block)
|
@@ -113,7 +140,7 @@ module DTK
|
|
113
140
|
block ? block.call(raw_response) : raw_response
|
114
141
|
end
|
115
142
|
end
|
116
|
-
|
143
|
+
|
117
144
|
def get(url, body={}, opts={})
|
118
145
|
get_raw(url,body, opts){|raw_response|Response.new(json_parse_if_needed(raw_response))}
|
119
146
|
end
|
@@ -124,7 +151,7 @@ module DTK
|
|
124
151
|
block ? block.call(raw_response) : raw_response
|
125
152
|
end
|
126
153
|
end
|
127
|
-
|
154
|
+
|
128
155
|
def delete_raw(url,body={},opts={},&block)
|
129
156
|
error_handling(opts) do
|
130
157
|
# DELETE method supports only query params
|
@@ -146,7 +173,7 @@ module DTK
|
|
146
173
|
item.kind_of?(String) ? JSON.parse(item) : item
|
147
174
|
end
|
148
175
|
private
|
149
|
-
|
176
|
+
|
150
177
|
def generate_query_params_url(url, params_hash)
|
151
178
|
if params_hash.empty?
|
152
179
|
return url
|
@@ -156,7 +183,7 @@ module DTK
|
|
156
183
|
end
|
157
184
|
end
|
158
185
|
|
159
|
-
def error_handling(opts={},&block)
|
186
|
+
def error_handling(opts={},&block)
|
160
187
|
begin
|
161
188
|
block.call
|
162
189
|
rescue ::RestClient::ResourceNotFound, RestClient::Request::Unauthorized, RestClient::BadRequest,::RestClient::InternalServerError => e
|
@@ -172,13 +199,13 @@ module DTK
|
|
172
199
|
rescue Exception => e
|
173
200
|
error_response({ErrorsSubFieldCode => e.class.to_s, ErrorsOriginalException => e},opts)
|
174
201
|
end
|
175
|
-
end
|
202
|
+
end
|
176
203
|
|
177
204
|
def error_response(error_or_errors,opts={})
|
178
205
|
errors = error_or_errors.kind_of?(Hash) ? [error_or_errors] : error_or_errors
|
179
206
|
(opts[:error_response_class]||Error).new(StatusField => StatusNotok, ErrorsField => errors)
|
180
207
|
end
|
181
|
-
|
208
|
+
|
182
209
|
RestClientErrors = {
|
183
210
|
"RestClient::Forbidden" => "forbidden",
|
184
211
|
"RestClient::ServerBrokeConnection" => "broken",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dtk-common-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rich PELAVIN
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|