fastbound-ruby 1.1.4 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3234150290b474d2c48fa931dd0521b5dfbd2ec37c3667320e1a3aa4d81b33b
4
- data.tar.gz: 32796d9b23c397033e9d6bd992c7ee3dda6d0a837e167b0c5fa832b780e61b47
3
+ metadata.gz: 31b5843e0ee1e182bba7b7cde61e1fc92e8138ec403bec8b2a912f5aafe22724
4
+ data.tar.gz: 057b27b313d77ac069c8b667ab39b9baa54722dac78448726fcb96a4b3acb820
5
5
  SHA512:
6
- metadata.gz: 2c3806b5820f5a8f5bd4425320264e43af0a42b8e677d597055fe8f7a22b6f18a1558e54f07d2b0f558e3e893940b38dfb952ba9a3102bf8ecd17f2d852cd110
7
- data.tar.gz: bc30fe452a020d9efee102eaeab2261713f79aa0de339fd4923c897b519517d21c1d509f662467a23b2de8bf27ad0026e28f8823ff71459d8d1e5cb978478614
6
+ metadata.gz: dcf2aeb6731c8cc1067aac4bcfa6e7c4272b42700ded3cf074ae38e3032c4f84a36dc688361b1f0830ba8375203fe65e06cfbaaf1af4d5819d69091b295dec13
7
+ data.tar.gz: cf8f4ae0a3ee11b31267b64c5735e22e6997c9442e31842daa99c73fe2c780f4c1d95704ccfa9877b1db2c022cc12661f6c167bf7950a21ab63ac2002ebf8d94
@@ -82,12 +82,11 @@ module FastBound
82
82
  def create_and_commit(acquisition_data, item_data, contact_data)
83
83
  requires!(acquisition_data, *CREATE_AND_EDIT_ATTRS[:required])
84
84
  requires!(item_data, *Item::CREATE_AND_EDIT_ATTRS[:required])
85
- requires!(contact_data, *Contact::CREATE_AND_EDIT_ATTRS[:required])
86
85
 
87
86
  endpoint = ENDPOINTS[:create_and_commit]
88
87
  acquisition_data = standardize_body_data(acquisition_data, CREATE_AND_EDIT_ATTRS[:permitted])
89
88
  item_data = standardize_body_data(item_data, Item::CREATE_AND_EDIT_ATTRS[:permitted])
90
- contact_data = standardize_body_data(contact_data, Contact::CREATE_AND_EDIT_ATTRS[:permitted])
89
+ contact_data = standardize_body_data(contact_data, Contact::CREATE_AND_EDIT_ATTRS)
91
90
  request_data = acquisition_data.merge(
92
91
  contact: contact_data,
93
92
  items: [item_data]
@@ -13,38 +13,41 @@ module FastBound
13
13
  def get_request(client, endpoint)
14
14
  request = Net::HTTP::Get.new(request_url(client, endpoint))
15
15
 
16
+ set_request_headers(client, request)
16
17
  submit_request(client, request)
17
18
  end
18
19
 
19
20
  def post_request(client, endpoint, data = {})
20
21
  request = Net::HTTP::Post.new(request_url(client, endpoint))
21
22
 
23
+ set_request_headers(client, request, 'application/json')
22
24
  submit_request(client, request, data)
23
25
  end
24
26
 
25
27
  def put_request(client, endpoint, data = {})
26
28
  request = Net::HTTP::Put.new(request_url(client, endpoint))
27
29
 
30
+ set_request_headers(client, request, 'application/json')
28
31
  submit_request(client, request, data)
29
32
  end
30
33
 
31
34
  def delete_request(client, endpoint)
32
35
  request = Net::HTTP::Delete.new(request_url(client, endpoint))
33
36
 
37
+ set_request_headers(client, request)
34
38
  submit_request(client, request)
35
39
  end
36
40
 
37
41
  def post_file_request(client, endpoint, file_data)
38
42
  request = Net::HTTP::Post.new(request_url(client, endpoint))
39
43
 
44
+ set_request_headers(client, request)
40
45
  submit_file_request(client, request, file_data)
41
46
  end
42
47
 
43
48
  private
44
49
 
45
50
  def submit_request(client, request, data = {})
46
- set_request_headers(client, request)
47
-
48
51
  request.body = data.is_a?(Hash) ? data.to_json : data
49
52
 
50
53
  process_request(request)
@@ -56,7 +59,6 @@ module FastBound
56
59
  headers.merge!(content_type_header("multipart/form-data; boundary=#{boundary}"))
57
60
 
58
61
  build_multipart_request_body(request, file_data, boundary)
59
- set_request_headers(client, request)
60
62
  process_request(request)
61
63
  end
62
64
 
@@ -89,10 +91,11 @@ module FastBound
89
91
  request.body = body.join
90
92
  end
91
93
 
92
- def set_request_headers(client, request)
94
+ def set_request_headers(client, request, content_type = nil)
93
95
  request['User-Agent'] = USER_AGENT
94
96
  request['Authorization'] = ['Basic', Base64.strict_encode64(client.api_key + ':')].join(' ')
95
97
  request['X-AuditUser'] = client.account_email
98
+ request['Content-Type'] = content_type if content_type.present?
96
99
  end
97
100
 
98
101
  def request_url(client, endpoint)
@@ -5,14 +5,11 @@ module FastBound
5
5
 
6
6
  include FastBound::API
7
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
- }
8
+ CREATE_AND_EDIT_ATTRS = %i(
9
+ external_id ffl_number ffl_expires lookup_ffl license_name trade_name sotein sot_class business_type
10
+ organization_name first_name middle_name last_name premise_address_1 premise_address_2 premise_city
11
+ premise_county premise_state premise_zip_code premise_country phone_number fax email_address
12
+ ).freeze
16
13
 
17
14
  CREATE_AND_EDIT_LICENSE_ATTRS = {
18
15
  permitted: %i( type number expiration copy_on_file ).freeze,
@@ -49,17 +46,15 @@ module FastBound
49
46
  end
50
47
 
51
48
  def create(contact_data)
52
- requires!(contact_data, *CREATE_AND_EDIT_ATTRS[:required])
53
-
54
49
  endpoint = ENDPOINTS[:create]
55
- contact_data = standardize_body_data(contact_data, CREATE_AND_EDIT_ATTRS[:permitted])
50
+ contact_data = standardize_body_data(contact_data, CREATE_AND_EDIT_ATTRS)
56
51
 
57
52
  post_request(@client, endpoint, contact_data)
58
53
  end
59
54
 
60
55
  def edit(contact_id, contact_data)
61
56
  endpoint = ENDPOINTS[:edit] % contact_id
62
- contact_data = standardize_body_data(contact_data, CREATE_AND_EDIT_ATTRS[:permitted])
57
+ contact_data = standardize_body_data(contact_data, CREATE_AND_EDIT_ATTRS)
63
58
 
64
59
  put_request(@client, endpoint, contact_data)
65
60
  end
@@ -152,19 +152,18 @@ module FastBound
152
152
  post_request(@client, endpoint, commit_data)
153
153
  end
154
154
 
155
- def create_and_commit(disposition_data, items_data, contact_data, commit_data = {})
156
- requires!(contact_data, *Contact::CREATE_AND_EDIT_ATTRS[:required])
155
+ def create_and_commit(disposition_data, items_data, contact_data = {}, commit_data = nil)
157
156
  items_data.each { |item| requires!(item, :id) }
158
157
 
159
158
  endpoint = ENDPOINTS[:create_and_commit]
160
159
  disposition_data = standardize_body_data(disposition_data, EDIT_AND_CREATE_COMMIT_ATTRS)
161
160
  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])
161
+ contact_data = standardize_body_data(contact_data, Contact::CREATE_AND_EDIT_ATTRS)
163
162
  request_data = disposition_data.merge(
164
163
  contact: contact_data,
165
164
  items: items_data,
166
165
  manufacturingChanges: commit_data
167
- )
166
+ ).compact
168
167
 
169
168
  post_request(@client, endpoint, request_data)
170
169
  end
@@ -28,7 +28,7 @@ module FastBound
28
28
  puts "-- DEBUG: #{self}: RequestError: #{@response.inspect}"
29
29
  end
30
30
 
31
- raise FastBound::Error::RequestError.new(@response.body)
31
+ raise FastBound::Error::RequestError.new([@response.body, @response.message].reject(&:blank?).join(" | "))
32
32
  end
33
33
  end
34
34
 
@@ -1,3 +1,3 @@
1
1
  module FastBound
2
- VERSION = "1.1.4"
2
+ VERSION = "1.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastbound-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeffrey Dill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-14 00:00:00.000000000 Z
11
+ date: 2022-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler