request_via 0.1.0 → 0.2.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 +52 -18
- data/lib/request_via/func.rb +9 -2
- data/lib/request_via/version.rb +1 -1
- data/lib/request_via.rb +12 -4
- data/request_via.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d09f830e111ee1a4cc0a3a20d9f4a4c9336b41f
|
4
|
+
data.tar.gz: e5e3ccad0cb0879d0e0477982fd7256a6fc7903b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cb4e2a6bdb5bcd1a3e15ec93076e7cf93bf42b52dc85a3aff6c6465f5928fdaeefc3acc55ddd86c01f6ac89c0b23faa80f9b8021b80d577d7d0d889144d5ae2
|
7
|
+
data.tar.gz: cf8d9947ea0982db0cb01560b21610ed01101cbf63872d90834393e0fb95f4a130488fd03b26a48c30513324b0c0f24730d11d81e9d95a6282aea6098a966d2b
|
data/README.md
CHANGED
@@ -1,6 +1,32 @@
|
|
1
1
|
# RequestVia
|
2
2
|
|
3
|
-
A fast and functional (API and paradigm) HTTP client, using only standard library
|
3
|
+
A fast and functional (API and paradigm) HTTP client, using only Ruby's standard library as dependency. e.g: Net::HTTP and URI.
|
4
|
+
|
5
|
+
![gif](http://g.recordit.co/S6EPTX5hHH.gif)
|
6
|
+
|
7
|
+
List of all commands shown in the GIF:
|
8
|
+
```ruby
|
9
|
+
require 'request_via'
|
10
|
+
|
11
|
+
# Thanks to @ElliottLandsborough Dog CEO API (https://github.com/ElliottLandsborough/dog-ceo-api)
|
12
|
+
|
13
|
+
# --- Single request
|
14
|
+
|
15
|
+
response = RequestVia::Get.('https://dog.ceo/api/breed/boxer/images/random');
|
16
|
+
response.body
|
17
|
+
|
18
|
+
# --- Make requests over a map iteration
|
19
|
+
|
20
|
+
dogs = [ 'akita', 'chihuahua', 'beagle' ]
|
21
|
+
dogs_images = dogs.map { |breed_name| "https://dog.ceo/api/breed/#{breed_name}/images/random" }
|
22
|
+
dogs_images.map(&RequestVia::Get).map(&:body)
|
23
|
+
|
24
|
+
# --- Make requests over an ASYNC map iteration
|
25
|
+
|
26
|
+
require 'parallel' # https://rubygems.org/gems/parallel
|
27
|
+
|
28
|
+
Parallel.map(dogs_images, &RequestVia::Get).map(&:body)
|
29
|
+
```
|
4
30
|
|
5
31
|
## Installation
|
6
32
|
|
@@ -22,36 +48,44 @@ Or install it yourself as:
|
|
22
48
|
|
23
49
|
Making a GET request with http
|
24
50
|
```ruby
|
25
|
-
|
26
|
-
|
51
|
+
# Use http:// as the protocol when there is no one defined.
|
52
|
+
RequestVia::Get.call('example.com')
|
27
53
|
|
28
|
-
|
54
|
+
RequestVia::Get.call('http://example.com')
|
29
55
|
|
30
|
-
|
31
|
-
|
32
|
-
|
56
|
+
# We recommend to use the `.()` syntax to invoke/make the HTTP requests.
|
57
|
+
# Read more about this: https://ruby-doc.org/core-2.2.2/Proc.html#method-i-call
|
58
|
+
RequestVia::Get.('example.com')
|
33
59
|
|
34
|
-
|
35
|
-
|
60
|
+
# Request with params
|
61
|
+
RequestVia::Get.('example.com', params: { foo: 'bar' })
|
36
62
|
|
37
|
-
|
38
|
-
|
63
|
+
# Request with headers
|
64
|
+
RequestVia::Get.('example.com/foo', headers: { 'X-Requested-With': 'RequestVia gem' })
|
39
65
|
|
40
|
-
|
41
|
-
|
66
|
+
# Return the response and request objects as result
|
67
|
+
response, request = RequestVia::Get.('example.com/foo', response_and_request: true)
|
42
68
|
```
|
43
69
|
|
44
|
-
|
70
|
+
Supported HTTP methods.
|
45
71
|
(**NOTE:** you can use all arguments of previous examples)
|
46
72
|
```ruby
|
47
|
-
|
48
|
-
|
49
|
-
|
73
|
+
RequestVia::Post.()
|
74
|
+
|
75
|
+
RequestVia::Put.()
|
76
|
+
|
77
|
+
RequestVia::Delete.()
|
78
|
+
|
79
|
+
RequestVia::Options.()
|
80
|
+
|
81
|
+
RequestVia::Trace.()
|
82
|
+
|
83
|
+
RequestVia::Patch.()
|
50
84
|
```
|
51
85
|
|
52
86
|
Making a HTTPS request.
|
53
87
|
```ruby
|
54
|
-
|
88
|
+
RequestVia::Get.('https://example.com')
|
55
89
|
```
|
56
90
|
|
57
91
|
## Development
|
data/lib/request_via/func.rb
CHANGED
@@ -50,11 +50,18 @@ module RequestVia
|
|
50
50
|
}.freeze
|
51
51
|
|
52
52
|
FetchWithBodyVia = -> http_method {
|
53
|
-
FetchWith.(URIWithoutParams, RequestWithBody.(http_method))
|
53
|
+
FetchWith.(URIWithoutParams, RequestWithBody.(http_method))
|
54
54
|
}.freeze
|
55
55
|
|
56
56
|
FetchWithQueryStringVia = -> http_method {
|
57
|
-
FetchWith.(URIWithParams, RequestWithoutBody.(http_method))
|
57
|
+
FetchWith.(URIWithParams, RequestWithoutBody.(http_method))
|
58
58
|
}.freeze
|
59
|
+
|
60
|
+
FetchStrategyTo = -> http_method {
|
61
|
+
strategy_to = \
|
62
|
+
http_method::REQUEST_HAS_BODY ? FetchWithBodyVia : FetchWithQueryStringVia
|
63
|
+
|
64
|
+
strategy_to.(http_method)
|
65
|
+
}
|
59
66
|
end
|
60
67
|
end
|
data/lib/request_via/version.rb
CHANGED
data/lib/request_via.rb
CHANGED
@@ -8,11 +8,19 @@ require "request_via/http_client"
|
|
8
8
|
require "request_via/func"
|
9
9
|
|
10
10
|
module RequestVia
|
11
|
-
Get = Func::
|
11
|
+
Get = Func::FetchStrategyTo.(Net::HTTP::Get).freeze
|
12
12
|
|
13
|
-
|
13
|
+
Head = Func::FetchStrategyTo.(Net::HTTP::Head).freeze
|
14
14
|
|
15
|
-
Post = Func::
|
15
|
+
Post = Func::FetchStrategyTo.(Net::HTTP::Post).freeze
|
16
16
|
|
17
|
-
|
17
|
+
Put = Func::FetchStrategyTo.(Net::HTTP::Put).freeze
|
18
|
+
|
19
|
+
Delete = Func::FetchStrategyTo.(Net::HTTP::Delete).freeze
|
20
|
+
|
21
|
+
Options = Func::FetchStrategyTo.(Net::HTTP::Options).freeze
|
22
|
+
|
23
|
+
Trace = Func::FetchStrategyTo.(Net::HTTP::Trace).freeze
|
24
|
+
|
25
|
+
Patch = Func::FetchStrategyTo.(Net::HTTP::Patch).freeze
|
18
26
|
end
|
data/request_via.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Rodrigo Serradura"]
|
10
10
|
spec.email = ["rodrigo@ysimplicity.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{The functional HTTP client
|
13
|
-
spec.description = %q{A fast and functional (API and paradigm) HTTP client, using only standard library
|
12
|
+
spec.summary = %q{The Ruby's functional HTTP client (Net::HTTP wrapper)}
|
13
|
+
spec.description = %q{A fast and functional (API and paradigm) HTTP client, using only Ruby's standard library as dependency. e.g: Net::HTTP and URI.}
|
14
14
|
spec.homepage = "https://github.com/serradura/request_via"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request_via
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,8 +66,8 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.1'
|
69
|
-
description: 'A fast and functional (API and paradigm) HTTP client, using only
|
70
|
-
library
|
69
|
+
description: 'A fast and functional (API and paradigm) HTTP client, using only Ruby''s
|
70
|
+
standard library as dependency. e.g: Net::HTTP and URI.'
|
71
71
|
email:
|
72
72
|
- rodrigo@ysimplicity.com
|
73
73
|
executables: []
|
@@ -111,5 +111,5 @@ rubyforge_project:
|
|
111
111
|
rubygems_version: 2.6.14
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
|
-
summary: The functional HTTP client
|
114
|
+
summary: The Ruby's functional HTTP client (Net::HTTP wrapper)
|
115
115
|
test_files: []
|