Class: FaxplusApi::Base
- Inherits:
-
Object
- Object
- FaxplusApi::Base
- Defined in:
- lib/faxplus_api/base.rb
Instance Method Summary collapse
-
#initialize(client) ⇒ Base
constructor
A new instance of Base.
- #make_request(url:, data:, method: 'get', content_type: 'application/json') ⇒ Object
Constructor Details
#initialize(client) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 |
# File 'lib/faxplus_api/base.rb', line 6 def initialize(client) @client = client @access_token = client.access_token @base_url = client.base_url end |
Instance Method Details
#make_request(url:, data:, method: 'get', content_type: 'application/json') ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/faxplus_api/base.rb', line 12 def make_request(url:, data:, method: 'get', content_type: 'application/json') begin response = if method == 'post' RestClient.post(url, data, headers(content_type)) elsif method == 'put' RestClient.put(url, data, headers(content_type)) elsif method == 'get' RestClient.get(url, headers(content_type)) elsif method == 'delete' RestClient.delete(url, headers(content_type)) end rescue RestClient::ExceptionWithResponse => e return { error: e.response.body } end return response.body if response.body.nil? JSON.parse(response.body, symbolize_names: true) rescue response.body end |