Sha256: 6e5e8a8447f83d0dd5e7e01e80ec3022540b0d0db3c5f6f204832cb650472239

Contents?: true

Size: 1.7 KB

Versions: 7

Compression:

Stored size: 1.7 KB

Contents

module XeroGateway
  class PartnerApp < Gateway
    
    class CertificateRequired < StandardError; end
    
    NO_SSL_CLIENT_CERT_MESSAGE   = "You need to provide a client ssl certificate and key pair (these are the ones you got from Entrust and should not be password protected) as :ssl_client_cert and :ssl_client_key (should be .crt or .pem files)"
    NO_PRIVATE_KEY_ERROR_MESSAGE = "You need to provide your private key (corresponds to the public key you uploaded at api.xero.com) as :private_key_file (should be .crt or .pem files)"
    
    def_delegators :client, :session_handle, :renew_access_token, :authorization_expires_at
     
    def initialize(consumer_key, consumer_secret, options = {})
      
      raise CertificateRequired.new(NO_SSL_CLIENT_CERT_MESSAGE)   unless options[:ssl_client_cert]
      raise CertificateRequired.new(NO_SSL_CLIENT_CERT_MESSAGE)   unless options[:ssl_client_key]
      raise CertificateRequired.new(NO_PRIVATE_KEY_ERROR_MESSAGE) unless options[:private_key_file]
      
      options.merge!(
        :site             => "https://api-partner.network.xero.com",
        :authorize_url    => 'https://api.xero.com/oauth/Authorize', 
        :signature_method => 'RSA-SHA1',
        :ssl_client_cert  => OpenSSL::X509::Certificate.new(File.read(options[:ssl_client_cert])),
        :ssl_client_key   => OpenSSL::PKey::RSA.new(File.read(options[:ssl_client_key])),
        :private_key_file => options[:private_key_file]
      )
      
      @xero_url = options[:xero_url] || "https://api-partner.xero.com/api.xro/2.0"  
      @client   = OAuth.new(consumer_key, consumer_secret, options)
    end

    def set_session_handle(handle)
      client.session_handle = handle
    end
    
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
xero_gateway-2.3.0 lib/xero_gateway/partner_app.rb
xero_gateway-float-2.1.7 lib/xero_gateway/partner_app.rb
xero_gateway-float-2.1.6 lib/xero_gateway/partner_app.rb
xero_gateway-float-2.1.4 lib/xero_gateway/partner_app.rb
xero_gateway-float-2.1.3 lib/xero_gateway/partner_app.rb
xero_gateway-float-2.1.1 lib/xero_gateway/partner_app.rb
xero_gateway-2.1.0 lib/xero_gateway/partner_app.rb