Class: Mambu::Connection
- Inherits:
-
Object
- Object
- Mambu::Connection
- Defined in:
- lib/mambu/connection.rb
Instance Method Summary collapse
- #api_url ⇒ Object
- #connection ⇒ Object
- #get(url, options = {}) ⇒ Object
-
#initialize(username, password, tenant) ⇒ Connection
constructor
A new instance of Connection.
- #loan_product(id) ⇒ Object
- #loan_products ⇒ Object
- #post(url, options = {}) ⇒ Object
- #request(method, url, options) ⇒ Object
- #valid? ⇒ Boolean
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_url ⇒ Object
28 29 30 |
# File 'lib/mambu/connection.rb', line 28 def api_url "https://#{@tenant}.mambu.com/api" end |
#connection ⇒ Object
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, = {}) request(:get, url, ) 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_products ⇒ Object
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, = {}) request(:post, url, ) end |
#request(method, url, options) ⇒ Object
18 19 20 |
# File 'lib/mambu/connection.rb', line 18 def request(method, url, ) Mambu::Response.new(connection.send(method, url, )) end |
#valid? ⇒ Boolean
32 33 34 |
# File 'lib/mambu/connection.rb', line 32 def valid? @username.present? && @password.present? && @tenant.present? end |