Class: FundAmerica::API

Inherits:
Object
  • Object
show all
Defined in:
lib/fund_america/api.rb

Class Method Summary collapse

Class Method Details

.clear_dataObject

End point: sandbox.fundamerica.com/api/test_mode/clear_data (POST) Usage: FundAmerica::API.clear_data Output: Clears all test data created in sandbox mode Important: Sandbox mode only method



27
28
29
# File 'lib/fund_america/api.rb', line 27

def clear_data
  API::request(:post, 'https://sandbox.fundamerica.com/api/test_mode/clear_data')
end

.investor_suitabilitytokens(options) ⇒ Object

End point: apps.fundamerica.com/api/investorsuitabilitytokens (POST) Usage: FundAmerica::API.investor_suitabilitytokens(options)



33
34
35
# File 'lib/fund_america/api.rb', line 33

def investor_suitabilitytokens(options)
  API::request(:post, 'investorsuitabilitytokens', options)
end

.ledger_entry(ledger_entry_id) ⇒ Object

End point: apps.fundamerica.com/api/ledger_entries/:id (GET) Usage: FundAmerica::API.ledger_entry(ledger_entry_id)



39
40
41
# File 'lib/fund_america/api.rb', line 39

def ledger_entry(ledger_entry_id)
  API::request(:get, "ledger_entries/#{ledger_entry_id}")
end

.request(method, uri, options = {}) ⇒ Object

This method is called from each end point method to make API requests using HTTParty gem. Takes the method, uri and options as input Handles response and errors



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fund_america/api.rb', line 8

def request method, uri, options={}
  options = FundAmerica.basic_auth.merge!({:body => options})
  uri = FundAmerica.base_uri + uri unless uri.include?('test_mode')
  response = HTTParty.send(method, uri, options)
  parsed_response = JSON.parse(response.body)
  if response.code.to_i == 200
    # Returns parsed_response - a hash of response body
    # if response is successful
    parsed_response
  else
    # Raises error if the response is not sucessful
    raise FundAmerica::Error.new(parsed_response, response.code.to_i)
  end
end