Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netsuite.v0.9.3 with BOM #583

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ test/version_tmp
tmp
vendor/
.tags*
.editorconfig
22 changes: 19 additions & 3 deletions lib/netsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
require 'netsuite/errors'
require 'netsuite/utilities'
require 'netsuite/utilities/data_center'
require 'netsuite/utilities/strings'
require 'netsuite/rest/utilities/roles'
require 'netsuite/rest/utilities/request'
require 'netsuite/core_ext/string/lower_camelcase'

module NetSuite
autoload :Configuration, 'netsuite/configuration'
Expand All @@ -33,6 +33,7 @@ module Namespaces
autoload :SetupCustom, 'netsuite/namespaces/setup_custom'
autoload :ListEmp, 'netsuite/namespaces/list_emp'
autoload :ListMkt, 'netsuite/namespaces/list_mkt'
autoload :ListBom, 'netsuite/namespaces/list_bom'
end

module Support
Expand All @@ -48,7 +49,9 @@ module Support
end

module Actions
autoload :AbstractAction, 'netsuite/actions/abstract_action'
autoload :Add, 'netsuite/actions/add'
autoload :AttachFile, 'netsuite/actions/attach_file'
autoload :Delete, 'netsuite/actions/delete'
autoload :DeleteList, 'netsuite/actions/delete_list'
autoload :Get, 'netsuite/actions/get'
Expand Down Expand Up @@ -87,6 +90,8 @@ module Records
autoload :BinTransfer, 'netsuite/records/bin_transfer'
autoload :BinTransferInventory, 'netsuite/records/bin_transfer_inventory'
autoload :BinTransferInventoryList, 'netsuite/records/bin_transfer_inventory_list'
autoload :Bom, 'netsuite/records/bom'
autoload :BomRevision, 'netsuite/records/bom_revision'
autoload :CashSale, 'netsuite/records/cash_sale'
autoload :CashSaleItem, 'netsuite/records/cash_sale_item'
autoload :CashSaleItemList, 'netsuite/records/cash_sale_item_list'
Expand Down Expand Up @@ -132,8 +137,6 @@ module Records
autoload :CustomerRefundApplyList, 'netsuite/records/customer_refund_apply_list'
autoload :CustomerRefundDeposit, 'netsuite/records/customer_refund_deposit'
autoload :CustomerRefundDepositList, 'netsuite/records/customer_refund_deposit_list'
autoload :CustomerSubscription, 'netsuite/records/customer_subscription'
autoload :CustomerSubscriptionsList, 'netsuite/records/customer_subscriptions_list'
autoload :CustomerStatus, 'netsuite/records/customer_status'
autoload :CustomerPartner, 'netsuite/records/customer_partner'
autoload :CustomerSalesTeam, 'netsuite/records/customer_sales_team'
Expand Down Expand Up @@ -192,14 +195,22 @@ module Records
autoload :Invoice, 'netsuite/records/invoice'
autoload :InvoiceItem, 'netsuite/records/invoice_item'
autoload :InvoiceItemList, 'netsuite/records/invoice_item_list'
autoload :ItemAvailability, 'netsuite/records/item_availability'
autoload :ItemFulfillment, 'netsuite/records/item_fulfillment'
autoload :ItemFulfillmentItem, 'netsuite/records/item_fulfillment_item'
autoload :ItemFulfillmentItemList, 'netsuite/records/item_fulfillment_item_list'
autoload :ItemFulfillmentPackage, 'netsuite/records/item_fulfillment_package'
autoload :ItemFulfillmentPackageList, 'netsuite/records/item_fulfillment_package_list'
autoload :ItemFulfillmentPackageFedEx, 'netsuite/records/item_fulfillment_package_fed_ex'
autoload :ItemFulfillmentPackageUps, 'netsuite/records/item_fulfillment_package_ups'
autoload :ItemFulfillmentPackageUsps, 'netsuite/records/item_fulfillment_package_usps'
autoload :ItemFulfillmentPackageFedExList, 'netsuite/records/item_fulfillment_package_fed_ex_list'
autoload :ItemFulfillmentPackageUpsList, 'netsuite/records/item_fulfillment_package_ups_list'
autoload :ItemFulfillmentPackageUspsList, 'netsuite/records/item_fulfillment_package_usps_list'
autoload :ItemGroup, 'netsuite/records/item_group'
autoload :ItemMember, 'netsuite/records/item_member'
autoload :ItemMemberList, 'netsuite/records/item_member_list'
autoload :ItemOptionCustomField, 'netsuite/records/item_option_custom_field'
autoload :ItemReceipt, 'netsuite/records/item_receipt'
autoload :ItemReceiptItemList, 'netsuite/records/item_receipt_item_list'
autoload :ItemReceiptItem, 'netsuite/records/item_receipt_item'
Expand All @@ -223,6 +234,7 @@ module Records
autoload :NonInventoryResaleItem, 'netsuite/records/non_inventory_resale_item'
autoload :Note, 'netsuite/records/note'
autoload :NoteType, 'netsuite/records/note_type'
autoload :NullFieldList, 'netsuite/records/null_field_list'
autoload :Opportunity, 'netsuite/records/opportunity'
autoload :OpportunityItem, 'netsuite/records/opportunity_item'
autoload :OpportunityItemList, 'netsuite/records/opportunity_item_list'
Expand Down Expand Up @@ -268,6 +280,8 @@ module Records
autoload :SerializedInventoryItemLocationsList, 'netsuite/records/serialized_inventory_item_locations_list'
autoload :ShipAddress, 'netsuite/records/ship_address'
autoload :SiteCategory, 'netsuite/records/site_category'
autoload :Subscription, 'netsuite/records/subscription'
autoload :SubscriptionsList, 'netsuite/records/subscriptions_list'
autoload :Subsidiary, 'netsuite/records/subsidiary'
autoload :SubtotalItem, 'netsuite/records/subtotal_item'
autoload :SupportCase, 'netsuite/records/support_case'
Expand All @@ -283,6 +297,8 @@ module Records
autoload :TransferOrder, 'netsuite/records/transfer_order'
autoload :TransferOrderItemList, 'netsuite/records/transfer_order_item_list'
autoload :TransferOrderItem, 'netsuite/records/transfer_order_item'
autoload :Translation, 'netsuite/records/translation'
autoload :TranslationList, 'netsuite/records/translation_list'
autoload :UnitsType, 'netsuite/records/units_type'
autoload :UnitsTypeUomList, 'netsuite/records/units_type_uom_list'
autoload :UnitsTypeUom, 'netsuite/records/units_type_uom'
Expand Down
32 changes: 32 additions & 0 deletions lib/netsuite/actions/abstract_action.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module NetSuite
module Actions
class AbstractAction
def request(credentials={})
NetSuite::Configuration.connection(request_options, credentials, soap_header_extra_info).call(action_name, message: request_body)
end

protected

def action_name
raise NotImplementedError, 'Not implemented on abstract class'
end

def initialize
raise NotImplementedError, 'Not implemented on abstract class'
end

def request_body
raise NotImplementedError, 'Not implemented on abstract class'
end

def request_options
{}
end

def soap_header_extra_info
{}
end
end
end
end

19 changes: 12 additions & 7 deletions lib/netsuite/actions/add.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://system.netsuite.com/help/helpcenter/en_US/Output/Help/SuiteCloudCustomizationScriptingWebServices/SuiteTalkWebServices/add.html
module NetSuite
module Actions
class Add
class Add < AbstractAction
include Support::Requests

attr_reader :response_hash
Expand All @@ -12,10 +12,6 @@ def initialize(object = nil)

private

def request(credentials={})
NetSuite::Configuration.connection({}, credentials).call(:add, :message => request_body)
end

# <soap:Body>
# <platformMsgs:add>
# <platformMsgs:record xsi:type="listRel:Customer">
Expand Down Expand Up @@ -49,7 +45,11 @@ def success?
end

def response_body
@response_body ||= response_hash[:base_ref]
@response_body ||= if response_hash[:base_ref].is_a?(Nori::StringIOFile)
{ :@internal_id => Nokogiri::XML(@response.to_s).remove_namespaces!.at_xpath('//baseRef')[:internalId] }
else
response_hash[:base_ref]
end
end

def response_errors
Expand All @@ -62,12 +62,17 @@ def response_hash
@response_hash ||= @response.to_hash[:add_response][:write_response]
end

def action_name
:add
end

def errors
error_obj = response_hash[:status][:status_detail]
error_obj = [error_obj] if error_obj.class == Hash
error_obj.map do |error|
next if error.keys == [:after_submit_failed]
NetSuite::Error.new(error)
end
end.compact
end

module Support
Expand Down
87 changes: 87 additions & 0 deletions lib/netsuite/actions/attach_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
module NetSuite
module Actions
class AttachFile < AbstractAction
include Support::Requests

def initialize(object, file)
@object = object
@file = file
end

private

# <soap:Body>
# <platformMsgs:attach>
# <platformCore:attachReference xsi:type="platformCore:AttachContactReference">
# <platformCore::attachTo internalId="176" type="customer" xsi:type="platformCore::RecordRef">
# </platformCore:attachTo>
# <platformCore:attachRecord internalId="1467" type="file" xsi:type="platformCore:RecordRef"/>
# </platformCore:attachReference>
# </platformMsgs:attach>
# </soap:Body>

def request_body
{
'platformCore:attachReference' => {
'@xsi:type' => 'platformCore:AttachBasicReference',
'platformCore:attachTo' => {
'@internalId' => @object.internal_id,
'@type' => @object.netsuite_type,
'@xsi:type' => 'platformCore:RecordRef'
},
'platformCore:attachedRecord' => {
'@internalId' => @file.internal_id,
'@type' => 'file',
'@xsi:type' => 'platformCore:RecordRef'
}
}
}
end

def success?
@success ||= response_hash[:status][:@is_success] == 'true'
end

def response_body
@response_body ||= response_hash[:base_ref]
end

def response_errors
if response_hash[:status] && response_hash[:status][:status_detail]
@response_errors ||= errors
end
end

def response_hash
@response_hash ||= @response.to_hash[:attach_response][:write_response]
end

def action_name
:attach
end

def errors
error_obj = response_hash[:status][:status_detail]
error_obj = [error_obj] if error_obj.class == Hash
error_obj.map do |error|
NetSuite::Error.new(error)
end
end

module Support
def attach_file(file, credentials = {})
response = NetSuite::Actions::AttachFile.call([self, file], credentials)

@errors = response.errors

if response.success?
@internal_id = response.body[:@internal_id]
true
else
false
end
end
end
end
end
end
43 changes: 32 additions & 11 deletions lib/netsuite/actions/delete.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# https://system.netsuite.com/help/helpcenter/en_US/Output/Help/SuiteCloudCustomizationScriptingWebServices/SuiteTalkWebServices/delete.html
module NetSuite
module Actions
class Delete
class Delete < AbstractAction
include Support::Requests

def initialize(object = nil, options = {})
Expand All @@ -11,17 +11,8 @@ def initialize(object = nil, options = {})

private

def request(credentials={})
NetSuite::Configuration.connection(
{namespaces: {
'xmlns:platformMsgs' => "urn:messages_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
'xmlns:platformCore' => "urn:core_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com"
}}, credentials
).call :delete, message: request_body
end

def soap_type
@object.class.to_s.split('::').last.lower_camelcase
NetSuite::Support::Records.netsuite_type(@object)
end

# <soap:Body>
Expand Down Expand Up @@ -65,13 +56,43 @@ def response_body
@response_body ||= response_hash[:base_ref]
end

def response_errors
if response_hash[:status] && response_hash[:status][:status_detail]
@response_errors ||= errors
end
end

def request_options
{
namespaces: {
'xmlns:platformMsgs' => "urn:messages_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
'xmlns:platformCore' => "urn:core_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com"
}
}
end

def action_name
:delete
end

def errors
error_obj = response_hash[:status][:status_detail]
error_obj = [error_obj] if error_obj.class == Hash
error_obj.map do |error|
NetSuite::Error.new(error)
end
end

module Support
def delete(options = {}, credentials={})
response = if options.empty?
NetSuite::Actions::Delete.call([self], credentials)
else
NetSuite::Actions::Delete.call([self, options], credentials)
end

@errors = response.errors

response.success?
end
end
Expand Down
26 changes: 15 additions & 11 deletions lib/netsuite/actions/delete_list.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module NetSuite
module Actions
class DeleteList
class DeleteList < AbstractAction
include Support::Requests

def initialize(klass, options = { })
Expand All @@ -10,15 +10,6 @@ def initialize(klass, options = { })

private

def request(credentials={})
NetSuite::Configuration.connection(
{namespaces: {
'xmlns:platformMsgs' => "urn:messages_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
'xmlns:platformCore' => "urn:core_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com"
}}, credentials
).call :delete_list, message: request_body
end

# <soap:Body>
# <platformMsgs:deleteList>
# <platformMsgs:baseRef internalId="1" type="customer" xsi:type="platformCore:RecordRef"/>
Expand All @@ -40,7 +31,7 @@ def request_body
}
end
else
type = @klass.to_s.split('::').last.lower_camelcase
type = NetSuite::Support::Records.netsuite_type(@klass)
record_type = 'platformCore:RecordRef'

list.map do |internal_id|
Expand Down Expand Up @@ -71,6 +62,19 @@ def response_errors
end
end

def request_options
{
namespaces: {
'xmlns:platformMsgs' => "urn:messages_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
'xmlns:platformCore' => "urn:core_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com"
}
}
end

def action_name
:delete_list
end

def errors
errors = response_list.select { |r| r[:status] && r[:status][:status_detail] }.map do |obj|
error_obj = obj[:status][:status_detail]
Expand Down
Loading