Module: Invoicexpress::Client::Items

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

Instance Method Summary collapse

Instance Method Details

#create_item(item, options = {}) ⇒ Invoicexpress::Models::Item

Creates a new item. Regarding item taxes, if the tax name is not found, no tax is applied to that item.

Parameters:

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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



36
37
38
39
40
41
# File 'lib/invoicexpress/client/items.rb', line 36

def create_item(item, options={})
  raise(ArgumentError, "item has the wrong type") unless item.is_a?(Invoicexpress::Models::Item)

  params = { :klass => Invoicexpress::Models::Item, :body => item }
  post("items.xml", params.merge(options))
end

#delete_item(item, options = {}) ⇒ Object

Deletes an item.

Parameters:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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



62
63
64
65
# File 'lib/invoicexpress/client/items.rb', line 62

def delete_item(item, options={})
  params = { :klass => Invoicexpress::Models::Item }
  delete("items/#{id_from_item(item)}.xml", params.merge(options))
end

#item(item, options = {}) ⇒ Invoicexpress::Models::Item

Returns a specific item.

Parameters:

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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



23
24
25
26
27
# File 'lib/invoicexpress/client/items.rb', line 23

def item(item, options={})
  params = { :klass => Invoicexpress::Models::Item }

  get("items/#{id_from_item(item)}.xml", params.merge(options))
end

#items(options = {}) ⇒ Array<Invoicexpress::Models::Item>

Returns a list of all your items.

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized



11
12
13
14
15
# File 'lib/invoicexpress/client/items.rb', line 11

def items(options = {})
  params = { :klass => Invoicexpress::Models::Item }

  get("items.xml", params.merge(options))
end

#update_item(item, options = {}) ⇒ Invoicexpress::Models::Item

Updates an item.

Parameters:

Returns:

Raises:

  • Invoicexpress::Unauthorized When the client is unauthorized

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

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



50
51
52
53
54
55
# File 'lib/invoicexpress/client/items.rb', line 50

def update_item(item, options={})
  raise(ArgumentError, "item has the wrong type") unless item.is_a?(Invoicexpress::Models::Item)
  
  params = { :klass => Invoicexpress::Models::Item, :body => item }
  put("items/#{item.id}.xml", params.merge(options))
end