request_via 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96966b105f6993992128f43dc645693bbeb67c38
4
- data.tar.gz: 52d09d862ab40f0c45e1cdb9977cad25befdc7cf
3
+ metadata.gz: 2d09f830e111ee1a4cc0a3a20d9f4a4c9336b41f
4
+ data.tar.gz: e5e3ccad0cb0879d0e0477982fd7256a6fc7903b
5
5
  SHA512:
6
- metadata.gz: 85d778b4792ac8e2a2cf74ba798ed888d76e34261f18040763635b868f7963a73e5f67a0499f91d3157a6aa7b51aa586bd4d05c6b4ed1548967c1e52a751a47a
7
- data.tar.gz: 5febbd08d8711a931e4b07f4510e4e9339e33313b154bacf205a37952b3d6d13fd4edcb86bade9af71ba152dc1a12d5fc27e3e74d1323b66b93cb525c6cf474f
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's dependencies. e.g: Net::HTTP, and URI.
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
- # Use http:// as the protocol when there is no one defined.
26
- RequestVia::Get.call('example.com')
51
+ # Use http:// as the protocol when there is no one defined.
52
+ RequestVia::Get.call('example.com')
27
53
 
28
- RequestVia::Get.call('http://example.com')
54
+ RequestVia::Get.call('http://example.com')
29
55
 
30
- # We recommend use `.()` syntax to invoke/make the HTTP requests
31
- # Read more about this syntax sugar: https://ruby-doc.org/core-2.2.2/Proc.html#method-i-call
32
- RequestVia::Get.('example.com')
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
- # Request with params
35
- RequestVia::Get.('example.com', params: { foo: 'bar' })
60
+ # Request with params
61
+ RequestVia::Get.('example.com', params: { foo: 'bar' })
36
62
 
37
- # Request with headers
38
- RequestVia::Get.('example.com/foo', headers: {'X-Requested-With': 'RequestVia gem' })
63
+ # Request with headers
64
+ RequestVia::Get.('example.com/foo', headers: { 'X-Requested-With': 'RequestVia gem' })
39
65
 
40
- # Return the response and request objects as result
41
- response, request = RequestVia::Get.('example.com/foo', response_and_request: true)
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
- Making other HTTP method requests.
70
+ Supported HTTP methods.
45
71
  (**NOTE:** you can use all arguments of previous examples)
46
72
  ```ruby
47
- RequestVia::Post.('example.com')
48
- RequestVia::Put.('example.com')
49
- RequestVia::Delete.('example.com')
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
- RequestVia::Get.('https://example.com')
88
+ RequestVia::Get.('https://example.com')
55
89
  ```
56
90
 
57
91
  ## Development
@@ -50,11 +50,18 @@ module RequestVia
50
50
  }.freeze
51
51
 
52
52
  FetchWithBodyVia = -> http_method {
53
- FetchWith.(URIWithoutParams, RequestWithBody.(http_method)).freeze
53
+ FetchWith.(URIWithoutParams, RequestWithBody.(http_method))
54
54
  }.freeze
55
55
 
56
56
  FetchWithQueryStringVia = -> http_method {
57
- FetchWith.(URIWithParams, RequestWithoutBody.(http_method)).freeze
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
@@ -3,7 +3,7 @@
3
3
  module RequestVia
4
4
  module SemVer
5
5
  MAJOR = 0
6
- MINOR = 1
6
+ MINOR = 2
7
7
  PATCH = 0
8
8
  end
9
9
 
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::FetchWithQueryStringVia.(Net::HTTP::Get)
11
+ Get = Func::FetchStrategyTo.(Net::HTTP::Get).freeze
12
12
 
13
- Put = Func::FetchWithBodyVia.(Net::HTTP::Put)
13
+ Head = Func::FetchStrategyTo.(Net::HTTP::Head).freeze
14
14
 
15
- Post = Func::FetchWithBodyVia.(Net::HTTP::Post)
15
+ Post = Func::FetchStrategyTo.(Net::HTTP::Post).freeze
16
16
 
17
- Delete = Func::FetchWithQueryStringVia.(Net::HTTP::Delete)
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's dependencies. e.g: Net::HTTP, and URI.}
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.1.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-30 00:00:00.000000000 Z
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 standard
70
- library''s dependencies. e.g: Net::HTTP, and URI.'
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: []