service_client 0.1.2 → 0.1.4

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: 521a1eeca83e5e229c94fcd20c94e9173e30ef27036e961c1d5dcfc02294d7e1
4
- data.tar.gz: 46b385eb2d4619a8eafe55af1379ec8753d3fd8e314cff577694e972ed5545ef
3
+ metadata.gz: 83056ee0b53ce4dd289dd6ad8ff474491a7432e146ee64b20cb253ae1f403786
4
+ data.tar.gz: 3a3b5f000c9db7b65f240952ecb079ec02decbad0b29a7e4ed6b70428ac815d8
5
5
  SHA512:
6
- metadata.gz: 39065c89a4675a343e87bf748eb910bd2d9b132655653e72e3e9459e8e834fc129d716b0cf5837d0c6a1f8c154304c289e060b02c3ac689d388fdd1cd42b06fc
7
- data.tar.gz: 1811584d2b959c7db852620e711ce1946bff3434960681695113e8779adf946e48c81ee037f28928c2b468a7fc86bb6a1ce47dcf34fad711e9bc43c27f5a4823
6
+ metadata.gz: 88d8a46deccaeb9f1bd1f730153968e05a99c85c8512b3daf614ec8a8eeb7d66c40583d3a7bc57b74ec8f65a99d430984755ab09b8d04004dc5ffe6f77fdb472
7
+ data.tar.gz: 46e90c9a75e91a530950e8059b3481618a5b59b867ffe8fc37f0b71142e5fade5f81b1317b376d3e1511650c5b47cc1cef1ddac46c3290ec192c2f730f4c6dec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- service_client (0.1.2)
4
+ service_client (0.1.3)
5
5
  httparty (~> 0.18.0)
6
6
 
7
7
  GEM
data/doc/index.html ADDED
@@ -0,0 +1,266 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+
4
+ <head>
5
+ <meta charset="UTF-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>
8
+ File: README
9
+
10
+ &mdash; Documentation by YARD 0.9.28
11
+
12
+ </title>
13
+
14
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
15
+
16
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
17
+
18
+ <script type="text/javascript">
19
+ pathId = "README";
20
+ relpath = '';
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+
31
+ <body>
32
+ <div class="nav_wrap">
33
+ <iframe id="nav" src="class_list.html?1"></iframe>
34
+ <div id="resizer"></div>
35
+ </div>
36
+
37
+ <div id="main" tabindex="-1">
38
+ <div id="header">
39
+ <div id="menu">
40
+
41
+ <a href="_index.html">Index</a> &raquo;
42
+ <span class="title">File: README</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link" href="class_list.html">
49
+
50
+ <svg width="24" height="24">
51
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
52
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
54
+ </svg>
55
+ </a>
56
+
57
+ </div>
58
+ <div class="clear"></div>
59
+ </div>
60
+
61
+ <div id="content">
62
+ <div id='filecontents'>
63
+ <h1 id="serviceclient">ServiceClient</h1>
64
+
65
+ <p>Welcome to your new gem! In this directory, you’ll find the files you need to be able to package up your Ruby
66
+ library into a gem. Put your Ruby code in the file <code>lib/service_client</code>. To experiment with that
67
+ code, run <code>bin/console</code> for an interactive prompt.</p>
68
+
69
+ <h2 id="installation">Installation</h2>
70
+
71
+ <p>Add this line to your application’s Gemfile:</p>
72
+
73
+ <p><code>ruby
74
+ gem 'service_client'
75
+ </code></p>
76
+
77
+ <p>And then execute:</p>
78
+
79
+ <p><code>bash
80
+ bundle install
81
+ </code></p>
82
+
83
+ <p>Or install it yourself as:</p>
84
+
85
+ <p><code>bash
86
+ gem install service_client
87
+ </code></p>
88
+
89
+ <h2 id="usage">Usage</h2>
90
+
91
+ <p>Basic usage example:</p>
92
+
93
+ <pre>
94
+ class CustomerClient < ServiceClient::Base
95
+ def find(id)
96
+ response = get(“https://api.com/customers/#id”)
97
+
98
+ response.data
99
+ rescue ServiceClient::Errors::NoDataFoundError => e
100
+ puts e.response.code # 404
101
+ puts e.response.headers
102
+ puts e.response.data
103
+ rescue ServiceClient::Errors::InternalServerError => e
104
+ puts e.response.code # 500
105
+ puts e.response.headers
106
+ puts e.response.data
107
+ # All errors of HTTP status code
108
+ end
109
+
110
+ def all
111
+ get(nil)
112
+ rescue ServiceClient::ParamsRequired => e
113
+ puts e.message
114
+ end
115
+ </pre>
116
+
117
+ <h2 id="methods-of-class">Methods of class</h2>
118
+
119
+ <h1 id="get">GET</h1>
120
+ <code>
121
+ ServiceClient::Base.get(url, headers:)
122
+ </code>
123
+
124
+ <h1 id="post">POST</h1>
125
+ <code>
126
+ ServiceClient::Base.post(url, headers:, body:)
127
+ </code>
128
+
129
+ <h1 id="put">PUT</h1>
130
+ <code>
131
+ ServiceClient::Base.put(url, headers:, body:)
132
+ </code>
133
+
134
+ <h1 id="delete">DELETE</h1>
135
+ <code>
136
+ ServiceClient::Base.delete(url, headers:, body:)
137
+ </code>
138
+
139
+ <h2 id="classes-of-errors">Classes of errors</h2>
140
+
141
+ <pre>
142
+ # 400 – Bad Request
143
+ ServiceClient::Errors::BadRequestError
144
+ # 401 – Unauthorized
145
+ ServiceClient::Errors::UnauthorizedError
146
+ # 402 – Payment Required
147
+ ServiceClient::Errors::PaymentRequiredError
148
+ # 403 – Forbidden
149
+ ServiceClient::Errors::ForbiddenError
150
+ # 404 – Not Found
151
+ ServiceClient::Errors::NotFoundError
152
+ # 405 – Method Not Allowed
153
+ ServiceClient::Errors::MethodNotAllowedError
154
+ # 406 – Not Acceptable
155
+ ServiceClient::Errors::NotAcceptableError
156
+ # 407 – Proxy Authentication Required
157
+ ServiceClient::Errors::ProxyAuthenticationRequiredError
158
+ # 408 – Request Timeout
159
+ ServiceClient::Errors::RequestTimeoutError
160
+ # 409 – Conflict
161
+ ServiceClient::Errors::ConflictError
162
+ # 410 – Gone
163
+ ServiceClient::Errors::GoneError
164
+ # 411 – Length Required
165
+ ServiceClient::Errors::LengthRequiredError
166
+ # 412 – Precondition Failed
167
+ ServiceClient::Errors::PreconditionFailedError
168
+ # 413 – Request Entity Too Large
169
+ ServiceClient::Errors::RequestEntityTooLargeError
170
+ # 414 – Request-URI Too Long
171
+ ServiceClient::Errors::RequestURITooLongError
172
+ # 415 – Unsupported Media Type
173
+ ServiceClient::Errors::UnsupportedMediaTypeError
174
+ # 416 – Requested Range Not Satisfiable
175
+ ServiceClient::Errors::RequestedRangeNotSatisfiableError
176
+ # 417 – Expectation Failed
177
+ ServiceClient::Errors::ExpectationFailedError
178
+ # 420 – Enhance Your Calm
179
+ ServiceClient::Errors::EnhanceYourCalmError
180
+ # 422 – Unprocessable Entity
181
+ ServiceClient::Errors::UnprocessableEntityError
182
+ # 423 – Locked
183
+ ServiceClient::Errors::LockedError
184
+ # 424 – Failed Dependency
185
+ ServiceClient::Errors::FailedDependencyError
186
+ # 426 – Upgrade Required
187
+ ServiceClient::Errors::UpgradeRequiredError
188
+ # 428 – Precondition Required
189
+ ServiceClient::Errors::PreconditionRequiredError
190
+ # 429 – Too Many Requests
191
+ ServiceClient::Errors::TooManyRequestsError
192
+ # 431 – Request Header Fields Too Large
193
+ ServiceClient::Errors::RequestHeaderFieldsTooLargeError
194
+ # 444 – No Response
195
+ ServiceClient::Errors::NoResponseError
196
+ # 449 – Retry With
197
+ ServiceClient::Errors::RetryWithError
198
+ # 450 – Bllocked by Windows Parental Controls
199
+ ServiceClient::Errors::BlockedByWindowsParentalControlsError
200
+ # 451 – Unavailable For Legal Reasons
201
+ ServiceClient::Errors::UnavailableForLegalReasonsError
202
+ # 499 – Client Closed Request
203
+ ServiceClient::Errors::ClientClosedRequestError
204
+ # 500 – Internal Server Error
205
+ ServiceClient::Errors::InternalServerError
206
+ # 501 – Not Implemented
207
+ ServiceClient::Errors::NotImplementedError
208
+ # 502 – Bad Gateway
209
+ ServiceClient::Errors::BadGatewayError
210
+ # 503 – Service Unavailable
211
+ ServiceClient::Errors::ServiceUnavailableError
212
+ # 504 – Gateway Timeout
213
+ ServiceClient::Errors::GatewayTimeoutError
214
+ # 505 – HTTP Version Not Supported
215
+ ServiceClient::Errors::HTTPVersionNotSupportedError
216
+ # 506 – Variant Also Negotiates
217
+ ServiceClient::Errors::VariantAlsoNegotiatesError
218
+ # 507 – Insufficient Storage
219
+ ServiceClient::Errors::InsufficientStorageError
220
+ # 508 – Loop Detected
221
+ ServiceClient::Errors::LoopDetectedError
222
+ # 510 – Not Extended
223
+ ServiceClient::Errors::NotExtendedError
224
+ # 511 – Network Authentication Required
225
+ ServiceClient::Errors::NetworkAuthenticationRequiredError
226
+ # 598 – Network Read Timeout Error
227
+ ServiceClient::Errors::NetworkReadTimeoutError
228
+ # 599 – Network Connect Timeout Error
229
+ ServiceClient::Errors::NetworkConnectTimeoutError
230
+ </pre>
231
+
232
+
233
+ <h2 id="development">Development</h2>
234
+
235
+ <p>After checking out the repo, run <code>bin/setup</code> to install dependencies. Then, run
236
+ <code>rake spec</code> to run the tests. You can also run <code>bin/console</code> for an interactive prompt
237
+ that will allow you to experiment.
238
+ </p>
239
+
240
+ <p>To install this gem onto your local machine, run <code>bundle exec rake install</code>. To release a new
241
+ version, update the version number in <code>version.rb</code>, and then run
242
+ <code>bundle exec rake release</code>, which will create a git tag for the version, push git commits and tags,
243
+ and push the <code>.gem</code> file to <a href="https://rubygems.org">rubygems.org</a>.
244
+ </p>
245
+
246
+ <h2 id="contributing">Contributing</h2>
247
+
248
+ <p>Bug reports and pull requests are welcome on GitHub at https://github.com/nemuba/service_client.</p>
249
+
250
+ <h2 id="license">License</h2>
251
+
252
+ <p>The gem is available as open source under the terms of the <a href="https://opensource.org/licenses/MIT">MIT
253
+ License</a>.</p>
254
+ </div>
255
+ </div>
256
+
257
+ <div id="footer">
258
+ Generated on Wed Feb 22 21:05:55 2023 by
259
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
260
+ 0.9.28 (ruby-2.7.1).
261
+ </div>
262
+
263
+ </div>
264
+ </body>
265
+
266
+ </html>
@@ -4,17 +4,24 @@ require 'httparty'
4
4
  require_relative 'response'
5
5
 
6
6
  module ServiceClient
7
- # Base class
7
+ # ParamsRequired error
8
8
  class ParamsRequired < StandardError; end
9
-
10
- class Base
11
- # ParamsRequired error
12
9
 
10
+ # Base class
11
+ class Base
13
12
  class << self
13
+ def base_url(url = nil)
14
+ @base_url = url
15
+ end
16
+
17
+ def default_headers(headers = nil)
18
+ @default_headers = headers
19
+ end
20
+
14
21
  def post(url = nil, headers: nil, body: nil)
15
22
  raise_params_required(url: url, headers: headers, body: body)
16
23
 
17
- request = HTTParty.post(url, headers: headers, body: body)
24
+ request = HTTParty.post(build_url(url), headers: build_headers(headers), body: body)
18
25
 
19
26
  make_response(request)
20
27
  end
@@ -22,7 +29,7 @@ module ServiceClient
22
29
  def get(url = nil, headers: nil)
23
30
  raise_params_required(url: url)
24
31
 
25
- request = HTTParty.get(url, headers: headers)
32
+ request = HTTParty.get(build_url(url), headers: build_headers(headers))
26
33
 
27
34
  make_response(request)
28
35
  end
@@ -30,7 +37,7 @@ module ServiceClient
30
37
  def put(url = nil, headers: nil, body: nil)
31
38
  raise_params_required(url: url, body: body)
32
39
 
33
- request = HTTParty.put(url, headers: headers, body: body)
40
+ request = HTTParty.put(build_url(url), headers: build_headers(headers), body: body)
34
41
 
35
42
  make_response(request)
36
43
  end
@@ -38,7 +45,7 @@ module ServiceClient
38
45
  def delete(url = nil, headers: nil)
39
46
  raise_params_required(url: url)
40
47
 
41
- request = HTTParty.delete(url, headers: headers)
48
+ request = HTTParty.delete(build_url(url), headers: build_headers(headers))
42
49
 
43
50
  make_response(request)
44
51
  end
@@ -60,6 +67,23 @@ module ServiceClient
60
67
  def params_nil?(params)
61
68
  params.values.any?(&:nil?)
62
69
  end
70
+
71
+ def build_url(path)
72
+ base_url = instance_variable_get('@base_url')
73
+
74
+ return if base_url.nil? && path.nil?
75
+
76
+ [base_url, path].compact.join('/')
77
+ end
78
+
79
+ def build_headers(headers)
80
+ default_headers = instance_variable_get('@default_headers')
81
+ return default_headers if headers.nil?
82
+
83
+ return headers if default_headers.nil?
84
+
85
+ default_headers.merge(headers)
86
+ end
63
87
  end
64
88
  end
65
89
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ServiceClient
4
- VERSION = "0.1.2".freeze
4
+ VERSION = '0.1.4'
5
5
  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.2
4
+ version: 0.1.4
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-22 00:00:00.000000000 Z
11
+ date: 2023-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -43,7 +43,8 @@ email:
43
43
  - alef.oliveira@dimensa.com.br
44
44
  executables: []
45
45
  extensions: []
46
- extra_rdoc_files: []
46
+ extra_rdoc_files:
47
+ - doc/index.html
47
48
  files:
48
49
  - Gemfile
49
50
  - Gemfile.lock
@@ -53,6 +54,7 @@ files:
53
54
  - Rakefile
54
55
  - bin/console
55
56
  - bin/setup
57
+ - doc/index.html
56
58
  - lib/service_client.rb
57
59
  - lib/service_client/base.rb
58
60
  - lib/service_client/errors.rb
@@ -73,14 +75,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
75
  requirements:
74
76
  - - ">="
75
77
  - !ruby/object:Gem::Version
76
- version: 2.3.0
78
+ version: 2.7.1
77
79
  required_rubygems_version: !ruby/object:Gem::Requirement
78
80
  requirements:
79
81
  - - ">="
80
82
  - !ruby/object:Gem::Version
81
83
  version: '0'
82
84
  requirements: []
83
- rubygems_version: 3.1.2
85
+ rubygems_version: 3.4.7
84
86
  signing_key:
85
87
  specification_version: 4
86
88
  summary: Service client