api_client_base 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +166 -0
- data/Rakefile +6 -0
- data/api_client_base.gemspec +43 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/api_client_base/client/class_methods.rb +34 -0
- data/lib/api_client_base/client.rb +27 -0
- data/lib/api_client_base/request.rb +71 -0
- data/lib/api_client_base/response.rb +39 -0
- data/lib/api_client_base/version.rb +3 -0
- data/lib/api_client_base.rb +15 -0
- metadata +189 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a47670c0ba3b9854d0b1fe79fff7b6c507770b02
|
4
|
+
data.tar.gz: ddbab067dc66987450d9784f95fceba9c819a71b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 17c4e3977db0ee463d9606c84b43a68c82ad7b32fed463a05348c1d99a7f54f1ef6e38206611b83b238d2e517272c98fe75375f62d8bf52c0ba9cb5f0ace32b1
|
7
|
+
data.tar.gz: 5ceaf0fcd18fd69a6ff01a0f555ce4f22bf669b35ba55afcd2c2cdcbcaeaa9390739a9f370fc145160cf71327240be29bef83d28525fe8c383056bdbdbd599ab
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Change Log
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
5
|
+
and this project adheres to [Semantic Versioning](http://semver.org/).
|
6
|
+
|
7
|
+
## [Unreleased]
|
8
|
+
### Added
|
9
|
+
- Initial release
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ramon.tayag@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ramon Tayag
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
# APIClientBase
|
2
|
+
|
3
|
+
Abstractions to help author API wrappers in Ruby.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
- Add `api_client_base` as a dependency to your gem's gemspec.
|
8
|
+
- `require 'api_client_base'` in `lib/yourgem.rb`
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
This gem assumes your gem will follow a certain structure.
|
13
|
+
|
14
|
+
- Actions that your gem can perform are done through a class, like `APIWrapper::Client`.
|
15
|
+
- Each action has request and response classes.
|
16
|
+
- Request class takes care of appending the endpoint's path to the host, preparing params, and specifying the right http method to call
|
17
|
+
- Response class takes care of parsing the response and making the data easily accessible for consumption.
|
18
|
+
|
19
|
+
### Configuring the `Client`
|
20
|
+
|
21
|
+
#### Default Options
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
module MyGem
|
25
|
+
class Client
|
26
|
+
# specifying a symbol for `default_opts` will look for a method of that name
|
27
|
+
# and pass that into the request
|
28
|
+
HOST = "https://production.com"
|
29
|
+
include APIClientBase::Client.module(default_opts: :default_opts)
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def default_opts
|
34
|
+
{ host: HOST, secret: MyGem.configuration.secret }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Client
|
39
|
+
# You may also give a hash directly
|
40
|
+
HOST = "https://production.com"
|
41
|
+
include APIClientBase::Client.module(default_opts: {host: HOST})
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
#### Actions
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
module MyGem
|
50
|
+
class Client
|
51
|
+
include APIClientBase::Client.module(default_opts: :all_opts)
|
52
|
+
api_action :get_user
|
53
|
+
|
54
|
+
# `api_action` basically creates a method like:
|
55
|
+
# def get_user(opts={})
|
56
|
+
# request = GetUserRequest.new(all_opts.merge(opts))
|
57
|
+
# raw_response = request.()
|
58
|
+
# GetUserResponse.new(raw_response: raw_response)
|
59
|
+
# end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def all_opts
|
64
|
+
# At least include `host`. Other things you may need to include: `token`, `secret`
|
65
|
+
{ host: "http://prod.com" }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
- `api_action` accepts the method name, and optional hash of arguments. These may contain:
|
72
|
+
- `args`: if not defined, the args expected by the method is nothing, or a hash. If given, it must be an array of symbols. For example, if `args: [:id, :name]` is given, then the method defined is effectively: `def my_action(id, name)` but what is passed into the request object is still `{id: "id-value", name: "name-value"}`
|
73
|
+
|
74
|
+
You still need to create `MyGem::GetUserRequest` and `MyGem::GetUserResponse`. See the "requests" and "responses" section below.
|
75
|
+
|
76
|
+
#### Requests
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
module MyGem
|
80
|
+
class GetUserRequest
|
81
|
+
include APIClientBase::Request.module(
|
82
|
+
# you may define the action by `action: :post`. Defaults to `:get`.
|
83
|
+
# You may also opt to define `#default_action` (see below)
|
84
|
+
)
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def path
|
89
|
+
"/api/v1/users/#{self.user_id}"
|
90
|
+
end
|
91
|
+
|
92
|
+
# Following methods are optional. Override them if you need to send something specific
|
93
|
+
|
94
|
+
def headers
|
95
|
+
{"Content-Type" => "application/json"}
|
96
|
+
end
|
97
|
+
|
98
|
+
def body
|
99
|
+
{secret: "my-secret"}.to_json
|
100
|
+
end
|
101
|
+
|
102
|
+
def params
|
103
|
+
{my: "params"}
|
104
|
+
end
|
105
|
+
|
106
|
+
def default_action
|
107
|
+
:post # defaults to :get
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
#### Responses
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
module MyGem
|
117
|
+
class GetUserResponse
|
118
|
+
include APIClientBase::Response.module
|
119
|
+
# - has `#status` method that is delegated to `raw_response.status`
|
120
|
+
# - has `#code` method to get the response's code
|
121
|
+
# - has `#raw_response` which is a Typhoeus response object
|
122
|
+
|
123
|
+
# You're encouraged to use Virtus attributes to extract information cleanly
|
124
|
+
attribute :id, Integer, lazy: true, default: :default_id
|
125
|
+
attribute :name, String, lazy: true, default: :default_name
|
126
|
+
attribute :body, Object, lazy: true, default: :default_body
|
127
|
+
|
128
|
+
private
|
129
|
+
|
130
|
+
# Optional: define `#default_success` to determine what it means for
|
131
|
+
# the response to be successful. For example, the code might be 200
|
132
|
+
# but you consider it a failed call if there are no results
|
133
|
+
def default_success
|
134
|
+
code == 200 && !body[:users].empty?
|
135
|
+
end
|
136
|
+
|
137
|
+
def default_body
|
138
|
+
JSON.parse(raw_response.body).with_indifferent_access
|
139
|
+
end
|
140
|
+
|
141
|
+
def default_id
|
142
|
+
body[:id]
|
143
|
+
end
|
144
|
+
|
145
|
+
def default_name
|
146
|
+
body[:name]
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
```
|
151
|
+
|
152
|
+
You can an example gem at https://github.com/imacchiato/bridge_client-ruby.
|
153
|
+
|
154
|
+
## Development
|
155
|
+
|
156
|
+
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.
|
157
|
+
|
158
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
159
|
+
|
160
|
+
## Contributing
|
161
|
+
|
162
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/imacchiato/api_client-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
163
|
+
|
164
|
+
## License
|
165
|
+
|
166
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'api_client_base/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "api_client_base"
|
8
|
+
spec.version = APIClientBase::VERSION
|
9
|
+
spec.authors = ["Ramon Tayag"]
|
10
|
+
spec.email = ["ramon.tayag@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Abstractions to help author API wrappers in Ruby.}
|
13
|
+
spec.description = %q{Abstractions to help author API wrappers in Ruby.}
|
14
|
+
spec.homepage = "https://github.com/imacchiato/api_client-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "activesupport", ">= 3.0"
|
34
|
+
spec.add_dependency "virtus", ">= 1.0"
|
35
|
+
spec.add_dependency "typhoeus", ">= 1.0"
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
38
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
39
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
40
|
+
spec.add_development_dependency "virtus-matchers"
|
41
|
+
spec.add_development_dependency "vcr", "~> 3.0"
|
42
|
+
spec.add_development_dependency "webmock"
|
43
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "api_client_base"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module APIClientBase
|
2
|
+
module Client
|
3
|
+
module ClassMethods
|
4
|
+
|
5
|
+
def api_action(action_name, opts={})
|
6
|
+
define_method action_name do |args|
|
7
|
+
namespace = self.class.name.deconstantize.constantize
|
8
|
+
|
9
|
+
request_class_name = [action_name.to_s.classify, "Request"].join
|
10
|
+
request_class = namespace.const_get(request_class_name)
|
11
|
+
|
12
|
+
response_class_name = [action_name.to_s.classify, "Response"].join
|
13
|
+
response_class = namespace.const_get(response_class_name)
|
14
|
+
|
15
|
+
if opts[:args].is_a?(Array)
|
16
|
+
request_args = opts[:args].each_with_object({}).
|
17
|
+
with_index { |(arg, hash), i| hash[arg] = args[i] }
|
18
|
+
else
|
19
|
+
request_args = args
|
20
|
+
end
|
21
|
+
|
22
|
+
default_request_opts_method =
|
23
|
+
self.class.api_client_base_client_options[:default_opts]
|
24
|
+
default_request_opts = send(default_request_opts_method)
|
25
|
+
|
26
|
+
request = request_class.new(default_request_opts.merge(request_args))
|
27
|
+
raw_response = request.()
|
28
|
+
response_class.new(raw_response: raw_response)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module APIClientBase
|
2
|
+
module Client
|
3
|
+
|
4
|
+
def self.module(opts={})
|
5
|
+
mod = Module.new do
|
6
|
+
mattr_accessor :api_client_base_client_options
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.class_attribute :api_client_base_client_options
|
10
|
+
base.api_client_base_client_options = self.api_client_base_client_options
|
11
|
+
base.send :include, APIClientBase::Client
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
mod.api_client_base_client_options = opts
|
16
|
+
|
17
|
+
mod
|
18
|
+
end
|
19
|
+
|
20
|
+
extend ActiveSupport::Concern
|
21
|
+
|
22
|
+
included do
|
23
|
+
extend APIClientBase::Client::ClassMethods
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module APIClientBase
|
2
|
+
module Request
|
3
|
+
|
4
|
+
def self.module(opts={})
|
5
|
+
mod = Module.new do
|
6
|
+
mattr_accessor :api_client_base_request_options
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.class_attribute :api_client_base_request_options
|
10
|
+
base.api_client_base_request_options =
|
11
|
+
self.api_client_base_request_options
|
12
|
+
base.send :include, APIClientBase::Request
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
mod.api_client_base_request_options = opts
|
17
|
+
|
18
|
+
mod
|
19
|
+
end
|
20
|
+
|
21
|
+
extend ActiveSupport::Concern
|
22
|
+
|
23
|
+
included do
|
24
|
+
include Virtus.model
|
25
|
+
attribute :host, String
|
26
|
+
attribute :uri, String, lazy: true, default: :default_uri
|
27
|
+
attribute :action, Symbol, default: :default_action
|
28
|
+
attribute(:api_client_base_path, String, {
|
29
|
+
lazy: true,
|
30
|
+
default: :default_api_client_base_path,
|
31
|
+
})
|
32
|
+
end
|
33
|
+
|
34
|
+
def call
|
35
|
+
request = Typhoeus::Request.new(
|
36
|
+
uri,
|
37
|
+
method: action,
|
38
|
+
headers: headers,
|
39
|
+
body: body,
|
40
|
+
params: params,
|
41
|
+
)
|
42
|
+
|
43
|
+
request.run
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def headers ; {} ; end
|
49
|
+
def body ; nil ; end
|
50
|
+
def params ; {} ; end
|
51
|
+
|
52
|
+
def default_action
|
53
|
+
self.class.api_client_base_request_options[:action] || :get
|
54
|
+
end
|
55
|
+
|
56
|
+
def default_uri
|
57
|
+
uri = URI(host)
|
58
|
+
uri.path = api_client_base_path
|
59
|
+
uri.to_s
|
60
|
+
end
|
61
|
+
|
62
|
+
def default_api_client_base_path
|
63
|
+
path.scan(/:\w+/).reduce(path) do |new_path, var|
|
64
|
+
attribute_name = var.gsub(":", "")
|
65
|
+
value = self.send(attribute_name)
|
66
|
+
new_path.gsub(var, value.to_s)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module APIClientBase
|
2
|
+
module Response
|
3
|
+
|
4
|
+
def self.module(opts={})
|
5
|
+
mod = Module.new do
|
6
|
+
mattr_accessor :api_client_base_response_options
|
7
|
+
|
8
|
+
def self.included(base)
|
9
|
+
base.class_attribute :api_client_base_response_options
|
10
|
+
base.api_client_base_response_options =
|
11
|
+
self.api_client_base_response_options
|
12
|
+
base.send :include, APIClientBase::Response
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
mod.api_client_base_response_options = opts
|
17
|
+
|
18
|
+
mod
|
19
|
+
end
|
20
|
+
|
21
|
+
extend ActiveSupport::Concern
|
22
|
+
|
23
|
+
included do
|
24
|
+
include Virtus.model
|
25
|
+
attribute :raw_response, Object
|
26
|
+
attribute :success, self::Boolean, lazy: true, default: :default_success
|
27
|
+
attribute :code, Integer, lazy: true, default: :default_code
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_success
|
31
|
+
raw_response.success?
|
32
|
+
end
|
33
|
+
|
34
|
+
def default_code
|
35
|
+
raw_response.code
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
require "active_support/core_ext/class/attribute"
|
3
|
+
require "active_support/core_ext/module/attribute_accessors"
|
4
|
+
require "active_support/inflector"
|
5
|
+
require "typhoeus"
|
6
|
+
require "virtus"
|
7
|
+
require "api_client_base/version"
|
8
|
+
require "api_client_base/client"
|
9
|
+
require "api_client_base/client/class_methods"
|
10
|
+
require "api_client_base/request"
|
11
|
+
require "api_client_base/response"
|
12
|
+
|
13
|
+
module APIClientBase
|
14
|
+
# Your code goes here...
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: api_client_base
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ramon Tayag
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: virtus
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: typhoeus
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: virtus-matchers
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: vcr
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webmock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Abstractions to help author API wrappers in Ruby.
|
140
|
+
email:
|
141
|
+
- ramon.tayag@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- ".travis.yml"
|
149
|
+
- CHANGELOG.md
|
150
|
+
- CODE_OF_CONDUCT.md
|
151
|
+
- Gemfile
|
152
|
+
- LICENSE.txt
|
153
|
+
- README.md
|
154
|
+
- Rakefile
|
155
|
+
- api_client_base.gemspec
|
156
|
+
- bin/console
|
157
|
+
- bin/setup
|
158
|
+
- lib/api_client_base.rb
|
159
|
+
- lib/api_client_base/client.rb
|
160
|
+
- lib/api_client_base/client/class_methods.rb
|
161
|
+
- lib/api_client_base/request.rb
|
162
|
+
- lib/api_client_base/response.rb
|
163
|
+
- lib/api_client_base/version.rb
|
164
|
+
homepage: https://github.com/imacchiato/api_client-ruby
|
165
|
+
licenses:
|
166
|
+
- MIT
|
167
|
+
metadata:
|
168
|
+
allowed_push_host: https://rubygems.org
|
169
|
+
post_install_message:
|
170
|
+
rdoc_options: []
|
171
|
+
require_paths:
|
172
|
+
- lib
|
173
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '0'
|
178
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - ">="
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '0'
|
183
|
+
requirements: []
|
184
|
+
rubyforge_project:
|
185
|
+
rubygems_version: 2.5.1
|
186
|
+
signing_key:
|
187
|
+
specification_version: 4
|
188
|
+
summary: Abstractions to help author API wrappers in Ruby.
|
189
|
+
test_files: []
|