Class: FreshBooks::Connection
- Inherits:
-
Object
- Object
- FreshBooks::Connection
- Defined in:
- lib/freshbooks/connection.rb
Constant Summary collapse
- @@logger =
Logger.new(STDOUT)
Instance Attribute Summary collapse
-
#account_url ⇒ Object
readonly
Returns the value of attribute account_url.
-
#auth_token ⇒ Object
readonly
Returns the value of attribute auth_token.
-
#request_headers ⇒ Object
readonly
Returns the value of attribute request_headers.
Class Method Summary collapse
Instance Method Summary collapse
- #call_api(method, elements = []) ⇒ Object
-
#initialize(account_url, auth_token, request_headers = {}) ⇒ Connection
constructor
A new instance of Connection.
- #logger ⇒ Object
Constructor Details
#initialize(account_url, auth_token, request_headers = {}) ⇒ Connection
Returns a new instance of Connection.
19 20 21 22 23 24 25 |
# File 'lib/freshbooks/connection.rb', line 19 def initialize(account_url, auth_token, request_headers = {}) raise InvalidAccountUrlError.new unless account_url =~ /^[0-9a-zA-Z\-_]+\.freshbooks\.com$/ @account_url = account_url @auth_token = auth_token @request_headers = request_headers end |
Instance Attribute Details
#account_url ⇒ Object (readonly)
Returns the value of attribute account_url.
7 8 9 |
# File 'lib/freshbooks/connection.rb', line 7 def account_url @account_url end |
#auth_token ⇒ Object (readonly)
Returns the value of attribute auth_token.
7 8 9 |
# File 'lib/freshbooks/connection.rb', line 7 def auth_token @auth_token end |
#request_headers ⇒ Object (readonly)
Returns the value of attribute request_headers.
7 8 9 |
# File 'lib/freshbooks/connection.rb', line 7 def request_headers @request_headers end |
Class Method Details
.log_level=(level) ⇒ Object
14 15 16 |
# File 'lib/freshbooks/connection.rb', line 14 def self.log_level=(level) @@logger.level = level end |
Instance Method Details
#call_api(method, elements = []) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/freshbooks/connection.rb', line 27 def call_api(method, elements = []) # puts "#{self.class}#call_api: Creating a request with method: #{method} and elements: #{elements.inspect}" request = create_request(method, elements) # puts "#{self.class}#call_api: Sending request \"#{request}\"" self.logger.debug request result = post(request) # puts "#{self.class}#call_api: Received: \"#{result}\"" self.logger.debug result Response.new(result) end |
#logger ⇒ Object
10 11 12 |
# File 'lib/freshbooks/connection.rb', line 10 def logger @@logger end |