RestclientApiBase

以 REST 方式调用外部 API 的基础类, 默认 Content-Type 为 JSON

Dependency

active_support/concern

rest-client

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

  1. Fork it ( https://github.com/Naixspirit/restclient_api_base/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request