koine-rest_client 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Koine
4
+ module RestClient
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'addressable'
4
+
5
+ module Koine
6
+ # Url builder
7
+ class Url
8
+ # Exception for when the argument is invalid
9
+ ArgumentError = Class.new(::ArgumentError)
10
+
11
+ def initialize(url)
12
+ @url = validate(url).to_s.freeze
13
+ freeze
14
+ end
15
+
16
+ # :reek:UncommunicativeVariableName
17
+ # :reek:DuplicateMethodCall
18
+ def with_query_params(params)
19
+ if params.empty?
20
+ return self.class.new(to_s.split('?').first)
21
+ end
22
+
23
+ url = parsed.tap do |p|
24
+ p.query_values = params
25
+ end
26
+
27
+ self.class.new(url.to_s)
28
+ end
29
+
30
+ def with_query_param(param_name, value)
31
+ with_query_params(query_params.merge(param_name.to_s => value))
32
+ end
33
+
34
+ def query_params
35
+ parsed.query_values || {}
36
+ end
37
+
38
+ def uri
39
+ parsed.request_uri
40
+ end
41
+
42
+ def to_s(unescape: nil)
43
+ unless unescape
44
+ return @url
45
+ end
46
+
47
+ url = @url.to_s.dup
48
+
49
+ unescape.to_s.each_char do |char|
50
+ url = url.gsub(CGI.escape(char), char)
51
+ end
52
+
53
+ url
54
+ end
55
+
56
+ def ==(other)
57
+ other.class == self.class && other.to_s == to_s
58
+ end
59
+
60
+ private
61
+
62
+ def parsed(url = nil)
63
+ url ||= to_s
64
+ Addressable::URI.parse(url.to_s)
65
+ end
66
+
67
+ # :reek:TooManyStatements
68
+ def validate(input_url)
69
+ parsed(input_url).tap do |url|
70
+ url.send(:validate)
71
+
72
+ unless url.scheme
73
+ reject(url)
74
+ end
75
+ end
76
+ rescue StandardError => _exception
77
+ reject(input_url)
78
+ end
79
+
80
+ def reject(url)
81
+ raise ArgumentError, "Invalid url '#{url}'"
82
+ end
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,244 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: koine-rest_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Marcelo Jacobus
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: addressable
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.17.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.17.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: reek
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-performance
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: object_comparator
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: awesome_print
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Another http client - with support to async calls
182
+ email:
183
+ - marcelo.jacobus@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".reek.yml"
190
+ - ".rspec"
191
+ - ".rubocop.yml"
192
+ - ".travis.yml"
193
+ - CHANGELOG.md
194
+ - CODE_OF_CONDUCT.md
195
+ - Gemfile
196
+ - LICENSE.txt
197
+ - README.md
198
+ - Rakefile
199
+ - bin/console
200
+ - bin/mock_server
201
+ - bin/setup
202
+ - koine-rest_client.gemspec
203
+ - lib/koine/rest_client.rb
204
+ - lib/koine/rest_client/adapters/http_party_adapter.rb
205
+ - lib/koine/rest_client/async_builder.rb
206
+ - lib/koine/rest_client/async_queue.rb
207
+ - lib/koine/rest_client/bad_request_error.rb
208
+ - lib/koine/rest_client/client.rb
209
+ - lib/koine/rest_client/error.rb
210
+ - lib/koine/rest_client/internal_server_error.rb
211
+ - lib/koine/rest_client/not_found_error.rb
212
+ - lib/koine/rest_client/request.rb
213
+ - lib/koine/rest_client/response_parser.rb
214
+ - lib/koine/rest_client/rspec_mock_client.rb
215
+ - lib/koine/rest_client/version.rb
216
+ - lib/koine/url.rb
217
+ homepage: https://github.com/mjacobus/koine-rest_client
218
+ licenses:
219
+ - MIT
220
+ metadata:
221
+ allowed_push_host: https://rubygems.org
222
+ homepage_uri: https://github.com/mjacobus/koine-rest_client
223
+ source_code_uri: https://github.com/mjacobus/koine-rest_client
224
+ changelog_uri: https://github.com/mjacobus/koine-rest_client/CHANGELOG.md
225
+ post_install_message:
226
+ rdoc_options: []
227
+ require_paths:
228
+ - lib
229
+ required_ruby_version: !ruby/object:Gem::Requirement
230
+ requirements:
231
+ - - ">="
232
+ - !ruby/object:Gem::Version
233
+ version: '0'
234
+ required_rubygems_version: !ruby/object:Gem::Requirement
235
+ requirements:
236
+ - - ">="
237
+ - !ruby/object:Gem::Version
238
+ version: '0'
239
+ requirements: []
240
+ rubygems_version: 3.0.3
241
+ signing_key:
242
+ specification_version: 4
243
+ summary: Another http client
244
+ test_files: []