Class: InterFAX::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/interfax/client.rb

Defined Under Namespace

Classes: BadRequestError, NotFoundError, ServerError, UnauthorizedError

Constant Summary collapse

HOST =
"rest.interfax.net".freeze
USER_AGENT =
"InterFAX Ruby #{InterFAX::VERSION}".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/interfax/client.rb', line 18

def initialize(options = {})
  self.username = options.fetch(:username) do
    ENV['INTERFAX_USERNAME'] || raise(KeyError, "Missing required argument: username")
  end

  self.password = options.fetch(:password) do
    ENV['INTERFAX_PASSWORD'] || raise(KeyError, "Missing required argument: password")
  end

  self.host = options.fetch(:host) do
    ENV['INTERFAX_HOST'] || HOST
  end

  self.http = Net::HTTP.new(host, Net::HTTP.https_default_port)
  http.set_debug_output $stdout if options[:debug]
  http.use_ssl = true
end

Instance Attribute Details

#accountObject



36
37
38
# File 'lib/interfax/client.rb', line 36

def 
  @account ||= InterFAX::Account.new(self)
end

#documentsObject



52
53
54
# File 'lib/interfax/client.rb', line 52

def documents
  @documents ||= InterFAX::Documents.new(self)
end

#filesObject



56
57
58
# File 'lib/interfax/client.rb', line 56

def files
  @files ||= InterFAX::Files.new(self)
end

#hostObject

Returns the value of attribute host.



12
13
14
# File 'lib/interfax/client.rb', line 12

def host
  @host
end

#httpObject

Returns the value of attribute http.



12
13
14
# File 'lib/interfax/client.rb', line 12

def http
  @http
end

#inboundObject



48
49
50
# File 'lib/interfax/client.rb', line 48

def inbound
  @inbound ||= InterFAX::Inbound.new(self)
end

#outboundObject



44
45
46
# File 'lib/interfax/client.rb', line 44

def outbound
  @outbound ||= InterFAX::Outbound.new(self)
end

#passwordObject

Returns the value of attribute password.



12
13
14
# File 'lib/interfax/client.rb', line 12

def password
  @password
end

#usernameObject

Returns the value of attribute username.



12
13
14
# File 'lib/interfax/client.rb', line 12

def username
  @username
end

Instance Method Details

#delete(path) ⇒ Object



76
77
78
79
80
# File 'lib/interfax/client.rb', line 76

def delete path
  uri = uri_for(path)
  request = Net::HTTP::Delete.new(uri.request_uri)
  transmit(request)
end

#deliver(params = {}) ⇒ Object



40
41
42
# File 'lib/interfax/client.rb', line 40

def deliver params = {}
  outbound.deliver(params)
end

#get(path, params = {}, valid_keys = {}) ⇒ Object



60
61
62
63
64
# File 'lib/interfax/client.rb', line 60

def get path, params = {}, valid_keys = {}
  uri = uri_for(path, params, valid_keys)
  request = Net::HTTP::Get.new(uri.request_uri)
  transmit(request)
end

#post(path, params = {}, valid_keys = {}, headers = {}, body = nil) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/interfax/client.rb', line 66

def post path, params = {}, valid_keys = {}, headers = {}, body = nil
  uri = uri_for(path, params, valid_keys)
  request = Net::HTTP::Post.new(uri.request_uri)
  headers.each do |key, value|
    request[key] = value
  end
  request.body = body if body
  transmit(request)
end