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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb8cb470284651d4be7b3eebab9557a4ecbe78c3
4
- data.tar.gz: d3fa11c7f03a0b967cbe18705824fe7400137ddd
3
+ metadata.gz: acc28ff8a522e13127ae5033b259e2fefa7ae111
4
+ data.tar.gz: eaccf0d6dbdc82b77b05f54f87566eb9ba907f15
5
5
  SHA512:
6
- metadata.gz: fb120c9d48dfdcd1f5b580fc0441173b4defc94ead5de463a290bd1390e8b6943deff2efef46c1b48a23338d547597491aef63df5c855ef5691a326b9f0a5540
7
- data.tar.gz: 64e52aa458076f81cc5e1dbe135bcdce190cedc5a2398ca6d5578c4990fa496f60c07f52e9075b7e6e45859df66cb00949cf47fc5fc046ab68301621b9d4f34f
6
+ metadata.gz: 53f62ccb2411888f918fab08d4bcf27655f9496edb076749462835f10898766cd7623c623e96836d610c5cb2803dc984b3b6e306b6e4be4fc0e6835f3c92df86
7
+ data.tar.gz: 11fead07b4ddd85dcb7a169ef0aee8052b49c50171da304b57c53c1574ae10a8c5b5f26499919dc4ee8fb668d5a14c8a755945d01bf752715c52b350ac224ab9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rest_api_client (0.1.0)
4
+ rest_api_client (0.2.0)
5
5
  activesupport (>= 4.2)
6
6
  faraday (~> 0.15.3)
7
7
  faraday_middleware (~> 0.13.1)
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # VendorApiClient
2
2
 
3
- A client to subclass from, this gem implements the common HTTP verbs using Faraday to help reduce boiler plates.
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
 
@@ -4,7 +4,5 @@ require 'rest_api_client/client'
4
4
  Dir['./rest_api_client'].each { |f| puts f }
5
5
 
6
6
  module RestApiClient
7
- def self.client(options = {})
8
- Client.new(options)
9
- end
7
+
10
8
  end
@@ -1,6 +1,6 @@
1
1
  require 'faraday'
2
2
  require 'faraday_middleware'
3
- require 'active_support/core_ext/object/blank.rb'
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
- module Request
2
+ module Request
3
3
 
4
- [:get, :post, :put, :delete].each do |method|
5
- define_method(method) do |path, body: {}, params: {}, opts: {}|
6
- request(method, path, body, params, opts)
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
- 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)
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
@@ -1,3 +1,3 @@
1
1
  module RestApiClient
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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{Subclass this client and jump into the real work of creating your awesome app straight away without worrying the nitty-gritties of HTTP call implementation.}
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.1.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-14 00:00:00.000000000 Z
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: Subclass this client and jump into the real work of creating your awesome
112
- app straight away without worrying the nitty-gritties of HTTP call implementation.
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: []