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.
-
#utc_offset ⇒ Object
readonly
Returns the value of attribute utc_offset.
Class Method Summary collapse
Instance Method Summary collapse
- #call_api(method, elements = []) ⇒ Object
- #direct_post(xml) ⇒ Object
-
#initialize(account_url, auth_token, request_headers = {}, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #logger ⇒ Object
- #logger=(value) ⇒ Object
- #start_session(&block) ⇒ Object
Constructor Details
#initialize(account_url, auth_token, request_headers = {}, options = {}) ⇒ Connection
Returns a new instance of Connection.
23 24 25 26 27 28 29 30 31 |
# File 'lib/freshbooks/connection.rb', line 23 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 @utc_offset = [:utc_offset] || -4 @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 |
#utc_offset ⇒ Object (readonly)
Returns the value of attribute utc_offset.
7 8 9 |
# File 'lib/freshbooks/connection.rb', line 7 def utc_offset @utc_offset end |
Class Method Details
.log_level=(level) ⇒ Object
18 19 20 |
# File 'lib/freshbooks/connection.rb', line 18 def self.log_level=(level) @@logger.level = level end |
Instance Method Details
#call_api(method, elements = []) ⇒ Object
33 34 35 36 37 |
# File 'lib/freshbooks/connection.rb', line 33 def call_api(method, elements = []) request = create_request(method, elements) result = post(request) Response.new(result) end |
#direct_post(xml) ⇒ Object
39 40 41 42 |
# File 'lib/freshbooks/connection.rb', line 39 def direct_post(xml) result = post(xml) Response.new(result) end |
#logger ⇒ Object
10 11 12 |
# File 'lib/freshbooks/connection.rb', line 10 def logger @@logger end |
#logger=(value) ⇒ Object
14 15 16 |
# File 'lib/freshbooks/connection.rb', line 14 def logger=(value) @@logger = value end |
#start_session(&block) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/freshbooks/connection.rb', line 44 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 |