rest_api_client 0.1.0.pre → 0.1.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 +57 -0
- data/README.md +23 -2
- data/lib/rest_api_client/client.rb +12 -13
- data/lib/rest_api_client/configuration.rb +14 -9
- data/lib/rest_api_client/error.rb +7 -0
- data/lib/rest_api_client/request.rb +2 -3
- data/lib/rest_api_client/version.rb +1 -1
- data/lib/rest_api_client.rb +2 -0
- data/rest_api_client.gemspec +7 -1
- metadata +64 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb8cb470284651d4be7b3eebab9557a4ecbe78c3
|
4
|
+
data.tar.gz: d3fa11c7f03a0b967cbe18705824fe7400137ddd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb120c9d48dfdcd1f5b580fc0441173b4defc94ead5de463a290bd1390e8b6943deff2efef46c1b48a23338d547597491aef63df5c855ef5691a326b9f0a5540
|
7
|
+
data.tar.gz: 64e52aa458076f81cc5e1dbe135bcdce190cedc5a2398ca6d5578c4990fa496f60c07f52e9075b7e6e45859df66cb00949cf47fc5fc046ab68301621b9d4f34f
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rest_api_client (0.1.0)
|
5
|
+
activesupport (>= 4.2)
|
6
|
+
faraday (~> 0.15.3)
|
7
|
+
faraday_middleware (~> 0.13.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (5.2.3)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 0.7, < 2)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
concurrent-ruby (1.1.5)
|
18
|
+
diff-lcs (1.3)
|
19
|
+
fakeweb (1.3.0)
|
20
|
+
faraday (0.15.4)
|
21
|
+
multipart-post (>= 1.2, < 3)
|
22
|
+
faraday_middleware (0.13.1)
|
23
|
+
faraday (>= 0.7.4, < 1.0)
|
24
|
+
i18n (1.6.0)
|
25
|
+
concurrent-ruby (~> 1.0)
|
26
|
+
minitest (5.11.3)
|
27
|
+
multipart-post (2.1.1)
|
28
|
+
rake (10.5.0)
|
29
|
+
rspec (3.8.0)
|
30
|
+
rspec-core (~> 3.8.0)
|
31
|
+
rspec-expectations (~> 3.8.0)
|
32
|
+
rspec-mocks (~> 3.8.0)
|
33
|
+
rspec-core (3.8.0)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-expectations (3.8.2)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.8.0)
|
38
|
+
rspec-mocks (3.8.0)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.8.0)
|
41
|
+
rspec-support (3.8.0)
|
42
|
+
thread_safe (0.3.6)
|
43
|
+
tzinfo (1.2.5)
|
44
|
+
thread_safe (~> 0.1)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
bundler (~> 2.0)
|
51
|
+
fakeweb (~> 1.3)
|
52
|
+
rake (~> 10.0)
|
53
|
+
rest_api_client!
|
54
|
+
rspec (~> 3.0)
|
55
|
+
|
56
|
+
BUNDLED WITH
|
57
|
+
2.0.1
|
data/README.md
CHANGED
@@ -20,13 +20,34 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
Create your own client by subclassing RrestApiClient.
|
23
|
+
Create your own client by subclassing RrestApiClient. Provide your host url in the initializer.
|
24
24
|
|
25
25
|
```
|
26
|
-
|
26
|
+
class Client < RestApiClient::Client
|
27
|
+
def initialize(options = {}, &block)
|
28
|
+
@url = 'http://my.site.com'
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def friends(queries)
|
33
|
+
get('/friends', params: queries)
|
34
|
+
end
|
35
|
+
|
36
|
+
## you code here...
|
37
|
+
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
Then you can use the HTTP verbs like this:
|
42
|
+
|
43
|
+
```
|
44
|
+
Client.new.friends({ gender: 'm' })
|
45
|
+
|
46
|
+
##== curl http://my.site.com/friends?gender=m
|
27
47
|
|
28
48
|
```
|
29
49
|
|
50
|
+
By default it sends and receives JSON. You can override it by passing in a block. See [Faraday configurations](https://github.com/lostisland/faraday) for details
|
30
51
|
## Development
|
31
52
|
|
32
53
|
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.
|
@@ -1,26 +1,25 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'active_support/core_ext/object/blank.rb'
|
4
|
+
require_relative 'request'
|
5
|
+
require_relative 'configuration'
|
6
|
+
require_relative 'response'
|
7
|
+
require_relative 'error'
|
8
|
+
|
1
9
|
module RestApiClient
|
2
10
|
class Client
|
3
11
|
include RestApiClient::Request
|
4
12
|
include RestApiClient::Response
|
5
13
|
include RestApiClient::Configuration
|
6
14
|
|
7
|
-
class << self
|
8
|
-
attr_accessor :url
|
9
|
-
end
|
10
|
-
|
11
15
|
attr_accessor :options, :connection
|
12
16
|
|
13
|
-
def initialize (options = {})
|
17
|
+
def initialize (options = {}, &block)
|
14
18
|
@options = default_options.merge(options)
|
15
|
-
|
16
|
-
|
17
|
-
faraday.request :url_encoded
|
18
|
-
faraday.headers[:Accept] = 'application/json'
|
19
|
-
faraday.headers['Content-Type'] = 'application/json'
|
20
|
-
#faraday.options[:timeout] = 300
|
21
|
-
faraday.adapter Faraday.default_adapter
|
22
|
-
end
|
19
|
+
middleware_config = block_given? ? block : default_middleware_config
|
20
|
+
@connection = Faraday.new(@options, &middleware_config)
|
23
21
|
end
|
22
|
+
|
24
23
|
end
|
25
24
|
|
26
25
|
end
|
@@ -1,19 +1,24 @@
|
|
1
1
|
module RestApiClient
|
2
2
|
module Configuration
|
3
|
-
URL =INSURER_CONFIG["vendor"]["url"].freeze
|
4
3
|
|
5
|
-
|
6
|
-
URL
|
7
|
-
end
|
8
|
-
|
9
|
-
def url
|
10
|
-
self.class.url || default_url
|
11
|
-
end
|
4
|
+
attr_accessor :url
|
12
5
|
|
13
6
|
def default_options
|
14
|
-
{
|
7
|
+
{
|
8
|
+
url: url
|
15
9
|
}
|
16
10
|
end
|
17
11
|
|
12
|
+
def default_middleware_config
|
13
|
+
lambda {|faraday|
|
14
|
+
faraday.request :json
|
15
|
+
faraday.request :url_encoded
|
16
|
+
faraday.headers[:Accept] = 'application/json'
|
17
|
+
faraday.headers['Content-Type'] = 'application/json'
|
18
|
+
#faraday.options[:timeout] = 300
|
19
|
+
faraday.adapter Faraday.default_adapter
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
18
23
|
end
|
19
24
|
end
|
@@ -10,13 +10,12 @@ module RestApiClient
|
|
10
10
|
def request(method, path, body, params, opts)
|
11
11
|
response = connection.send(method) do | request|
|
12
12
|
request.headers = request.headers.merge(opts[:headers]) if opts[:headers].present?
|
13
|
-
request.path =
|
13
|
+
request.path = path
|
14
14
|
request.params = params if params.present?
|
15
15
|
request.body = body if body.present?
|
16
16
|
end
|
17
|
+
puts connection.params
|
17
18
|
response = Response.create(response)
|
18
|
-
rescue Exception => e
|
19
|
-
#handle exception
|
20
19
|
end
|
21
20
|
|
22
21
|
end
|
data/lib/rest_api_client.rb
CHANGED
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{Subclass this client and jump into your
|
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.}
|
14
14
|
spec.homepage = "https://github.com/ej2015/rest_api_client"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -24,7 +24,13 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
|
+
spec.add_dependency "faraday", "~> 0.15.3"
|
28
|
+
spec.add_dependency "faraday_middleware", "~> 0.13.1"
|
29
|
+
spec.add_dependency "activesupport", ">=4.2"
|
30
|
+
|
27
31
|
spec.add_development_dependency "bundler", "~> 2.0"
|
28
32
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
33
|
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency "fakeweb", "~> 1.3"
|
35
|
+
|
30
36
|
end
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
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.1.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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.15.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.15.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.13.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.13.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.2'
|
13
55
|
- !ruby/object:Gem::Dependency
|
14
56
|
name: bundler
|
15
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,8 +94,22 @@ dependencies:
|
|
52
94
|
- - "~>"
|
53
95
|
- !ruby/object:Gem::Version
|
54
96
|
version: '3.0'
|
55
|
-
|
56
|
-
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fakeweb
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
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.
|
57
113
|
email:
|
58
114
|
- zorro.ej@gmail.com
|
59
115
|
executables: []
|
@@ -64,6 +120,7 @@ files:
|
|
64
120
|
- ".rspec"
|
65
121
|
- ".travis.yml"
|
66
122
|
- Gemfile
|
123
|
+
- Gemfile.lock
|
67
124
|
- LICENSE.txt
|
68
125
|
- README.md
|
69
126
|
- Rakefile
|
@@ -72,6 +129,7 @@ files:
|
|
72
129
|
- lib/rest_api_client.rb
|
73
130
|
- lib/rest_api_client/client.rb
|
74
131
|
- lib/rest_api_client/configuration.rb
|
132
|
+
- lib/rest_api_client/error.rb
|
75
133
|
- lib/rest_api_client/request.rb
|
76
134
|
- lib/rest_api_client/response.rb
|
77
135
|
- lib/rest_api_client/version.rb
|
@@ -91,9 +149,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
91
149
|
version: '0'
|
92
150
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
151
|
requirements:
|
94
|
-
- - "
|
152
|
+
- - ">="
|
95
153
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
154
|
+
version: '0'
|
97
155
|
requirements: []
|
98
156
|
rubyforge_project:
|
99
157
|
rubygems_version: 2.6.14
|