fastbound-ruby 1.1.2 → 1.1.6

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: 50df0cbbde2a5bddc6bf840dca3ea5e3427b513cde3a4536676b801916615246
4
- data.tar.gz: 72d930597d1867d1583d7e7b80b3f6c273184c1966421aa2814b9cbb9421b850
3
+ metadata.gz: d852c62270f374ee9e8114027108e39f67d74dbef1ca33c8f5ef2be371b04af3
4
+ data.tar.gz: da98709eff4b8b3e4efefc218abaea16914fc0c7698ff5a044b8ce6fe4b38903
5
5
  SHA512:
6
- metadata.gz: 27e08924d1543b95a0a28926160dee348fd9468c18563dd53ff9aa6bcd6298501108b8db5c38aeadf21e8adb7d32967e3dbbfb68e62bb1fd53ed008049ab7132
7
- data.tar.gz: 9cfd6874dd9de4964031202086c9ec857402056544e365de6eddccb2b29b22c6166214ec7bd83effb4e88ba7047d341c99d386f0b5a4646e1eebb915559a644d
6
+ metadata.gz: 18a3f83fc9a13b909fa3cb0014f3b44d3c1e085b33abf3cb3095a54d847e085ccc0ba1977f5ff064e497dc010c551b3fdd21f7a9b1d274e3ba6e4c185f348382
7
+ data.tar.gz: 28f1071c6db244a90509b22bcd4c398797cea10018f806771abc9d59ad087bc22e03715aca63c8c4005e510b6d5e0cd35dc2bbb8f88355ba7beb11d5bfb8179d
@@ -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,14 +59,14 @@ 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
 
63
65
  def process_request(request)
64
66
  uri = URI(request.path)
65
- http = Net::HTTP.new(uri.host, uri.port, use_ssl: true)
67
+ http = Net::HTTP.new(uri.host, uri.port)
66
68
 
69
+ http.use_ssl = true
67
70
  http.set_debug_output($stdout) if FastBound.config.full_debug?
68
71
 
69
72
  response = http.start { |_http| _http.request(request) }
@@ -88,10 +91,11 @@ module FastBound
88
91
  request.body = body.join
89
92
  end
90
93
 
91
- def set_request_headers(client, request)
94
+ def set_request_headers(client, request, content_type = nil)
92
95
  request['User-Agent'] = USER_AGENT
93
96
  request['Authorization'] = ['Basic', Base64.strict_encode64(client.api_key + ':')].join(' ')
94
97
  request['X-AuditUser'] = client.account_email
98
+ request['Content-Type'] = content_type if content_type.present?
95
99
  end
96
100
 
97
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 = {})
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
@@ -24,7 +24,11 @@ module FastBound
24
24
  _data.map(&:deep_symbolize_keys)
25
25
  end
26
26
  else
27
- raise FastBound::Error::RequestError.new(@response.body)
27
+ if FastBound.config.full_debug?
28
+ puts "-- DEBUG: #{self}: RequestError: #{@response.inspect}"
29
+ end
30
+
31
+ raise FastBound::Error::RequestError.new([@response.body, @response.message].reject(&:blank?).join(" | "))
28
32
  end
29
33
  end
30
34
 
@@ -1,3 +1,3 @@
1
1
  module FastBound
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.6"
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.2
4
+ version: 1.1.6
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-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler