Class: Xeroizer::PartnerApplication

Inherits:
GenericApplication show all
Extended by:
Forwardable
Defined in:
lib/xeroizer/partner_application.rb

Constant Summary

Constants included from Http

Http::ACCEPT_MIME_MAP

Instance Attribute Summary

Attributes inherited from GenericApplication

#client, #logger, #rate_limit_max_attempts, #rate_limit_sleep, #xero_url

Instance Method Summary collapse

Methods included from Record::ApplicationHelper

#record, #report

Methods included from Http

#http_get, #http_post, #http_put

Constructor Details

#initialize(consumer_key, consumer_secret, path_to_private_key, path_to_ssl_client_cert, path_to_ssl_client_key, options = {}) ⇒ PartnerApplication

Partner applications allow for public AccessToken’s received via the stanard OAuth authentication process to be renewed up until the session’s expiry. The default session expiry for Xero is 365 days and the default AccessToken expiry is 30 minutes.

Parameters:

  • consumer_key (String)

    consumer key/token from application developer (found at api.xero.com for your application).

  • consumer_secret (String)

    consumer secret from application developer (found at api.xero.com for your application).

  • path_to_private_key (String)

    application’s private key for message signing (uploaded to api.xero.com)

  • path_to_ssl_client_cert (String)

    client-side SSL certificate file to use for requests

  • path_to_ssl_client_key (String)

    client-side SSL private key to use for requests

  • options (Hash) (defaults to: {})

    other options to pass to the GenericApplication constructor



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/xeroizer/partner_application.rb', line 20

def initialize(consumer_key, consumer_secret, path_to_private_key, path_to_ssl_client_cert, path_to_ssl_client_key, options = {})
  default_options = {
    :xero_url         => 'https://api-partner.network.xero.com/api.xro/2.0',
    :site             => 'https://api-partner.network.xero.com',
    :authorize_url    => 'https://api.xero.com/oauth/Authorize',      
    :signature_method => 'RSA-SHA1'
  }
  options = default_options.merge(options).merge(
    :private_key_file => path_to_private_key,
    :ssl_client_cert  => OpenSSL::X509::Certificate.new(File.read(path_to_ssl_client_cert)),
    :ssl_client_key   => OpenSSL::PKey::RSA.new(File.read(path_to_ssl_client_key))
  )
  super(consumer_key, consumer_secret, options)
  
  # Load up an existing token if passed the token/key.
  if options[:access_token] && options[:access_key]
    authorize_from_access(options[:access_token], options[:access_key])
  end
  
  # Save the session_handle if passed in so we can renew the token.
  if options[:session_handle]
    client.session_handle = options[:session_handle]
  end
end