Skip to content

Commit be56426

Browse files
committed
Added AsyncAddList
1 parent 5bc69ea commit be56426

23 files changed

+735
-9
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
.bundle
44
.config
55
.yardoc
6+
.idea/
67
Gemfile.lock
78
InstalledFiles
89
_yardoc

lib/netsuite.rb

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77
require 'netsuite/core_ext/string/lower_camelcase'
88

99
module NetSuite
10-
autoload :Configuration, 'netsuite/configuration'
11-
autoload :Response, 'netsuite/response'
10+
autoload :Configuration, 'netsuite/configuration'
11+
autoload :Response, 'netsuite/response'
12+
autoload :Status, 'netsuite/status'
13+
14+
module Async
15+
autoload :Status, 'netsuite/async/status'
16+
autoload :WriteResponse, 'netsuite/async/write_response'
17+
autoload :WriteResponseList, 'netsuite/async/write_response_list'
18+
end
1219

1320
module Namespaces
1421
autoload :ActSched, 'netsuite/namespaces/act_sched'
@@ -55,6 +62,7 @@ module Actions
5562
autoload :UpsertList, 'netsuite/actions/upsert_list'
5663
autoload :Search, 'netsuite/actions/search'
5764
autoload :Login, 'netsuite/actions/login'
65+
autoload :AsyncAddList, 'netsuite/actions/async_add_list'
5866
end
5967

6068
module Records
+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# https://system.netsuite.com/help/helpcenter/en_US/Output/Help/SuiteCloudCustomizationScriptingWebServices/SuiteTalkWebServices/AsynchronousRequestProcessing.html
2+
module NetSuite
3+
module Actions
4+
class AsyncAddList
5+
include Support::Requests
6+
7+
def initialize(objects)
8+
@objects = objects
9+
end
10+
11+
private
12+
13+
def request(credentials={})
14+
NetSuite::Configuration.connection({element_form_default: :unqualified}, credentials).call(:async_add_list, message: request_body)
15+
end
16+
17+
# <soap:Body>
18+
# <asyncAddList>
19+
# <record xsi:type="listRel:Customer" externalId="ext1">
20+
# <listRel:entityId>Shutter Fly</listRel:entityId>
21+
# <listRel:companyName>Shutter Fly, Inc</listRel:companyName>
22+
# </record>
23+
# <record xsi:type="listRel:Customer" externalId="ext2">
24+
# <listRel:entityId>Target</listRel:entityId>
25+
# <listRel:companyName>Target</listRel:companyName>
26+
# </record>
27+
# </asyncAddList>
28+
# </soap:Body>
29+
def request_body
30+
attrs = @objects.map do |o|
31+
hash = o.to_record.merge({
32+
'@xsi:type' => o.record_type
33+
})
34+
if o.respond_to?(:external_id) && o.external_id
35+
hash['@externalId'] = o.external_id
36+
end
37+
hash
38+
end
39+
{ 'record' => attrs }
40+
end
41+
42+
#<soapenv:Body>
43+
# <asyncAddListResponse xmlns="urn:messages_2_5.platform.webservices.netsuite.com">
44+
# <asyncStatusResult xmlns="urn:core_2_5.platform.webservices.netsuite.com">
45+
# <jobId>ASYNCWEBSERVICES_563214_053120061943428686160042948_4bee0685</jobId>
46+
# <status>pending</status>
47+
# <percentCompleted>0.0</percentCompleted>
48+
# <estRemainingDuration>0.0</estRemainingDuration>
49+
# </asyncStatusResult>
50+
# </asyncAddListResponse>
51+
#</soapenv:Body>
52+
def response_body
53+
@response_body ||= begin
54+
response_hash = @response.to_hash
55+
response_hash[:async_add_list_response] ? response_hash[:async_add_list_response][:async_status_result] : nil
56+
end
57+
end
58+
59+
def success?
60+
!response_body.nil?
61+
end
62+
63+
module Support
64+
65+
def self.included(base)
66+
base.extend(ClassMethods)
67+
end
68+
69+
module ClassMethods
70+
def async_add_list(objects = [], credentials = {})
71+
objects_list = objects.map do |object|
72+
object.kind_of?(self) ? object : self.new(object)
73+
end
74+
response = NetSuite::Actions::AsyncAddList.call([objects_list], credentials)
75+
response.success? ? NetSuite::Async::Status.new(response.body) : false
76+
end
77+
end
78+
end
79+
end
80+
end
81+
end

lib/netsuite/async/status.rb

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
module NetSuite
2+
module Async
3+
class Status
4+
include Support::Fields
5+
6+
read_only_fields :job_id, :status, :percent_completed, :est_remaining_duration
7+
8+
def initialize(attributes = {})
9+
initialize_from_attributes_hash(attributes)
10+
end
11+
12+
#<soap:Body>
13+
# <platformMsgs:checkAsyncStatus>
14+
# <platformMsgs:jobId>ASYNCWEBSERVICES_563214_053120061943428686160042948_4bee0685
15+
# </platformMsgs:jobId>
16+
# </platformMsgs:checkAsyncStatus>
17+
#</soap:Body>
18+
19+
def self.get(options = {}, credentials = {})
20+
response = NetSuite::Configuration.connection(credentials).call(:check_async_status, :message => request_body(options))
21+
new(response.to_hash[:check_async_status_response][:async_status_result])
22+
end
23+
24+
def self.request_body(options)
25+
{
26+
'platformMsgs:jobId' => { :content! => options[:job_id] }
27+
}
28+
end
29+
30+
#<complexType name="AsyncStatusResult">
31+
# <sequence>
32+
# <element name="jobId" type="xsd:string"/>
33+
# <element name="status" type="platformCoreTyp:AsyncStatusType"/>
34+
# <element name="percentCompleted" type="xsd:double"/>
35+
# <element name="estRemainingDuration" type="xsd:double"/>
36+
#</sequence>
37+
#</complexType>
38+
39+
#<simpleType name="AsyncStatusType">
40+
# <restriction base="{http://www.w3.org/2001/XMLSchema}string">
41+
# <enumeration value="failed"/>
42+
# <enumeration value="finishedWithErrors"/>
43+
# <enumeration value="pending"/>
44+
# <enumeration value="processing"/>
45+
# <enumeration value="finished"/>
46+
# </restriction>
47+
#</simpleType>
48+
49+
def finished?
50+
['failed', 'finished', 'finishedWithErrors'].include?(status)
51+
end
52+
53+
def success?
54+
status == "finished"
55+
end
56+
57+
def errors?
58+
status == "finishedWithErrors"
59+
end
60+
61+
end
62+
end
63+
end

lib/netsuite/async/write_response.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module NetSuite
2+
module Async
3+
class WriteResponse
4+
5+
attr_reader :base_ref, :status
6+
7+
def initialize(write_result)
8+
@status = NetSuite::Status.new(write_result[:status])
9+
@base_ref = NetSuite::Records::RecordRef.new(write_result[:base_ref]) if write_result[:base_ref]
10+
end
11+
12+
def success?
13+
@status.success?
14+
end
15+
16+
end
17+
end
18+
end
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# https://system.netsuite.com/help/helpcenter/en_US/Output/Help/SuiteCloudCustomizationScriptingWebServices/SuiteTalkWebServices/AsynchronousRequestProcessing.html
2+
module NetSuite
3+
module Async
4+
class WriteResponseList
5+
6+
attr_reader :list, :status, :type
7+
8+
def initialize(async_result)
9+
@type = async_result[:"@xsi:type"]
10+
response_list = async_result[:write_response_list]
11+
@status = NetSuite::Status.new(response_list[:status]) if response_list[:status]
12+
responses = Array[response_list[:write_response]].flatten
13+
@list = responses.map { |response| NetSuite::Async::WriteResponse.new(response) }
14+
end
15+
16+
def self.get(options = {})
17+
response = NetSuite::Configuration.connection({element_form_default: :unqualified}).call(:get_async_result, message: request_body(options))
18+
self.new(response.to_hash[:get_async_result_response][:async_result])
19+
end
20+
21+
def has_errors?
22+
return true if @status && !@status.success?
23+
@list.each do |result|
24+
return true unless result.success?
25+
end
26+
false
27+
end
28+
29+
#<soap:Body>
30+
# <platformMsgs:getAsyncResult>
31+
# <platformMsgs:jobId>ASYNCWEBSERVICES_563214_053120061943428686160042948_4bee0685</platformMsgs:jobId>
32+
# <platformMsgs:pageIndex>1</platformMsgs:pageIndex>
33+
# </platformMsgs:getAsyncResult>
34+
#</soap:Body>
35+
def self.request_body(options)
36+
{
37+
'platformMsgs:jobId' => { :content! => options[:job_id] },
38+
'platformMsgs:pageIndex' => { :content! => options[:page_index] }
39+
}
40+
end
41+
42+
end
43+
end
44+
end

lib/netsuite/configuration.rb

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def namespaces
9696
'xmlns:platformCommon' => "urn:common_#{api_version}.platform.webservices.netsuite.com",
9797
'xmlns:listRel' => "urn:relationships_#{api_version}.lists.webservices.netsuite.com",
9898
'xmlns:tranSales' => "urn:sales_#{api_version}.transactions.webservices.netsuite.com",
99+
'xmlns:tranPurch' => "urn:purchases_#{api_version}.transactions.webservices.netsuite.com",
99100
'xmlns:actSched' => "urn:scheduling_#{api_version}.activities.webservices.netsuite.com",
100101
'xmlns:setupCustom' => "urn:customization_#{api_version}.setup.webservices.netsuite.com",
101102
'xmlns:listAcct' => "urn:accounting_#{api_version}.lists.webservices.netsuite.com",

lib/netsuite/records/invoice.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Invoice
77
include Support::Actions
88
include Namespaces::TranSales
99

10-
actions :get, :get_list, :initialize, :add, :delete, :upsert
10+
actions :get, :get_list, :initialize, :add, :delete, :upsert, :async_add_list
1111

1212
fields :balance, :bill_address,
1313
:billing_schedule, :contrib_pct, :created_date, :currency_name, :custom_field_list,

lib/netsuite/records/payment_method.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ class PaymentMethod
55
include Support::RecordRefs
66
include Support::Actions
77

8-
actions :add, :delete, :get, :get_list, :search, :search_more_with_id,
9-
:update, :upsert, :upsert_list
8+
actions :add, :delete, :get, :get_list, :search, :update, :upsert, :upsert_list
109

1110
fields :credit_card, :express_checkout_arrangement, :is_debit_card, :is_inactive, :is_online, :name,
1211
:pay_pal_email_address, :undep_funds, :use_express_checkout

lib/netsuite/status.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module NetSuite
2+
class StatusDetail < NetSuite::Error; end
3+
4+
class Status
5+
6+
attr_reader :is_success, :details
7+
8+
def initialize(status)
9+
@is_success = status[:@is_success] == 'true'
10+
@details = status[:status_detail] ? Array[status[:status_detail]].flatten.map { |d| NetSuite::StatusDetail.new(d) } : []
11+
end
12+
13+
def success?
14+
@is_success
15+
end
16+
17+
end
18+
end

lib/netsuite/support/actions.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ def action(name)
2828
self.send(:include, NetSuite::Actions::GetSelectValue::Support)
2929
when :search
3030
self.send(:include, NetSuite::Actions::Search::Support)
31-
when :search_more_with_id
32-
self.send(:include, NetSuite::Actions::SearchMoreWithId::Support)
3331
when :add
3432
self.send(:include, NetSuite::Actions::Add::Support)
3533
when :upsert
@@ -42,6 +40,8 @@ def action(name)
4240
self.send(:include, NetSuite::Actions::Update::Support)
4341
when :initialize
4442
self.send(:include, NetSuite::Actions::Initialize::Support)
43+
when :async_add_list
44+
self.send(:include, NetSuite::Actions::AsyncAddList::Support)
4545
else
4646
raise "Unknown action: #{name.inspect}"
4747
end

0 commit comments

Comments
 (0)