Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5b99969
Fix issue with empty `record_list` node in search result
andrykonchin May 16, 2019
2e58c99
Adding guide to finding the account ID
iloveitaly May 18, 2019
56413df
Add direct_revenue_posting field to non-inventory sale item model
antoinesaliba May 20, 2019
7684482
Improving configuration documentation
iloveitaly May 26, 2019
df796ee
Adding subsidiary_list to OtherChargeSaleItem
iloveitaly May 28, 2019
ba4a55b
Adding new netsuite error
iloveitaly May 29, 2019
b0d5396
Adding lot numbered item to get_item
iloveitaly May 30, 2019
1a6081d
Added support case types and messages
jeremycrosbie Jun 10, 2019
3a5ae3e
added more properties to matrix_option_list
joerzepiejewski Jul 11, 2019
659d463
Version bump
iloveitaly Jul 11, 2019
5dfa2ef
Add credit cards to customer
jeremycrosbie Jul 24, 2019
af26673
rescue Exception => rescue StandardError
shaicoleman Sep 4, 2019
cd350c2
Add cost to ServiceResaleItem.
Sep 11, 2019
e48f808
Add spec for ServiceResaleItem.
Sep 11, 2019
ec46a26
Update data center url method name in README
Sep 9, 2019
35f393a
Support passing streams as log option
iloveitaly Oct 25, 2019
a5ba921
Bumping ruby version
iloveitaly Oct 25, 2019
cf9f5c2
Adding spec for using IO stream as a log destination
iloveitaly Oct 25, 2019
b404f18
Add the status field to ItemFulfillments
jormon Nov 20, 2019
de0286b
update classification to include parent record_ref
toyhammered Mar 4, 2020
1292ddc
Fixing classification parent and custom field field definition
iloveitaly Mar 4, 2020
a2b0376
Fixes Issues #450
toyhammered Mar 6, 2020
4d6ac2f
Fixing classification test
iloveitaly Mar 6, 2020
1585ca8
add item vendor list to non inventory resale item
nkulbiski Apr 25, 2020
f13ef9c
Add amount as a read_only_field to Invoice
jormon Apr 23, 2020
f900e5d
Adding search join to CustomerPayment
justincatalana May 10, 2020
653532f
Typo: proces -> process in README
dleve123 Jul 2, 2020
73a24dc
Fix deprecation warnings in custom_field_list_spec.rb
dleve123 Aug 3, 2020
a1dfef7
Backfill tests for Configuration#log_level & #log_level=
dleve123 Aug 3, 2020
49bdd03
Add failing tests: can not override log level
dleve123 Aug 3, 2020
0b01431
Configuration: Allow for log_level overriding
dleve123 Aug 3, 2020
0d0ba9f
Explicitly and consistently mark pending specs in configuration_spec.rb
dleve123 Aug 3, 2020
abdc7de
Docs: Document log_level in README and provide suggestion for Rails a…
dleve123 Aug 4, 2020
67ad6bc
Bumping CI build dependencies to remove vulnerability warnings
iloveitaly Aug 4, 2020
48a8fb3
circle ci v2
iloveitaly Aug 4, 2020
2e0bbc0
Adding rspec_junit_formatter for circleci ruby orb
iloveitaly Aug 4, 2020
d65aa39
Bump ruby version
iloveitaly Aug 4, 2020
cc6c318
add subsidiary to partner record
nkulbiski Aug 14, 2020
6f73221
add sales_role to employee record
nkulbiski Aug 14, 2020
3dffc39
Adding Estimate support for Quotes
jeperkins4 Sep 1, 2020
c2d7933
Version bump
iloveitaly Sep 23, 2020
8960d58
Addressing gemspec warnings. Ensure savon is less than 2.11
iloveitaly Sep 23, 2020
0b430cc
[#2101] add runSuiteScriptAndTriggerWorkflow header support on Update…
Jun 5, 2019
0c9902f
do not pass run_suite_scripts flag with nil value
Jun 6, 2019
ca636da
dup soap header when setting per request web preferences configuration
Jun 6, 2019
eee4d44
[#13198] Updated exceptions to retry list
DmytroVasin Jun 17, 2022
13cc24f
Merge pull request #6 from ShipHawk/dm-13198-update-exceptions-to-retry
vasiliysablin Jun 20, 2022
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
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0
2.6.6
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source 'https://rubygems.org'
gemspec

gem 'simplecov', :require => false
gem 'rspec_junit_formatter'

gem 'pry-nav'
gem 'pry-rescue'
Expand All @@ -11,5 +12,5 @@ gem 'tzinfo', '1.2.5'
# gem 'tzinfo', '2.0.0'

# required for CircleCI to build properly with ruby 1.9.3
gem 'json', '~> 1.8.3'
gem 'rack', '~> 1.6.4'
gem 'json', '~> 2.3.0'
gem 'rack', '~> 2.1.4'
49 changes: 37 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,36 @@ This gem is built for ruby 1.9.x+, checkout the [1-8-stable](https://github.com/

## Configuration

Not sure how to find your account id? Search for "web service preferences" in the NetSuite global search.
The most important thing you'll need is your NetSuite account ID. Not sure how to find your account id? [Here's a guide.](http://mikebian.co/find-netsuite-web-services-account-number/)

For most use-cases, the following configuration will be sufficient:

```ruby
NetSuite.configure do
reset!

account 'TSTDRV1576318'
api_version '2018_2'

email 'email@example.com'
password 'password'
role 10

# use `NetSuite::Utilities.data_center_url('TSTDRV1576318')` to retrieve the URL
# you'll want to do this in a background process and strip the protocol out of the return string
wsdl_domain 'tstdrv1576318.suitetalk.api.netsuite.com'
end
```

The `wsdl_domain` configuration is most important. Note that if you use `wsdl` or other configuration options below, you'll want to look at the configuration source to understand more about how the different options interact with each other. Some of the configuration options will mutate the state of other options.

Here's the various options that are are available for configuration:

```ruby
NetSuite.configure do
reset!

# optional, defaults to 2011_2
api_version '2012_1'
api_version '2018_2'

# optionally specify full wsdl URL (to switch to sandbox, for example)
wsdl "https://webservices.sandbox.netsuite.com/wsdl/v#{api_version}_0/netsuite.wsdl"
Expand All @@ -79,21 +101,24 @@ NetSuite.configure do
# construct the full wsdl location - e.g. "https://#{wsdl_domain}/wsdl/v#{api_version}_0/netsuite.wsdl"
wsdl_domain "webservices.na2.netsuite.com"

# or specify the sandbox flag if you don't want to deal with specifying a full URL
sandbox true

# often the netsuite servers will hang which would cause a timeout exception to be raised
# if you don't mind waiting (e.g. processing NS via DJ), increasing the timeout should fix the issue
read_timeout 100000
# if you don't mind waiting (e.g. processing NS via a background worker), increasing the timeout should fix the issue
read_timeout 100_000

# you can specify a file or file descriptor to send the log output to (defaults to STDOUT)
# If using within a Rails app, consider setting to `Rails.logger` to leverage existing
# application-level log configuration
log File.join(Rails.root, 'log/netsuite.log')

# login information
email 'email@domain.com'
password 'password'
# Defaults to :debug level logging for Savon API calls. Decrease the verbosity
# by setting log_level to `:info`, for example
# log_level :debug

# password-based login information
email 'email@domain.com'
password 'password'
account '12345'
role 1111
role 1111

# optional, ensures that read-only fields don't cause API errors
soap_header 'platformMsgs:preferences' => {
Expand Down
47 changes: 33 additions & 14 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
# https://leonid.shevtsov.me/post/multiple-rubies-on-circleci/
version: 2.1

machine:
environment:
RUBY_VERSIONS: 2.0.0,2.1.10,2.2.9,2.3.7,2.4.4,2.5.1,2.6.1
orbs:
# orbs are basically bundles of pre-written build scripts that work for common cases
# https://github.com/CircleCI-Public/ruby-orb
ruby: circleci/ruby@1.1

dependencies:
override:
- gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
- rvm get head
- rvm install $RUBY_VERSIONS
- rvm $RUBY_VERSIONS --verbose do gem install bundler -v 1.17.3
- rvm $RUBY_VERSIONS --verbose do bundle install
jobs:
# skipping build step because Gemfile.lock is not included in the source
# this makes the bundler caching step a noop
test:
parameters:
ruby-version:
type: string
docker:
- image: cimg/ruby:<< parameters.ruby-version >>
steps:
- checkout
- ruby/install-deps:
bundler-version: '1.17.2'
with-cache: false
- ruby/rspec-test

test:
override:
- rvm $RUBY_VERSIONS --verbose do bundle exec rspec spec
# strangely, there seems to be very little documentation about exactly how martix builds work.
# By defining a param inside your job definition, Circle CI will automatically spawn a job for
# unique param value passed via `matrix`. Neat!
# https://circleci.com/blog/circleci-matrix-jobs/
workflows:
build_and_test:
jobs:
- test:
matrix:
parameters:
# https://github.com/CircleCI-Public/cimg-ruby
# only supports the last three ruby versions
ruby-version: ["2.5", "2.6", "2.7"]
7 changes: 7 additions & 0 deletions lib/netsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ module Records
autoload :CustomerAddressbook, 'netsuite/records/customer_addressbook'
autoload :CustomerAddressbookList, 'netsuite/records/customer_addressbook_list'
autoload :CustomerCategory, 'netsuite/records/customer_category'
autoload :CustomerCreditCards, 'netsuite/records/customer_credit_cards'
autoload :CustomerCreditCardsList, 'netsuite/records/customer_credit_cards_list'
autoload :CustomerCurrency, 'netsuite/records/customer_currency'
autoload :CustomerCurrencyList, 'netsuite/records/customer_currency_list'
autoload :CustomerDeposit, 'netsuite/records/customer_deposit'
Expand Down Expand Up @@ -156,6 +158,9 @@ module Records
autoload :Duration, 'netsuite/records/duration'
autoload :Employee, 'netsuite/records/employee'
autoload :EntityCustomField, 'netsuite/records/entity_custom_field'
autoload :Estimate, 'netsuite/records/estimate'
autoload :EstimateItem, 'netsuite/records/estimate_item'
autoload :EstimateItemList, 'netsuite/records/estimate_item_list'
autoload :File, 'netsuite/records/file'
autoload :GiftCertificate, 'netsuite/records/gift_certificate'
autoload :GiftCertificateItem, 'netsuite/records/gift_certificate_item'
Expand Down Expand Up @@ -209,6 +214,7 @@ module Records
autoload :LotNumberedInventoryItem, 'netsuite/records/lot_numbered_inventory_item'
autoload :MatrixOptionList, 'netsuite/records/matrix_option_list'
autoload :MemberList, 'netsuite/records/member_list'
autoload :Message, 'netsuite/records/message'
autoload :NonInventorySaleItem, 'netsuite/records/non_inventory_sale_item'
autoload :NonInventoryPurchaseItem, 'netsuite/records/non_inventory_purchase_item'
autoload :NonInventoryResaleItem, 'netsuite/records/non_inventory_resale_item'
Expand Down Expand Up @@ -262,6 +268,7 @@ module Records
autoload :Subsidiary, 'netsuite/records/subsidiary'
autoload :SubtotalItem, 'netsuite/records/subtotal_item'
autoload :SupportCase, 'netsuite/records/support_case'
autoload :SupportCaseType, 'netsuite/records/support_case_type'
autoload :TaxType, 'netsuite/records/tax_type'
autoload :TaxGroup, 'netsuite/records/tax_group'
autoload :Task, 'netsuite/records/task'
Expand Down
21 changes: 17 additions & 4 deletions lib/netsuite/actions/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ class Update

def initialize(klass, attributes)
@klass = klass
@web_services_preferences = {}

if attributes.has_key?(:run_suite_scripts)
@web_services_preferences[:run_suite_scripts] = attributes.delete(:run_suite_scripts)
end

@attributes = attributes
end

def request(credentials={})
NetSuite::Configuration.connection({}, credentials).call :update, :message => request_body
connection_params = { web_services_preferences: @web_services_preferences }
NetSuite::Configuration.connection(connection_params, credentials).call :update, :message => request_body
end

# <platformMsgs:update>
Expand Down Expand Up @@ -70,19 +77,25 @@ def errors
end

module Support
def update(options = {}, credentials={})
options[:internal_id] = internal_id if respond_to?(:internal_id) && internal_id
def update(options = {}, credentials = {}, web_services_preferences = {})

if web_services_preferences.has_key?(:run_suite_scripts)
options.merge!(run_suite_scripts: web_services_preferences[:run_suite_scripts])
end

options.merge!(:internal_id => internal_id) if respond_to?(:internal_id) && internal_id

if !options.include?(:external_id) && (respond_to?(:external_id) && external_id)
options[:external_id] = external_id
end

options.merge!(:external_id => external_id) if respond_to?(:external_id) && external_id

response = NetSuite::Actions::Update.call([self.class, options], credentials)
@errors = response.errors
response.success?
end
end

end
end
end
30 changes: 25 additions & 5 deletions lib/netsuite/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ def attributes
end

def connection(params={}, credentials={})
preferences = params.delete(:web_services_preferences)

client = Savon.client({
wsdl: cached_wsdl || wsdl,
read_timeout: read_timeout,
open_timeout: open_timeout,
namespaces: namespaces,
soap_header: auth_header(credentials).update(soap_header),
soap_header: auth_header(credentials).update(soap_header_with_web_preferences_headers(preferences)),
pretty_print_xml: true,
filters: filters,
logger: logger,
Expand Down Expand Up @@ -350,7 +352,10 @@ def log(path = nil)

def logger(value = nil)
if value.nil?
attributes[:logger] ||= ::Logger.new((log && !log.empty?) ? log : $stdout)
# if passed a IO object (like StringIO) `empty?` won't exist
valid_log = log && !(log.respond_to?(:empty?) && log.empty?)

attributes[:logger] ||= ::Logger.new(valid_log ? log : $stdout)
else
attributes[:logger] = value
end
Expand All @@ -370,12 +375,27 @@ def silent=(value)
end

def log_level(value = nil)
self.log_level = value || :debug
attributes[:log_level]
self.log_level = value if value

attributes[:log_level] || :debug
end

def log_level=(value)
attributes[:log_level] ||= value
attributes[:log_level] = value
end

def soap_header_with_web_preferences_headers(web_services_preferences)
base_soap_header = soap_header.dup

return base_soap_header if web_services_preferences.nil?

if web_services_preferences.has_key?(:run_suite_scripts)
base_soap_header['platformMsgs:preferences'] ||= {}
run_scripts_tag = 'platformMsgs:runServerSuiteScriptAndTriggerWorkflows'
base_soap_header['platformMsgs:preferences'][run_scripts_tag] = web_services_preferences[:run_suite_scripts]
end

base_soap_header
end
end
end
5 changes: 4 additions & 1 deletion lib/netsuite/records/classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ class Classification

actions :add, :get, :get_list, :delete, :upsert, :search

fields :name, :include_children, :is_inactive, :class_translation_list, :custom_field_list, :parent
fields :name, :include_children, :is_inactive, :class_translation_list

field :subsidiary_list, RecordRefList
field :custom_field_list, CustomFieldList

record_refs :parent

attr_reader :internal_id
attr_accessor :external_id
Expand Down
2 changes: 1 addition & 1 deletion lib/netsuite/records/custom_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CustomRecord

field :custom_field_list, CustomFieldList

record_refs :custom_form, :owner, :rec_type
record_refs :custom_form, :owner, :rec_type, :parent

attr_reader :internal_id
attr_accessor :external_id
Expand Down
3 changes: 2 additions & 1 deletion lib/netsuite/records/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Customer

fields :account_number, :aging, :alt_email, :alt_name, :alt_phone, :bill_pay,
:buying_reason, :buying_time_frame, :campaign_category, :click_stream, :comments, :company_name,
:consol_aging, :consol_days_overdue, :contrib_pct, :credit_cards_list, :credit_hold_override,
:consol_aging, :consol_days_overdue, :contrib_pct, :credit_hold_override,
:credit_limit, :date_created, :days_overdue, :default_address,
:download_list, :email, :email_preference, :email_transactions, :end_date, :entity_id,
:estimated_budget, :fax, :fax_transactions, :first_name, :first_visit, :give_access, :global_subscription_status,
Expand All @@ -28,6 +28,7 @@ class Customer
:vat_reg_number, :visits, :web_lead

field :addressbook_list, CustomerAddressbookList
field :credit_cards_list, CustomerCreditCardsList
field :custom_field_list, CustomFieldList
field :contact_roles_list, ContactAccessRolesList
field :currency_list, CustomerCurrencyList
Expand Down
36 changes: 36 additions & 0 deletions lib/netsuite/records/customer_credit_cards.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module NetSuite
module Records
class CustomerCreditCards
include Support::Fields
include Support::RecordRefs
include Support::Records

# https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2017_1/schema/other/customercreditcards.html?mode=package

fields :cc_default, :cc_expire_date, :cc_memo, :cc_name, :cc_number, :debitcard_issue_no, :state_from, :validfrom
record_refs :card_state, :payment_method

attr_reader :internal_id

def initialize(attributes_or_record = {})
case attributes_or_record
when self.class
initialize_from_record(attributes_or_record)
when Hash
initialize_from_attributes_hash(attributes_or_record)
end
end

def initialize_from_record(obj)
self.cc_default = obj.cc_default
self.cc_expire_date = obj.cc_expire_date
self.cc_memo = obj.cc_memo
self.cc_name = obj.cc_name
self.cc_number = obj.cc_number
self.debitcard_issue_no = obj.debitcard_issue_no
self.state_from = obj.state_from
self.validfrom = obj.validfrom
end
end
end
end
10 changes: 10 additions & 0 deletions lib/netsuite/records/customer_credit_cards_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module NetSuite
module Records
class CustomerCreditCardsList < Support::Sublist
include Namespaces::ListRel

sublist :credit_cards, CustomerCreditCards
alias :credit_card :credit_cards
end
end
end
1 change: 1 addition & 0 deletions lib/netsuite/records/customer_payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CustomerPayment

attr_reader :internal_id
attr_accessor :external_id
attr_accessor :search_joins

def initialize(attributes = {})
@internal_id = attributes.delete(:internal_id) || attributes.delete(:@internal_id)
Expand Down
2 changes: 1 addition & 1 deletion lib/netsuite/records/employee.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Employee
:phonetic_name, :purchase_order_approval_limit, :purchase_order_approver, :purchase_order_limit, :release_date,
:resident_status, :salutation, :social_security_number, :visa_exp_date, :visa_type

record_refs :currency, :department, :location, :subsidiary, :employee_type, :employee_status, :supervisor
record_refs :currency, :department, :location, :sales_role, :subsidiary, :employee_type, :employee_status, :supervisor

field :custom_field_list, CustomFieldList
field :roles_list, RoleList
Expand Down
Loading