fastbound-ruby 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +67 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +57 -0
- data/LICENSE +21 -0
- data/README.md +33 -0
- data/bin/console +10 -0
- data/bin/setup +3 -0
- data/fastbound-ruby.gemspec +24 -0
- data/lib/fastbound-ruby/account.rb +23 -0
- data/lib/fastbound-ruby/acquisition.rb +134 -0
- data/lib/fastbound-ruby/api.rb +121 -0
- data/lib/fastbound-ruby/attachment.rb +23 -0
- data/lib/fastbound-ruby/base.rb +24 -0
- data/lib/fastbound-ruby/client.rb +59 -0
- data/lib/fastbound-ruby/contact.rb +123 -0
- data/lib/fastbound-ruby/disposition.rb +222 -0
- data/lib/fastbound-ruby/error.rb +11 -0
- data/lib/fastbound-ruby/item.rb +89 -0
- data/lib/fastbound-ruby/response.rb +48 -0
- data/lib/fastbound-ruby/smart_list.rb +34 -0
- data/lib/fastbound-ruby/version.rb +3 -0
- data/lib/fastbound-ruby/webhook.rb +60 -0
- data/lib/fastbound-ruby.rb +18 -0
- data/rakefile +20 -0
- metadata +125 -0
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'fastbound-ruby/api'
|
2
|
+
|
3
|
+
module FastBound
|
4
|
+
class Contact < Base
|
5
|
+
|
6
|
+
include FastBound::API
|
7
|
+
|
8
|
+
CREATE_AND_EDIT_ATTRS = {
|
9
|
+
permitted: %i(
|
10
|
+
external_id ffl_number ffl_expires lookup_ffl license_name trade_name sotein sot_class business_type
|
11
|
+
organization_name first_name middle_name last_name premise_address_1 premise_address_2 premise_city
|
12
|
+
premise_county premise_state premise_zip_code premise_country phone_number fax email_address
|
13
|
+
).freeze,
|
14
|
+
required: %i( ffl_number ffl_expires premise_address_1 premise_city premise_state premise_zip_code ).freeze
|
15
|
+
}
|
16
|
+
|
17
|
+
CREATE_AND_EDIT_LICENSE_ATTRS = {
|
18
|
+
permitted: %i( type number expiration copy_on_file ).freeze,
|
19
|
+
required: %i( type number ).freeze
|
20
|
+
}
|
21
|
+
|
22
|
+
MERGE_ATTRS = {
|
23
|
+
permitted: %i( winning_contact_id losing_contact_id ).freeze,
|
24
|
+
required: %i( winning_contact_id losing_contact_id ).freeze
|
25
|
+
}
|
26
|
+
|
27
|
+
ENDPOINTS = {
|
28
|
+
list: "contacts?%s".freeze,
|
29
|
+
create: "contacts".freeze,
|
30
|
+
edit: "contacts/%s".freeze,
|
31
|
+
fetch: "contacts/%s".freeze,
|
32
|
+
fetch_by_external_id: "contacts/getbyexternalid/%s".freeze,
|
33
|
+
delete: "contacts/%s".freeze,
|
34
|
+
merge: "contacts/merge".freeze,
|
35
|
+
create_license: "contacts/%s/licenses".freeze,
|
36
|
+
edit_license: "contacts/%s/licenses/%s".freeze,
|
37
|
+
fetch_license: "contacts/%s/licenses/%s".freeze,
|
38
|
+
delete_license: "contacts/%s/licenses/%s".freeze,
|
39
|
+
}
|
40
|
+
|
41
|
+
def initialize(client)
|
42
|
+
@client = client
|
43
|
+
end
|
44
|
+
|
45
|
+
def list(params = {})
|
46
|
+
endpoint = ENDPOINTS[:list] % convert_params_to_request_query(params)
|
47
|
+
|
48
|
+
get_request(@client, endpoint)
|
49
|
+
end
|
50
|
+
|
51
|
+
def create(contact_data)
|
52
|
+
requires!(contact_data, CREATE_AND_EDIT_ATTRS[:required])
|
53
|
+
|
54
|
+
endpoint = ENDPOINTS[:create]
|
55
|
+
contact_data = standardize_body_data(contact_data, CREATE_AND_EDIT_ATTRS[:permitted])
|
56
|
+
|
57
|
+
post_request(@client, endpoint, contact_data)
|
58
|
+
end
|
59
|
+
|
60
|
+
def edit(contact_id, contact_data)
|
61
|
+
endpoint = ENDPOINTS[:edit] % contact_id
|
62
|
+
contact_data = standardize_body_data(contact_data, CREATE_AND_EDIT_ATTRS[:permitted])
|
63
|
+
|
64
|
+
put_request(@client, endpoint, contact_data)
|
65
|
+
end
|
66
|
+
|
67
|
+
def fetch(contact_id)
|
68
|
+
endpoint = ENDPOINTS[:fetch] % contact_id
|
69
|
+
|
70
|
+
get_request(@client, endpoint)
|
71
|
+
end
|
72
|
+
|
73
|
+
def fetch_by_external_id(external_id)
|
74
|
+
endpoint = ENDPOINTS[:fetch_by_external_id] % external_id
|
75
|
+
|
76
|
+
get_request(@client, endpoint)
|
77
|
+
end
|
78
|
+
|
79
|
+
def delete(contact_id)
|
80
|
+
endpoint = ENDPOINTS[:delete] % contact_id
|
81
|
+
|
82
|
+
delete_request(@client, endpoint)
|
83
|
+
end
|
84
|
+
|
85
|
+
def merge(merge_data)
|
86
|
+
requires!(merge_data, MERGE_ATTRS[:required])
|
87
|
+
|
88
|
+
endpoint = ENDPOINTS[:merge]
|
89
|
+
merge_data = standardize_body_data(merge_data, MERGE_ATTRS[:permitted])
|
90
|
+
|
91
|
+
post_request(@client, endpoint, merge_data)
|
92
|
+
end
|
93
|
+
|
94
|
+
def create_license(contact_id, license_data)
|
95
|
+
requires!(license_data, CREATE_AND_EDIT_LICENSE_ATTRS[:required])
|
96
|
+
|
97
|
+
endpoint = ENDPOINTS[:create_license] % contact_id
|
98
|
+
license_data = standardize_body_data(license_data, CREATE_AND_EDIT_LICENSE_ATTRS[:permitted])
|
99
|
+
|
100
|
+
post_request(@client, endpoint, license_data)
|
101
|
+
end
|
102
|
+
|
103
|
+
def edit_license(contact_id, license_data)
|
104
|
+
endpoint = ENDPOINTS[:edit_license] % contact_id
|
105
|
+
license_data = standardize_body_data(license_data, CREATE_AND_EDIT_LICENSE_ATTRS[:permitted])
|
106
|
+
|
107
|
+
put_request(@client, endpoint, license_data)
|
108
|
+
end
|
109
|
+
|
110
|
+
def fetch_license(contact_id, license_id)
|
111
|
+
endpoint = ENDPOINTS[:fetch_license] % [contact_id, license_id]
|
112
|
+
|
113
|
+
get_request(@client, endpoint)
|
114
|
+
end
|
115
|
+
|
116
|
+
def delete_license(contact_id, license_id)
|
117
|
+
endpoint = ENDPOINTS[:delete_license] % [contact_id, license_id]
|
118
|
+
|
119
|
+
delete_request(@client, endpoint)
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,222 @@
|
|
1
|
+
require 'fastbound-ruby/api'
|
2
|
+
|
3
|
+
module FastBound
|
4
|
+
class Disposition < Base
|
5
|
+
|
6
|
+
include FastBound::API
|
7
|
+
|
8
|
+
CREATE_ATTRS = {
|
9
|
+
permitted: %i(
|
10
|
+
external_id date type note ttsn generate_ttsn otsn purchase_order_number invoice_number
|
11
|
+
shipment_tracking_number is_manufacturing_disposition
|
12
|
+
).freeze,
|
13
|
+
required: %i( type ).freeze
|
14
|
+
}
|
15
|
+
|
16
|
+
CREATE_AS_NFA_ATTRS = {
|
17
|
+
permitted: %i(
|
18
|
+
external_id date submission_date type note ttsn generate_ttsn otsn purchase_order_number
|
19
|
+
invoice_number shipment_tracking_number
|
20
|
+
).freeze,
|
21
|
+
required: %i( type ).freeze
|
22
|
+
}
|
23
|
+
|
24
|
+
CREATE_AS_THEFT_LOSS_ATTRS = %i(
|
25
|
+
external_id date note theft_loss_discovered_date theft_loss_type theft_loss_police_incident_number
|
26
|
+
theft_loss_atf_issued_incident_number
|
27
|
+
).freeze
|
28
|
+
|
29
|
+
CREATE_AS_DESTROYED_ATTRS = %i(
|
30
|
+
external_id date note destroyed_date destroyed_description destroyed_witness_1 destroyed_witness_2
|
31
|
+
).freeze
|
32
|
+
|
33
|
+
EDIT_AND_CREATE_COMMIT_ATTRS = [
|
34
|
+
%i( request_type contact_id contact_external_id ),
|
35
|
+
CREATE_ATTRS[:permitted],
|
36
|
+
CREATE_AS_NFA_ATTRS[:permitted],
|
37
|
+
CREATE_AS_THEFT_LOSS_ATTRS,
|
38
|
+
CREATE_AS_DESTROYED_ATTRS
|
39
|
+
].flatten.uniq.freeze
|
40
|
+
|
41
|
+
ITEM_ATTRS = {
|
42
|
+
add: %i( id price ).freeze,
|
43
|
+
add_by_external_id: %i( external_id price ).freeze
|
44
|
+
}
|
45
|
+
|
46
|
+
COMMIT_ATTRS = %i(
|
47
|
+
change_manufacturer change_country_of_manufacture change_importer change_model change_caliber
|
48
|
+
change_type change_barrel_length change_overall_length change_condition change_cost change_price
|
49
|
+
change_mpn change_upc change_location change_item_note manufacturer country_of_manufacture importer
|
50
|
+
model caliber type barrel_length overall_length condition cost price mpn upc location item_note
|
51
|
+
).freeze
|
52
|
+
|
53
|
+
ENDPOINTS = {
|
54
|
+
list: "dispositions".freeze,
|
55
|
+
list_only_with_4473: "dispositions/only4473s".freeze,
|
56
|
+
create: "dispositions".freeze,
|
57
|
+
create_as_nfa: "dispositions/nfa".freeze,
|
58
|
+
create_as_theft_loss: "dispositions/theftloss".freeze,
|
59
|
+
create_as_destroyed: "dispositions/destroyed".freeze,
|
60
|
+
edit: "dispositions/%s".freeze,
|
61
|
+
fetch: "dispositions/%s".freeze,
|
62
|
+
fetch_by_external_id: "dispositions/getbyexternalid/%s".freeze,
|
63
|
+
delete: "dispositions/%s".freeze,
|
64
|
+
commit: "dispositions/%s/commit".freeze,
|
65
|
+
create_and_commit: "dispositions/createandcommit".freeze,
|
66
|
+
add_items: "dispositions/%s/items".freeze,
|
67
|
+
add_items_by_external_id: "dispositions/%s/items/addbyexternalid".freeze,
|
68
|
+
fetch_items: "dispositions/%s/items".freeze,
|
69
|
+
edit_item_price: "dispositions/%s/items/%s".freeze,
|
70
|
+
remove_item: "dispositions/%s/items/remove/%s".freeze,
|
71
|
+
remove_item_by_external_id: "dispositions/%s/items/removebyexternalid/%s".freeze,
|
72
|
+
attach_contact: "dispositions/%s/attachcontact/%s".freeze
|
73
|
+
}
|
74
|
+
|
75
|
+
def initialize(client)
|
76
|
+
@client = client
|
77
|
+
end
|
78
|
+
|
79
|
+
def list(params = {})
|
80
|
+
endpoint = ENDPOINTS[:list] % convert_params_to_request_query(params)
|
81
|
+
|
82
|
+
get_request(@client, endpoint)
|
83
|
+
end
|
84
|
+
|
85
|
+
def list_only_with_4473(params = {})
|
86
|
+
endpoint = ENDPOINTS[:list_only_with_4473] % convert_params_to_request_query(params)
|
87
|
+
|
88
|
+
get_request(@client, endpoint)
|
89
|
+
end
|
90
|
+
|
91
|
+
def create(disposition_data)
|
92
|
+
requires!(disposition_data, CREATE_ATTRS[:required])
|
93
|
+
|
94
|
+
endpoint = ENDPOINTS[:create]
|
95
|
+
disposition_data = standardize_body_data(disposition_data, CREATE_ATTRS[:permitted])
|
96
|
+
|
97
|
+
post_request(@client, endpoint, disposition_data)
|
98
|
+
end
|
99
|
+
|
100
|
+
def create_as_nfa(disposition_data)
|
101
|
+
requires!(disposition_data, CREATE_AS_NFA_ATTRS[:required])
|
102
|
+
|
103
|
+
endpoint = ENDPOINTS[:create_as_nfa]
|
104
|
+
disposition_data = standardize_body_data(disposition_data, CREATE_AS_NFA_ATTRS[:permitted])
|
105
|
+
|
106
|
+
post_request(@client, endpoint, disposition_data)
|
107
|
+
end
|
108
|
+
|
109
|
+
def create_as_theft_loss(disposition_data)
|
110
|
+
endpoint = ENDPOINTS[:create_as_theft_loss]
|
111
|
+
disposition_data = standardize_body_data(disposition_data, CREATE_AS_THEFT_LOSS_ATTRS)
|
112
|
+
|
113
|
+
post_request(@client, endpoint, disposition_data)
|
114
|
+
end
|
115
|
+
|
116
|
+
def create_as_destroyed(disposition_data)
|
117
|
+
endpoint = ENDPOINTS[:create_as_destroyed]
|
118
|
+
disposition_data = standardize_body_data(disposition_data, CREATE_AS_DESTROYED_ATTRS)
|
119
|
+
|
120
|
+
post_request(@client, endpoint, disposition_data)
|
121
|
+
end
|
122
|
+
|
123
|
+
def edit(disposition_id, disposition_data)
|
124
|
+
endpoint = ENDPOINTS[:edit] % disposition_id
|
125
|
+
disposition_data = standardize_body_data(disposition_data, EDIT_AND_CREATE_COMMIT_ATTRS)
|
126
|
+
|
127
|
+
put_request(@client, endpoint, disposition_data)
|
128
|
+
end
|
129
|
+
|
130
|
+
def fetch(disposition_id)
|
131
|
+
endpoint = ENDPOINTS[:fetch] % disposition_id
|
132
|
+
|
133
|
+
get_request(@client, endpoint)
|
134
|
+
end
|
135
|
+
|
136
|
+
def fetch_by_external_id(external_id)
|
137
|
+
endpoint = ENDPOINTS[:fetch_by_external_id] % external_id
|
138
|
+
|
139
|
+
get_request(@client, endpoint)
|
140
|
+
end
|
141
|
+
|
142
|
+
def delete(disposition_id)
|
143
|
+
endpoint = ENDPOINTS[:delete] % disposition_id
|
144
|
+
|
145
|
+
delete_request(@client, endpoint)
|
146
|
+
end
|
147
|
+
|
148
|
+
def commit(disposition_id, commit_data = {})
|
149
|
+
endpoint = ENDPOINTS[:commit] % disposition_id
|
150
|
+
commit_data = { manufacturingChanges: standardize_body_data(commit_data, COMMIT_ATTRS) }
|
151
|
+
|
152
|
+
post_request(@client, endpoint, commit_data)
|
153
|
+
end
|
154
|
+
|
155
|
+
def create_and_commit(disposition_data, items_data, contact_data, commit_data = {})
|
156
|
+
requires!(contact_data, Contact::CREATE_AND_EDIT_ATTRS[:required])
|
157
|
+
items_data.each { |item| requires!(item, :id) }
|
158
|
+
|
159
|
+
endpoint = ENDPOINTS[:create_and_commit]
|
160
|
+
disposition_data = standardize_body_data(disposition_data, EDIT_AND_CREATE_COMMIT_ATTRS)
|
161
|
+
items_data = items_data.map { |item| standardize_body_data(item, ITEM_ATTRS[:add]) }
|
162
|
+
contact_data = standardize_body_data(contact_data, Contact::CREATE_AND_EDIT_ATTRS[:permitted])
|
163
|
+
request_data = disposition_data.merge(
|
164
|
+
contact: contact_data,
|
165
|
+
items: items_data,
|
166
|
+
manufacturingChanges: commit_data
|
167
|
+
)
|
168
|
+
|
169
|
+
post_request(@client, endpoint, request_data)
|
170
|
+
end
|
171
|
+
|
172
|
+
def add_items(disposition_id, items_data)
|
173
|
+
items_data.each { |item| requires!(item, :id) }
|
174
|
+
|
175
|
+
endpoint = ENDPOINTS[:add_items] % disposition_id
|
176
|
+
items_data = { items: items_data.map { |item| standardize_body_data(item, ITEM_ATTRS[:add]) } }
|
177
|
+
|
178
|
+
post_request(@client, endpoint, items_data)
|
179
|
+
end
|
180
|
+
|
181
|
+
def add_items_by_external_id(disposition_id, items_data)
|
182
|
+
items_data.each { |item| requires!(item, :external_id) }
|
183
|
+
|
184
|
+
endpoint = ENDPOINTS[:add_items_by_external_id] % disposition_id
|
185
|
+
items_data = { items: items_data.map { |item| standardize_body_data(item, ITEM_ATTRS[:add_by_external_id]) } }
|
186
|
+
|
187
|
+
post_request(@client, endpoint, items_data)
|
188
|
+
end
|
189
|
+
|
190
|
+
def fetch_items(disposition_id)
|
191
|
+
endpoint = ENDPOINTS[:fetch_items] % disposition_id
|
192
|
+
|
193
|
+
get_request(@client, endpoint)
|
194
|
+
end
|
195
|
+
|
196
|
+
def edit_item_price(disposition_id, item_id, price)
|
197
|
+
endpoint = ENDPOINTS[:edit_item_price] % [disposition_id, item_id]
|
198
|
+
item_data = { price: price }
|
199
|
+
|
200
|
+
put_request(@client, endpoint, item_data)
|
201
|
+
end
|
202
|
+
|
203
|
+
def remove_item(disposition_id, item_id)
|
204
|
+
endpoint = ENDPOINTS[:remove_item] % [disposition_id, item_id]
|
205
|
+
|
206
|
+
delete_request(@client, endpoint)
|
207
|
+
end
|
208
|
+
|
209
|
+
def remove_item_by_external_id(disposition_id, external_id)
|
210
|
+
endpoint = ENDPOINTS[:remove_item_by_external_id] % [disposition_id, external_id]
|
211
|
+
|
212
|
+
delete_request(@client, endpoint)
|
213
|
+
end
|
214
|
+
|
215
|
+
def attach_contact(disposition_id, contact_id)
|
216
|
+
endpoint = ENDPOINTS[:attach_contact] % [disposition_id, contact_id]
|
217
|
+
|
218
|
+
put_request(@client, endpoint)
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module FastBound
|
2
|
+
class Error < StandardError
|
3
|
+
|
4
|
+
class NoContent < FastBound::Error; end
|
5
|
+
class NotAuthorized < FastBound::Error; end
|
6
|
+
class NotFound < FastBound::Error; end
|
7
|
+
class RequestError < FastBound::Error; end
|
8
|
+
class TimeoutError < FastBound::Error; end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'fastbound-ruby/api'
|
2
|
+
|
3
|
+
module FastBound
|
4
|
+
class Item < Base
|
5
|
+
|
6
|
+
include FastBound::API
|
7
|
+
|
8
|
+
CREATE_AND_EDIT_ATTRS = {
|
9
|
+
permitted: %i(
|
10
|
+
external_id item_number do_not_dispose note manufacturer importer country_of_manufacture serial model caliber type
|
11
|
+
barrel_length total_length condition cost price mpn upc location location_verified_utc ttsn otsn submission_date
|
12
|
+
acquisition_type acquire_date acquire_purchase_order_number acquire_invoice_number acquire_shipment_tracking_number
|
13
|
+
disposition_type dispose_date dispose_purchase_order_number dispose_invoice_number dispose_shipment_tracking_number
|
14
|
+
theft_loss_discovered_date theft_loss_type theft_loss_atf_issued_incident_number theft_loss_police_incident_number
|
15
|
+
destroyed_date destroyed_description destroyed_witness_1 destroyed_witness_2
|
16
|
+
lightspeed_system_id lightspeed_serial_id lightspeed_sale_id
|
17
|
+
).freeze,
|
18
|
+
required: %i( manufacturer model serial caliber type ).freeze
|
19
|
+
}
|
20
|
+
|
21
|
+
ENDPOINTS = {
|
22
|
+
list: "items".freeze,
|
23
|
+
fetch: "items/%s".freeze,
|
24
|
+
edit: "items/%s".freeze,
|
25
|
+
delete: "items/%s".freeze,
|
26
|
+
fetch_by_external_id: "items/getbyexternalid/%s".freeze,
|
27
|
+
undispose: "items/%s/undispose".freeze,
|
28
|
+
set_external_id: "items/%s/setexternalid".freeze,
|
29
|
+
set_external_ids: "items/setexternalids".freeze,
|
30
|
+
}
|
31
|
+
|
32
|
+
def initialize(client)
|
33
|
+
@client = client
|
34
|
+
end
|
35
|
+
|
36
|
+
def list
|
37
|
+
endpoint = ENDPOINTS[:list]
|
38
|
+
|
39
|
+
get_request(@client, endpoint)
|
40
|
+
end
|
41
|
+
|
42
|
+
def fetch(item_id)
|
43
|
+
endpoint = ENDPOINTS[:fetch] % item_id
|
44
|
+
|
45
|
+
get_request(@client, endpoint)
|
46
|
+
end
|
47
|
+
|
48
|
+
def edit(item_id, item_data)
|
49
|
+
endpoint = ENDPOINTS[:edit] % item_id
|
50
|
+
item_data = standardize_body_data(item_data, CREATE_AND_EDIT_ATTRS[:permitted])
|
51
|
+
|
52
|
+
put_request(@client, endpoint, item_data)
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete(item_id)
|
56
|
+
endpoint = ENDPOINTS[:delete] % item_id
|
57
|
+
|
58
|
+
delete_request(@client, endpoint)
|
59
|
+
end
|
60
|
+
|
61
|
+
def fetch_by_external_id(external_id)
|
62
|
+
endpoint = ENDPOINTS[:fetch_by_external_id] % external_id
|
63
|
+
|
64
|
+
get_request(@client, endpoint)
|
65
|
+
end
|
66
|
+
|
67
|
+
def undispose(item_id)
|
68
|
+
endpoint = ENDPOINTS[:undispose] % item_id
|
69
|
+
|
70
|
+
put_request(@client, endpoint)
|
71
|
+
end
|
72
|
+
|
73
|
+
def set_external_id(item_id, external_id)
|
74
|
+
endpoint = ENDPOINTS[:set_external_id] % item_id
|
75
|
+
item_data = { externalId: external_id }
|
76
|
+
|
77
|
+
put_request(@client, endpoint, item_data)
|
78
|
+
end
|
79
|
+
|
80
|
+
def set_external_ids(item_id, items)
|
81
|
+
endpoint = ENDPOINTS[:set_external_ids] % item_id
|
82
|
+
items = items.is_a?(Array) ? items : items[:items]
|
83
|
+
item_data = { items: items.each { |h| h[:externalId] ||= h.delete(:external_id) } }
|
84
|
+
|
85
|
+
put_request(@client, endpoint, item_data)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module FastBound
|
2
|
+
class Response
|
3
|
+
|
4
|
+
attr_accessor :success
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@response = response
|
8
|
+
|
9
|
+
case @response
|
10
|
+
when Net::HTTPUnauthorized
|
11
|
+
raise FastBound::Error::NotAuthorized.new(@response.body)
|
12
|
+
when Net::HTTPNotFound
|
13
|
+
raise FastBound::Error::NotFound.new(@response.body)
|
14
|
+
when Net::HTTPNoContent
|
15
|
+
raise FastBound::Error::NoContent.new(@response.body)
|
16
|
+
when Net::HTTPOK, Net::HTTPSuccess
|
17
|
+
self.success = true
|
18
|
+
_data = (JSON.parse(@response.body) if @response.body.present?)
|
19
|
+
|
20
|
+
@data = case
|
21
|
+
when _data.is_a?(Hash)
|
22
|
+
_data.deep_symbolize_keys
|
23
|
+
when _data.is_a?(Array)
|
24
|
+
_data.map(&:deep_symbolize_keys)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
raise FastBound::Error::RequestError.new(@response.body)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def [](key)
|
32
|
+
@data[key]
|
33
|
+
end
|
34
|
+
|
35
|
+
def body
|
36
|
+
@data
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch(key)
|
40
|
+
@data.fetch(key)
|
41
|
+
end
|
42
|
+
|
43
|
+
def success?
|
44
|
+
!!success
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'fastbound-ruby/api'
|
2
|
+
|
3
|
+
module FastBound
|
4
|
+
class SmartList < Base
|
5
|
+
|
6
|
+
include FastBound::API
|
7
|
+
|
8
|
+
ENDPOINTS = {
|
9
|
+
acquire_type: "smartlists/acquiretype".freeze,
|
10
|
+
caliber: "smartlists/caliber".freeze,
|
11
|
+
condition: "smartlists/condition".freeze,
|
12
|
+
country_of_manufacture: "smartlists/countryofmanufacture".freeze,
|
13
|
+
delete_type: "smartlists/deletetype".freeze,
|
14
|
+
dispose_type: "smartlists/disposetype".freeze,
|
15
|
+
importer: "smartlists/importer".freeze,
|
16
|
+
item_type: "smartlists/itemtype".freeze,
|
17
|
+
license_type: "smartlists/licensetype".freeze,
|
18
|
+
location: "smartlists/location".freeze,
|
19
|
+
theft_loss_type: "smartlists/theftlosstype".freeze,
|
20
|
+
manufacturer: "smartlists/manufacturer".freeze,
|
21
|
+
manufacturing_dispose_type: "smartlists/manufacturingdisposetype".freeze,
|
22
|
+
manufacturing_acquire_type: "smartlists/manufacturingacquiretype".freeze
|
23
|
+
}
|
24
|
+
|
25
|
+
def initialize(client)
|
26
|
+
@client = client
|
27
|
+
end
|
28
|
+
|
29
|
+
ENDPOINTS.keys.each do |endpoint|
|
30
|
+
define_method(endpoint) { get_request(@client, ENDPOINTS[endpoint]) }
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'fastbound-ruby/api'
|
2
|
+
|
3
|
+
module FastBound
|
4
|
+
class Webhook < Base
|
5
|
+
|
6
|
+
include FastBound::API
|
7
|
+
|
8
|
+
CREATE_AND_EDIT_ATTRS = {
|
9
|
+
permitted: %i( name url description events ).freeze,
|
10
|
+
required: %i( name url events ).freeze
|
11
|
+
}
|
12
|
+
|
13
|
+
ENDPOINTS = {
|
14
|
+
create: "webhooks".freeze,
|
15
|
+
edit: "webhooks/%s".freeze,
|
16
|
+
fetch: "webhooks/%s".freeze,
|
17
|
+
delete: "webhooks/%s".freeze,
|
18
|
+
events: "webhooks/events".freeze
|
19
|
+
}
|
20
|
+
|
21
|
+
def initialize(client)
|
22
|
+
@client = client
|
23
|
+
end
|
24
|
+
|
25
|
+
def create(webhook_data)
|
26
|
+
requires!(webhook_data, CREATE_AND_EDIT_ATTRS[:required])
|
27
|
+
|
28
|
+
endpoint = ENDPOINTS[:create]
|
29
|
+
webhook_data = standardize_body_data(webhook_data, CREATE_AND_EDIT_ATTRS[:permitted])
|
30
|
+
|
31
|
+
post_request(@client, endpoint, webhook_data)
|
32
|
+
end
|
33
|
+
|
34
|
+
def edit(webhook_name, webhook_data)
|
35
|
+
endpoint = ENDPOINTS[:edit] % webhook_name
|
36
|
+
webhook_data = standardize_body_data(webhook_data, CREATE_AND_EDIT_ATTRS[:permitted])
|
37
|
+
|
38
|
+
put_request(@client, endpoint, webhook_data)
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch(webhook_name)
|
42
|
+
endpoint = ENDPOINTS[:fetch] % webhook_name
|
43
|
+
|
44
|
+
get_request(@client, endpoint)
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete(webhook_name)
|
48
|
+
endpoint = ENDPOINTS[:delete] % webhook_name
|
49
|
+
|
50
|
+
delete_request(@client, endpoint)
|
51
|
+
end
|
52
|
+
|
53
|
+
def events
|
54
|
+
endpoint = ENDPOINTS[:events]
|
55
|
+
|
56
|
+
get_request(@client, endpoint)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'fastbound-ruby/base'
|
2
|
+
require 'fastbound-ruby/version'
|
3
|
+
|
4
|
+
require 'fastbound-ruby/api'
|
5
|
+
require 'fastbound-ruby/account'
|
6
|
+
require 'fastbound-ruby/acquisition'
|
7
|
+
require 'fastbound-ruby/attachment'
|
8
|
+
require 'fastbound-ruby/client'
|
9
|
+
require 'fastbound-ruby/contact'
|
10
|
+
require 'fastbound-ruby/disposition'
|
11
|
+
require 'fastbound-ruby/error'
|
12
|
+
require 'fastbound-ruby/item'
|
13
|
+
require 'fastbound-ruby/response'
|
14
|
+
require 'fastbound-ruby/smart_list'
|
15
|
+
require 'fastbound-ruby/webhook'
|
16
|
+
|
17
|
+
module FastBound
|
18
|
+
end
|
data/rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'yard'
|
4
|
+
|
5
|
+
task :default => :spec
|
6
|
+
|
7
|
+
desc 'Run the specs'
|
8
|
+
RSpec::Core::RakeTask.new(:spec)
|
9
|
+
|
10
|
+
desc 'Generate API docs'
|
11
|
+
YARD::Rake::YardocTask.new(:docs) do |t|
|
12
|
+
t.files = ['lib/**/*.rb']
|
13
|
+
end
|
14
|
+
|
15
|
+
namespace :docs do
|
16
|
+
desc 'Run the docs server'
|
17
|
+
task :server do
|
18
|
+
$stdout.puts `yard server --reload --bind 0.0.0.0`
|
19
|
+
end
|
20
|
+
end
|