nice_http 1.2.1 → 1.3.0

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 +17 -0
  3. data/lib/nice_http.rb +48 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a5130a17c74e266e3867624db6c52cb602ce96af5c8abc318b4e90fd90769d0
4
- data.tar.gz: a99c7f2aa2e61c2eb5436d28ac7c6fa5e01087a85cd62c984bf53cfce33d9864
3
+ metadata.gz: 63153fd3b4b62180ef7a62578c560b99948a72933eba3fef407c0362da034e7c
4
+ data.tar.gz: 48b6370d5bec5db4d283f0f9693888b1e09e6e1caca0be08dc955459c3b035a6
5
5
  SHA512:
6
- metadata.gz: fa7f863a14d48983d188265d44f01c05a18206ac8a656c61ed0c18bc9bad1280dbdc1bb7999c078fbe490811f3192c03c96387f81c8c5872f6dc0c89ce6b563e
7
- data.tar.gz: '05739e8ecfa8f834df126c10b179420a461b2791b96e0e0e03ae3a9924b72c76c9f930eed83c49b2d43ac33c8d2800f9b02f8566a3defa2a171b0802d949e484'
6
+ metadata.gz: c1ed875c7378cbb2cb3c657c661010c29b3dbd73b0de847ee9faba462f5237c2bd00236373f83f17f21390b20520f0d7347c9366ac7b07f820dc82e03cbeaf8a
7
+ data.tar.gz: e3b696ec3b44a283b1104c96f8cb923b1b7952efd7811f17210084ba3e22259a5f1066a9470c55e6da1447be4817040fa9ee0fc3341bb3d152996636cfbb1833
data/README.md CHANGED
@@ -13,6 +13,8 @@ Also you can use mock responses by using :mock_response key on the request hash
13
13
 
14
14
  NiceHttp will take care of the redirections and the cookies, and for security tests you will be able to modify the cookies or disable and control the redirections by yourself.
15
15
 
16
+ NiceHttp is able to use hashes as requests data and uses the Request Hash structure: https://github.com/MarioRuiz/Request-Hash
17
+
16
18
  To be able to generate random requests take a look at the documentation for nice_hash gem: https://github.com/MarioRuiz/nice_hash
17
19
 
18
20
  Example that creates 1000 good random and unique requests to register an user and test that the validation of the fields are correct by the user was able to be registered. Send 800 requests where just one field is wrong and verify the user was not able to be created: https://gist.github.com/MarioRuiz/824d7a462b62fd85f02c1a09455deefb
@@ -193,6 +195,21 @@ pp resp.data.json
193
195
 
194
196
  ```
195
197
 
198
+ If the request hash contains a key :method with one of these possible values: :get, :head, :delete, :post or :patch, then it is possible to use the `send_request` method and pass just the request hash:
199
+
200
+ ```ruby
201
+ req= {
202
+ path: "/api/users",
203
+ method: :post,
204
+ data: {
205
+ name: "morpheus",
206
+ job: "leader"
207
+ }
208
+ }
209
+ resp = @http.send_request req
210
+ ```
211
+
212
+
196
213
  ## Responses
197
214
 
198
215
  The response will include at least the keys:
data/lib/nice_http.rb CHANGED
@@ -753,6 +753,54 @@ class NiceHttp
753
753
  end
754
754
  end
755
755
 
756
+ ######################################################
757
+ # It will send the request depending on the :method declared on the request hash
758
+ # Take a look at https://github.com/MarioRuiz/Request-Hash
759
+ #
760
+ # @param request_hash [Hash] containing at least key :path and :method. The methods that are accepted are: :get, :head, :post, :put, :delete, :patch
761
+ #
762
+ # @return [Hash] response
763
+ # Including at least the symbol keys:
764
+ # :data = the response data body.
765
+ # :message = plain text response.
766
+ # :code = code response (200=ok,500=wrong...).
767
+ # All keys in response are lowercase.
768
+ # data, message and code can also be accessed as attributes like .message .code .data.
769
+ # In case of fatal error returns { fatal_error: "the error description", code: nil, message: nil, data: '' }
770
+ # @example
771
+ # resp = @http.send_request Requests::Customer.remove_session
772
+ # assert resp.code == 204
773
+ ######################################################
774
+ def send_request(request_hash)
775
+ unless request_hash.is_a?(Hash) and request_hash.key?(:method) and request_hash.key?(:path) and
776
+ request_hash[:method].is_a?(Symbol) and
777
+ [:get, :head, :post, :put, :delete, :patch].include?(request_hash[:method])
778
+
779
+ message = "send_request: it needs to be supplied a Request Hash that includes a :method and :path. "
780
+ message += "Supported methods: :get, :head, :post, :put, :delete, :patch"
781
+ @logger.fatal message
782
+ return {fatal_error: message, code: nil, message: nil}
783
+ else
784
+ case request_hash[:method]
785
+ when :get
786
+ resp = get request_hash
787
+ when :post
788
+ resp = post request_hash
789
+ when :head
790
+ resp = head request_hash
791
+ when :put
792
+ resp = put request_hash
793
+ when :delete
794
+ resp = delete request_hash
795
+ when :patch
796
+ resp = patch request_hash
797
+ end
798
+ return resp
799
+ end
800
+
801
+
802
+ end
803
+
756
804
  ######################################################
757
805
  # Close HTTP connection
758
806
  ######################################################
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nice_http
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mario Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-24 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nice_hash