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

add 2014_1 wsdl, make search results work when there is only a single result on a page #82

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions lib/netsuite/actions/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ def request_body
elsif condition[:value].is_a?(Array) && condition[:type] == 'SearchDateField'
# date ranges are handled via searchValue (start range) and searchValue2 (end range)

h[element_name] = {
'@operator' => condition[:operator],
"platformCore:searchValue" => condition[:value].first.to_s,
"platformCore:searchValue2" => condition[:value].last.to_s
}
elsif condition[:value].is_a?(Array) && condition[:operator] == 'between'

h[element_name] = {
'@operator' => condition[:operator],
"platformCore:searchValue" => condition[:value].first.to_s,
Expand Down
39 changes: 39 additions & 0 deletions lib/netsuite/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ def attributes
def connection(params={}, credentials={})
Savon.client({
wsdl: wsdl,
ssl_ca_cert_file: ssl_ca_cert_file,
ssl_verify_mode: (ssl_verify_mode || :peer),
ssl_version: ssl_version,
read_timeout: read_timeout,
namespaces: namespaces,
soap_header: auth_header(credentials),
Expand All @@ -22,6 +25,42 @@ def connection(params={}, credentials={})
}.update(params))
end

def ssl_version=(_ssl_version)
attributes[:ssl_version] = _ssl_version
end

def ssl_version(_ssl_version = nil)
if _ssl_version
self.ssl_version = _ssl_version
else
attributes[:ssl_version]
end
end

def ssl_verify_mode=(verify_mode)
attributes[:ssl_verify_mode] = verify_mode
end

def ssl_verify_mode(verify_mode = nil)
if verify_mode
self.ssl_verify_mode = verify_mode
else
attributes[:verify_mode]
end
end

def ssl_ca_cert_file=(path)
attributes[:ssl_ca_cert_file] = path
end

def ssl_ca_cert_file(path = nil)
if path
self.ssl_ca_cert_file = path
else
attributes[:ssl_ca_cert_file]
end
end

def api_version(version = nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these additional SSL configuration options needed? I'm hesitant to merge them in unless there is a strong general use case.

if version
self.api_version = version
Expand Down
2 changes: 1 addition & 1 deletion lib/netsuite/records/sales_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class SalesOrder
:rev_rec_on_rev_commitment, :sales_effective_date, :shipping_cost, :shipping_tax1_rate, :shipping_tax2_rate, :source,
:start_date, :status, :sync_partner_teams, :sync_sales_teams, :tax2_total, :tax_rate, :to_be_emailed, :to_be_faxed,
:to_be_printed, :total_cost_estimate, :tran_date, :tran_id, :tran_is_vsoe_bundle, :vat_reg_num,
:vsoe_auto_calc
:vsoe_auto_calc, :quantity, :bill_city, :bill_state, :ship_city, :ship_state, :cost_estimate, :amount, :is_ship_address

field :transaction_ship_address, ShipAddress
field :transaction_bill_address, BillAddress
Expand Down
10 changes: 5 additions & 5 deletions lib/netsuite/support/search_result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def initialize(response, result_class)
if response.body.has_key?(:record_list)
# basic search results
record_list = response.body[:record_list][:record]
record_list = [record_list] if @total_records == 1
record_list = [record_list] unless record_list.is_a?(Array)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious... why was this needed? What situation broke the existing implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have more than one page of items and the last page has only a single item.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, got it. Nice catch! Merged this into master.


record_list.each do |record|
results << result_class.new(record)
end
elsif response.body.has_key? :search_row_list
elsif response.body.has_key?(:search_row_list)
# advanced search results
record_list = response.body[:search_row_list][:search_row]
record_list = [record_list] if @total_records == 1
record_list = response.body[:search_row_list].try(:[], :search_row) || []
record_list = [record_list] unless record_list.is_a?(Array)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In what case this did this occur?

record_list.each do |record|
# TODO because of customFieldList we need to either make this recursive
Expand Down Expand Up @@ -90,4 +90,4 @@ def results_in_batches

end
end
end
end
2 changes: 1 addition & 1 deletion netsuite.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
gem.require_paths = ['lib']
gem.version = Netsuite::VERSION

gem.add_dependency 'savon', '~> 2.3.0'
gem.add_dependency 'savon', '~> 2.2.0'

gem.add_development_dependency 'rspec', '~> 2.99'
end