module Invoicexpress::Client::Taxes

Public Instance Methods

create_tax(tax, options={}) click to toggle source

Creates a tax.

@param tax [Invoicexpress::Models::Tax] The tax to create @return Invoicexpress::Models::Tax The tax created @raise Invoicexpress::Unauthorized When the client is unauthorized @raise Invoicexpress::UnprocessableEntity When there are errors on the submission

# File lib/invoicexpress/client/taxes.rb, line 33
def create_tax(tax, options={})
  raise(ArgumentError, "tax has the wrong type") unless tax.is_a?(Invoicexpress::Models::Tax)

  params = { :klass => Invoicexpress::Models::Tax, :body => tax }
  post("taxes.xml", params.merge(options))
end
delete_tax(tax, options={}) click to toggle source

Deletes a tax.

@param tax [Invoicexpress::Models::Tax, String] The tax or tax ID @raise Invoicexpress::Unauthorized When the client is unauthorized @raise Invoicexpress::NotFound When the tax doesn't exist

# File lib/invoicexpress/client/taxes.rb, line 61
def delete_tax(tax, options={})
  params = { :klass => Invoicexpress::Models::Tax }

  delete("taxes/#{id_from_tax(tax)}.xml", params.merge(options))
end
tax(tax, options={}) click to toggle source

Returns a specific tax.

@param tax [Invoicexpress::Models::Tax, String] The tax or tax ID @return Invoicexpress::Models::Tax The tax @raise Invoicexpress::Unauthorized When the client is unauthorized @raise Invoicexpress::NotFound When the tax doesn't exist

# File lib/invoicexpress/client/taxes.rb, line 21
def tax(tax, options={})
  params = { :klass => Invoicexpress::Models::Tax }

  get("taxes/#{id_from_tax(tax)}.xml", params.merge(options))
end
taxes(options = {}) click to toggle source

Returns all your taxes (lol)

@return [Array<Invoicexpress::Models::Tax>] An array with all your taxes @raise Invoicexpress::Unauthorized When the client is unauthorized

# File lib/invoicexpress/client/taxes.rb, line 9
def taxes(options = {})
  params = { :klass => Invoicexpress::Models::Tax }

  get("taxes.xml", params.merge(options))
end
update_tax(tax, options={}) click to toggle source

Updates a tax.

@param tax [Invoicexpress::Models::Tax] The tax to update @raise Invoicexpress::Unauthorized When the client is unauthorized @raise Invoicexpress::NotFound When the tax doesn't exist @raise Invoicexpress::UnprocessableEntity When there are errors on the submission

# File lib/invoicexpress/client/taxes.rb, line 46
def update_tax(tax, options={})
  raise(ArgumentError, "tax has the wrong type") unless tax.is_a?(Invoicexpress::Models::Tax)

  if !tax.id
    raise ArgumentError, "Tax ID is required"
  end
  params = { :klass => Invoicexpress::Models::Tax, :body => tax }
  put("taxes/#{tax.id}.xml", params.merge(options))
end

Private Instance Methods

id_from_tax(item) click to toggle source
# File lib/invoicexpress/client/taxes.rb, line 68
def id_from_tax(item)
  if item.is_a?(Invoicexpress::Models::Tax)
    item.id
  elsif item.is_a?(String)
    item
  elsif item.is_a?(Integer)
    item.to_s
  else
    raise ArgumentError, "Cannot get tax id from #{item}"
  end
end