koine-rest_client 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +30 -0
- data/.rubocop.yml +1 -1
- data/Gemfile +12 -0
- data/README.md +4 -0
- data/koine-rest_client.gemspec +0 -11
- data/lib/koine/rest_client/errors.rb +64 -0
- data/lib/koine/rest_client/request.rb +16 -1
- data/lib/koine/rest_client/response_parser.rb +38 -1
- data/lib/koine/rest_client/version.rb +1 -1
- data/lib/koine/rest_client.rb +1 -4
- metadata +8 -150
- data/lib/koine/rest_client/bad_request_error.rb +0 -9
- data/lib/koine/rest_client/error.rb +0 -14
- data/lib/koine/rest_client/internal_server_error.rb +0 -9
- data/lib/koine/rest_client/not_found_error.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d572492742b6f56fb9c22b8c2074aed8a5383d90875938dfbaf35ccb22d2fe8
|
4
|
+
data.tar.gz: ce09b90ea4866d789f37a777bb935b2d8ea66a9f6914de6fd28e286d80857ae5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f34b6d2a7605afcad75f8f51e301c66470d965d9e0d8fc86f44e0c25c37c1f8e4e6c365ecca9209ac7e27e3a6f679019f42702615e0eefcdcd23c0bef9e8d8cc
|
7
|
+
data.tar.gz: c4cdb8cac74fceca8815e94e3939b2d0f95d9a3ea244a80658358271e73cad5da4c112d30417567a965f8e4ea2d12f93f2a1f45c3d646feff31d4d301c1d2787
|
@@ -0,0 +1,30 @@
|
|
1
|
+
name: RSpec
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- '*'
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
name: RSpec with ruby ${{ matrix.ruby }}
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby:
|
17
|
+
- '3.0.2'
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- name: Set up Ruby
|
21
|
+
uses: ruby/setup-ruby@v1
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby }}
|
24
|
+
bundler-cache: true
|
25
|
+
- name: Run the default task
|
26
|
+
run: bundle exec rake
|
27
|
+
- name: Coveralls
|
28
|
+
uses: coverallsapp/github-action@master
|
29
|
+
with:
|
30
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
@@ -4,3 +4,15 @@ source 'https://rubygems.org'
|
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in koine-rest_client.gemspec
|
6
6
|
gemspec
|
7
|
+
|
8
|
+
gem 'awesome_print'
|
9
|
+
gem 'bundler', '~> 2.0'
|
10
|
+
gem 'object_comparator'
|
11
|
+
gem 'rake', '~> 10.0'
|
12
|
+
gem 'reek'
|
13
|
+
gem 'rspec', '~> 3.0'
|
14
|
+
gem 'rubocop'
|
15
|
+
gem 'rubocop-performance'
|
16
|
+
gem 'rubocop-rspec'
|
17
|
+
gem 'simplecov', require: false
|
18
|
+
gem 'simplecov-lcov', require: false
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Koine::RestClient
|
2
2
|
|
3
|
+
[![RSpec](https://github.com/mjacobus/koine-rest_client/actions/workflows/rspec.yml/badge.svg)](https://github.com/mjacobus/koine-rest_client/actions/workflows/rspec.yml)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/mjacobus/koine-rest_client/badge.svg?branch=master)](https://coveralls.io/github/mjacobus/koine-rest_client?branch=master)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/8b7bf0a115757ca74d9a/maintainability)](https://codeclimate.com/github/mjacobus/koine-rest_client/maintainability)
|
6
|
+
|
3
7
|
Another http client with async
|
4
8
|
|
5
9
|
## Installation
|
data/koine-rest_client.gemspec
CHANGED
@@ -32,15 +32,4 @@ Gem::Specification.new do |spec|
|
|
32
32
|
|
33
33
|
spec.add_dependency 'addressable', '>= 2.3'
|
34
34
|
spec.add_dependency 'httparty', '>= 0.17.0'
|
35
|
-
|
36
|
-
spec.add_development_dependency 'bundler', '~> 2.0'
|
37
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
38
|
-
spec.add_development_dependency 'reek'
|
39
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
|
-
spec.add_development_dependency 'rubocop'
|
41
|
-
spec.add_development_dependency 'rubocop-performance'
|
42
|
-
spec.add_development_dependency 'rubocop-rspec'
|
43
|
-
spec.add_development_dependency 'simplecov'
|
44
|
-
spec.add_development_dependency 'object_comparator'
|
45
|
-
spec.add_development_dependency 'awesome_print'
|
46
35
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses
|
4
|
+
#
|
5
|
+
module Koine
|
6
|
+
module RestClient
|
7
|
+
# base class for http errors
|
8
|
+
class Error < StandardError
|
9
|
+
attr_reader :response
|
10
|
+
|
11
|
+
def initialize(response)
|
12
|
+
@response = response
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
@message ||= @response&.body
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# 400
|
21
|
+
BadRequestError = Class.new(Error)
|
22
|
+
NotFoundError = Class.new(Error)
|
23
|
+
UnauthorizedError = Class.new(Error)
|
24
|
+
PaymentRequiredExperimentalError = Class.new(Error)
|
25
|
+
ForbiddenError = Class.new(Error)
|
26
|
+
MethodNotAllowedError = Class.new(Error)
|
27
|
+
NotAcceptableError = Class.new(Error)
|
28
|
+
ProxyAuthenticationRequiredError = Class.new(Error)
|
29
|
+
RequestTimeoutError = Class.new(Error)
|
30
|
+
ConflictError = Class.new(Error)
|
31
|
+
GoneError = Class.new(Error)
|
32
|
+
LengthRequiredError = Class.new(Error)
|
33
|
+
PreconditionFailedError = Class.new(Error)
|
34
|
+
PayloadTooLargeError = Class.new(Error)
|
35
|
+
URITooLongError = Class.new(Error)
|
36
|
+
UnsupportedMediaTypeError = Class.new(Error)
|
37
|
+
RangeNotSatisfiableError = Class.new(Error)
|
38
|
+
ExpectationFailedError = Class.new(Error)
|
39
|
+
ImATeapotError = Class.new(Error)
|
40
|
+
MisdirectedRequestError = Class.new(Error)
|
41
|
+
UnprocessableEntityError = Class.new(Error)
|
42
|
+
LockedError = Class.new(Error)
|
43
|
+
FailedDependencyError = Class.new(Error)
|
44
|
+
TooEarlyExperimentalError = Class.new(Error)
|
45
|
+
UpgradeRequiredError = Class.new(Error)
|
46
|
+
PreconditionRequiredError = Class.new(Error)
|
47
|
+
TooManyRequestsError = Class.new(Error)
|
48
|
+
RequestHeaderFieldsTooLargeError = Class.new(Error)
|
49
|
+
UnavailableForLegalReasonsError = Class.new(Error)
|
50
|
+
|
51
|
+
# 500
|
52
|
+
InternalServerError = Class.new(Error)
|
53
|
+
NotImplementedError = Class.new(Error)
|
54
|
+
BadGatewayError = Class.new(Error)
|
55
|
+
ServiceUnavailableError = Class.new(Error)
|
56
|
+
GatewayTimeoutError = Class.new(Error)
|
57
|
+
HTTPVersionNotSupportedError = Class.new(Error)
|
58
|
+
VariantAlsoNegotiatesError = Class.new(Error)
|
59
|
+
InsufficientStorageError = Class.new(Error)
|
60
|
+
LoopDetectedError = Class.new(Error)
|
61
|
+
NotExtendedError = Class.new(Error)
|
62
|
+
NetworkAuthenticationRequiredError = Class.new(Error)
|
63
|
+
end
|
64
|
+
end
|
@@ -77,7 +77,6 @@ module Koine
|
|
77
77
|
attr_writer :path
|
78
78
|
attr_writer :query_params
|
79
79
|
attr_writer :headers
|
80
|
-
attr_writer :body
|
81
80
|
|
82
81
|
# :reek:FeatureEnvy
|
83
82
|
def new(attribute, value)
|
@@ -86,6 +85,22 @@ module Koine
|
|
86
85
|
object.freeze
|
87
86
|
end
|
88
87
|
end
|
88
|
+
|
89
|
+
def body=(body)
|
90
|
+
if json_request? && body.is_a?(Hash)
|
91
|
+
body = JSON.dump(body)
|
92
|
+
end
|
93
|
+
|
94
|
+
@body = body
|
95
|
+
end
|
96
|
+
|
97
|
+
# rubocop:disable Performance/Casecmp
|
98
|
+
def json_request?
|
99
|
+
headers.find do |key, value|
|
100
|
+
key.downcase == 'content-type' && value.downcase.match('application/json')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
# rubocop:enable Performance/Casecmp
|
89
104
|
end
|
90
105
|
end
|
91
106
|
end
|
@@ -23,8 +23,45 @@ module Koine
|
|
23
23
|
def error_for_code(code)
|
24
24
|
{
|
25
25
|
400 => BadRequestError,
|
26
|
+
401 => UnauthorizedError,
|
27
|
+
402 => PaymentRequiredExperimentalError,
|
28
|
+
403 => ForbiddenError,
|
26
29
|
404 => NotFoundError,
|
27
|
-
|
30
|
+
405 => MethodNotAllowedError,
|
31
|
+
406 => NotAcceptableError,
|
32
|
+
407 => ProxyAuthenticationRequiredError,
|
33
|
+
408 => RequestTimeoutError,
|
34
|
+
409 => ConflictError,
|
35
|
+
410 => GoneError,
|
36
|
+
411 => LengthRequiredError,
|
37
|
+
412 => PreconditionFailedError,
|
38
|
+
413 => PayloadTooLargeError,
|
39
|
+
414 => URITooLongError,
|
40
|
+
415 => UnsupportedMediaTypeError,
|
41
|
+
416 => RangeNotSatisfiableError,
|
42
|
+
417 => ExpectationFailedError,
|
43
|
+
418 => ImATeapotError,
|
44
|
+
421 => MisdirectedRequestError,
|
45
|
+
422 => UnprocessableEntityError,
|
46
|
+
423 => LockedError,
|
47
|
+
424 => FailedDependencyError,
|
48
|
+
425 => TooEarlyExperimentalError,
|
49
|
+
426 => UpgradeRequiredError,
|
50
|
+
428 => PreconditionRequiredError,
|
51
|
+
429 => TooManyRequestsError,
|
52
|
+
431 => RequestHeaderFieldsTooLargeError,
|
53
|
+
451 => UnavailableForLegalReasonsError,
|
54
|
+
500 => InternalServerError,
|
55
|
+
501 => NotImplementedError,
|
56
|
+
502 => BadGatewayError,
|
57
|
+
503 => ServiceUnavailableError,
|
58
|
+
504 => GatewayTimeoutError,
|
59
|
+
505 => HTTPVersionNotSupportedError,
|
60
|
+
506 => VariantAlsoNegotiatesError,
|
61
|
+
507 => InsufficientStorageError,
|
62
|
+
508 => LoopDetectedError,
|
63
|
+
510 => NotExtendedError,
|
64
|
+
511 => NetworkAuthenticationRequiredError
|
28
65
|
}.fetch(code) { Error }
|
29
66
|
end
|
30
67
|
end
|
data/lib/koine/rest_client.rb
CHANGED
@@ -2,15 +2,12 @@
|
|
2
2
|
|
3
3
|
require 'httparty'
|
4
4
|
require 'koine/url'
|
5
|
-
require 'koine/rest_client/
|
5
|
+
require 'koine/rest_client/errors'
|
6
6
|
require 'koine/rest_client/version'
|
7
7
|
require 'koine/rest_client/client'
|
8
8
|
require 'koine/rest_client/async_builder'
|
9
9
|
require 'koine/rest_client/async_queue'
|
10
10
|
require 'koine/rest_client/response_parser'
|
11
|
-
require 'koine/rest_client/bad_request_error'
|
12
|
-
require 'koine/rest_client/not_found_error'
|
13
|
-
require 'koine/rest_client/internal_server_error'
|
14
11
|
require 'koine/rest_client/request'
|
15
12
|
require 'koine/rest_client/adapters/http_party_adapter'
|
16
13
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: koine-rest_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcelo Jacobus
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -38,146 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
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
41
|
description: Another http client - with support to async calls
|
182
42
|
email:
|
183
43
|
- marcelo.jacobus@gmail.com
|
@@ -185,6 +45,7 @@ executables: []
|
|
185
45
|
extensions: []
|
186
46
|
extra_rdoc_files: []
|
187
47
|
files:
|
48
|
+
- ".github/workflows/rspec.yml"
|
188
49
|
- ".gitignore"
|
189
50
|
- ".reek.yml"
|
190
51
|
- ".rspec"
|
@@ -204,11 +65,8 @@ files:
|
|
204
65
|
- lib/koine/rest_client/adapters/http_party_adapter.rb
|
205
66
|
- lib/koine/rest_client/async_builder.rb
|
206
67
|
- lib/koine/rest_client/async_queue.rb
|
207
|
-
- lib/koine/rest_client/bad_request_error.rb
|
208
68
|
- lib/koine/rest_client/client.rb
|
209
|
-
- lib/koine/rest_client/
|
210
|
-
- lib/koine/rest_client/internal_server_error.rb
|
211
|
-
- lib/koine/rest_client/not_found_error.rb
|
69
|
+
- lib/koine/rest_client/errors.rb
|
212
70
|
- lib/koine/rest_client/request.rb
|
213
71
|
- lib/koine/rest_client/response_parser.rb
|
214
72
|
- lib/koine/rest_client/rspec_mock_client.rb
|
@@ -222,7 +80,7 @@ metadata:
|
|
222
80
|
homepage_uri: https://github.com/mjacobus/koine-rest_client
|
223
81
|
source_code_uri: https://github.com/mjacobus/koine-rest_client
|
224
82
|
changelog_uri: https://github.com/mjacobus/koine-rest_client/CHANGELOG.md
|
225
|
-
post_install_message:
|
83
|
+
post_install_message:
|
226
84
|
rdoc_options: []
|
227
85
|
require_paths:
|
228
86
|
- lib
|
@@ -237,8 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
95
|
- !ruby/object:Gem::Version
|
238
96
|
version: '0'
|
239
97
|
requirements: []
|
240
|
-
rubygems_version: 3.
|
241
|
-
signing_key:
|
98
|
+
rubygems_version: 3.2.33
|
99
|
+
signing_key:
|
242
100
|
specification_version: 4
|
243
101
|
summary: Another http client
|
244
102
|
test_files: []
|