service_client 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 346614efbcf2a797ae8cb217ab590cbeaa35b6d2c8b75c808b437411bec9cd5f
4
- data.tar.gz: 9e8957a321ced64da1f0f8ceae671f2005b28eed236f74f2fcdfaf0e7c87dc35
3
+ metadata.gz: 521a1eeca83e5e229c94fcd20c94e9173e30ef27036e961c1d5dcfc02294d7e1
4
+ data.tar.gz: 46b385eb2d4619a8eafe55af1379ec8753d3fd8e314cff577694e972ed5545ef
5
5
  SHA512:
6
- metadata.gz: edb896efd67024f3480f34cef5a589aaba511e05a08906c7def7f2c696bdf5fe7a4d6e323f49d1c4b634369b6a2cfe5b4eabb9f7515f684c11689f1a9845cc53
7
- data.tar.gz: d4c7f8a8564fb4a7b36715732a88dd2ba7f73819d75692e94c7d3f68cc288d704e242e6e90e27c3a652dc8e2845a55ba8fc93319c6a4401f4b4cc8686a1daa22
6
+ metadata.gz: 39065c89a4675a343e87bf748eb910bd2d9b132655653e72e3e9459e8e834fc129d716b0cf5837d0c6a1f8c154304c289e060b02c3ac689d388fdd1cd42b06fc
7
+ data.tar.gz: 1811584d2b959c7db852620e711ce1946bff3434960681695113e8779adf946e48c81ee037f28928c2b468a7fc86bb6a1ce47dcf34fad711e9bc43c27f5a4823
data/Gemfile CHANGED
@@ -8,3 +8,4 @@ ruby "2.7.1"
8
8
  gem "rake", "~> 12.0"
9
9
  gem "rspec", "~> 3.0"
10
10
  gem "httparty", "~> 0.18.0"
11
+ gem "rack", "~> 2.2.3"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- service_client (0.1.0)
4
+ service_client (0.1.2)
5
5
  httparty (~> 0.18.0)
6
6
 
7
7
  GEM
@@ -15,6 +15,7 @@ GEM
15
15
  mime-types-data (~> 3.2015)
16
16
  mime-types-data (3.2022.0105)
17
17
  multi_xml (0.6.0)
18
+ rack (2.2.6.2)
18
19
  rake (12.3.3)
19
20
  rspec (3.12.0)
20
21
  rspec-core (~> 3.12.0)
@@ -36,6 +37,7 @@ PLATFORMS
36
37
  DEPENDENCIES
37
38
  bundler (= 2.1.4)
38
39
  httparty (~> 0.18.0)
40
+ rack (~> 2.2.3)
39
41
  rake (~> 12.0)
40
42
  rspec (~> 3.0)
41
43
  service_client!
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
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
4
 
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
@@ -14,15 +12,154 @@ gem 'service_client'
14
12
 
15
13
  And then execute:
16
14
 
17
- $ bundle install
15
+ ```bash
16
+ bundle install
17
+ ```
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
- $ gem install service_client
21
+ ```bash
22
+ gem install service_client
23
+ ```
22
24
 
23
25
  ## Usage
24
26
 
25
- TODO: Write usage instructions here
27
+ Basic usage example:
28
+
29
+ ```ruby
30
+ class CustomerClient < ServiceClient::Base
31
+ def find(id)
32
+ response = get("https://api.com/customers/#{id}")
33
+
34
+ response.data
35
+ rescue ServiceClient::Errors::NoDataFoundError => e
36
+ puts e.response.code # 404
37
+ puts e.response.headers
38
+ puts e.response.data
39
+ rescue ServiceClient::Errors::InternalServerError => e
40
+ puts e.response.code # 500
41
+ puts e.response.headers
42
+ puts e.response.data
43
+ # All errors of HTTP status code
44
+ end
45
+
46
+ def all
47
+ get(nil)
48
+ rescue ServiceClient::ParamsRequired => e
49
+ puts e.message
50
+ end
51
+ end
52
+
53
+ ```
54
+
55
+ ## Methods of class
56
+
57
+ ```ruby
58
+ # GET
59
+ ServiceClient::Base.get(url, headers:)
60
+
61
+ # POST
62
+ ServiceClient::Base.post(url, headers:, body:)
63
+
64
+ # PUT
65
+ ServiceClient::Base.put(url, headers:, body:)
66
+
67
+ # DELETE
68
+ ServiceClient::Base.delete(url, headers:, body:)
69
+ ```
70
+
71
+ ## Classes of errors
72
+
73
+ ```ruby
74
+ # 400 – Bad Request
75
+ ServiceClient::Errors::BadRequestError
76
+ # 401 – Unauthorized
77
+ ServiceClient::Errors::UnauthorizedError
78
+ # 402 – Payment Required
79
+ ServiceClient::Errors::PaymentRequiredError
80
+ # 403 – Forbidden
81
+ ServiceClient::Errors::ForbiddenError
82
+ # 404 – Not Found
83
+ ServiceClient::Errors::NotFoundError
84
+ # 405 – Method Not Allowed
85
+ ServiceClient::Errors::MethodNotAllowedError
86
+ # 406 – Not Acceptable
87
+ ServiceClient::Errors::NotAcceptableError
88
+ # 407 – Proxy Authentication Required
89
+ ServiceClient::Errors::ProxyAuthenticationRequiredError
90
+ # 408 – Request Timeout
91
+ ServiceClient::Errors::RequestTimeoutError
92
+ # 409 – Conflict
93
+ ServiceClient::Errors::ConflictError
94
+ # 410 – Gone
95
+ ServiceClient::Errors::GoneError
96
+ # 411 – Length Required
97
+ ServiceClient::Errors::LengthRequiredError
98
+ # 412 – Precondition Failed
99
+ ServiceClient::Errors::PreconditionFailedError
100
+ # 413 – Request Entity Too Large
101
+ ServiceClient::Errors::RequestEntityTooLargeError
102
+ # 414 – Request-URI Too Long
103
+ ServiceClient::Errors::RequestURITooLongError
104
+ # 415 – Unsupported Media Type
105
+ ServiceClient::Errors::UnsupportedMediaTypeError
106
+ # 416 – Requested Range Not Satisfiable
107
+ ServiceClient::Errors::RequestedRangeNotSatisfiableError
108
+ # 417 – Expectation Failed
109
+ ServiceClient::Errors::ExpectationFailedError
110
+ # 420 – Enhance Your Calm
111
+ ServiceClient::Errors::EnhanceYourCalmError
112
+ # 422 – Unprocessable Entity
113
+ ServiceClient::Errors::UnprocessableEntityError
114
+ # 423 – Locked
115
+ ServiceClient::Errors::LockedError
116
+ # 424 – Failed Dependency
117
+ ServiceClient::Errors::FailedDependencyError
118
+ # 426 – Upgrade Required
119
+ ServiceClient::Errors::UpgradeRequiredError
120
+ # 428 – Precondition Required
121
+ ServiceClient::Errors::PreconditionRequiredError
122
+ # 429 – Too Many Requests
123
+ ServiceClient::Errors::TooManyRequestsError
124
+ # 431 – Request Header Fields Too Large
125
+ ServiceClient::Errors::RequestHeaderFieldsTooLargeError
126
+ # 444 – No Response
127
+ ServiceClient::Errors::NoResponseError
128
+ # 449 – Retry With
129
+ ServiceClient::Errors::RetryWithError
130
+ # 450 – Bllocked by Windows Parental Controls
131
+ ServiceClient::Errors::BlockedByWindowsParentalControlsError
132
+ # 451 – Unavailable For Legal Reasons
133
+ ServiceClient::Errors::UnavailableForLegalReasonsError
134
+ # 499 – Client Closed Request
135
+ ServiceClient::Errors::ClientClosedRequestError
136
+ # 500 – Internal Server Error
137
+ ServiceClient::Errors::InternalServerError
138
+ # 501 – Not Implemented
139
+ ServiceClient::Errors::NotImplementedError
140
+ # 502 – Bad Gateway
141
+ ServiceClient::Errors::BadGatewayError
142
+ # 503 – Service Unavailable
143
+ ServiceClient::Errors::ServiceUnavailableError
144
+ # 504 – Gateway Timeout
145
+ ServiceClient::Errors::GatewayTimeoutError
146
+ # 505 – HTTP Version Not Supported
147
+ ServiceClient::Errors::HTTPVersionNotSupportedError
148
+ # 506 – Variant Also Negotiates
149
+ ServiceClient::Errors::VariantAlsoNegotiatesError
150
+ # 507 – Insufficient Storage
151
+ ServiceClient::Errors::InsufficientStorageError
152
+ # 508 – Loop Detected
153
+ ServiceClient::Errors::LoopDetectedError
154
+ # 510 – Not Extended
155
+ ServiceClient::Errors::NotExtendedError
156
+ # 511 – Network Authentication Required
157
+ ServiceClient::Errors::NetworkAuthenticationRequiredError
158
+ # 598 – Network Read Timeout Error
159
+ ServiceClient::Errors::NetworkReadTimeoutError
160
+ # 599 – Network Connect Timeout Error
161
+ ServiceClient::Errors::NetworkConnectTimeoutError
162
+ ```
26
163
 
27
164
  ## Development
28
165
 
@@ -32,8 +169,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
169
 
33
170
  ## Contributing
34
171
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/service_client.
36
-
172
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nemuba/service_client.
37
173
 
38
174
  ## License
39
175
 
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'httparty'
4
+ require_relative 'response'
5
+
6
+ module ServiceClient
7
+ # Base class
8
+ class ParamsRequired < StandardError; end
9
+
10
+ class Base
11
+ # ParamsRequired error
12
+
13
+ class << self
14
+ def 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 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 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 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
+ private
47
+
48
+ def make_response(response)
49
+ Response.call(response)
50
+ end
51
+
52
+ def raise_params_required(params)
53
+ raise ParamsRequired, "Params: #{nil_params(params)} are required" if params_nil?(params)
54
+ end
55
+
56
+ def nil_params(params)
57
+ params.select { |_, value| value.nil? }.keys
58
+ end
59
+
60
+ def params_nil?(params)
61
+ params.values.any?(&:nil?)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ServiceClient
2
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2".freeze
3
5
  end
@@ -1,66 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
3
+ require 'httparty'
2
4
  require_relative 'service_client/version'
3
5
  require_relative 'service_client/response'
6
+ require_relative 'service_client/base'
4
7
  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 CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: service_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alef Ojeda de Oliveira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-05 00:00:00.000000000 Z
11
+ date: 2023-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -47,12 +47,14 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - Gemfile
49
49
  - Gemfile.lock
50
+ - LICENSE
50
51
  - LICENSE.txt
51
52
  - README.md
52
53
  - Rakefile
53
54
  - bin/console
54
55
  - bin/setup
55
56
  - lib/service_client.rb
57
+ - lib/service_client/base.rb
56
58
  - lib/service_client/errors.rb
57
59
  - lib/service_client/response.rb
58
60
  - lib/service_client/version.rb