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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 457e80f8bbd15d0c31db2b9c22eb0cdad23d220263b046333e7f23233fd39f7c
4
- data.tar.gz: b2631a86209e6e280069118793f8610360675ace8cc84841a091389220cb9c78
3
+ metadata.gz: 7ef65f89b3f06c126d7607aac92943b498c8f039d90f3c08edcd1b7d0487b88a
4
+ data.tar.gz: d7f48ebb1fff73fe3f80b6bb50ac23a1a744bcbb76078d1afb964f5b33540cf8
5
5
  SHA512:
6
- metadata.gz: fccbcdc8f74870d091a5d660ea44b76b400037570db2bfa1af2516fffa14a4f1ec49625785e65062da585eb36fc8d75bb62b6395f705da6a9fd68c5d06ac93d0
7
- data.tar.gz: 8040052bf21eaa5c8693abccc82959d3739684cda46145ab2921d5fc09ed734a69ff57816057126163070d403bff2a9acb9907cf6b918a6ccc0941609225a4f5
6
+ metadata.gz: 976ed740ebb730981e5f301e6562d00d54eaa2cb874e384840ee53845699f5871eb4ee3b725d0d5da3213d6ff2a17f6d2d10070e7223920d4a9368c4c3a90c44
7
+ data.tar.gz: '08423c1ccd725ec0e7069d94cb03cf66f5635f5ee6656204e71c3cbe3a1925e815a786a19293cc9f062159e4b366ce17cbe2ee169c36a993ce5a0aae53c3d8cf'
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # Request::Builder
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/request/builder`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Write usage instructions here
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
 
@@ -1,5 +1,5 @@
1
1
  module Request
2
2
  module Builder
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -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{Request DSL}
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.0
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: Request DSL
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: []