nice_http 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/nice_http.rb +25 -25
- 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: 609d0cfed9e68d29af972ceb77095bfae7591899aa2715ce59987ea22298e98d
|
4
|
+
data.tar.gz: 4bcaecdde1849f12198487e0a619759b5c56c907dda577fc6518d2efed21c8d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a29e0ae4d2d40f650a43abfc4be521bb7933c923b3f6852e373582de52629999d2bce1102978b831288fd586e7ad773d114b3f877e7c2adf8d7d590510afdbb0
|
7
|
+
data.tar.gz: 279c1f0bd6bf5f760038f7bbf3bdfd242ccbdf133af3239eaf6f6466f824de8f0d9352ce0fbbe0075354c5ce8f0948cefca86136bff072da0baed617aeb5072c
|
data/README.md
CHANGED
@@ -39,7 +39,7 @@ pp resp.data.json(:first_name, :last_name)
|
|
39
39
|
|
40
40
|
resp = http.post( {
|
41
41
|
path: "/api/users",
|
42
|
-
data: {
|
42
|
+
data: { name: "morpheus", job: "leader" }
|
43
43
|
} )
|
44
44
|
|
45
45
|
pp resp.data.json
|
@@ -176,12 +176,12 @@ pp resp.data.json(:job)
|
|
176
176
|
```
|
177
177
|
|
178
178
|
|
179
|
-
In case you want to modify the request before sending it, for example just changing one field but the rest will be the same, you can supply a new key :
|
179
|
+
In case you want to modify the request before sending it, for example just changing one field but the rest will be the same, you can supply a new key :values_for in the request hash that will contain a hash with the keys to be changed and NiceHttp will perform the necessary changes at any level:
|
180
180
|
|
181
181
|
```ruby
|
182
182
|
|
183
183
|
req = Requests::Example.create_user_hash
|
184
|
-
req.
|
184
|
+
req.values_for = {job: "developer"}
|
185
185
|
|
186
186
|
resp = http.post req
|
187
187
|
|
data/lib/nice_http.rb
CHANGED
@@ -250,7 +250,7 @@ require_relative 'nice_http/utils'
|
|
250
250
|
# :code = code response (200=ok,500=wrong...).
|
251
251
|
# All keys in response are lowercase.
|
252
252
|
# data, message and code can also be accessed as attributes like .message .code .data.
|
253
|
-
# In case of fatal error returns {fatal_error: "the error description", code: nil, message: nil, data: ''}
|
253
|
+
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
|
254
254
|
#
|
255
255
|
# @example
|
256
256
|
# resp = @http.get(Requests::Customer.get_profile)
|
@@ -369,7 +369,7 @@ require_relative 'nice_http/utils'
|
|
369
369
|
# :code = code response (200=ok,500=wrong...).
|
370
370
|
# All keys in response are lowercase.
|
371
371
|
# data, message and code can also be accessed as attributes like .message .code .data.
|
372
|
-
# In case of fatal error returns {fatal_error: "the error description", code: nil, message: nil, data: ''}
|
372
|
+
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
|
373
373
|
# @example
|
374
374
|
# resp = @http.post(Requests::Customer.update_customer)
|
375
375
|
# assert resp.code == 201
|
@@ -466,7 +466,7 @@ require_relative 'nice_http/utils'
|
|
466
466
|
# :code = code response (200=ok,500=wrong...).
|
467
467
|
# All keys in response are lowercase.
|
468
468
|
# data, message and code can also be accessed as attributes like .message .code .data.
|
469
|
-
# In case of fatal error returns {fatal_error: "the error description", code: nil, message: nil, data: ''}
|
469
|
+
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
|
470
470
|
# @example
|
471
471
|
# resp = @http.put(Requests::Customer.remove_phone)
|
472
472
|
######################################################
|
@@ -534,7 +534,7 @@ require_relative 'nice_http/utils'
|
|
534
534
|
# :code = code response (200=ok,500=wrong...).
|
535
535
|
# All keys in response are lowercase.
|
536
536
|
# data, message and code can also be accessed as attributes like .message .code .data.
|
537
|
-
# In case of fatal error returns {fatal_error: "the error description", code: nil, message: nil, data: ''}
|
537
|
+
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
|
538
538
|
# @example
|
539
539
|
# resp = @http.patch(Requests::Customer.unrelease_account)
|
540
540
|
######################################################
|
@@ -613,7 +613,7 @@ require_relative 'nice_http/utils'
|
|
613
613
|
# :code = code response (200=ok,500=wrong...).
|
614
614
|
# All keys in response are lowercase.
|
615
615
|
# data, message and code can also be accessed as attributes like .message .code .data.
|
616
|
-
# In case of fatal error returns {fatal_error: "the error description", code: nil, message: nil, data: ''}
|
616
|
+
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
|
617
617
|
# @example
|
618
618
|
# resp = @http.delete(Requests::Customer.remove_session)
|
619
619
|
# assert resp.code == 204
|
@@ -682,7 +682,7 @@ require_relative 'nice_http/utils'
|
|
682
682
|
# :code = code response (200=ok,500=wrong...).
|
683
683
|
# All keys in response are lowercase.
|
684
684
|
# message and code can also be accessed as attributes like .message .code.
|
685
|
-
# In case of fatal error returns {fatal_error: "the error description", code: nil, message: nil}
|
685
|
+
# In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil }
|
686
686
|
######################################################
|
687
687
|
def head(argument)
|
688
688
|
begin
|
@@ -860,22 +860,22 @@ require_relative 'nice_http/utils'
|
|
860
860
|
content_type_included=true
|
861
861
|
end
|
862
862
|
# to be backwards compatible since before was :values
|
863
|
-
if arguments[0].include?(:values) and !arguments[0].include?(:
|
864
|
-
arguments[0][:
|
863
|
+
if arguments[0].include?(:values) and !arguments[0].include?(:values_for)
|
864
|
+
arguments[0][:values_for] = arguments[0][:values]
|
865
865
|
end
|
866
866
|
if content_type_included and (!headers_t["Content-Type"][/text\/xml/].nil? or
|
867
867
|
!headers_t["Content-Type"]["application/soap+xml"].nil? or
|
868
868
|
!headers_t["Content-Type"][/application\/jxml/].nil?) then
|
869
|
-
if arguments[0].include?(:
|
870
|
-
arguments[0][:
|
869
|
+
if arguments[0].include?(:values_for) then
|
870
|
+
arguments[0][:values_for].each {|key, value|
|
871
871
|
data=NiceHttpUtils.set_value_xml_tag(key.to_s(), data, value.to_s(), true)
|
872
872
|
}
|
873
873
|
end
|
874
874
|
elsif content_type_included and !headers_t["Content-Type"][/application\/json/].nil? and data.to_s()!="" then
|
875
875
|
require 'json'
|
876
876
|
if data.kind_of?(String) then
|
877
|
-
if arguments[0].include?(:
|
878
|
-
arguments[0][:
|
877
|
+
if arguments[0].include?(:values_for) then
|
878
|
+
arguments[0][:values_for].each {|key, value|
|
879
879
|
data.gsub!(/(( *|^)"?#{key.to_s()}"? *: *")(.*)(" *, *$)/, '\1' + value+ '\4') # "key":"value", or key:"value",
|
880
880
|
data.gsub!(/(( *|^)"?#{key.to_s()}"? *: *")(.*)(" *$)/, '\1' + value+ '\4') # "key":"value" or key:"value"
|
881
881
|
data.gsub!(/(( *|^)"?#{key.to_s()}"? *: *[^"])([^"].*)([^"] *, *$)/, '\1' + value+ '\4') # "key":456, or key:456,
|
@@ -887,10 +887,10 @@ require_relative 'nice_http/utils'
|
|
887
887
|
data.each {|key, value|
|
888
888
|
data_n[key.to_s()]=value
|
889
889
|
}
|
890
|
-
if arguments[0].include?(:
|
891
|
-
#req[:
|
890
|
+
if arguments[0].include?(:values_for) then
|
891
|
+
#req[:values_for][:loginName] or req[:values_for]["loginName"]
|
892
892
|
new_values_hash=Hash.new()
|
893
|
-
arguments[0][:
|
893
|
+
arguments[0][:values_for].each {|kv, vv|
|
894
894
|
if data_n.keys.include?(kv.to_s()) then
|
895
895
|
new_values_hash[kv.to_s()]=vv
|
896
896
|
end
|
@@ -909,18 +909,18 @@ require_relative 'nice_http/utils'
|
|
909
909
|
row.each {|key, value|
|
910
910
|
data_n[key.to_s()]=value
|
911
911
|
}
|
912
|
-
if arguments[0].include?(:
|
913
|
-
#req[:
|
912
|
+
if arguments[0].include?(:values_for) then
|
913
|
+
#req[:values_for][:loginName] or req[:values_for]["loginName"]
|
914
914
|
new_values_hash=Hash.new()
|
915
|
-
if arguments[0][:
|
916
|
-
arguments[0][:
|
915
|
+
if arguments[0][:values_for].kind_of?(Hash) then #values[:mykey][3]
|
916
|
+
arguments[0][:values_for].each {|kv, vv|
|
917
917
|
if data_n.keys.include?(kv.to_s()) and !vv[indx].nil? then
|
918
918
|
new_values_hash[kv.to_s()]=vv[indx]
|
919
919
|
end
|
920
920
|
}
|
921
|
-
elsif arguments[0][:
|
922
|
-
if !arguments[0][:
|
923
|
-
arguments[0][:
|
921
|
+
elsif arguments[0][:values_for].kind_of?(Array) then #values[5][:mykey]
|
922
|
+
if !arguments[0][:values_for][indx].nil? then
|
923
|
+
arguments[0][:values_for][indx].each {|kv, vv|
|
924
924
|
if data_n.keys.include?(kv.to_s()) then
|
925
925
|
new_values_hash[kv.to_s()]=vv
|
926
926
|
end
|
@@ -939,10 +939,10 @@ require_relative 'nice_http/utils'
|
|
939
939
|
@logger.fatal("Wrong format on request application/json, be sure is a Hash, Array of Hashes or JSON string")
|
940
940
|
return :error, :error, :error
|
941
941
|
end
|
942
|
-
elsif content_type_included and arguments[0].include?(:
|
943
|
-
if arguments[0][:
|
942
|
+
elsif content_type_included and arguments[0].include?(:values_for) then
|
943
|
+
if arguments[0][:values_for].kind_of?(Hash) and arguments[0][:values_for].keys.size>0 then
|
944
944
|
if !headers_t.nil? and headers_t.kind_of?(Hash) and headers_t["Content-Type"]!="application/x-www-form-urlencoded" and headers_t["content-type"]!="application/x-www-form-urlencoded" then
|
945
|
-
@logger.warn(":
|
945
|
+
@logger.warn(":values_for key given without a valid content-type or data for request. No values modified on the request")
|
946
946
|
end
|
947
947
|
end
|
948
948
|
end
|