RestclientApiBase
以 REST 方式调用外部 API 的基础类, 默认 Content-Type 为 JSON
Dependency
Installation
Add this line to your application's Gemfile:
gem 'restclient_api_base'
And then execute:
$ bundle
Or install it yourself as:
$ gem install restclient_api_base
Usage
require 'restclient_api_base'
module A
include RestclientApiBase
self.base_url = 'http://www.example.com' # define app base url
self.private_params = { key: 'api_key' } # define app secret key
end
A.get('/api/xxx', key_1: value_1, key_2: value_2) # => { response: json_response }
A.post('/api/xxx', key_1: value_1, key_2: value_2)
A.patch('/api/xxx', key_1: value_1, key_2: value_2)
Contributing
- Fork it ( https://github.com/Naixspirit/restclient_api_base/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request