rest_api_client 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -1
- data/lib/rest_api_client.rb +1 -3
- data/lib/rest_api_client/client.rb +1 -2
- data/lib/rest_api_client/configuration.rb +14 -1
- data/lib/rest_api_client/request.rb +16 -16
- data/lib/rest_api_client/version.rb +1 -1
- data/rest_api_client.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: acc28ff8a522e13127ae5033b259e2fefa7ae111
|
4
|
+
data.tar.gz: eaccf0d6dbdc82b77b05f54f87566eb9ba907f15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53f62ccb2411888f918fab08d4bcf27655f9496edb076749462835f10898766cd7623c623e96836d610c5cb2803dc984b3b6e306b6e4be4fc0e6835f3c92df86
|
7
|
+
data.tar.gz: 11fead07b4ddd85dcb7a169ef0aee8052b49c50171da304b57c53c1574ae10a8c5b5f26499919dc4ee8fb668d5a14c8a755945d01bf752715c52b350ac224ab9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# VendorApiClient
|
2
2
|
|
3
|
-
A
|
3
|
+
A base class implemented with Faraday, this gem provides some of the common features typically needed in a REST api client.
|
4
|
+
|
5
|
+
It only handles JSON requests/payloads.
|
6
|
+
|
7
|
+
It is not meant to be a flexible HTTP client library. Use it if the defaults work for you. Otherwise it might be better to use something like Faraday directly.
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
data/lib/rest_api_client.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'faraday_middleware'
|
3
|
-
require 'active_support/core_ext/object/blank
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
4
|
require_relative 'request'
|
5
5
|
require_relative 'configuration'
|
6
6
|
require_relative 'response'
|
@@ -19,7 +19,6 @@ module RestApiClient
|
|
19
19
|
middleware_config = block_given? ? block : default_middleware_config
|
20
20
|
@connection = Faraday.new(@options, &middleware_config)
|
21
21
|
end
|
22
|
-
|
23
22
|
end
|
24
23
|
|
25
24
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
1
3
|
module RestApiClient
|
2
4
|
module Configuration
|
3
5
|
|
@@ -7,7 +9,7 @@ module RestApiClient
|
|
7
9
|
{
|
8
10
|
url: url
|
9
11
|
}
|
10
|
-
end
|
12
|
+
end
|
11
13
|
|
12
14
|
def default_middleware_config
|
13
15
|
lambda {|faraday|
|
@@ -15,10 +17,21 @@ module RestApiClient
|
|
15
17
|
faraday.request :url_encoded
|
16
18
|
faraday.headers[:Accept] = 'application/json'
|
17
19
|
faraday.headers['Content-Type'] = 'application/json'
|
20
|
+
faraday.response :logger, logger
|
18
21
|
#faraday.options[:timeout] = 300
|
19
22
|
faraday.adapter Faraday.default_adapter
|
20
23
|
}
|
21
24
|
end
|
22
25
|
|
26
|
+
def logger
|
27
|
+
log_output = $stdout
|
28
|
+
if defined? Rails
|
29
|
+
log_out = 'logs/api_logs.txt' unless Rails.env.development?
|
30
|
+
end
|
31
|
+
logger = Logger.new log_output
|
32
|
+
logger.level = Logger::INFO
|
33
|
+
logger
|
34
|
+
end
|
35
|
+
|
23
36
|
end
|
24
37
|
end
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module RestApiClient
|
2
|
-
|
2
|
+
module Request
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
4
|
+
[:get, :post, :put, :delete, :head].each do |method|
|
5
|
+
define_method(method) do |path, body: {}, params: {}, opts: {}|
|
6
|
+
request(method, path, body, params, opts)
|
8
7
|
end
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
10
|
+
def request(method, path, body, params, opts)
|
11
|
+
response = connection.send(method) do | request|
|
12
|
+
request.headers = request.headers.merge(opts[:headers]) if opts[:headers].present?
|
13
|
+
request.path = path
|
14
|
+
request.params = params if params.present?
|
15
|
+
request.body = body if body.present?
|
16
|
+
end
|
17
|
+
puts connection.params
|
18
|
+
response = Response.create(response)
|
21
19
|
end
|
20
|
+
|
21
|
+
end
|
22
22
|
end
|
data/rest_api_client.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["zorro.ej@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{A small client to reduce boilerplate code}
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{Start creating your awesome app straight away without worrying the nitty-gritties of HTTP call implementation.}
|
14
14
|
spec.homepage = "https://github.com/ej2015/rest_api_client"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Edgar
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -108,8 +108,8 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '1.3'
|
111
|
-
description:
|
112
|
-
|
111
|
+
description: Start creating your awesome app straight away without worrying the nitty-gritties
|
112
|
+
of HTTP call implementation.
|
113
113
|
email:
|
114
114
|
- zorro.ej@gmail.com
|
115
115
|
executables: []
|