netsuite 0.7.9 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/Gemfile +7 -2
- data/README.md +164 -61
- data/circle.yml +33 -13
- data/lib/netsuite.rb +55 -19
- data/lib/netsuite/actions/login.rb +20 -1
- data/lib/netsuite/actions/search.rb +1 -6
- data/lib/netsuite/actions/update.rb +6 -2
- data/lib/netsuite/actions/update_list.rb +109 -0
- data/lib/netsuite/actions/upsert.rb +2 -0
- data/lib/netsuite/configuration.rb +21 -4
- data/lib/netsuite/errors.rb +3 -0
- data/lib/netsuite/records/assembly_build.rb +39 -0
- data/lib/netsuite/records/assembly_component.rb +28 -0
- data/lib/netsuite/records/assembly_component_list.rb +12 -0
- data/lib/netsuite/records/assembly_item.rb +1 -0
- data/lib/netsuite/records/assembly_unbuild.rb +40 -0
- data/lib/netsuite/records/bin_number.rb +18 -0
- data/lib/netsuite/records/bin_number_list.rb +1 -20
- data/lib/netsuite/records/bin_transfer.rb +38 -0
- data/lib/netsuite/records/bin_transfer_inventory.rb +20 -0
- data/lib/netsuite/records/bin_transfer_inventory_list.rb +10 -0
- data/lib/netsuite/records/cash_refund.rb +101 -3
- data/lib/netsuite/records/cash_refund_item.rb +1 -1
- data/lib/netsuite/records/cash_sale.rb +1 -0
- data/lib/netsuite/records/classification.rb +5 -2
- data/lib/netsuite/records/contact.rb +2 -1
- data/lib/netsuite/records/contact_addressbook.rb +64 -0
- data/lib/netsuite/records/contact_addressbook_list.rb +11 -0
- data/lib/netsuite/records/credit_memo.rb +1 -0
- data/lib/netsuite/records/currency_rate.rb +4 -3
- data/lib/netsuite/records/custom_field_list.rb +16 -3
- data/lib/netsuite/records/custom_record.rb +3 -3
- data/lib/netsuite/records/custom_record_ref.rb +1 -0
- data/lib/netsuite/records/customer.rb +5 -4
- data/lib/netsuite/records/customer_credit_cards.rb +36 -0
- data/lib/netsuite/records/customer_credit_cards_list.rb +10 -0
- data/lib/netsuite/records/customer_deposit.rb +6 -2
- data/lib/netsuite/records/customer_deposit_apply.rb +17 -0
- data/lib/netsuite/records/customer_deposit_apply_list.rb +12 -0
- data/lib/netsuite/records/customer_payment.rb +1 -0
- data/lib/netsuite/records/customer_sales_team.rb +24 -0
- data/lib/netsuite/records/customer_sales_team_list.rb +9 -0
- data/lib/netsuite/records/customer_status.rb +29 -0
- data/lib/netsuite/records/customer_subscription.rb +18 -0
- data/lib/netsuite/records/customer_subscriptions_list.rb +10 -0
- data/lib/netsuite/records/deposit_other.rb +0 -10
- data/lib/netsuite/records/employee.rb +3 -2
- data/lib/netsuite/records/entity_custom_field.rb +53 -0
- data/lib/netsuite/records/estimate.rb +42 -0
- data/lib/netsuite/records/estimate_item.rb +40 -0
- data/lib/netsuite/records/estimate_item_list.rb +11 -0
- data/lib/netsuite/records/inbound_shipment.rb +33 -0
- data/lib/netsuite/records/inbound_shipment_item.rb +39 -0
- data/lib/netsuite/records/inbound_shipment_item_list.rb +11 -0
- data/lib/netsuite/records/inter_company_journal_entry.rb +48 -0
- data/lib/netsuite/records/inter_company_journal_entry_line.rb +28 -0
- data/lib/netsuite/records/inter_company_journal_entry_line_list.rb +14 -0
- data/lib/netsuite/records/inventory_adjustment.rb +1 -1
- data/lib/netsuite/records/inventory_adjustment_inventory.rb +2 -2
- data/lib/netsuite/records/inventory_item.rb +2 -2
- data/lib/netsuite/records/inventory_number.rb +35 -0
- data/lib/netsuite/records/inventory_number_locations.rb +16 -0
- data/lib/netsuite/records/inventory_number_locations_list.rb +10 -0
- data/lib/netsuite/records/inventory_transfer.rb +2 -2
- data/lib/netsuite/records/inventory_transfer_inventory_list.rb +0 -2
- data/lib/netsuite/records/invoice.rb +4 -4
- data/lib/netsuite/records/item_fulfillment.rb +2 -1
- data/lib/netsuite/records/job.rb +2 -1
- data/lib/netsuite/records/lot_numbered_assembly_item.rb +64 -0
- data/lib/netsuite/records/lot_numbered_inventory_item.rb +116 -0
- data/lib/netsuite/records/matrix_option_list.rb +12 -4
- data/lib/netsuite/records/message.rb +30 -0
- data/lib/netsuite/records/non_inventory_resale_item.rb +3 -2
- data/lib/netsuite/records/non_inventory_sale_item.rb +2 -1
- data/lib/netsuite/records/other_charge_sale_item.rb +2 -2
- data/lib/netsuite/records/partner.rb +1 -1
- data/lib/netsuite/records/price.rb +17 -0
- data/lib/netsuite/records/price_level.rb +26 -0
- data/lib/netsuite/records/price_list.rb +9 -0
- data/lib/netsuite/records/pricing.rb +20 -0
- data/lib/netsuite/records/pricing_matrix.rb +2 -2
- data/lib/netsuite/records/promotions.rb +26 -0
- data/lib/netsuite/records/promotions_list.rb +9 -0
- data/lib/netsuite/records/return_authorization.rb +3 -2
- data/lib/netsuite/records/return_authorization_item.rb +43 -0
- data/lib/netsuite/records/return_authorization_item_list.rb +11 -0
- data/lib/netsuite/records/sales_order.rb +1 -0
- data/lib/netsuite/records/sales_order_item.rb +12 -5
- data/lib/netsuite/records/sales_role.rb +26 -0
- data/lib/netsuite/records/sales_tax_item.rb +3 -1
- data/lib/netsuite/records/serialized_assembly_item.rb +239 -0
- data/lib/netsuite/records/serialized_inventory_item.rb +2 -2
- data/lib/netsuite/records/serialized_inventory_item_location.rb +37 -0
- data/lib/netsuite/records/serialized_inventory_item_locations_list.rb +10 -0
- data/lib/netsuite/records/serialized_inventory_item_numbers.rb +15 -0
- data/lib/netsuite/records/serialized_inventory_item_numbers_list.rb +10 -0
- data/lib/netsuite/records/service_resale_item.rb +1 -1
- data/lib/netsuite/records/service_sale_item.rb +2 -1
- data/lib/netsuite/records/subsidiary.rb +1 -0
- data/lib/netsuite/records/support_case.rb +1 -1
- data/lib/netsuite/records/support_case_type.rb +26 -0
- data/lib/netsuite/records/task.rb +2 -1
- data/lib/netsuite/records/tax_group.rb +3 -1
- data/lib/netsuite/records/transaction_body_custom_field.rb +61 -0
- data/lib/netsuite/records/transaction_column_custom_field.rb +59 -0
- data/lib/netsuite/records/transfer_order_item.rb +2 -2
- data/lib/netsuite/records/vendor.rb +1 -0
- data/lib/netsuite/records/vendor_bill.rb +2 -1
- data/lib/netsuite/records/vendor_credit.rb +2 -0
- data/lib/netsuite/records/work_order.rb +8 -0
- data/lib/netsuite/support/actions.rb +2 -0
- data/lib/netsuite/support/country.rb +27 -14
- data/lib/netsuite/support/search_result.rb +20 -5
- data/lib/netsuite/utilities.rb +100 -43
- data/lib/netsuite/version.rb +2 -2
- data/netsuite.gemspec +5 -4
- data/spec/netsuite/actions/login_spec.rb +23 -0
- data/spec/netsuite/actions/update_list_spec.rb +107 -0
- data/spec/netsuite/actions/update_spec.rb +42 -0
- data/spec/netsuite/configuration_spec.rb +79 -6
- data/spec/netsuite/records/address_spec.rb +10 -0
- data/spec/netsuite/records/basic_record_spec.rb +18 -1
- data/spec/netsuite/records/bin_number_spec.rb +23 -0
- data/spec/netsuite/records/classification_spec.rb +10 -1
- data/spec/netsuite/records/custom_field_list_spec.rb +46 -5
- data/spec/netsuite/records/custom_record_spec.rb +1 -1
- data/spec/netsuite/records/customer_credit_cards_list_spec.rb +23 -0
- data/spec/netsuite/records/customer_sales_team_list_spec.rb +41 -0
- data/spec/netsuite/records/customer_spec.rb +44 -2
- data/spec/netsuite/records/customer_subscription_spec.rb +41 -0
- data/spec/netsuite/records/customer_subscriptions_list_spec.rb +19 -0
- data/spec/netsuite/records/employee_spec.rb +2 -2
- data/spec/netsuite/records/entity_custom_field_spec.rb +34 -0
- data/spec/netsuite/records/estimate_item_list_spec.rb +26 -0
- data/spec/netsuite/records/estimate_item_spec.rb +40 -0
- data/spec/netsuite/records/estimate_spec.rb +216 -0
- data/spec/netsuite/records/inter_company_journal_entry_line_list_spec.rb +26 -0
- data/spec/netsuite/records/inter_company_journal_entry_line_spec.rb +60 -0
- data/spec/netsuite/records/inter_company_journal_entry_spec.rb +156 -0
- data/spec/netsuite/records/inventory_item_spec.rb +57 -0
- data/spec/netsuite/records/inventory_transfer_spec.rb +21 -0
- data/spec/netsuite/records/invoice_spec.rb +4 -4
- data/spec/netsuite/records/matrix_option_list_spec.rb +15 -5
- data/spec/netsuite/records/message_spec.rb +49 -0
- data/spec/netsuite/records/non_inventory_resale_item_spec.rb +165 -0
- data/spec/netsuite/records/non_inventory_sale_item_spec.rb +1 -1
- data/spec/netsuite/records/partner_spec.rb +141 -0
- data/spec/netsuite/records/price_level_spec.rb +16 -0
- data/spec/netsuite/records/pricing_matrix_spec.rb +15 -13
- data/spec/netsuite/records/return_authorization_item_list_spec.rb +26 -0
- data/spec/netsuite/records/return_authorization_item_spec.rb +43 -0
- data/spec/netsuite/records/sales_order_item_spec.rb +11 -5
- data/spec/netsuite/records/service_resale_item_spec.rb +134 -0
- data/spec/netsuite/records/support_case_type_spec.rb +22 -0
- data/spec/netsuite/records/transaction_body_custom_field_spec.rb +32 -0
- data/spec/netsuite/records/transaction_column_custom_field_spec.rb +32 -0
- data/spec/netsuite/records/vendor_credit_spec.rb +29 -0
- data/spec/netsuite/support/search_result_spec.rb +24 -0
- data/spec/netsuite/utilities_spec.rb +50 -0
- data/spec/spec_helper.rb +5 -4
- data/spec/support/fixtures/update_list/update_list_items.xml +22 -0
- data/spec/support/fixtures/update_list/update_list_one_item.xml +18 -0
- data/spec/support/fixtures/update_list/update_list_with_errors.xml +32 -0
- metadata +123 -8
@@ -17,9 +17,10 @@ module NetSuite
|
|
17
17
|
# <platformCore:pageIndex>1</platformCore:pageIndex>
|
18
18
|
# <platformCore:searchId>WEBSERVICES_738944_SB2_03012013650784545962753432_28d96bd280</platformCore:searchId>
|
19
19
|
|
20
|
-
def initialize(response, result_class)
|
20
|
+
def initialize(response, result_class, credentials)
|
21
21
|
@result_class = result_class
|
22
22
|
@response = response
|
23
|
+
@credentials = credentials
|
23
24
|
|
24
25
|
@total_records = response.body[:total_records].to_i
|
25
26
|
@total_pages = response.body[:total_pages].to_i
|
@@ -28,8 +29,19 @@ module NetSuite
|
|
28
29
|
if @total_records > 0
|
29
30
|
if response.body.has_key?(:record_list)
|
30
31
|
# basic search results
|
31
|
-
|
32
|
-
|
32
|
+
|
33
|
+
# `recordList` node can contain several nested `record` nodes, only one node or be empty
|
34
|
+
# so we have to handle all these cases:
|
35
|
+
# * { record_list: nil }
|
36
|
+
# * { record_list: { record: => {...} } }
|
37
|
+
# * { record_list: { record: => [{...}, {...}, ...] } }
|
38
|
+
record_list = if response.body[:record_list].nil?
|
39
|
+
[]
|
40
|
+
elsif response.body[:record_list][:record].is_a?(Array)
|
41
|
+
response.body[:record_list][:record]
|
42
|
+
else
|
43
|
+
[response.body[:record_list][:record]]
|
44
|
+
end
|
33
45
|
|
34
46
|
record_list.each do |record|
|
35
47
|
results << result_class.new(record)
|
@@ -98,8 +110,11 @@ module NetSuite
|
|
98
110
|
yield results
|
99
111
|
|
100
112
|
next_search = @result_class.search(
|
101
|
-
|
102
|
-
|
113
|
+
{
|
114
|
+
search_id: @response.body[:search_id],
|
115
|
+
page_index: @response.body[:page_index].to_i + 1
|
116
|
+
},
|
117
|
+
@credentials
|
103
118
|
)
|
104
119
|
|
105
120
|
@results = next_search.results
|
data/lib/netsuite/utilities.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
1
3
|
module NetSuite
|
2
4
|
module Utilities
|
3
5
|
extend self
|
@@ -37,6 +39,36 @@ module NetSuite
|
|
37
39
|
server_time_response.body[:get_server_time_response][:get_server_time_result][:server_time]
|
38
40
|
end
|
39
41
|
|
42
|
+
def netsuite_data_center_urls(account_id)
|
43
|
+
data_center_call_response = NetSuite::Configuration.connection({
|
44
|
+
# NOTE force a production WSDL so the sandbox settings are ignored
|
45
|
+
# as of 1/20/18 NS will start using the account ID to determine
|
46
|
+
# if a account is sandbox (123_SB1) as opposed to using a sandbox domain
|
47
|
+
|
48
|
+
wsdl: 'https://webservices.netsuite.com/wsdl/v2017_2_0/netsuite.wsdl',
|
49
|
+
|
50
|
+
# NOTE don't inherit default namespace settings, it includes the API version
|
51
|
+
namespaces: {
|
52
|
+
'xmlns:platformCore' => "urn:core_2017_2.platform.webservices.netsuite.com"
|
53
|
+
},
|
54
|
+
|
55
|
+
soap_header: {}
|
56
|
+
}).call(:get_data_center_urls, message: {
|
57
|
+
'platformMsgs:account' => account_id
|
58
|
+
})
|
59
|
+
|
60
|
+
if data_center_call_response.success?
|
61
|
+
data_center_call_response.body[:get_data_center_urls_response][:get_data_center_urls_result][:data_center_urls]
|
62
|
+
else
|
63
|
+
false
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# TODO consider what to dop with this duplicate data center implementation
|
68
|
+
def data_center_url(*args)
|
69
|
+
DataCenter.get(*args)
|
70
|
+
end
|
71
|
+
|
40
72
|
def backoff(options = {})
|
41
73
|
# TODO the default backoff attempts should be customizable the global config
|
42
74
|
options[:attempts] ||= 8
|
@@ -46,7 +78,7 @@ module NetSuite
|
|
46
78
|
begin
|
47
79
|
count += 1
|
48
80
|
yield
|
49
|
-
rescue
|
81
|
+
rescue StandardError => e
|
50
82
|
exceptions_to_retry = [
|
51
83
|
Errno::ECONNRESET,
|
52
84
|
Errno::ETIMEDOUT,
|
@@ -56,7 +88,9 @@ module NetSuite
|
|
56
88
|
Savon::SOAPFault,
|
57
89
|
Savon::InvalidResponseError,
|
58
90
|
Zlib::BufError,
|
59
|
-
Savon::HTTPError
|
91
|
+
Savon::HTTPError,
|
92
|
+
SocketError,
|
93
|
+
Net::OpenTimeout
|
60
94
|
]
|
61
95
|
|
62
96
|
# available in ruby > 1.9
|
@@ -65,9 +99,12 @@ module NetSuite
|
|
65
99
|
end
|
66
100
|
|
67
101
|
# available in ruby > 2.2.0
|
68
|
-
if defined?(
|
69
|
-
|
70
|
-
|
102
|
+
exceptions_to_retry << IO::EINPROGRESSWaitWritable if defined?(IO::EINPROGRESSWaitWritable)
|
103
|
+
exceptions_to_retry << OpenSSL::SSL::SSLErrorWaitReadable if defined?(OpenSSL::SSL::SSLErrorWaitReadable)
|
104
|
+
|
105
|
+
# depends on the http library chosen
|
106
|
+
exceptions_to_retry << Excon::Error::Timeout if defined?(Excon::Error::Timeout)
|
107
|
+
exceptions_to_retry << Excon::Error::Socket if defined?(Excon::Error::Socket)
|
71
108
|
|
72
109
|
if !exceptions_to_retry.include?(e.class)
|
73
110
|
raise
|
@@ -78,11 +115,20 @@ module NetSuite
|
|
78
115
|
# https://github.com/stripe/stripe-netsuite/issues/815
|
79
116
|
if !e.message.include?("Only one request may be made against a session at a time") &&
|
80
117
|
!e.message.include?('java.util.ConcurrentModificationException') &&
|
118
|
+
!e.message.include?('java.lang.NullPointerException') &&
|
119
|
+
!e.message.include?('java.lang.IllegalStateException') &&
|
120
|
+
!e.message.include?('java.lang.reflect.InvocationTargetException') &&
|
81
121
|
!e.message.include?('com.netledger.common.exceptions.NLDatabaseOfflineException') &&
|
82
122
|
!e.message.include?('com.netledger.database.NLConnectionUtil$NoCompanyDbsOnlineException') &&
|
123
|
+
!e.message.include?('com.netledger.cache.CacheUnavailableException') &&
|
124
|
+
!e.message.include?('java.lang.IllegalStateException') &&
|
83
125
|
!e.message.include?('An unexpected error occurred.') &&
|
126
|
+
!e.message.include?('An unexpected error has occurred. Technical Support has been alerted to this problem.') &&
|
84
127
|
!e.message.include?('Session invalidation is in progress with different thread') &&
|
128
|
+
!e.message.include?('[missing resource APP:ERRORMESSAGE:WS_AN_UNEXPECTED_ERROR_OCCURRED] [missing resource APP:ERRORMESSAGE:ERROR_ID_1]') &&
|
85
129
|
!e.message.include?('SuiteTalk concurrent request limit exceeded. Request blocked.') &&
|
130
|
+
# maintenance is the new outage: this message is being used for intermittent errors
|
131
|
+
!e.message.include?('The account you are trying to access is currently unavailable while we undergo our regularly scheduled maintenance.') &&
|
86
132
|
!e.message.include?('The Connection Pool is not intialized.') &&
|
87
133
|
# it looks like NetSuite mispelled their error message...
|
88
134
|
!e.message.include?('The Connection Pool is not intiialized.')
|
@@ -103,15 +149,16 @@ module NetSuite
|
|
103
149
|
|
104
150
|
def request_failed?(ns_object)
|
105
151
|
return false if ns_object.errors.nil? || ns_object.errors.empty?
|
152
|
+
ns_object.errors.any? { |x| x.type == "ERROR" }
|
153
|
+
end
|
106
154
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
# end
|
155
|
+
def get_field_options(recordType, fieldName)
|
156
|
+
options = NetSuite::Records::BaseRefList.get_select_value(
|
157
|
+
field: fieldName,
|
158
|
+
recordType: recordType
|
159
|
+
)
|
113
160
|
|
114
|
-
|
161
|
+
options.base_refs
|
115
162
|
end
|
116
163
|
|
117
164
|
def get_item(ns_item_internal_id, opts = {})
|
@@ -126,6 +173,8 @@ module NetSuite
|
|
126
173
|
ns_item ||= NetSuite::Utilities.get_record(NetSuite::Records::GiftCertificateItem, ns_item_internal_id, opts)
|
127
174
|
ns_item ||= NetSuite::Utilities.get_record(NetSuite::Records::KitItem, ns_item_internal_id, opts)
|
128
175
|
ns_item ||= NetSuite::Utilities.get_record(NetSuite::Records::SerializedInventoryItem, ns_item_internal_id, opts)
|
176
|
+
ns_item ||= NetSuite::Utilities.get_record(NetSuite::Records::LotNumberedAssemblyItem, ns_item_internal_id, opts)
|
177
|
+
ns_item ||= NetSuite::Utilities.get_record(NetSuite::Records::LotNumberedInventoryItem, ns_item_internal_id, opts)
|
129
178
|
|
130
179
|
if ns_item.nil?
|
131
180
|
fail NetSuite::RecordNotFound, "item with ID #{ns_item_internal_id} not found"
|
@@ -189,7 +238,11 @@ module NetSuite
|
|
189
238
|
field_name = 'email'
|
190
239
|
end
|
191
240
|
|
192
|
-
field_name ||= '
|
241
|
+
field_name ||= if record.to_s.end_with?('Item')
|
242
|
+
'displayName'
|
243
|
+
else
|
244
|
+
'name'
|
245
|
+
end
|
193
246
|
|
194
247
|
# TODO remove backoff when it's built-in to search
|
195
248
|
search = backoff { record.search({
|
@@ -210,37 +263,41 @@ module NetSuite
|
|
210
263
|
nil
|
211
264
|
end
|
212
265
|
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
#
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
266
|
+
# http://mikebian.co/notes-on-dates-timezones-with-netsuites-suitetalk-api/
|
267
|
+
# https://wyeworks.com/blog/2016/6/22/behavior-changes-in-ruby-2.4
|
268
|
+
# https://github.com/rails/rails/commit/c9c5788a527b70d7f983e2b4b47e3afd863d9f48
|
269
|
+
|
270
|
+
# assumes UTC0 unix timestamp
|
271
|
+
def normalize_time_to_netsuite_date(unix_timestamp)
|
272
|
+
# convert to date to eliminate hr/min/sec
|
273
|
+
time = Time.at(unix_timestamp).
|
274
|
+
utc.
|
275
|
+
to_date.
|
276
|
+
to_datetime
|
277
|
+
|
278
|
+
# tzinfo allows us to determine the dst status of the time being passed in
|
279
|
+
# NetSuite requires that the time be passed to the API with the PDT TZ offset
|
280
|
+
# of the time passed in (i.e. not the current TZ offset of PDT)
|
281
|
+
|
282
|
+
if defined?(TZInfo)
|
283
|
+
# if no version is defined, less than 2.0
|
284
|
+
# https://github.com/tzinfo/tzinfo/blob/master/CHANGES.md#added
|
285
|
+
if !defined?(TZInfo::VERSION)
|
286
|
+
# https://stackoverflow.com/questions/2927111/ruby-get-time-in-given-timezone
|
287
|
+
offset = TZInfo::Timezone.get("America/Los_Angeles").period_for_utc(time).utc_total_offset_rational
|
288
|
+
time = time.new_offset(offset)
|
289
|
+
else
|
290
|
+
time = TZInfo::Timezone.get("America/Los_Angeles").utc_to_local(time)
|
291
|
+
offset = time.offset
|
292
|
+
end
|
293
|
+
else
|
294
|
+
# if tzinfo is not installed, let's give it our best guess: -7
|
295
|
+
offset = Rational(-7, 24)
|
296
|
+
time = time.new_offset("-07:00")
|
297
|
+
end
|
242
298
|
|
243
|
-
|
299
|
+
time = (time + (offset * -1))
|
300
|
+
time.iso8601
|
244
301
|
end
|
245
302
|
|
246
303
|
end
|
data/lib/netsuite/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = '0.
|
1
|
+
module NetSuite
|
2
|
+
VERSION = '0.8.6'
|
3
3
|
end
|
data/netsuite.gemspec
CHANGED
@@ -2,8 +2,9 @@
|
|
2
2
|
require File.expand_path('../lib/netsuite/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
+
gem.licenses = ['MIT']
|
5
6
|
gem.authors = ['Ryan Moran', 'Michael Bianco']
|
6
|
-
gem.email = ['ryan.moran@gmail.com', 'mike@
|
7
|
+
gem.email = ['ryan.moran@gmail.com', 'mike@mikebian.co']
|
7
8
|
gem.description = %q{NetSuite SuiteTalk API Wrapper}
|
8
9
|
gem.summary = %q{NetSuite SuiteTalk API (SOAP) Wrapper}
|
9
10
|
gem.homepage = 'https://github.com/NetSweet/netsuite'
|
@@ -13,9 +14,9 @@ Gem::Specification.new do |gem|
|
|
13
14
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
15
|
gem.name = 'netsuite'
|
15
16
|
gem.require_paths = ['lib']
|
16
|
-
gem.version =
|
17
|
+
gem.version = NetSuite::VERSION
|
17
18
|
|
18
|
-
gem.add_dependency 'savon', '>= 2.3.0'
|
19
|
+
gem.add_dependency 'savon', '>= 2.3.0', '<= 2.11.1'
|
19
20
|
|
20
|
-
gem.add_development_dependency 'rspec', '~> 3.
|
21
|
+
gem.add_development_dependency 'rspec', '~> 3.8.0'
|
21
22
|
end
|
@@ -41,4 +41,27 @@ describe NetSuite::Actions::Login do
|
|
41
41
|
role: 234
|
42
42
|
}) }.to raise_error(Savon::SOAPFault)
|
43
43
|
end
|
44
|
+
|
45
|
+
it 'handles a login call when token based auth is in place' do
|
46
|
+
NetSuite.configure do
|
47
|
+
consumer_key '123'
|
48
|
+
consumer_secret '123'
|
49
|
+
token_id '123'
|
50
|
+
token_secret '123'
|
51
|
+
|
52
|
+
api_version '2017_2'
|
53
|
+
end
|
54
|
+
|
55
|
+
message = {"platformMsgs:passport"=>{"platformCore:email"=>"email", "platformCore:password"=>"password", "platformCore:account"=>"1234", "platformCore:role"=>234}}
|
56
|
+
savon.expects(:login).with(:message => message).returns(File.read('spec/support/fixtures/login/success.xml'))
|
57
|
+
|
58
|
+
result = NetSuite::Actions::Login.call({
|
59
|
+
email: 'email',
|
60
|
+
password: 'password',
|
61
|
+
role: 234
|
62
|
+
})
|
63
|
+
|
64
|
+
expect(result.success?).to eq(true)
|
65
|
+
expect(result.body[:user_id]).to_not be_nil
|
66
|
+
end
|
44
67
|
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NetSuite::Actions::UpdateList do
|
4
|
+
before { savon.mock! }
|
5
|
+
after { savon.unmock! }
|
6
|
+
|
7
|
+
context 'Items' do
|
8
|
+
context 'one item' do
|
9
|
+
let(:item) do
|
10
|
+
[
|
11
|
+
NetSuite::Records::InventoryItem.new(internal_id: '624113', item_id: 'Target', upccode: 'Target')
|
12
|
+
]
|
13
|
+
end
|
14
|
+
|
15
|
+
before do
|
16
|
+
savon.expects(:update_list).with(:message =>
|
17
|
+
{
|
18
|
+
'record' => [{
|
19
|
+
'listAcct:itemId' => 'Target',
|
20
|
+
'@xsi:type' => 'listAcct:InventoryItem',
|
21
|
+
'@internalId' => '624113'
|
22
|
+
}]
|
23
|
+
}).returns(File.read('spec/support/fixtures/update_list/update_list_one_item.xml'))
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'makes a valid request to the NetSuite API' do
|
27
|
+
NetSuite::Actions::UpdateList.call(item)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'returns a valid Response object' do
|
31
|
+
response = NetSuite::Actions::UpdateList.call(item)
|
32
|
+
expect(response).to be_kind_of(NetSuite::Response)
|
33
|
+
expect(response).to be_success
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'two items' do
|
38
|
+
let(:items) do
|
39
|
+
[
|
40
|
+
NetSuite::Records::InventoryItem.new(internal_id: '624172', item_id: 'Shutter Fly', upccode: 'Shutter Fly, Inc.'),
|
41
|
+
NetSuite::Records::InventoryItem.new(internal_id: '624113', item_id: 'Target', upccode: 'Target')
|
42
|
+
]
|
43
|
+
end
|
44
|
+
|
45
|
+
before do
|
46
|
+
savon.expects(:update_list).with(:message =>
|
47
|
+
{
|
48
|
+
'record' => [{
|
49
|
+
'listAcct:itemId' => 'Shutter Fly',
|
50
|
+
'@xsi:type' => 'listAcct:InventoryItem',
|
51
|
+
'@internalId' => '624172'
|
52
|
+
},
|
53
|
+
{
|
54
|
+
'listAcct:itemId' => 'Target',
|
55
|
+
'@xsi:type' => 'listAcct:InventoryItem',
|
56
|
+
'@internalId' => '624113'
|
57
|
+
}
|
58
|
+
]
|
59
|
+
}).returns(File.read('spec/support/fixtures/update_list/update_list_items.xml'))
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'makes a valid request to the NetSuite API' do
|
63
|
+
NetSuite::Actions::UpdateList.call(items)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'returns a valid Response object' do
|
67
|
+
response = NetSuite::Actions::UpdateList.call(items)
|
68
|
+
expect(response).to be_kind_of(NetSuite::Response)
|
69
|
+
expect(response).to be_success
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'with errors' do
|
75
|
+
let(:items) do
|
76
|
+
[
|
77
|
+
NetSuite::Records::InventoryItem.new(internal_id: '624172-bad', item_id: 'Shutter Fly', upccode: 'Shutter Fly, Inc.'),
|
78
|
+
NetSuite::Records::InventoryItem.new(internal_id: '624113-bad', item_id: 'Target', upccode: 'Target')
|
79
|
+
]
|
80
|
+
end
|
81
|
+
|
82
|
+
before do
|
83
|
+
savon.expects(:update_list).with(:message =>
|
84
|
+
{
|
85
|
+
'record' => [{
|
86
|
+
'listAcct:itemId' => 'Shutter Fly',
|
87
|
+
'@xsi:type' => 'listAcct:InventoryItem',
|
88
|
+
'@internalId' => '624172-bad'
|
89
|
+
},
|
90
|
+
{
|
91
|
+
'listAcct:itemId' => 'Target',
|
92
|
+
'@xsi:type' => 'listAcct:InventoryItem',
|
93
|
+
'@internalId' => '624113-bad'
|
94
|
+
}
|
95
|
+
]
|
96
|
+
}).returns(File.read('spec/support/fixtures/update_list/update_list_with_errors.xml'))
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'constructs error objects' do
|
100
|
+
response = NetSuite::Actions::UpdateList.call(items)
|
101
|
+
expect(response.errors.keys).to match_array(['624172', '624113'])
|
102
|
+
expect(response.errors['624172'].first.code).to eq('USER_ERROR')
|
103
|
+
expect(response.errors['624172'].first.message).to eq('Please enter value(s) for: ItemId')
|
104
|
+
expect(response.errors['624172'].first.type).to eq('ERROR')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -19,6 +19,48 @@ describe NetSuite::Actions::Update do
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
+
describe 'updating the external ID' do
|
23
|
+
let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
|
24
|
+
|
25
|
+
# https://github.com/NetSweet/netsuite/pull/416
|
26
|
+
# if the external ID is set, and the external ID field is ommitted on an update, the external ID field does not change
|
27
|
+
# if the external_id field is set to nil, it should not be passed to netsuite
|
28
|
+
# passing an empty string to the external ID field does not remove it
|
29
|
+
|
30
|
+
it 'does not pass the external ID to an update call if not modified or included in update options' do
|
31
|
+
expect(NetSuite::Actions::Update).to receive(:call).
|
32
|
+
with([customer.class, {}], {}).
|
33
|
+
and_return(response)
|
34
|
+
|
35
|
+
expect(customer.update).to be_truthy
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should update the external ID when the attribute on the record is set' do
|
39
|
+
expect(NetSuite::Actions::Update).to receive(:call).
|
40
|
+
with([customer.class, {external_id: 'foo'}], {}).
|
41
|
+
and_return(response)
|
42
|
+
|
43
|
+
customer.external_id = 'foo'
|
44
|
+
expect(customer.update).to be_truthy
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should update the external ID to nil when the attribute on the record is set' do
|
48
|
+
expect(NetSuite::Actions::Update).to receive(:call).
|
49
|
+
with([customer.class, {external_id: nil}], {}).
|
50
|
+
and_return(response)
|
51
|
+
|
52
|
+
expect(customer.update(external_id: nil)).to be_truthy
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should update the external ID to the options value not the attribute value' do
|
56
|
+
expect(NetSuite::Actions::Update).to receive(:call).
|
57
|
+
with([customer.class, {external_id: 'bar'}], {}).
|
58
|
+
and_return(response)
|
59
|
+
|
60
|
+
customer.external_id = 'foo'
|
61
|
+
expect(customer.update(external_id: 'bar')).to be_truthy
|
62
|
+
end
|
63
|
+
end
|
22
64
|
|
23
65
|
context 'when successful' do
|
24
66
|
|