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
self.logger_name = 'Error' # define error name in log dir
self.debug = true # debug
end
res = A.get('/api/xxx', key_1: value_1, key_2: value_2) # => { response: json_response }
res.code # => 200
res. # => { 'key' => 'value' }
res.headers # => {:content_type=>"text/html; charset=utf-8", :cache_control=>"private" ...
res = A.post('/api/xxx', key_1: value_1, key_2: value_2)
res = A.patch('/api/xxx', key_1: value_1, key_2: value_2)
write_log(res) # => [2014-08-19T22:10:29.438 INFO (32890)] res..
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