Class: FaxplusApi::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/faxplus_api/base.rb

Direct Known Subclasses

Account, Fax, File, Number, Outbox, Webhook

Instance Method Summary collapse

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') ⇒ 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')
  begin
    response =  if method == 'post'
                  RestClient.post(url, data.to_json, headers)
                elsif method == 'put'
                  RestClient.put(url, data.to_json, headers)
                elsif method == 'get'
                  RestClient.get(url, headers)
                elsif method == 'delete'
                  RestClient.delete(url, headers)
                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