Class: FastBound::Disposition
- Inherits:
-
Base
- Object
- Base
- FastBound::Disposition
show all
- Includes:
- API
- Defined in:
- lib/fastbound-ruby/disposition.rb
Constant Summary
collapse
- CREATE_ATTRS =
{
permitted: %i(
external_id date type note ttsn generate_ttsn otsn purchase_order_number invoice_number
shipment_tracking_number is_manufacturing_disposition
).freeze,
required: %i( type ).freeze
}
- CREATE_AS_NFA_ATTRS =
{
permitted: %i(
external_id date submission_date type note ttsn generate_ttsn otsn purchase_order_number
invoice_number shipment_tracking_number
).freeze,
required: %i( type ).freeze
}
- CREATE_AS_THEFT_LOSS_ATTRS =
%i(
external_id date note theft_loss_discovered_date theft_loss_type theft_loss_police_incident_number
theft_loss_atf_issued_incident_number
).freeze
- CREATE_AS_DESTROYED_ATTRS =
%i(
external_id date note destroyed_date destroyed_description destroyed_witness_1 destroyed_witness_2
).freeze
- EDIT_AND_CREATE_COMMIT_ATTRS =
[
%i( request_type contact_id contact_external_id ),
CREATE_ATTRS[:permitted],
CREATE_AS_NFA_ATTRS[:permitted],
CREATE_AS_THEFT_LOSS_ATTRS,
CREATE_AS_DESTROYED_ATTRS
].flatten.uniq.freeze
- ITEM_ATTRS =
{
add: %i( id price ).freeze,
add_by_external_id: %i( external_id price ).freeze
}
- COMMIT_ATTRS =
%i(
change_manufacturer change_country_of_manufacture change_importer change_model change_caliber
change_type change_barrel_length change_overall_length change_condition change_cost change_price
change_mpn change_upc change_location change_item_note manufacturer country_of_manufacture importer
model caliber type barrel_length overall_length condition cost price mpn upc location item_note
).freeze
- ENDPOINTS =
{
list: "dispositions".freeze,
list_only_with_4473: "dispositions/only4473s".freeze,
create: "dispositions".freeze,
create_as_nfa: "dispositions/nfa".freeze,
create_as_theft_loss: "dispositions/theftloss".freeze,
create_as_destroyed: "dispositions/destroyed".freeze,
edit: "dispositions/%s".freeze,
fetch: "dispositions/%s".freeze,
fetch_by_external_id: "dispositions/getbyexternalid/%s".freeze,
delete: "dispositions/%s".freeze,
commit: "dispositions/%s/commit".freeze,
create_and_commit: "dispositions/createandcommit".freeze,
add_items: "dispositions/%s/items".freeze,
add_items_by_external_id: "dispositions/%s/items/addbyexternalid".freeze,
fetch_items: "dispositions/%s/items".freeze,
edit_item_price: "dispositions/%s/items/%s".freeze,
remove_item: "dispositions/%s/items/remove/%s".freeze,
remove_item_by_external_id: "dispositions/%s/items/removebyexternalid/%s".freeze,
attach_contact: "dispositions/%s/attachcontact/%s".freeze
}
Constants included
from API
API::FILE_UPLOAD_ATTRS, API::ROOT_URL, API::USER_AGENT
Instance Method Summary
collapse
-
#add_items(disposition_id, items_data) ⇒ Object
-
#add_items_by_external_id(disposition_id, items_data) ⇒ Object
-
#attach_contact(disposition_id, contact_id) ⇒ Object
-
#commit(disposition_id, commit_data = {}) ⇒ Object
-
#create(disposition_data) ⇒ Object
-
#create_and_commit(disposition_data, items_data, contact_data = {}, commit_data = nil) ⇒ Object
-
#create_as_destroyed(disposition_data) ⇒ Object
-
#create_as_nfa(disposition_data) ⇒ Object
-
#create_as_theft_loss(disposition_data) ⇒ Object
-
#delete(disposition_id) ⇒ Object
-
#edit(disposition_id, disposition_data) ⇒ Object
-
#edit_item_price(disposition_id, item_id, price) ⇒ Object
-
#fetch(disposition_id) ⇒ Object
-
#fetch_by_external_id(external_id) ⇒ Object
-
#fetch_items(disposition_id) ⇒ Object
-
#initialize(client) ⇒ Disposition
constructor
A new instance of Disposition.
-
#list(params = {}) ⇒ Object
-
#list_only_with_4473(params = {}) ⇒ Object
-
#remove_item(disposition_id, item_id) ⇒ Object
-
#remove_item_by_external_id(disposition_id, external_id) ⇒ Object
Methods included from API
#delete_request, #get_request, #post_file_request, #post_request, #put_request
Constructor Details
Returns a new instance of Disposition.
75
76
77
|
# File 'lib/fastbound-ruby/disposition.rb', line 75
def initialize(client)
@client = client
end
|
Instance Method Details
#add_items(disposition_id, items_data) ⇒ Object
171
172
173
174
175
176
177
178
|
# File 'lib/fastbound-ruby/disposition.rb', line 171
def add_items(disposition_id, items_data)
items_data.each { |item| requires!(item, :id) }
endpoint = ENDPOINTS[:add_items] % disposition_id
items_data = { items: items_data.map { |item| standardize_body_data(item, ITEM_ATTRS[:add]) } }
post_request(@client, endpoint, items_data)
end
|
#add_items_by_external_id(disposition_id, items_data) ⇒ Object
180
181
182
183
184
185
186
187
|
# File 'lib/fastbound-ruby/disposition.rb', line 180
def add_items_by_external_id(disposition_id, items_data)
items_data.each { |item| requires!(item, :external_id) }
endpoint = ENDPOINTS[:add_items_by_external_id] % disposition_id
items_data = { items: items_data.map { |item| standardize_body_data(item, ITEM_ATTRS[:add_by_external_id]) } }
post_request(@client, endpoint, items_data)
end
|
214
215
216
217
218
|
# File 'lib/fastbound-ruby/disposition.rb', line 214
def attach_contact(disposition_id, contact_id)
endpoint = ENDPOINTS[:attach_contact] % [disposition_id, contact_id]
put_request(@client, endpoint)
end
|
#commit(disposition_id, commit_data = {}) ⇒ Object
148
149
150
151
152
153
|
# File 'lib/fastbound-ruby/disposition.rb', line 148
def commit(disposition_id, commit_data = {})
endpoint = ENDPOINTS[:commit] % disposition_id
commit_data = { manufacturingChanges: standardize_body_data(commit_data, COMMIT_ATTRS) }
post_request(@client, endpoint, commit_data)
end
|
#create(disposition_data) ⇒ Object
91
92
93
94
95
96
97
98
|
# File 'lib/fastbound-ruby/disposition.rb', line 91
def create(disposition_data)
requires!(disposition_data, *CREATE_ATTRS[:required])
endpoint = ENDPOINTS[:create]
disposition_data = standardize_body_data(disposition_data, CREATE_ATTRS[:permitted])
post_request(@client, endpoint, disposition_data)
end
|
#create_and_commit(disposition_data, items_data, contact_data = {}, commit_data = nil) ⇒ Object
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/fastbound-ruby/disposition.rb', line 155
def create_and_commit(disposition_data, items_data, contact_data = {}, commit_data = nil)
items_data.each { |item| requires!(item, :id) }
endpoint = ENDPOINTS[:create_and_commit]
disposition_data = standardize_body_data(disposition_data, EDIT_AND_CREATE_COMMIT_ATTRS)
items_data = items_data.map { |item| standardize_body_data(item, ITEM_ATTRS[:add]) }
contact_data = standardize_body_data(contact_data, Contact::CREATE_AND_EDIT_ATTRS)
request_data = disposition_data.merge(
contact: contact_data,
items: items_data,
manufacturingChanges: commit_data
).compact
post_request(@client, endpoint, request_data)
end
|
#create_as_destroyed(disposition_data) ⇒ Object
116
117
118
119
120
121
|
# File 'lib/fastbound-ruby/disposition.rb', line 116
def create_as_destroyed(disposition_data)
endpoint = ENDPOINTS[:create_as_destroyed]
disposition_data = standardize_body_data(disposition_data, CREATE_AS_DESTROYED_ATTRS)
post_request(@client, endpoint, disposition_data)
end
|
#create_as_nfa(disposition_data) ⇒ Object
100
101
102
103
104
105
106
107
|
# File 'lib/fastbound-ruby/disposition.rb', line 100
def create_as_nfa(disposition_data)
requires!(disposition_data, *CREATE_AS_NFA_ATTRS[:required])
endpoint = ENDPOINTS[:create_as_nfa]
disposition_data = standardize_body_data(disposition_data, CREATE_AS_NFA_ATTRS[:permitted])
post_request(@client, endpoint, disposition_data)
end
|
#create_as_theft_loss(disposition_data) ⇒ Object
109
110
111
112
113
114
|
# File 'lib/fastbound-ruby/disposition.rb', line 109
def create_as_theft_loss(disposition_data)
endpoint = ENDPOINTS[:create_as_theft_loss]
disposition_data = standardize_body_data(disposition_data, CREATE_AS_THEFT_LOSS_ATTRS)
post_request(@client, endpoint, disposition_data)
end
|
#delete(disposition_id) ⇒ Object
142
143
144
145
146
|
# File 'lib/fastbound-ruby/disposition.rb', line 142
def delete(disposition_id)
endpoint = ENDPOINTS[:delete] % disposition_id
delete_request(@client, endpoint)
end
|
#edit(disposition_id, disposition_data) ⇒ Object
123
124
125
126
127
128
|
# File 'lib/fastbound-ruby/disposition.rb', line 123
def edit(disposition_id, disposition_data)
endpoint = ENDPOINTS[:edit] % disposition_id
disposition_data = standardize_body_data(disposition_data, EDIT_AND_CREATE_COMMIT_ATTRS)
put_request(@client, endpoint, disposition_data)
end
|
#edit_item_price(disposition_id, item_id, price) ⇒ Object
195
196
197
198
199
200
|
# File 'lib/fastbound-ruby/disposition.rb', line 195
def edit_item_price(disposition_id, item_id, price)
endpoint = ENDPOINTS[:edit_item_price] % [disposition_id, item_id]
item_data = { price: price }
put_request(@client, endpoint, item_data)
end
|
#fetch(disposition_id) ⇒ Object
130
131
132
133
134
|
# File 'lib/fastbound-ruby/disposition.rb', line 130
def fetch(disposition_id)
endpoint = ENDPOINTS[:fetch] % disposition_id
get_request(@client, endpoint)
end
|
#fetch_by_external_id(external_id) ⇒ Object
136
137
138
139
140
|
# File 'lib/fastbound-ruby/disposition.rb', line 136
def fetch_by_external_id(external_id)
endpoint = ENDPOINTS[:fetch_by_external_id] % external_id
get_request(@client, endpoint)
end
|
#fetch_items(disposition_id) ⇒ Object
189
190
191
192
193
|
# File 'lib/fastbound-ruby/disposition.rb', line 189
def fetch_items(disposition_id)
endpoint = ENDPOINTS[:fetch_items] % disposition_id
get_request(@client, endpoint)
end
|
#list(params = {}) ⇒ Object
79
80
81
82
83
|
# File 'lib/fastbound-ruby/disposition.rb', line 79
def list(params = {})
endpoint = ENDPOINTS[:list] % convert_params_to_request_query(params)
get_request(@client, endpoint)
end
|
#list_only_with_4473(params = {}) ⇒ Object
85
86
87
88
89
|
# File 'lib/fastbound-ruby/disposition.rb', line 85
def list_only_with_4473(params = {})
endpoint = ENDPOINTS[:list_only_with_4473] % convert_params_to_request_query(params)
get_request(@client, endpoint)
end
|
#remove_item(disposition_id, item_id) ⇒ Object
202
203
204
205
206
|
# File 'lib/fastbound-ruby/disposition.rb', line 202
def remove_item(disposition_id, item_id)
endpoint = ENDPOINTS[:remove_item] % [disposition_id, item_id]
delete_request(@client, endpoint)
end
|
#remove_item_by_external_id(disposition_id, external_id) ⇒ Object
208
209
210
211
212
|
# File 'lib/fastbound-ruby/disposition.rb', line 208
def remove_item_by_external_id(disposition_id, external_id)
endpoint = ENDPOINTS[:remove_item_by_external_id] % [disposition_id, external_id]
delete_request(@client, endpoint)
end
|