Sha256: b33ec69e78d2d331b17ef6ccdb7966986585ebdc2e21b9859ceb76d5e872221c

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

module XeroGateway
  class PartnerApp < Gateway

    class CertificateRequired < StandardError; end

    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_PRIVATE_KEY_ERROR_MESSAGE) unless options[:private_key_file]
      
      #required by Xero for new partner apps, but only issuing warning to keep backward compat for any grandfathered apps
      puts "WARNING: a unique User-Agent header is required for Xero partner apps, and is missing - this should be supplied as :user_agent" unless options[:user_agent]

      defaults = {
        :site             => "https://api.xero.com",
        :authorize_url    => 'https://api.xero.com/oauth/Authorize',
        :signature_method => 'RSA-SHA1',
      }

      options = defaults.merge(options)

      super(consumer_key, consumer_secret, defaults.merge(options))
    end

    def set_session_handle(handle)
      client.session_handle = handle
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
xero_gateway-2.7.0 lib/xero_gateway/partner_app.rb
xero_gateway-2.6.0 lib/xero_gateway/partner_app.rb
xero_gateway-2.5.0 lib/xero_gateway/partner_app.rb