Class: IfaxappApi::Fax

Inherits:
Object
  • Object
show all
Defined in:
lib/ifaxapp_api/fax.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Fax

Returns a new instance of Fax.



7
8
9
# File 'lib/ifaxapp_api/fax.rb', line 7

def initialize(client)
  @client = client
end

Instance Method Details

#default_headersObject



61
62
63
64
65
66
# File 'lib/ifaxapp_api/fax.rb', line 61

def default_headers
  {
    'Content-Type' => 'application/json',
    'Accept' => 'application/json'
  }
end

#resend(params: {}, url: 'fax-resend') ⇒ Object

Resend Fax Params

"jobId" : 12345



34
35
36
37
38
# File 'lib/ifaxapp_api/fax.rb', line 34

def resend(params: {}, url: 'fax-resend')
  url = API_URL + url
  headers = default_headers.merge('accessToken' => @client.api_key)
  send_request(url, params, headers)
end

#send(params: {}, url: 'fax-send') ⇒ Object

Send Params params = {

"faxNumber" : "+12345678901",
"faxData" : [{
      "fileName" : "abc.pdf",
      "fileUrl" : "HTTP url of file"
    },
    {
      "fileName" : "xyz.pdf",
      "fileUrl" : "HTTP url of file"
}]

}



23
24
25
26
27
# File 'lib/ifaxapp_api/fax.rb', line 23

def send(params: {}, url: 'fax-send')
  url = API_URL + url
  headers = default_headers.merge('accessToken' => @client.api_key)
  send_request(url, params, headers)
end

#send_request(url, data, headers, method = 'post') ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/ifaxapp_api/fax.rb', line 50

def send_request(url, data, headers, method = 'post')
  begin
    if method == 'post'
      response = RestClient.post(url, data.to_json, headers)
    end
  rescue RestClient::ExceptionWithResponse => e
    return { error: e.response.body }
  end
  response.body
end

#status(params: {}, url: 'fax-status') ⇒ Object

Fax Status Params

"jobId" : 12345



44
45
46
47
48
# File 'lib/ifaxapp_api/fax.rb', line 44

def status(params: {}, url: 'fax-status')
  url = API_URL + url
  headers = default_headers.merge('accessToken' => @client.api_key)
  send_request(url, params, headers)
end