service_client 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/service_client/errors.rb +159 -0
- data/lib/service_client/response.rb +32 -0
- data/lib/service_client/version.rb +3 -0
- data/lib/service_client.rb +66 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 346614efbcf2a797ae8cb217ab590cbeaa35b6d2c8b75c808b437411bec9cd5f
|
4
|
+
data.tar.gz: 9e8957a321ced64da1f0f8ceae671f2005b28eed236f74f2fcdfaf0e7c87dc35
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: edb896efd67024f3480f34cef5a589aaba511e05a08906c7def7f2c696bdf5fe7a4d6e323f49d1c4b634369b6a2cfe5b4eabb9f7515f684c11689f1a9845cc53
|
7
|
+
data.tar.gz: d4c7f8a8564fb4a7b36715732a88dd2ba7f73819d75692e94c7d3f68cc288d704e242e6e90e27c3a652dc8e2845a55ba8fc93319c6a4401f4b4cc8686a1daa22
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
service_client (0.1.0)
|
5
|
+
httparty (~> 0.18.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.5.0)
|
11
|
+
httparty (0.18.1)
|
12
|
+
mime-types (~> 3.0)
|
13
|
+
multi_xml (>= 0.5.2)
|
14
|
+
mime-types (3.4.1)
|
15
|
+
mime-types-data (~> 3.2015)
|
16
|
+
mime-types-data (3.2022.0105)
|
17
|
+
multi_xml (0.6.0)
|
18
|
+
rake (12.3.3)
|
19
|
+
rspec (3.12.0)
|
20
|
+
rspec-core (~> 3.12.0)
|
21
|
+
rspec-expectations (~> 3.12.0)
|
22
|
+
rspec-mocks (~> 3.12.0)
|
23
|
+
rspec-core (3.12.1)
|
24
|
+
rspec-support (~> 3.12.0)
|
25
|
+
rspec-expectations (3.12.2)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.12.0)
|
28
|
+
rspec-mocks (3.12.3)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.12.0)
|
31
|
+
rspec-support (3.12.0)
|
32
|
+
|
33
|
+
PLATFORMS
|
34
|
+
ruby
|
35
|
+
|
36
|
+
DEPENDENCIES
|
37
|
+
bundler (= 2.1.4)
|
38
|
+
httparty (~> 0.18.0)
|
39
|
+
rake (~> 12.0)
|
40
|
+
rspec (~> 3.0)
|
41
|
+
service_client!
|
42
|
+
|
43
|
+
RUBY VERSION
|
44
|
+
ruby 2.7.1p83
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Alef Ojeda de Oliveira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# ServiceClient
|
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/service_client`. 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
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'service_client'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install service_client
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/service_client.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "service_client"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Purpose: ServiceClient::Errors module
|
4
|
+
|
5
|
+
# Compare this snippet from lib/service_client/errors.rb:
|
6
|
+
module ServiceClient
|
7
|
+
# Errors module
|
8
|
+
module Errors
|
9
|
+
# StandardError class
|
10
|
+
class BaseError < StandardError
|
11
|
+
attr_reader :response
|
12
|
+
|
13
|
+
def initialize(msg, response)
|
14
|
+
@response = response
|
15
|
+
super(msg)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# 400 – Bad Request
|
20
|
+
class BadRequestError < BaseError; end
|
21
|
+
# 401 – Unauthorized
|
22
|
+
class UnauthorizedError < BaseError; end
|
23
|
+
# 402 – Payment Required
|
24
|
+
class PaymentRequiredError < BaseError; end
|
25
|
+
# 403 – Forbidden
|
26
|
+
class ForbiddenError < BaseError; end
|
27
|
+
# 404 – Not Found
|
28
|
+
class NotFoundError < BaseError; end
|
29
|
+
# 405 – Method Not Allowed
|
30
|
+
class MethodNotAllowedError < BaseError; end
|
31
|
+
# 406 – Not Acceptable
|
32
|
+
class NotAcceptableError < BaseError; end
|
33
|
+
# 407 – Proxy Authentication Required
|
34
|
+
class ProxyAuthenticationRequiredError < BaseError; end
|
35
|
+
# 408 – Request Timeout
|
36
|
+
class RequestTimeoutError < BaseError; end
|
37
|
+
# 409 – Conflict
|
38
|
+
class ConflictError < BaseError; end
|
39
|
+
# 410 – Gone
|
40
|
+
class GoneError < BaseError; end
|
41
|
+
# 411 – Length Required
|
42
|
+
class LengthRequiredError < BaseError; end
|
43
|
+
# 412 – Precondition Failed
|
44
|
+
class PreconditionFailedError < BaseError; end
|
45
|
+
# 413 – Request Entity Too Large
|
46
|
+
class RequestEntityTooLargeError < BaseError; end
|
47
|
+
# 414 – Request-URI Too Long
|
48
|
+
class RequestURITooLongError < BaseError; end
|
49
|
+
# 415 – Unsupported Media Type
|
50
|
+
class UnsupportedMediaTypeError < BaseError; end
|
51
|
+
# 416 – Requested Range Not Satisfiable
|
52
|
+
class RequestedRangeNotSatisfiableError < BaseError; end
|
53
|
+
# 417 – Expectation Failed
|
54
|
+
class ExpectationFailedError < BaseError; end
|
55
|
+
# 420 – Enhance Your Calm
|
56
|
+
class EnhanceYourCalmError < BaseError; end
|
57
|
+
# 422 – Unprocessable Entity
|
58
|
+
class UnprocessableEntityError < BaseError; end
|
59
|
+
# 423 – Locked
|
60
|
+
class LockedError < BaseError; end
|
61
|
+
# 424 – Failed Dependency
|
62
|
+
class FailedDependencyError < BaseError; end
|
63
|
+
# 426 – Upgrade Required
|
64
|
+
class UpgradeRequiredError < BaseError; end
|
65
|
+
# 428 – Precondition Required
|
66
|
+
class PreconditionRequiredError < BaseError; end
|
67
|
+
# 429 – Too Many Requests
|
68
|
+
class TooManyRequestsError < BaseError; end
|
69
|
+
# 431 – Request Header Fields Too Large
|
70
|
+
class RequestHeaderFieldsTooLargeError < BaseError; end
|
71
|
+
# 444 – No Response
|
72
|
+
class NoResponseError < BaseError; end
|
73
|
+
# 449 – Retry With
|
74
|
+
class RetryWithError < BaseError; end
|
75
|
+
# 450 – Bllocked by Windows Parental Controls
|
76
|
+
class BlockedByWindowsParentalControlsError < BaseError; end
|
77
|
+
# 451 – Unavailable For Legal Reasons
|
78
|
+
class UnavailableForLegalReasonsError < BaseError; end
|
79
|
+
# 499 – Client Closed Request
|
80
|
+
class ClientClosedRequestError < BaseError; end
|
81
|
+
# 500 – Internal Server Error
|
82
|
+
class InternalServerError < BaseError; end
|
83
|
+
# 501 – Not Implemented
|
84
|
+
class NotImplementedError < BaseError; end
|
85
|
+
# 502 – Bad Gateway
|
86
|
+
class BadGatewayError < BaseError; end
|
87
|
+
# 503 – Service Unavailable
|
88
|
+
class ServiceUnavailableError < BaseError; end
|
89
|
+
# 504 – Gateway Timeout
|
90
|
+
class GatewayTimeoutError < BaseError; end
|
91
|
+
# 505 – HTTP Version Not Supported
|
92
|
+
class HTTPVersionNotSupportedError < BaseError; end
|
93
|
+
# 506 – Variant Also Negotiates
|
94
|
+
class VariantAlsoNegotiatesError < BaseError; end
|
95
|
+
# 507 – Insufficient Storage
|
96
|
+
class InsufficientStorageError < BaseError; end
|
97
|
+
# 508 – Loop Detected
|
98
|
+
class LoopDetectedError < BaseError; end
|
99
|
+
# 510 – Not Extended
|
100
|
+
class NotExtendedError < BaseError; end
|
101
|
+
# 511 – Network Authentication Required
|
102
|
+
class NetworkAuthenticationRequiredError < BaseError; end
|
103
|
+
# 598 – Network Read Timeout Error
|
104
|
+
class NetworkReadTimeoutError < BaseError; end
|
105
|
+
# 599 – Network Connect Timeout Error
|
106
|
+
class NetworkConnectTimeoutError < BaseError; end
|
107
|
+
|
108
|
+
ERRORS = {
|
109
|
+
'400': BadRequestError,
|
110
|
+
'401': UnauthorizedError,
|
111
|
+
'402': PaymentRequiredError,
|
112
|
+
'403': ForbiddenError,
|
113
|
+
'404': NotFoundError,
|
114
|
+
'405': MethodNotAllowedError,
|
115
|
+
'406': NotAcceptableError,
|
116
|
+
'407': ProxyAuthenticationRequiredError,
|
117
|
+
'408': RequestTimeoutError,
|
118
|
+
'409': ConflictError,
|
119
|
+
'410': GoneError,
|
120
|
+
'411': LengthRequiredError,
|
121
|
+
'412': PreconditionFailedError,
|
122
|
+
'413': RequestEntityTooLargeError,
|
123
|
+
'414': RequestURITooLongError,
|
124
|
+
'415': UnsupportedMediaTypeError,
|
125
|
+
'416': RequestedRangeNotSatisfiableError,
|
126
|
+
'417': ExpectationFailedError,
|
127
|
+
'420': EnhanceYourCalmError,
|
128
|
+
'422': UnprocessableEntityError,
|
129
|
+
'423': LockedError,
|
130
|
+
'424': FailedDependencyError,
|
131
|
+
'426': UpgradeRequiredError,
|
132
|
+
'428': PreconditionRequiredError,
|
133
|
+
'429': TooManyRequestsError,
|
134
|
+
'431': RequestHeaderFieldsTooLargeError,
|
135
|
+
'444': NoResponseError,
|
136
|
+
'449': RetryWithError,
|
137
|
+
'450': BlockedByWindowsParentalControlsError,
|
138
|
+
'451': UnavailableForLegalReasonsError,
|
139
|
+
'499': ClientClosedRequestError,
|
140
|
+
'500': InternalServerError,
|
141
|
+
'501': NotImplementedError,
|
142
|
+
'502': BadGatewayError,
|
143
|
+
'503': ServiceUnavailableError,
|
144
|
+
'504': GatewayTimeoutError,
|
145
|
+
'505': HTTPVersionNotSupportedError,
|
146
|
+
'506': VariantAlsoNegotiatesError,
|
147
|
+
'507': InsufficientStorageError,
|
148
|
+
'508': LoopDetectedError,
|
149
|
+
'510': NotExtendedError,
|
150
|
+
'511': NetworkAuthenticationRequiredError,
|
151
|
+
'598': NetworkReadTimeoutError,
|
152
|
+
'599': NetworkConnectTimeoutError,
|
153
|
+
}.freeze
|
154
|
+
|
155
|
+
def raise_error(code, response)
|
156
|
+
raise ERRORS[code.to_sym].new(ERRORS[code.to_sym].class.name, response)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'errors'
|
3
|
+
# Purpose: Response class for ServiceClient
|
4
|
+
#
|
5
|
+
# Compare this snippet from lib/service_client/response.rb:
|
6
|
+
module ServiceClient
|
7
|
+
# Response class
|
8
|
+
class Response
|
9
|
+
include ServiceClient::Errors
|
10
|
+
|
11
|
+
attr_accessor :code, :data, :headers
|
12
|
+
|
13
|
+
def initialize(response)
|
14
|
+
@code = response.code
|
15
|
+
@data = response.parsed_response
|
16
|
+
@headers = response.headers
|
17
|
+
end
|
18
|
+
|
19
|
+
def call
|
20
|
+
case code
|
21
|
+
when 200..299
|
22
|
+
self
|
23
|
+
else
|
24
|
+
raise_error(code.to_s, self)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.call(response)
|
29
|
+
new(response).call
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative 'service_client/version'
|
3
|
+
require_relative 'service_client/response'
|
4
|
+
require_relative 'service_client/errors'
|
5
|
+
require 'httparty'
|
6
|
+
|
7
|
+
# Service Client
|
8
|
+
module ServiceClient
|
9
|
+
# ParamsRequired error
|
10
|
+
class ParamsRequired < StandardError; end
|
11
|
+
|
12
|
+
# Call class
|
13
|
+
class Call
|
14
|
+
def self.post(url = nil, headers: nil, body: nil)
|
15
|
+
raise_params_required(url: url, headers: headers, body: body)
|
16
|
+
|
17
|
+
request = HTTParty.post(url, headers: headers, body: body)
|
18
|
+
|
19
|
+
make_response(request)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get(url = nil, headers: nil)
|
23
|
+
raise_params_required(url: url)
|
24
|
+
|
25
|
+
request = HTTParty.get(url, headers: headers)
|
26
|
+
|
27
|
+
make_response(request)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.put(url = nil, headers: nil, body: nil)
|
31
|
+
raise_params_required(url: url, body: body)
|
32
|
+
|
33
|
+
request = HTTParty.put(url, headers: headers, body: body)
|
34
|
+
|
35
|
+
make_response(request)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.delete(url = nil, headers: nil)
|
39
|
+
raise_params_required(url: url)
|
40
|
+
|
41
|
+
request = HTTParty.delete(url, headers: headers)
|
42
|
+
|
43
|
+
make_response(request)
|
44
|
+
end
|
45
|
+
|
46
|
+
class << self
|
47
|
+
private
|
48
|
+
|
49
|
+
def make_response(response)
|
50
|
+
Response.call(response)
|
51
|
+
end
|
52
|
+
|
53
|
+
def raise_params_required(params)
|
54
|
+
raise ParamsRequired, "Params: #{nil_params(params)} are required" if params_nil?(params)
|
55
|
+
end
|
56
|
+
|
57
|
+
def nil_params(params)
|
58
|
+
params.select { |_, value| value.nil? }.keys
|
59
|
+
end
|
60
|
+
|
61
|
+
def params_nil?(params)
|
62
|
+
params.values.any?(&:nil?)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: service_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alef Ojeda de Oliveira
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-02-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.1.4
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.4
|
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.18.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.18.0
|
41
|
+
description: Service client
|
42
|
+
email:
|
43
|
+
- alef.oliveira@dimensa.com.br
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- Gemfile
|
49
|
+
- Gemfile.lock
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/console
|
54
|
+
- bin/setup
|
55
|
+
- lib/service_client.rb
|
56
|
+
- lib/service_client/errors.rb
|
57
|
+
- lib/service_client/response.rb
|
58
|
+
- lib/service_client/version.rb
|
59
|
+
homepage: https://github.com/nemuba/service_client
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata:
|
63
|
+
homepage_uri: https://github.com/nemuba/service_client
|
64
|
+
source_code_uri: https://github.com/nemuba/service_client
|
65
|
+
changelog_uri: https://github.com/nemuba/service_client/blob/master/CHANGELOG.md
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 2.3.0
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubygems_version: 3.1.2
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Service client
|
85
|
+
test_files: []
|