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
- #start_session(&block) ⇒ Object
Constructor Details
#initialize(account_url, auth_token, request_headers = {}) ⇒ Connection
Returns a new instance of Connection.
19 20 21 22 23 24 25 26 27 |
# 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 @start_session_count = 0 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
29 30 31 32 33 |
# File 'lib/freshbooks/connection.rb', line 29 def call_api(method, elements = []) request = create_request(method, elements) result = post(request) Response.new(result) end |
#logger ⇒ Object
10 11 12 |
# File 'lib/freshbooks/connection.rb', line 10 def logger @@logger end |
#start_session(&block) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/freshbooks/connection.rb', line 35 def start_session(&block) @connection = obtain_connection if @start_session_count == 0 @start_session_count = @start_session_count + 1 begin block.call(@connection) ensure @start_session_count = @start_session_count - 1 close if @start_session_count == 0 end end |