Class: Xero::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/xero/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Connection

Returns a new instance of Connection.



6
7
8
9
10
11
12
13
# File 'lib/xero/connection.rb', line 6

def initialize(options = {})
  self.consumer_options = {
    site: 'https://api.xero.com',
    request_token_path: '/oauth/RequestToken',
    access_token_path: '/oauth/AccessToken',
    authorize_path: '/oauth/Authorize'
  }.reverse_merge(options)
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



4
5
6
# File 'lib/xero/connection.rb', line 4

def client
  @client
end

#consumer_optionsObject

Returns the value of attribute consumer_options.



4
5
6
# File 'lib/xero/connection.rb', line 4

def consumer_options
  @consumer_options
end

Instance Method Details

#access_tokenObject



22
23
24
25
26
27
# File 'lib/xero/connection.rb', line 22

def access_token
  @access_token ||= ::OAuth::AccessToken.new(
    consumer, Xero.configuration.consumer_key,
    Xero.configuration.consumer_secret
  )
end

#consumerObject



15
16
17
18
19
20
# File 'lib/xero/connection.rb', line 15

def consumer
  @consumer ||= ::OAuth::Consumer.new(
    Xero.configuration.consumer_key, Xero.configuration.consumer_secret,
    self.consumer_options
  )
end

#get(path, params = {}) ⇒ Object



33
34
35
36
# File 'lib/xero/connection.rb', line 33

def get(path, params = {})
  path = "#{path}?#{params.to_query}" unless params.blank?
  make_request(:get, path)
end

#get_by_id(path, id) ⇒ Object



29
30
31
# File 'lib/xero/connection.rb', line 29

def get_by_id(path, id)
  make_request(:get, "#{path}/#{id}")
end

#post(path, payload, params = {}) ⇒ Object



38
39
40
# File 'lib/xero/connection.rb', line 38

def post(path, payload, params = {})
  make_request(:post, path, { xml: payload })
end