module Invoicexpress::Client::Schedules

Public Instance Methods

activate_schedule(schedule, options={}) click to toggle source

Activates a previously deactivated schedule

@param schedule [Schedule] The schedule to change @raise Invoicexpress::Unauthorized When the client is unauthorized @raise Invoicexpress::UnprocessableEntity When there are errors on the submission @raise Invoicexpress::NotFound When the invoice doesn't exist

# File lib/invoicexpress/client/schedules.rb, line 75
def activate_schedule(schedule, options={})
  raise(ArgumentError, "schedule has the wrong type") unless schedule.is_a?(Invoicexpress::Models::Schedule)

  params = { :body => schedule, :klass => Invoicexpress::Models::Schedule }
  put("schedules/#{id_from_schedule(schedule)}/activate", params.merge(options))
end
create_schedule(schedule, options={}) click to toggle source

Creates a new schedule. It also allows you to create a new client and/or items in the same request. If the client name does not exist a new one is created. Regarding item taxes, if the tax name is not found, it is ignored and no tax is applied to that item. If no item exists with the given name a new one will be created. If the item exists it will be updated with the new values. Be careful when updating the schedule items, as any missing items from the original invoice are deleted.

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

# File lib/invoicexpress/client/schedules.rb, line 28
def create_schedule(schedule, options={})
  raise(ArgumentError, "schedule has the wrong type") unless schedule.is_a?(Invoicexpress::Models::Schedule)

  params = { :klass => Invoicexpress::Models::Schedule, :body => schedule }
  post("schedules.xml", params.merge(options))
end
deactivate_schedule(schedule, options={}) click to toggle source

Deactivates a schedule. No invoices are created while the schedule is deactivated

@param schedule [Schedule] The schedule to change @raise Invoicexpress::Unauthorized When the client is unauthorized @raise Invoicexpress::UnprocessableEntity When there are errors on the submission @raise Invoicexpress::NotFound When the invoice doesn't exist

# File lib/invoicexpress/client/schedules.rb, line 89
def deactivate_schedule(schedule, options={})
  raise(ArgumentError, "schedule has the wrong type") unless schedule.is_a?(Invoicexpress::Models::Schedule)

  params = { :body => schedule, :klass => Invoicexpress::Models::Schedule }
  put("schedules/#{id_from_schedule(schedule)}/deactivate", params.merge(options))
end
schedule(schedule, options={}) click to toggle source

Returns a specific schedule.

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

# File lib/invoicexpress/client/schedules.rb, line 41
def schedule(schedule, options={})
  params = { :klass => Invoicexpress::Models::Schedule }
  get("schedules/#{id_from_schedule(schedule)}.xml", params.merge(options))
end
schedules(options = {}) click to toggle source

Returns all your schedules.

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

# File lib/invoicexpress/client/schedules.rb, line 10
def schedules(options = {})
  params = { :klass => Invoicexpress::Models::Schedule }

  get("schedules.xml", params.merge(options))
end
update_schedule(schedule, options={}) click to toggle source

Updates a schedule. It also allows you to create a new client and/or items in the same request. If the client name does not exist a new one is created. Regarding item taxes, if the tax name is not found, it is ignored and no tax is applied to that item. If no item exists with the given name a new one will be created. If the item exists it will be updated with the new values. Be careful when updating the schedule items, as any missing items from the original invoice are deleted.

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

# File lib/invoicexpress/client/schedules.rb, line 58
def update_schedule(schedule, options={})
  raise(ArgumentError, "schedule has the wrong type") unless schedule.is_a?(Invoicexpress::Models::Schedule)
  if !schedule.id
    raise ArgumentError, "Schedule's ID is required"
  end
  params = { :klass => Invoicexpress::Models::Schedule, :body  => schedule.to_core_schedule() }
  put("schedules/#{schedule.id}.xml", params.merge(options))
end

Private Instance Methods

id_from_schedule(item) click to toggle source
# File lib/invoicexpress/client/schedules.rb, line 97
def id_from_schedule(item)
  if item.is_a?(Invoicexpress::Models::Schedule)
    item.id
  elsif item.is_a?(String)
    item
  elsif item.is_a?(Integer)
    item.to_s
  else
    raise ArgumentError, "Cannot get schedule id from #{item}"
  end
end