request-builder 0.1.0 → 0.1.1
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 +70 -4
- data/lib/request/builder/version.rb +1 -1
- data/request-builder.gemspec +4 -4
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ef65f89b3f06c126d7607aac92943b498c8f039d90f3c08edcd1b7d0487b88a
|
4
|
+
data.tar.gz: d7f48ebb1fff73fe3f80b6bb50ac23a1a744bcbb76078d1afb964f5b33540cf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 976ed740ebb730981e5f301e6562d00d54eaa2cb874e384840ee53845699f5871eb4ee3b725d0d5da3213d6ff2a17f6d2d10070e7223920d4a9368c4c3a90c44
|
7
|
+
data.tar.gz: '08423c1ccd725ec0e7069d94cb03cf66f5635f5ee6656204e71c3cbe3a1925e815a786a19293cc9f062159e4b366ce17cbe2ee169c36a993ce5a0aae53c3d8cf'
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Request::Builder
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
Simple DSL wrapper for faraday gem
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -22,7 +20,75 @@ Or install it yourself as:
|
|
22
20
|
|
23
21
|
## Usage
|
24
22
|
|
25
|
-
|
23
|
+
Include `Request::Builder` to your client class and describe your request using DSL
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class MyApiClient
|
27
|
+
include Request::Builder
|
28
|
+
|
29
|
+
option :my_option
|
30
|
+
option :my_header_value
|
31
|
+
|
32
|
+
configure do
|
33
|
+
adapter :net_http
|
34
|
+
response_middleware :json
|
35
|
+
request_middleware :json
|
36
|
+
method :get
|
37
|
+
logger Logger.new(STDOUT)
|
38
|
+
timeout 10
|
39
|
+
|
40
|
+
host 'http://api.forismatic.com/'
|
41
|
+
path '/api/1.0/'
|
42
|
+
|
43
|
+
params do
|
44
|
+
# you can pass a block or lambda to params
|
45
|
+
# this allows you to use object variables or configuration variables
|
46
|
+
param 'param1', &:my_option
|
47
|
+
param 'param2', -> { "#{my_option}" }
|
48
|
+
param 'param3' { my_option }
|
49
|
+
param 'param4' 'string'
|
50
|
+
end
|
51
|
+
|
52
|
+
headers do
|
53
|
+
header 'header1', &:my_header_value
|
54
|
+
end
|
55
|
+
|
56
|
+
# in body you can use object variables or configuration variables too
|
57
|
+
body do
|
58
|
+
{
|
59
|
+
'hello' => lang,
|
60
|
+
'path' => config.path
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
# this callback executes after receiving the response
|
65
|
+
before_validate do |body|
|
66
|
+
body.delete('unnecessary_param')
|
67
|
+
body.deep_symbolize_keys
|
68
|
+
body
|
69
|
+
end
|
70
|
+
|
71
|
+
# you can use dry-schema to validate response
|
72
|
+
schema do
|
73
|
+
required(:status).value(eql?: 'success')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
After you describe your request class you can use it:
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
result = MyApiClient.call(my_option: 'some_value', my_header_value: 'header_value')
|
83
|
+
|
84
|
+
result.success? # true if status code == 200 and schema is valid
|
85
|
+
result.failure?
|
86
|
+
result.status # result code - Integer
|
87
|
+
result.headers # hash of headers
|
88
|
+
result.body # raw body from request
|
89
|
+
result.schema_result # result of dry-schema
|
90
|
+
result.full_errors # array of errors from dry-schema
|
91
|
+
```
|
26
92
|
|
27
93
|
## Development
|
28
94
|
|
data/request-builder.gemspec
CHANGED
@@ -9,14 +9,14 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Anton Kostyuk"]
|
10
10
|
spec.email = ["anton.kostuk.2012@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Request DSL}
|
13
|
-
spec.description = %q{
|
14
|
-
spec.homepage = "https://github.com/RainbowPonny/request-builder"
|
12
|
+
spec.summary = %q{Ruby Request DSL}
|
13
|
+
spec.description = %q{Simple DSL wrapper for faraday gem}
|
14
|
+
spec.homepage = "https://github.com/RainbowPonny/ruby-request-builder"
|
15
15
|
spec.license = "MIT"
|
16
16
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
17
17
|
|
18
18
|
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
-
spec.metadata["source_code_uri"] = "https://github.com/RainbowPonny/request-builder"
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/RainbowPonny/ruby-request-builder"
|
20
20
|
|
21
21
|
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "request-builder.gemspec", "lib/**/*"]
|
22
22
|
spec.bindir = "bin"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Kostyuk
|
@@ -114,7 +114,7 @@ dependencies:
|
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: '3.0'
|
117
|
-
description:
|
117
|
+
description: Simple DSL wrapper for faraday gem
|
118
118
|
email:
|
119
119
|
- anton.kostuk.2012@gmail.com
|
120
120
|
executables: []
|
@@ -136,12 +136,12 @@ files:
|
|
136
136
|
- lib/request/builder/value_with_context.rb
|
137
137
|
- lib/request/builder/version.rb
|
138
138
|
- request-builder.gemspec
|
139
|
-
homepage: https://github.com/RainbowPonny/request-builder
|
139
|
+
homepage: https://github.com/RainbowPonny/ruby-request-builder
|
140
140
|
licenses:
|
141
141
|
- MIT
|
142
142
|
metadata:
|
143
|
-
homepage_uri: https://github.com/RainbowPonny/request-builder
|
144
|
-
source_code_uri: https://github.com/RainbowPonny/request-builder
|
143
|
+
homepage_uri: https://github.com/RainbowPonny/ruby-request-builder
|
144
|
+
source_code_uri: https://github.com/RainbowPonny/ruby-request-builder
|
145
145
|
post_install_message:
|
146
146
|
rdoc_options: []
|
147
147
|
require_paths:
|
@@ -160,5 +160,5 @@ requirements: []
|
|
160
160
|
rubygems_version: 3.1.6
|
161
161
|
signing_key:
|
162
162
|
specification_version: 4
|
163
|
-
summary: Request DSL
|
163
|
+
summary: Ruby Request DSL
|
164
164
|
test_files: []
|