diff --git a/README.md b/README.md index 396b09a34..4fe99cfed 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,21 @@ -Xeroizer API Library ![Project status](http://stillmaintained.com/waynerobinson/xeroizer.png) [![Build Status](https://travis-ci.org/waynerobinson/xeroizer.svg)](https://travis-ci.org/waynerobinson/xeroizer) +Xeroizer API Library ==================== **Homepage**: [http://waynerobinson.github.com/xeroizer](http://waynerobinson.github.com/xeroizer) + **Git**: [git://github.com/waynerobinson/xeroizer.git](git://github.com/waynerobinson/xeroizer.git) + **Github**: [https://github.com/waynerobinson/xeroizer](https://github.com/waynerobinson/xeroizer) + **Author**: Wayne Robinson [http://www.wayne-robinson.com](http://www.wayne-robinson.com) + **Contributors**: See Contributors section below + **Copyright**: 2007-2013 + **License**: MIT License + Introduction ------------ @@ -29,7 +36,7 @@ require 'rubygems' require 'xeroizer' # Create client (used to communicate with the API). -client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CONSUMER_SECRET) +client = Xeroizer::OAuth2Application.new(YOUR_OAUTH2_CLIENT_ID, YOUR_OAUTH2_CLIENT_SECRET) # Retrieve list of contacts (note: all communication must be made through the client). contacts = client.Contact.all(:order => 'Name') @@ -38,55 +45,6 @@ contacts = client.Contact.all(:order => 'Name') Authentication -------------- -Xero uses OAuth to authenticate API clients. The OAuth gem (with minor modification) by John Nunemaker ([http://github.com/jnunemaker/twitter](http://github.com/jnunemaker/twitter)) is used in this library. If you've used this before, things will all seem very familar. - -There are three methods of authentication detailed below: - -### All: Consumer Key/Secret - -All methods of authentication require your OAuth consumer key and secret. This can be found for your application -in the API management console at [http://api.xero.com](http://api.xero.com). - -### Public Applications - -Public applications use a 3-legged authorisation process. A user will need to authorise your -application against each organisation that you want access to. Your application can have access -to many organisations at once by going through the authorisation process for each organisation. - -The access token received will expire after 30 minutes. If you want access for longer you will need -the user to re-authorise your application. - -Authentication occurs in 3 steps: - -```ruby -client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CONSUMER_SECRET) - -# 1. Get a RequestToken from Xero. :oauth_callback is the URL the user will be redirected to -# after they have authenticated your application. -# -# Note: The callback URL's domain must match that listed for your application in http://api.xero.com -# otherwise the user will not be redirected and only be shown the authentication code. -request_token = client.request_token(:oauth_callback => 'http://yourapp.com/oauth/callback') - -# 2. Redirect the user to the URL specified by the RequestToken. -# -# Note: example uses redirect_to method defined in Rails controllers. -redirect_to request_token.authorize_url - -# 3. Exchange RequestToken for AccessToken. -# This access token will be used for all subsequent requests but it is stored within the client -# application so you don't have to record it. -# -# Note: This example assumes the callback URL is a Rails action. -client.authorize_from_request(request_token.token, request_token.secret, :oauth_verifier => params[:oauth_verifier]) -``` - -You can now use the client to access the Xero API methods, e.g. - -```ruby -contacts = client.Contact.all -``` - #### Example Rails Controller ```ruby @@ -97,25 +55,32 @@ class XeroSessionController < ApplicationController public def new - request_token = @xero_client.request_token(:oauth_callback => 'http://yourapp.com/xero_session/create') - session[:request_token] = request_token.token - session[:request_secret] = request_token.secret - - redirect_to request_token.authorize_url + url = @xero_client.authorize_url( + # The URL's domain must match that listed for your application + # otherwise the user will see an invalid redirect_uri error + redirect_uri: YOUR_CALLBACK_URL, + # space separated, see all scopes at https://developer.xero.com/documentation/oauth2/scopes. + # note that `offline_access` is required to get a refresh token, otherwise the access only lasts for 30 mins and cannot be refreshed. + scope: "accounting.settings.read offline_access" + ) + + redirect_to url end def create - @xero_client.authorize_from_request( - session[:request_token], - session[:request_secret], - :oauth_verifier => params[:oauth_verifier] ) + token = @xero_client.authorize_from_code( + params[:code], + redirect_uri: YOUR_CALLBACK_URL + ) + + connections = @xero_client.current_connections session[:xero_auth] = { - :access_token => @xero_client.access_token.token, - :access_key => @xero_client.access_token.secret } + :access_token => token[:access_token], + :refresh_token => token[:refresh_token], + :tenant_id => connections[1][:tenant_id] + } - session.data.delete(:request_token) - session.data.delete(:request_secret) end def destroy @@ -125,145 +90,24 @@ class XeroSessionController < ApplicationController private def get_xero_client - @xero_client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CONSUMER_SECRET) + @xero_client = Xeroizer::OAuth2Application.new( + YOUR_OAUTH2_CLIENT_ID, + YOUR_OAUTH2_CLIENT_SECRET, + ) # Add AccessToken if authorised previously. if session[:xero_auth] - @xero_client.authorize_from_access( - session[:xero_auth][:access_token], - session[:xero_auth][:access_key] ) + @xero_client.tenant_id = session[:xero_auth][:tenant_id] + + @xero_client.authorize_from_access(session[:xero_auth][:acesss_token]) end end end ``` -#### Storing AccessToken - -You can store the access token/secret pair so you can access the API again without user intervention. Currently these -tokens are only valid for 30 minutes and will raise a `Xeroizer::OAuth::TokenExpired` exception if you try to access -the API beyond the token's expiry time. - -If you want API access for longer consider creating a PartnerApplication which will allow you to renew tokens. - -```ruby -access_key = client.access_token.token -access_secret = client.access_token.secret -``` - -### Private Applications - -Note: Private Applications are now deprecated by Xero. Please see the section below on Custom Connections for their replacement. - -Private applications use a 2-legged authorisation process. When you register your application, you will select -the organisation that is authorised to your application. This cannot be changed afterwards, although you can -register another private application if you have multiple organisations. - -Note: You can only register organisations you are authorised to yourself. - -Private applications require a private RSA keypair which is used to sign each request to the API. You can -generate this keypair on Mac OSX or Linux with OpenSSL. For example: - - openssl genrsa -out privatekey.pem 1024 - openssl req -newkey rsa:1024 -x509 -key privatekey.pem -out publickey.cer -days 365 - openssl pkcs12 -export -out public_privatekey.pfx -inkey privatekey.pem -in publickey.cer - -You need to upload this `public_privatekey.pfx` file to your private application in [http://api.xero.com](http://api.xero.com). - -Example usage: - -```ruby -client = Xeroizer::PrivateApplication.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CONSUMER_SECRET, "/path/to/privatekey.pem") -contacts = client.Contact.all -``` - -To provide a private key directly, set the path to nil and pass in a `private_key` option instead. For example: - -```ruby -# Using environment variables (e.g. Heroku): -client = Xeroizer::PrivateApplication.new(key, secret, nil, private_key: ENV["XERO_PRIVATE_KEY"]) - -# Using Rails Credentials (Rails 5.2+): -client = Xeroizer::PrivateApplication.new(key, secret, nil, private_key: Rails.application.credentials.xero_private_key) -``` - -### Partner Applications - -Partner applications use a combination of 3-legged authorisation and private key message signing. - -Visit the [https://developer.xero.com/partner/app-partner](Becoming an app partner) page to get permission to create a partner application. - -After you have followed the instructions provided by Xero for partner applications and uploaded your certificate you can -access the partner application in a similar way to public applications. - -Authentication occcurs in 3 steps: - -```ruby -client = Xeroizer::PartnerApplication.new( - YOUR_OAUTH_CONSUMER_KEY, - YOUR_OAUTH_CONSUMER_SECRET, - "/path/to/privatekey.pem" - ) - -# 1. Get a RequestToken from Xero. :oauth_callback is the URL the user will be redirected to -# after they have authenticated your application. -# -# Note: The callback URL's domain must match that listed for your application in http://api.xero.com -# otherwise the user will not be redirected and only be shown the authentication code. -request_token = client.request_token(:oauth_callback => 'http://yourapp.com/oauth/callback') - -# 2. Redirect the user to the URL specified by the RequestToken. -# -# Note: example uses redirect_to method defined in Rails controllers. -redirect_to request_token.authorize_url - -# 3. Exchange RequestToken for AccessToken. -# This access token will be used for all subsequent requests but it is stored within the client -# application so you don't have to record it. -# -# Note: This example assumes the callback URL is a Rails action. -client.authorize_from_request(request_token.token, request_token.secret, :oauth_verifier => params[:oauth_verifier]) -``` - -This AccessToken will last for 30 minutes however, when using the partner application API you can -renew this token. To be able to renew this token, you need to save the following data from this organisation's -AccessToken: - -```ruby -session_handle = client.session_handle -access_key = client.access_token.token -access_secret = client.access_token.secret -``` - -Two other interesting attributes of the PartnerApplication client are: - -> **`#expires_at`**: Time this AccessToken will expire (usually 30 minutes into the future). -> **`#authorization_expires_at`**: How long this organisation has authorised you to access their data (usually 10 years into the future). - -#### AccessToken Renewal - -Renewal of an access token requires knowledge of the previous access token generated for this organisation. To renew: - -```ruby -# If you still have a client instance. -client.renew_access_token - -# If you are renewing from stored token/session details. -client.renew_access_token(access_token, access_secret, session_handle) -``` - -This will invalidate the previous token and refresh the `access_key` and `access_secret` as specified in the -initial authorisation process. You must always know the previous token's details to renew access to this -session. - -If you lose these details at any stage you can always reauthorise by redirecting the user back to the Xero OAuth gateway. - -#### Branding Themes API - -Once you are approved as a Xero Partner you can request unofficial documentation to do with customizing Payment Services and Branding Themes using the API. There is more info on that [here]( https://github.com/waynerobinson/xeroizer/pull/439). - ### OAuth2 Applications -For more details, checkout Xero's [documentation](https://developer.xero.com/documentation/oauth2/auth-flow) and [migration steps](https://developer.xero.com/documentation/oauth2/migrate). +For more details, checkout Xero's [documentation](https://developer.xero.com/documentation/oauth2/auth-flow) 1. Generate the authorization url and redirect the user to authenticate ```ruby @@ -365,12 +209,11 @@ Retrieving Data --------------- Each of the below record types is implemented within this library. To allow for multiple access tokens to be used at the same -time in a single application, the model classes are accessed from the instance of PublicApplication, PrivateApplication -or PartnerApplication. All class-level operations occur on this singleton. For example: +time in a single application, the model classes are accessed from the instance of OAuth2Application. All class-level operations occur on this singleton. For example: ```ruby -xero = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, YOUR_OAUTH_CONSUMER_SECRET) -xero.authorize_from_access(session[:xero_auth][:access_token], session[:xero_auth][:access_key]) +xero = Xeroizer::OAuth2Application.new(YOUR_OAUTH2_CLIENT_ID, YOUR_OAUTH2_CLIENT_SECRET, tenant_id: tenant_id) +xero.authorize_from_access(session[:xero_auth][:access_token]) contacts = xero.Contact.all(:order => 'Name') @@ -750,8 +593,8 @@ You can set this option when initializing an application: ```ruby # Sleep for 2 seconds every time the rate limit is exceeded. -client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, - YOUR_OAUTH_CONSUMER_SECRET, +client = Xeroizer::OAuth2Application.new(YOUR_OAUTH2_CLIENT_ID, + YOUR_OAUTH2_CLIENT_SECRET, :rate_limit_sleep => 2) ``` @@ -768,8 +611,8 @@ You can set this option when initializing an application: ```ruby # Sleep for 1 second and retry up to 3 times when Xero claims the nonce was used. -client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, - YOUR_OAUTH_CONSUMER_SECRET, +client = Xeroizer::OAuth2Application.new(YOUR_OAUTH2_CLIENT_ID, + YOUR_OAUTH2_CLIENT_SECRET, :nonce_used_max_attempts => 3) ``` @@ -781,8 +624,8 @@ You can add an optional parameter to the Xeroizer Application initialization, to ```ruby XeroLogger = Logger.new('log/xero.log', 'weekly') -client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, - YOUR_OAUTH_CONSUMER_SECRET, +client = Xeroizer::OAuth2Application.new(YOUR_OAUTH2_CLIENT_ID, + YOUR_OAUTH2_CLIENT_SECRET, :logger => XeroLogger) ``` @@ -794,7 +637,7 @@ time Xeroizer makes an HTTP request, which is potentially useful for both throttling and logging: ```ruby -Xeroizer::PublicApplication.new( +Xeroizer::OAuth2Application.new( credentials[:key], credentials[:secret], before_request: ->(request) { puts "Hitting this URL: #{request.url}" }, after_request: ->(request, response) { puts "Got this response: #{response.code}" }, @@ -813,8 +656,8 @@ By default, the API accepts unit prices (UnitAmount) to two decimals places. If ```ruby -client = Xeroizer::PublicApplication.new(YOUR_OAUTH_CONSUMER_KEY, - YOUR_OAUTH_CONSUMER_SECRET, +client = Xeroizer::OAuth2Application.new(YOUR_OAUTH2_CLIENT_ID, + YOUR_OAUTH2_CLIENT_SECRET, :unitdp => 4) ``` @@ -823,23 +666,19 @@ This option adds the unitdp=4 query string parameter to all requests for models Tests ----- -The tests within the repository can be run by setting up a [Private App](https://developer.xero.com/documentation/auth-and-limits/private-applications). You can create a Private App in the [developer portal](https://developer.xero.com/myapps/), it's suggested that you create it against the [Demo Company (AU)](https://developer.xero.com/documentation/getting-started/development-accounts). Demo Company expires after 28 days, so you will need to reset it and create a new Private App if you Demo Company has expired. Make sure you create the Demo Company in Australia region. +OAuth2 Tests -Once you have created your Private App, set these environment variables: -``` -EXPORT CONSUMER_KEY="your private app's consumer key" -EXPORT CONSUMER_SECRET="your private app's consumer secret" -EXPORT PRIVATE_KEY_PATH="the path to your private app's private key" -``` - -PRIVATE_KEY_PATH is the path to the private key for your Private App (you uploaded the Public Key when you created the Private App) +The tests within the repository can be run by setting up a [OAuth2 App](https://developer.xero.com/documentation/guides/oauth2/auth-flow/). You can create a Private App in the [developer portal](https://developer.xero.com/myapps/), it's suggested that you create it against the [Demo Company (AU)](https://developer.xero.com/documentation/getting-started/development-accounts). Demo Company expires after 28 days, so you will need to reset it and re-connect to it if your Demo Company has expired. Make sure you create the Demo Company in Australia region. -Then run the tests ``` +export XERO_CLIENT_ID="asd" +export XERO_CLIENT_SECRET="asdfg" +export XERO_ACCESS_TOKEN="sadfsdf" +export XERO_TENANT_ID="asdfasdfasdfasd" + rake test ``` - ### Contributors Xeroizer was inspired by the https://github.com/tlconnor/xero_gateway gem created by Tim Connor and Nik Wakelin and portions of the networking and authentication code are based completely off diff --git a/lib/xeroizer.rb b/lib/xeroizer.rb index 1506039ed..64c6721c4 100644 --- a/lib/xeroizer.rb +++ b/lib/xeroizer.rb @@ -112,8 +112,5 @@ require 'xeroizer/response' require 'xeroizer/generic_application' -require 'xeroizer/public_application' -require 'xeroizer/private_application' -require 'xeroizer/partner_application' require 'xeroizer/oauth2_application' require 'xeroizer/payroll_application' diff --git a/lib/xeroizer/models/contact.rb b/lib/xeroizer/models/contact.rb index 614c5046f..143ff6f32 100644 --- a/lib/xeroizer/models/contact.rb +++ b/lib/xeroizer/models/contact.rb @@ -21,7 +21,8 @@ class Contact < Base CONTACT_STATUS = { 'ACTIVE' => 'Active', 'DELETED' => 'Deleted', - 'ARCHIVED' => 'Archived' + 'ARCHIVED' => 'Archived', + 'GDPRREQUEST' => 'GDPR Request' } unless defined?(CONTACT_STATUS) include Attachment::Extensions diff --git a/lib/xeroizer/models/invoice.rb b/lib/xeroizer/models/invoice.rb index b63e98fb4..b96b0acdf 100644 --- a/lib/xeroizer/models/invoice.rb +++ b/lib/xeroizer/models/invoice.rb @@ -94,7 +94,8 @@ class Invoice < Base has_many :credit_notes has_many :prepayments - validates_presence_of :date, :due_date, :unless => :new_record? + validates_presence_of :date, :if => :new_record? + validates_presence_of :due_date, :if => :approved? validates_inclusion_of :type, :in => INVOICE_TYPES validates_inclusion_of :status, :in => INVOICE_STATUSES, :unless => :new_record? validates_inclusion_of :line_amount_types, :in => LINE_AMOUNT_TYPES, :unless => :new_record? diff --git a/lib/xeroizer/models/line_item.rb b/lib/xeroizer/models/line_item.rb index bd9683f3d..e7cc29893 100644 --- a/lib/xeroizer/models/line_item.rb +++ b/lib/xeroizer/models/line_item.rb @@ -44,7 +44,7 @@ def line_amount(summary_only = false) if quantity && unit_amount total = coerce_numeric(quantity) * coerce_numeric(unit_amount) if discount_rate.nonzero? - BigDecimal((total * ((100 - discount_rate) / 100)).to_s).round(2) + BigDecimal((total * ((100 - discount_rate.to_f) / 100)).to_s).round(2) elsif discount_amount BigDecimal((total - discount_amount).to_s).round(2) else diff --git a/lib/xeroizer/models/tax_component.rb b/lib/xeroizer/models/tax_component.rb index 6b0e472de..4d1cf30fb 100644 --- a/lib/xeroizer/models/tax_component.rb +++ b/lib/xeroizer/models/tax_component.rb @@ -8,6 +8,7 @@ class TaxComponent < Base string :name decimal :rate boolean :is_compound + boolean :is_non_recoverable end end end diff --git a/lib/xeroizer/partner_application.rb b/lib/xeroizer/partner_application.rb deleted file mode 100644 index 28b891ce1..000000000 --- a/lib/xeroizer/partner_application.rb +++ /dev/null @@ -1,52 +0,0 @@ -module Xeroizer - class PartnerApplication < GenericApplication - - extend Forwardable - def_delegators :client, :request_token, :authorize_from_request, :renew_access_token, :expires_at, :authorization_expires_at, :session_handle, :authorize_from_access - - public - - # 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. - # - # @param [String] consumer_key consumer key/token from application developer (found at http://api.xero.com for your application). - # @param [String] consumer_secret consumer secret from application developer (found at http://api.xero.com for your application). - # @param [String] path_to_private_key application's private key for message signing (uploaded to http://api.xero.com) - # @param [Hash] options other options to pass to the GenericApplication constructor - # @return [PartnerApplication] instance of PrivateApplication - def initialize(consumer_key, consumer_secret, path_to_private_key, options = {}) - default_options = { - :xero_url => 'https://api.xero.com/api.xro/2.0', - :site => 'https://api.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 - ) - client = OAuth.new(consumer_key, consumer_secret, options) - super(client, 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 - - private - - def read_certificate(cert) - if File.exists?(cert) - File.read(cert) - else - cert - end - end - end -end diff --git a/lib/xeroizer/private_application.rb b/lib/xeroizer/private_application.rb deleted file mode 100644 index ec165a23c..000000000 --- a/lib/xeroizer/private_application.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Xeroizer - class PrivateApplication < GenericApplication - - extend Forwardable - def_delegators :client, :authorize_from_access - - public - - # Private applications are defined in the Xero API website and can be accessed in the - # background without ever requiring a redirect to the Xero website for authorisation. - # - # @param [String] consumer_key consumer key/token from application developer (found at http://api.xero.com for your application). - # @param [String] consumer_secret consumer secret from application developer (found at http://api.xero.com for your application). - # @param [String] path_to_private_key application's private key for message signing (uploaded to http://api.xero.com) - # @param [Hash] options other options to pass to the GenericApplication constructor - # @return [PrivateApplication] instance of PrivateApplication - def initialize(consumer_key, consumer_secret, path_to_private_key, options = {}) - options[:signature_method] = 'RSA-SHA1' - options[:private_key_file] = path_to_private_key - client = OAuth.new(consumer_key, consumer_secret, options) - super(client, options) - @client.authorize_from_access(consumer_key, consumer_secret) - end - - end -end diff --git a/lib/xeroizer/public_application.rb b/lib/xeroizer/public_application.rb deleted file mode 100644 index dbd8e3a67..000000000 --- a/lib/xeroizer/public_application.rb +++ /dev/null @@ -1,22 +0,0 @@ -module Xeroizer - class PublicApplication < GenericApplication - - extend Forwardable - def_delegators :client, :request_token, :authorize_from_request, :authorize_from_access - - public - - # Public appliations are authenticated via the Xero website via OAuth. AccessTokens are valid for 30 minutes - # after authentication. To extend this time you must redirect the user to Xero's OAuth server again. - # - # @param [String] consumer_key consumer key/token from application developer (found at http://api.xero.com for your application) - # @param [String] consumer_secret consumer secret from application developer (found at http://api.xero.com for your application) - # @param [Hash] options other options to pass to the GenericApplication constructor - # @return [PublicApplication] instance of PrivateApplication - def initialize(consumer_key, consumer_secret, options = {}) - client = OAuth.new(consumer_key, consumer_secret, options) - super(client, options) - end - - end -end diff --git a/lib/xeroizer/version.rb b/lib/xeroizer/version.rb index a4eaedbef..cb9f81437 100644 --- a/lib/xeroizer/version.rb +++ b/lib/xeroizer/version.rb @@ -1,3 +1,3 @@ module Xeroizer - VERSION = "3.0.0-beta".freeze + VERSION = "3.0.0".freeze end diff --git a/test/acceptance/about_fetching_bank_transactions_test.rb b/test/acceptance/about_fetching_bank_transactions_test.rb index 8dc65ad42..74f6474db 100644 --- a/test/acceptance/about_fetching_bank_transactions_test.rb +++ b/test/acceptance/about_fetching_bank_transactions_test.rb @@ -37,7 +37,7 @@ class AboutFetchingBankTransactions < Test::Unit::TestCase it "has the limited set of attributes" do keys = [:line_amount_types, :contact, :date, :status, :updated_date_utc, :currency_code, :bank_transaction_id, :bank_account, :type, :reference, - :is_reconciled] + :is_reconciled, :has_attachments] assert_equal(keys, @the_first_bank_transaction.attributes.keys) end diff --git a/test/acceptance/acceptance_test.rb b/test/acceptance/acceptance_test.rb index be781f826..77ec19794 100644 --- a/test/acceptance/acceptance_test.rb +++ b/test/acceptance/acceptance_test.rb @@ -1,9 +1,4 @@ module AcceptanceTestHelpers - def self.oauth_client - config = load_config_from_file || load_config_from_env - Xeroizer::PrivateApplication.new(config.consumer_key, config.consumer_secret, config.key_file) - end - def self.oauth2_client config = self.load_oauth2_config_from_env Xeroizer::OAuth2Application.new( @@ -14,22 +9,6 @@ def self.oauth2_client ) end - def self.load_config_from_file - the_file_name = File.join(File.dirname(__FILE__), '..', '..', '.oauth') - - return nil unless File.exist? the_file_name - - Xeroizer::OAuthConfig.load IO.read the_file_name - end - - def self.load_config_from_env - raise "No CONSUMER_KEY environment variable specified." unless ENV["CONSUMER_KEY"] - raise "No CONSUMER_SECRET environment variable specified." unless ENV["CONSUMER_SECRET"] - raise "No PRIVATE_KEY_PATH environment variable specified." unless ENV["PRIVATE_KEY_PATH"] - raise "The file <#{ENV["PRIVATE_KEY_PATH"]}> does not exist." unless File.exist?(ENV["PRIVATE_KEY_PATH"]) - Xeroizer::OAuthCredentials.new ENV["CONSUMER_KEY"], ENV["CONSUMER_SECRET"], ENV["PRIVATE_KEY_PATH"] - end - def self.load_oauth2_config_from_env raise "No XERO_CLIENT_ID environment variable specified." unless ENV["XERO_CLIENT_ID"] raise "No XERO_CLIENT_SECRET environment variable specified." unless ENV["XERO_CLIENT_SECRET"] @@ -47,8 +26,7 @@ module AcceptanceTest class << self def included(klass) klass.class_eval do - def self.it_works_using_oauth1_and_oauth2(&block) - instance_exec(AcceptanceTestHelpers.oauth_client, 'oauth', &block) + def self.it_works_using_oauth2(&block) instance_exec(AcceptanceTestHelpers.oauth2_client, 'oauth2', &block) end diff --git a/test/acceptance/bank_transfer_test.rb b/test/acceptance/bank_transfer_test.rb index 12008b03e..28880e2f6 100644 --- a/test/acceptance/bank_transfer_test.rb +++ b/test/acceptance/bank_transfer_test.rb @@ -4,7 +4,7 @@ class BankTransfer < Test::Unit::TestCase include AcceptanceTest - it_works_using_oauth1_and_oauth2 do |client, client_type| + it_works_using_oauth2 do |client, client_type| can "create a bank for #{client_type}" do all_accounts = client.Account.all @from_bank_account = all_accounts.select { |acct| acct.status == "ACTIVE" && acct.type == "BANK" }.first diff --git a/test/test_helper.rb b/test/test_helper.rb index 88a1048f7..6b5548267 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -29,8 +29,10 @@ module TestHelper CONSUMER_SECRET = ENV["CONSUMER_SECRET"] || "fake_secret" unless defined?(CONSUMER_SECRET) PRIVATE_KEY_PATH = ENV["PRIVATE_KEY_PATH"] || "fake_key" unless defined?(PRIVATE_KEY_PATH) - CLIENT_ID = ENV["CLIENT_ID"] || "fake_client_id" unless defined?(CLIENT_ID) - CLIENT_SECRET = ENV["CLIENT_SECRET"] || "fake_client_secret" unless defined?(CLIENT_SECRET) + CLIENT_ID = ENV["XERO_CLIENT_ID"] || "fake_client_id" unless defined?(CLIENT_ID) + CLIENT_SECRET = ENV["XERO_CLIENT_SECRET"] || "fake_client_secret" unless defined?(CLIENT_SECRET) + ACCESS_TOKEN = ENV["XERO_ACCESS_TOKEN"] || "fake_access_token" unless defined?(ACCESS_TOKEN) + TENANT_ID = ENV["XERO_TENANT_ID"] || "fake_tenant_id" unless defined?(TENANT_ID) # Helper constant for checking regex GUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ unless defined?(GUID_REGEX) diff --git a/test/unit/generic_application_test.rb b/test/unit/generic_application_test.rb index 858ceea02..fd0a8d9b1 100644 --- a/test/unit/generic_application_test.rb +++ b/test/unit/generic_application_test.rb @@ -20,21 +20,6 @@ class GenericApplicationTest < Test::Unit::TestCase end end - context "oauth" do - setup do - client = Xeroizer::OAuth.new(CONSUMER_KEY, CONSUMER_SECRET, @options) - @application = Xeroizer::GenericApplication.new(client, @options) - end - - should "pass default headers" do - assert_equal(@headers, @application.default_headers) - end - - should "pass unitdp value" do - assert_equal(@unitdp, @application.unitdp) - end - end - context "oauth 2" do setup do client = Xeroizer::OAuth2.new(CLIENT_ID, CLIENT_SECRET, @options) diff --git a/test/unit/http_test.rb b/test/unit/http_test.rb index a365e4f67..696b0b43f 100644 --- a/test/unit/http_test.rb +++ b/test/unit/http_test.rb @@ -7,21 +7,9 @@ class HttpTest < UnitTestCase @uri = "https://api.xero.com/path" end - context "default_headers" do - setup do - @headers = { "User-Agent" => "Xeroizer/2.15.5" } - @application = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET, :default_headers => @headers) - end - - should "recognize default_headers" do - # Xeroizer::OAuth.any_instance.expects(:get).with("/test", has_entry(@headers)).returns(stub(:plain_body => "", :code => "200")) - # @application.http_get(@application.client, "http://example.com/test") - end - end - context "errors" do setup do - @application = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @application = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET, tenant_id: TENANT_ID, access_token: ACCESS_TOKEN) end context "400" do diff --git a/test/unit/models/address_test.rb b/test/unit/models/address_test.rb index 1e2a71c37..88a3df294 100644 --- a/test/unit/models/address_test.rb +++ b/test/unit/models/address_test.rb @@ -4,7 +4,7 @@ class AddressTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) @contact = @client.Contact.build end diff --git a/test/unit/models/contact_test.rb b/test/unit/models/contact_test.rb index 89917d7d0..8cc65566d 100644 --- a/test/unit/models/contact_test.rb +++ b/test/unit/models/contact_test.rb @@ -4,7 +4,7 @@ class ContactTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) end context "contact validators" do diff --git a/test/unit/models/credit_note_test.rb b/test/unit/models/credit_note_test.rb index 7cbec5842..3de358b3a 100644 --- a/test/unit/models/credit_note_test.rb +++ b/test/unit/models/credit_note_test.rb @@ -4,7 +4,7 @@ class CreditNoteTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) mock_api("CreditNotes") @credit_note = @client.CreditNote.first end diff --git a/test/unit/models/employee_test.rb b/test/unit/models/employee_test.rb index 5a69cd68f..f159c5e48 100644 --- a/test/unit/models/employee_test.rb +++ b/test/unit/models/employee_test.rb @@ -5,7 +5,7 @@ class EmployeeTest < Test::Unit::TestCase include Xeroizer::Record def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) @employee = @client.Employee.build @employee.employee_id = 'GUID' diff --git a/test/unit/models/invoice_test.rb b/test/unit/models/invoice_test.rb index a5acaec19..91b8f1695 100644 --- a/test/unit/models/invoice_test.rb +++ b/test/unit/models/invoice_test.rb @@ -4,7 +4,7 @@ class InvoiceTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) mock_api('Invoices') @invoice = @client.Invoice.first end @@ -59,7 +59,7 @@ def build_valid_authorised_invoice end should "build a valid DRAFT invoice with minimal attributes" do - invoice = @client.Invoice.build :type => "ACCREC", :contact => { :name => "ABC Limited" } + invoice = @client.Invoice.build :type => "ACCREC", :date => Date.today, :contact => { :name => "ABC Limited" } assert_equal(true, invoice.valid?) end diff --git a/test/unit/models/journal_line_test.rb b/test/unit/models/journal_line_test.rb index 4d97b53f6..dfab46c08 100644 --- a/test/unit/models/journal_line_test.rb +++ b/test/unit/models/journal_line_test.rb @@ -5,7 +5,7 @@ class JournalLineTest < Test::Unit::TestCase include Xeroizer::Record def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) end it "journal_line tracking specified correctly" do diff --git a/test/unit/models/journal_test.rb b/test/unit/models/journal_test.rb index a6eb49aba..a225a4e0d 100644 --- a/test/unit/models/journal_test.rb +++ b/test/unit/models/journal_test.rb @@ -5,7 +5,7 @@ class JournalTest < Test::Unit::TestCase include Xeroizer::Record def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) @journal = @client.Journal.build @journal.journal_id = "0d926df3-459f-4264-a3a3-49ac065eb0ed" diff --git a/test/unit/models/line_item_test.rb b/test/unit/models/line_item_test.rb index eab4e469c..ad96d6000 100644 --- a/test/unit/models/line_item_test.rb +++ b/test/unit/models/line_item_test.rb @@ -5,7 +5,7 @@ class LineItemTest < Test::Unit::TestCase include Xeroizer::Record def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) end it "line_item tracking specified correctly" do diff --git a/test/unit/models/manual_journal_test.rb b/test/unit/models/manual_journal_test.rb index e4538fb52..6e761c28c 100644 --- a/test/unit/models/manual_journal_test.rb +++ b/test/unit/models/manual_journal_test.rb @@ -4,7 +4,7 @@ class ManualJournalTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) mock_api('ManualJournals') end diff --git a/test/unit/models/organisation_test.rb b/test/unit/models/organisation_test.rb index 8af5f2d96..483a14cb8 100644 --- a/test/unit/models/organisation_test.rb +++ b/test/unit/models/organisation_test.rb @@ -4,7 +4,7 @@ class OrganisationTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) end context "sales_tax_basis_validations" do diff --git a/test/unit/models/payment_service_test.rb b/test/unit/models/payment_service_test.rb index f7ad52a77..d7eace97b 100644 --- a/test/unit/models/payment_service_test.rb +++ b/test/unit/models/payment_service_test.rb @@ -4,7 +4,7 @@ class PaymentServiceTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) end context "response parsing" do diff --git a/test/unit/models/phone_test.rb b/test/unit/models/phone_test.rb index 47ef9bf88..867e9be2b 100644 --- a/test/unit/models/phone_test.rb +++ b/test/unit/models/phone_test.rb @@ -4,7 +4,7 @@ class PhoneTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) @contact = @client.Contact.build end diff --git a/test/unit/models/prepayment_test.rb b/test/unit/models/prepayment_test.rb index 646ef797d..63f08dcfa 100644 --- a/test/unit/models/prepayment_test.rb +++ b/test/unit/models/prepayment_test.rb @@ -4,7 +4,7 @@ class PrepaymentTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) mock_api("Prepayments") @prepayment = @client.Prepayment.first end diff --git a/test/unit/models/repeating_invoice_test.rb b/test/unit/models/repeating_invoice_test.rb index ca2d5456f..b0abe29e8 100644 --- a/test/unit/models/repeating_invoice_test.rb +++ b/test/unit/models/repeating_invoice_test.rb @@ -4,7 +4,7 @@ class RepeatingInvoiceTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) mock_api('RepeatingInvoices') end diff --git a/test/unit/models/tax_rate_test.rb b/test/unit/models/tax_rate_test.rb index 9ad3605e3..70f714480 100644 --- a/test/unit/models/tax_rate_test.rb +++ b/test/unit/models/tax_rate_test.rb @@ -5,7 +5,7 @@ class TaxRateTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) end should "have a primary key value of :name" do diff --git a/test/unit/oauth_test.rb b/test/unit/oauth_test.rb deleted file mode 100644 index 6a6d2e8d9..000000000 --- a/test/unit/oauth_test.rb +++ /dev/null @@ -1,179 +0,0 @@ -require 'unit_test_helper' - -class OAuthTest < Test::Unit::TestCase - include TestHelper - - def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) - end - - context "with oauth error handling" do - - should "handle token expired" do - Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("token_expired"), :code => "401")) - - assert_raises Xeroizer::OAuth::TokenExpired do - @client.Organisation.first - end - end - - should "handle invalid request tokens" do - Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("invalid_request_token"), :code => "401")) - - assert_raises Xeroizer::OAuth::TokenInvalid do - @client.Organisation.first - end - end - - should "handle invalid consumer key" do - Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("invalid_consumer_key"), :code => "401")) - - assert_raises Xeroizer::OAuth::TokenInvalid do - @client.Organisation.first - end - end - - should "handle nonce used" do - Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("nonce_used"), :code => "401")) - - assert_raises Xeroizer::OAuth::NonceUsed do - @client.Organisation.first - end - end - - should "raise rate limit exceeded" do - Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("rate_limit_exceeded"), :code => "401")) - - assert_raises Xeroizer::OAuth::RateLimitExceeded do - @client.Organisation.first - end - end - - should "automatically handle rate limit exceeded" do - auto_rate_limit_client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET, :rate_limit_sleep => 1) - - # Return rate limit exceeded on first call, OK on the second - Xeroizer::OAuth.any_instance.stubs(:get).returns( - stub(:plain_body => get_file_as_string("rate_limit_exceeded"), :code => "401"), - stub(:plain_body => get_record_xml(:organisation), :code => '200') - ) - - auto_rate_limit_client.expects(:sleep_for).with(1).returns(1) - - auto_rate_limit_client.Organisation.first - end - - should "only retry rate limited request a configurable number of times" do - auto_rate_limit_client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET, :rate_limit_sleep => 1, :rate_limit_max_attempts => 4) - Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("rate_limit_exceeded"), :code => "401")) - - auto_rate_limit_client.expects(:sleep_for).with(1).times(4).returns(1) - - assert_raises Xeroizer::OAuth::RateLimitExceeded do - auto_rate_limit_client.Organisation.first - end - end - - should "retry nonce_used failures a configurable number of times" do - nonce_used_client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET, :nonce_used_max_attempts => 4) - Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("nonce_used"), :code => "401")) - - nonce_used_client.expects(:sleep_for).with(1).times(4).returns(1) - - assert_raises Xeroizer::OAuth::NonceUsed do - nonce_used_client.Organisation.first - end - end - - should "handle unknown errors" do - Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("bogus_oauth_error"), :code => "401")) - - assert_raises Xeroizer::OAuth::UnknownError do - @client.Organisation.first - end - end - - should "handle ApiExceptions" do - Xeroizer::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => get_file_as_string("api_exception.xml"), - :code => "400")) - - assert_raises Xeroizer::ApiException do - contact = @client.Contact.build(:name => 'Test Contact') - contact.save! - end - end - - should "handle random root elements" do - Xeroizer::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => "", - :code => "200")) - - assert_raises Xeroizer::UnparseableResponse do - contact = @client.Contact.build(:name => 'Test Contact') - contact.save! - end - end - - end - - context "with oauth2 error handling" do - context "when token is invalid" do - should "raise an invalid token error" do - Xeroizer::OAuth2.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("invalid_oauth2_request_token.json"), :code => "401")) - - assert_raises Xeroizer::OAuth::TokenInvalid do - Xeroizer::OAuth2Application.new("client id", "client secret", access_token: "access token").Organisation.first - end - end - end - - context "when token is expired" do - should "raise an expired token error" do - Xeroizer::OAuth2.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("expired_oauth2_token.json"), :code => "401")) - - assert_raises Xeroizer::OAuth::TokenExpired do - Xeroizer::OAuth2Application.new("client id", "client secret", access_token: "access token").Organisation.first - end - end - end - - context "when the tenant_id header is invalid or not present" do - should "handle oauth2 invalid tenant_id" do - Xeroizer::OAuth2.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("invalid_tenant_header.json"), :code => "403")) - - assert_raises Xeroizer::OAuth::Forbidden do - Xeroizer::OAuth2Application.new("client id", "client secret", access_token: "access token").Account.first - end - end - end - - context "when a bad request was made" do - should "handle a json payload" do - Xeroizer::OAuth2.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("bad_request.json"), :code => "400")) - - assert_raises Xeroizer::BadResponse do - Xeroizer::OAuth2Application.new("client id", "client secret", access_token: "access token").Account.first - end - end - end - - context "when an object is not found" do - should "raise an object not found error" do - Xeroizer::OAuth2.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("object_not_found.json"), :code => "404")) - - assert_raises Xeroizer::ObjectNotFound do - Xeroizer::OAuth2Application.new("client id", "client secret", access_token: "access token").Account.first - end - end - end - - context "when an error that isn't explicitly handled is received" do - should "raise an unknown error" do - Xeroizer::OAuth2.any_instance.stubs(:get).returns(stub(:plain_body => get_file_as_string("generic_response_error.json"), :code => "409")) - - assert_raises Xeroizer::OAuth::UnknownError do - Xeroizer::OAuth2Application.new("client id", "client secret", access_token: "access token").Account.first - end - end - end - end -end diff --git a/test/unit/private_application_test.rb b/test/unit/private_application_test.rb deleted file mode 100644 index e15378bbe..000000000 --- a/test/unit/private_application_test.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'unit_test_helper' - -class PrivateApplicationTest < Test::Unit::TestCase - include TestHelper - - def setup - @client = Xeroizer::PrivateApplication.new(CONSUMER_KEY, CONSUMER_SECRET, PRIVATE_KEY_PATH) - end - - context "initialization" do - - should "have a valid client" do - assert_kind_of(Xeroizer::OAuth, @client.client) - assert_equal(CONSUMER_KEY, @client.client.ctoken) - assert_equal(CONSUMER_SECRET, @client.client.csecret) - end - - end - -end diff --git a/test/unit/record/base_model_test.rb b/test/unit/record/base_model_test.rb index f2693bf1e..27b53cbc3 100644 --- a/test/unit/record/base_model_test.rb +++ b/test/unit/record/base_model_test.rb @@ -18,7 +18,7 @@ class OrangeModel < Xeroizer::Record::BaseModel end def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) @apple_model = AppleModel.new(@client, 'Apple') @pear_model = PearModel.new(@client, 'Pear') @orange_model = OrangeModel.new(@client, 'Orange') diff --git a/test/unit/record/base_test.rb b/test/unit/record/base_test.rb index cf8186f86..f2cdcd111 100644 --- a/test/unit/record/base_test.rb +++ b/test/unit/record/base_test.rb @@ -4,7 +4,8 @@ class RecordBaseTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET, tenant_id: TENANT_ID) + @client.authorize_from_access(ACCESS_TOKEN) @contact = @client.Contact.build(:name => 'Test Contact Name ABC') end @@ -26,14 +27,14 @@ def setup context "new_record? states" do should "new_record? should be false when loading data" do - Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_record_xml(:contact), :code => '200')) + Xeroizer::OAuth2.any_instance.stubs(:get).returns(stub(:plain_body => get_record_xml(:contact), :code => '200')) contact = @client.Contact.find('TESTID') assert_kind_of(Xeroizer::Record::Contact, contact) assert_equal(false, contact.new_record?) end should "new_record? should be false after successfully creating a record" do - Xeroizer::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => get_record_xml(:contact), :code => '200')) + Xeroizer::OAuth2.any_instance.stubs(:put).returns(stub(:plain_body => get_record_xml(:contact), :code => '200')) assert_equal(true, @contact.new_record?) assert_nil(@contact.contact_id) assert_equal(true, @contact.save, "Error saving contact: #{@contact.errors.inspect}") diff --git a/test/unit/record/model_definition_test.rb b/test/unit/record/model_definition_test.rb index 6e2938ea4..2f03fd511 100644 --- a/test/unit/record/model_definition_test.rb +++ b/test/unit/record/model_definition_test.rb @@ -63,7 +63,7 @@ class Xeroizer::Record::SummaryOnlyOffRecordModel < Xeroizer::Record::BaseModel; end def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) parent = stub(:application => @client, :mark_dirty => nil) @first = FirstRecord.new(parent) @second = SecondRecord.new(parent) diff --git a/test/unit/record/parse_params_test.rb b/test/unit/record/parse_params_test.rb index d7df10459..d2a582a8d 100644 --- a/test/unit/record/parse_params_test.rb +++ b/test/unit/record/parse_params_test.rb @@ -27,7 +27,7 @@ class ParseParamsTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) @model = Xeroizer::Record::ParseParamTestModel.new(@client, "ParseParamTest") end diff --git a/test/unit/record/parse_where_hash_test.rb b/test/unit/record/parse_where_hash_test.rb index 753d9b265..69ce8b759 100644 --- a/test/unit/record/parse_where_hash_test.rb +++ b/test/unit/record/parse_where_hash_test.rb @@ -27,7 +27,7 @@ class ParseWhereHashTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) @model = Xeroizer::Record::WhereHashTestModel.new(@client, "WhereHashTest") end diff --git a/test/unit/record/record_association_test.rb b/test/unit/record/record_association_test.rb index fbb33f2dd..5b941d088 100644 --- a/test/unit/record/record_association_test.rb +++ b/test/unit/record/record_association_test.rb @@ -4,7 +4,7 @@ class RecordAssociationTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) mock_api('Invoices') @client.stubs(:http_put).returns(get_record_xml(:invoice, "762aa45d-4632-45b5-8087-b4f47690665e")) end diff --git a/test/unit/record/validators_test.rb b/test/unit/record/validators_test.rb index 1730ae4b8..8ae541eae 100644 --- a/test/unit/record/validators_test.rb +++ b/test/unit/record/validators_test.rb @@ -40,7 +40,7 @@ def value_equals_twenty? end def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) @record = Xeroizer::Record::TestModel.new(@client, 'Test').build end diff --git a/test/unit/record_definition_test.rb b/test/unit/record_definition_test.rb index dfa2d1a43..da1ac8a3a 100644 --- a/test/unit/record_definition_test.rb +++ b/test/unit/record_definition_test.rb @@ -4,7 +4,7 @@ class RecordDefinitionTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) end context "record definitions" do diff --git a/test/unit/report_definition_test.rb b/test/unit/report_definition_test.rb index 7d130a2b8..92197050d 100644 --- a/test/unit/report_definition_test.rb +++ b/test/unit/report_definition_test.rb @@ -4,7 +4,7 @@ class ReportDefinitionTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) end context "report definitions" do diff --git a/test/unit/report_test.rb b/test/unit/report_test.rb index 3108a9961..e187bb7a2 100644 --- a/test/unit/report_test.rb +++ b/test/unit/report_test.rb @@ -6,7 +6,7 @@ class FactoryTest < Test::Unit::TestCase include TestHelper def setup - @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET) + @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET) mock_report_api("TrialBalance") @report = @client.TrialBalance.get end diff --git a/xeroizer.gemspec b/xeroizer.gemspec index e9b6f3deb..42f90ec4f 100644 --- a/xeroizer.gemspec +++ b/xeroizer.gemspec @@ -24,7 +24,7 @@ Gem::Specification.new do |s| s.test_files = `git ls-files -- test/*`.split("\n") s.require_paths = ["lib"] - s.add_development_dependency "bundler", "~> 1.5" + s.add_development_dependency "bundler", "~> 2.2" s.add_development_dependency "rake" s.add_development_dependency "mocha" s.add_development_dependency "shoulda", "~> 3.6.0"