Class: FastBound::Item
- Inherits:
-
Base
- Object
- Base
- FastBound::Item
show all
- Includes:
- API
- Defined in:
- lib/fastbound-ruby/item.rb
Constant Summary
collapse
- CREATE_AND_EDIT_ATTRS =
{
permitted: %i(
external_id item_number do_not_dispose note manufacturer importer country_of_manufacture serial model caliber type
barrel_length total_length condition cost price mpn upc location location_verified_utc ttsn otsn submission_date
acquisition_type acquire_date acquire_purchase_order_number acquire_invoice_number acquire_shipment_tracking_number
disposition_type dispose_date dispose_purchase_order_number dispose_invoice_number dispose_shipment_tracking_number
theft_loss_discovered_date theft_loss_type theft_loss_atf_issued_incident_number theft_loss_police_incident_number
destroyed_date destroyed_description destroyed_witness_1 destroyed_witness_2
lightspeed_system_id lightspeed_serial_id lightspeed_sale_id
).freeze,
required: %i( manufacturer model serial caliber type ).freeze
}
- ENDPOINTS =
{
list: "items?%s".freeze,
fetch: "items/%s".freeze,
edit: "items/%s".freeze,
delete: "items/%s".freeze,
fetch_by_external_id: "items/getbyexternalid/%s".freeze,
undispose: "items/%s/undispose".freeze,
set_external_id: "items/%s/setexternalid".freeze,
set_external_ids: "items/setexternalids".freeze,
}
Constants included
from API
API::FILE_UPLOAD_ATTRS, API::ROOT_URL, API::USER_AGENT
Instance Method Summary
collapse
Methods included from API
#delete_request, #get_request, #post_file_request, #post_request, #put_request
Constructor Details
#initialize(client) ⇒ Item
Returns a new instance of Item.
32
33
34
|
# File 'lib/fastbound-ruby/item.rb', line 32
def initialize(client)
@client = client
end
|
Instance Method Details
#delete(item_id) ⇒ Object
55
56
57
58
59
|
# File 'lib/fastbound-ruby/item.rb', line 55
def delete(item_id)
endpoint = ENDPOINTS[:delete] % item_id
delete_request(@client, endpoint)
end
|
#edit(item_id, item_data) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/fastbound-ruby/item.rb', line 48
def edit(item_id, item_data)
endpoint = ENDPOINTS[:edit] % item_id
item_data = standardize_body_data(item_data, CREATE_AND_EDIT_ATTRS[:permitted])
put_request(@client, endpoint, item_data)
end
|
#fetch(item_id) ⇒ Object
42
43
44
45
46
|
# File 'lib/fastbound-ruby/item.rb', line 42
def fetch(item_id)
endpoint = ENDPOINTS[:fetch] % item_id
get_request(@client, endpoint)
end
|
#fetch_by_external_id(external_id) ⇒ Object
61
62
63
64
65
|
# File 'lib/fastbound-ruby/item.rb', line 61
def fetch_by_external_id(external_id)
endpoint = ENDPOINTS[:fetch_by_external_id] % external_id
get_request(@client, endpoint)
end
|
#list(params = {}) ⇒ Object
36
37
38
39
40
|
# File 'lib/fastbound-ruby/item.rb', line 36
def list(params = {})
endpoint = ENDPOINTS[:list] % convert_params_to_request_query(params)
get_request(@client, endpoint)
end
|
#set_external_id(item_id, external_id) ⇒ Object
73
74
75
76
77
78
|
# File 'lib/fastbound-ruby/item.rb', line 73
def set_external_id(item_id, external_id)
endpoint = ENDPOINTS[:set_external_id] % item_id
item_data = { externalId: external_id }
put_request(@client, endpoint, item_data)
end
|
#set_external_ids(item_id, items) ⇒ Object
80
81
82
83
84
85
86
|
# File 'lib/fastbound-ruby/item.rb', line 80
def set_external_ids(item_id, items)
endpoint = ENDPOINTS[:set_external_ids] % item_id
items = items.is_a?(Array) ? items : items[:items]
item_data = { items: items.each { |h| h[:externalId] ||= h.delete(:external_id) } }
put_request(@client, endpoint, item_data)
end
|
#undispose(item_id) ⇒ Object
67
68
69
70
71
|
# File 'lib/fastbound-ruby/item.rb', line 67
def undispose(item_id)
endpoint = ENDPOINTS[:undispose] % item_id
put_request(@client, endpoint)
end
|