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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/nice_http.rb +25 -25
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc467413aa1e110d9ee4f26473a1a8777642836bc0c0187e00566fc2558fd80d
4
- data.tar.gz: '04568929a3b8180fded025a5cc144ebdddfa25416ad0e16455aa076febb8b1ae'
3
+ metadata.gz: 609d0cfed9e68d29af972ceb77095bfae7591899aa2715ce59987ea22298e98d
4
+ data.tar.gz: 4bcaecdde1849f12198487e0a619759b5c56c907dda577fc6518d2efed21c8d0
5
5
  SHA512:
6
- metadata.gz: c6d3572e818f3939c9bade93bcd1d7b4e4198e0da5fa2913f346b32ecdc5694cdd7df29337784d1453c080b15190e4fe2e477ba591102e0459ca32925e0117bc
7
- data.tar.gz: ab2b3cb27234d48fefea4b1c4ef61c123519450b202829dbc3d32bcfac1b91b29bebec1ae09dfa01160c77a9acd2e850e82114a45e1887ca65e7fe2d0651893c
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: {"name": "morpheus", "job": "leader"}
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 :values_at 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:
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.values_at = {job: "developer"}
184
+ req.values_for = {job: "developer"}
185
185
 
186
186
  resp = http.post req
187
187
 
@@ -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?(:values_at)
864
- arguments[0][:values_at] = arguments[0][:values]
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?(:values_at) then
870
- arguments[0][:values_at].each {|key, value|
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?(:values_at) then
878
- arguments[0][:values_at].each {|key, value|
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?(:values_at) then
891
- #req[:values_at][:loginName] or req[:values_at]["loginName"]
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][:values_at].each {|kv, vv|
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?(:values_at) then
913
- #req[:values_at][:loginName] or req[:values_at]["loginName"]
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][:values_at].kind_of?(Hash) then #values[:mykey][3]
916
- arguments[0][:values_at].each {|kv, vv|
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][:values_at].kind_of?(Array) then #values[5][:mykey]
922
- if !arguments[0][:values_at][indx].nil? then
923
- arguments[0][:values_at][indx].each {|kv, vv|
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?(:values_at) then
943
- if arguments[0][:values_at].kind_of?(Hash) and arguments[0][:values_at].keys.size>0 then
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(":values_at key given without a valid content-type or data for request. No values modified on the request")
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz