nice_http 1.3.5 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -0
- data/lib/nice_http.rb +5 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bcd4d796e7c83478eddd4867f495a2ae7576959bd8dab328af27ec2c3f4a537
|
4
|
+
data.tar.gz: 81e619eeea75c63308ef423fd479053ff79024e7aa06cda3ac21bd0965ea8c1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c25ec1337b1fe065189d8563ca8d53f61ab6d81d4716276baf671ea5a38e18f178d37f05033d47abb10d3066199115f926d5f60769de4feaea0458403eb42a3c
|
7
|
+
data.tar.gz: ba7a0dd378f499c07c8dc41b4569472aa94bf04d244b16fad7eff153901d426a68aa1beb842f486d72f53d27f8da988bf5c6088bd0b5c4da5a30f5350cd5b397
|
data/README.md
CHANGED
@@ -15,6 +15,8 @@ NiceHttp will take care of the redirections and the cookies, and for security te
|
|
15
15
|
|
16
16
|
NiceHttp is able to use hashes as requests data and uses the Request Hash structure: https://github.com/MarioRuiz/Request-Hash
|
17
17
|
|
18
|
+
**On the next link you have a full example using nice_http and RSpec to test REST APIs, Uber API and Reqres API: https://github.com/MarioRuiz/api-testing-example**
|
19
|
+
|
18
20
|
To be able to generate random requests take a look at the documentation for nice_hash gem: https://github.com/MarioRuiz/nice_hash
|
19
21
|
|
20
22
|
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
|
@@ -102,6 +104,17 @@ NiceHttp.defaults = {
|
|
102
104
|
}
|
103
105
|
```
|
104
106
|
|
107
|
+
To add a fixed path that would be added automatically to all your requests just before the specified request path, you can do it by adding it to `host`:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
http = NiceHttp.new('https://v2.namsor.com/NamSorAPIv2/')
|
111
|
+
|
112
|
+
resp = http.get('/api2/json/gender/Peter/Moon')
|
113
|
+
# The get request path will be: /NamSorAPIv2/api2/json/gender/Peter/Moon on server v2.namsor.com
|
114
|
+
|
115
|
+
resp = http.get('/api2/json/gender/Love/Sun?ret=true')
|
116
|
+
# The get request path will be: /NamSorAPIv2/api2/json/gender/Love/Sun on server v2.namsor.com
|
117
|
+
```
|
105
118
|
|
106
119
|
## Creating requests
|
107
120
|
|
data/lib/nice_http.rb
CHANGED
@@ -159,6 +159,7 @@ class NiceHttp
|
|
159
159
|
require "net/https"
|
160
160
|
@host = self.class.host
|
161
161
|
@port = self.class.port
|
162
|
+
@prepath = ''
|
162
163
|
@ssl = self.class.ssl
|
163
164
|
@headers = self.class.headers.dup
|
164
165
|
@debug = self.class.debug
|
@@ -180,6 +181,7 @@ class NiceHttp
|
|
180
181
|
@host = uri.host unless uri.host.nil?
|
181
182
|
@port = uri.port unless uri.port.nil?
|
182
183
|
@ssl = true if !uri.scheme.nil? && (uri.scheme == "https")
|
184
|
+
@prepath = uri.path unless uri.path=='/'
|
183
185
|
elsif args.is_a?(Hash) && !args.keys.empty?
|
184
186
|
@host = args[:host] if args.keys.include?(:host)
|
185
187
|
@port = args[:port] if args.keys.include?(:port)
|
@@ -232,11 +234,12 @@ class NiceHttp
|
|
232
234
|
end
|
233
235
|
|
234
236
|
|
235
|
-
if @host.to_s != "" and (@host.
|
237
|
+
if @host.to_s != "" and (@host.start_with?("http:") or @host.start_with?("https:"))
|
236
238
|
uri = URI.parse(@host)
|
237
239
|
@host = uri.host unless uri.host.nil?
|
238
240
|
@port = uri.port unless uri.port.nil?
|
239
241
|
@ssl = true if !uri.scheme.nil? && (uri.scheme == "https")
|
242
|
+
@prepath = uri.path unless uri.path=='/'
|
240
243
|
end
|
241
244
|
|
242
245
|
raise InfoMissing, :port if @port.to_s == ""
|
@@ -878,6 +881,7 @@ class NiceHttp
|
|
878
881
|
elsif arguments.size == 1 and arguments[0].kind_of?(String)
|
879
882
|
path = arguments[0].to_s()
|
880
883
|
end
|
884
|
+
path = (@prepath + path).gsub('//','/') unless path.nil? or path.start_with?('http:') or path.start_with?('https:')
|
881
885
|
@cookies.each { |cookie_path, cookies_hash|
|
882
886
|
cookie_path = "" if cookie_path == "/"
|
883
887
|
path_to_check = path
|
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.
|
4
|
+
version: 1.4.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-02-
|
11
|
+
date: 2019-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nice_hash
|