Module: Invoicexpress::Client::Schedules

Included in:
Invoicexpress::Client
Defined in:
lib/invoicexpress/client/schedules.rb

Instance Method Summary collapse

Instance Method Details

#activate_schedule(schedule, options = {}) ⇒ Object

Activates a previously deactivated schedule

Parameters:

  • schedule (Schedule)

    The schedule to change

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission

  • Invoicexpress::NotFound When the invoice doesn’t exist



75
76
77
78
79
80
# 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 = {}) ⇒ Object

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.

Parameters:

Returns:

  • Invoicexpress::Models::Schedule The schedule

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission



28
29
30
31
32
33
# 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 = {}) ⇒ Object

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

Parameters:

  • schedule (Schedule)

    The schedule to change

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission

  • Invoicexpress::NotFound When the invoice doesn’t exist



89
90
91
92
93
94
# 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 = {}) ⇒ Object

Returns a specific schedule.

Parameters:

Returns:

  • Invoicexpress::Models::Schedule The schedule

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::NotFound When the schedule doesn’t exist



41
42
43
44
# 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 = {}) ⇒ Array<Invoicexpress::Models::Schedule>

Returns all your schedules.

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized



10
11
12
13
14
# 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 = {}) ⇒ Object

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.

Parameters:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

  • Invoicexpress::UnprocessableEntity When there are errors on the submission

  • Invoicexpress::NotFound When the invoice doesn’t exist



58
59
60
61
62
63
64
65
# 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