Class: Mambu::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/mambu/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password, tenant) ⇒ Connection

Returns a new instance of Connection.



3
4
5
6
7
8
# File 'lib/mambu/connection.rb', line 3

def initialize(username, password, tenant)
  @username = username
  @password = password
  @tenant = tenant
  fail Mambu::Error, 'Insufficient credentials' unless valid?
end

Instance Method Details

#api_urlObject



28
29
30
# File 'lib/mambu/connection.rb', line 28

def api_url
  "https://#{@tenant}.mambu.com/api"
end

#connectionObject



22
23
24
25
26
# File 'lib/mambu/connection.rb', line 22

def connection
  conn = Faraday.new
  conn.basic_auth(@username, @password)
  conn
end

#get(url, options = {}) ⇒ Object



10
11
12
# File 'lib/mambu/connection.rb', line 10

def get(url, options = {})
  request(:get, url, options)
end

#loan_product(id) ⇒ Object



36
37
38
# File 'lib/mambu/connection.rb', line 36

def loan_product(id)
  Mambu::LoanProduct.find(id, self)
end

#loan_productsObject



40
41
42
# File 'lib/mambu/connection.rb', line 40

def loan_products
  Mambu::LoanProduct.find_all(self)
end

#post(url, options = {}) ⇒ Object



14
15
16
# File 'lib/mambu/connection.rb', line 14

def post(url, options = {})
  request(:post, url, options)
end

#request(method, url, options) ⇒ Object



18
19
20
# File 'lib/mambu/connection.rb', line 18

def request(method, url, options)
  Mambu::Response.new(connection.send(method, url, options))
end

#valid?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/mambu/connection.rb', line 32

def valid?
  @username.present? && @password.present? && @tenant.present?
end