nice_http 0.9.5 → 0.9.6
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 +4 -4
- data/README.md +33 -2
- data/lib/nice_http_utils.rb +15 -0
- 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: 953a8e522904b4aa3a6540c60498d3d9b1680859108246abc28fde9f7d934c6f
|
4
|
+
data.tar.gz: f9dad691419750bfd269b78c640fb091fc93861f8b3ddfead7a0300c737d9476
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e33f131f2cab1ff058d2341a7d06608845d318813dd5ae96c53978c60d1ef20dde719331e580bcdbe98aafab62c62cd5b4e668a395286f10e54bf96e9e0adf47
|
7
|
+
data.tar.gz: b550cfdd965307ac56d99209d4319b07db128fb99fcf81fbd6fff76b466d5f9364a5307068452ea8d3adca45f3f6da3b5889926d3fee92d0500e60b9537a797a
|
data/README.md
CHANGED
@@ -162,7 +162,6 @@ In case you want to modify the request before sending it, for example just chang
|
|
162
162
|
|
163
163
|
```ruby
|
164
164
|
|
165
|
-
|
166
165
|
req = Requests::Example.create_user_hash
|
167
166
|
req[:values] = {job: "developer"}
|
168
167
|
|
@@ -171,7 +170,6 @@ resp = http.post req
|
|
171
170
|
pp resp.data.json
|
172
171
|
#response: {:name=>"morpheus", :job=>"developer", :id=>"192", :createdAt=>"2018-12-14T14:41:54.371Z"}
|
173
172
|
|
174
|
-
|
175
173
|
```
|
176
174
|
|
177
175
|
## Responses
|
@@ -203,7 +201,40 @@ Also interesting keys would be: *time_elapsed_total*, *time_elapsed* and many mo
|
|
203
201
|
|
204
202
|
*auto_redirect*: (true or false) in case of true it will take care of the auto redirections.
|
205
203
|
|
204
|
+
## Authentication requests
|
205
|
+
|
206
|
+
All we need to do is to add to our request the correct authentication tokens, seeds, headers.
|
207
|
+
|
208
|
+
For example for Basic Authentication we need to add to the authorization header a seed generated with the user and password we want ot authenticate
|
209
|
+
|
210
|
+
```ruby
|
211
|
+
|
212
|
+
@http = NiceHttp.new("https://jigsaw.w3.org/")
|
213
|
+
|
214
|
+
@http.headers.authorization = NiceHttpUtils.basic_authentication(user: "guest", password: "guest")
|
215
|
+
|
216
|
+
# headers will be in this example: {:authorization=>"Basic Z3Vlc3Q6Z3Vlc3Q=\n"}
|
206
217
|
|
218
|
+
resp = @http.get("/HTTP/Basic/")
|
219
|
+
|
220
|
+
```
|
221
|
+
|
222
|
+
## Send multipart content
|
223
|
+
|
224
|
+
Example posting a csv file:
|
225
|
+
|
226
|
+
```ruby
|
227
|
+
|
228
|
+
require 'net/http/post/multipart'
|
229
|
+
request = {
|
230
|
+
path: "/customer/profile/",
|
231
|
+
headers: {'Content-Type' => 'multipart/form-data'},
|
232
|
+
data: (Net::HTTP::Post::Multipart.new "/customer/profile/",
|
233
|
+
"file" => UploadIO.new("./path/to/my/file.csv", "text/csv"))
|
234
|
+
}
|
235
|
+
response=@http.post(request)
|
236
|
+
|
237
|
+
```
|
207
238
|
|
208
239
|
## Contributing
|
209
240
|
|
data/lib/nice_http_utils.rb
CHANGED
@@ -95,4 +95,19 @@ module NiceHttpUtils
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
+
##################################################
|
99
|
+
# returns the seed for Basic authentication
|
100
|
+
# input:
|
101
|
+
# user
|
102
|
+
# password
|
103
|
+
# output:
|
104
|
+
# seed string to be used on Authorization key header on a get request
|
105
|
+
####################################################
|
106
|
+
def self.basic_authentication(user: , password: )
|
107
|
+
require 'base64'
|
108
|
+
seed = "Basic " + Base64.encode64(user + ":" + password)
|
109
|
+
return seed
|
110
|
+
end
|
111
|
+
|
112
|
+
|
98
113
|
end
|
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: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Ruiz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nice_hash
|