Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
string sanitization of inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesChristie committed Aug 16, 2012
1 parent c58888c commit c924863
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/netsuite-rest-client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'uri'

BASE_URL = "https://rest.netsuite.com/app/site/hosting/restlet.nl"
DEFAULT_SCRIPT_ID = 11
DEFAULT_SCRIPT_ID = 12
DEFAULT_DEPLOY_ID = 1
DEFAULT_SEARCH_BATCH_SIZE = 1000
DEFAULT_RETRY_LIMIT = 5
Expand Down Expand Up @@ -110,6 +110,8 @@ def delete(record_type, internal_ids, options={})
'deploy' => @deploy_id }
results = Array.new

internal_ids = internal_ids.map { |id| id.to_s }

internal_ids.each_slice(options[:batch_size] || DEFAULT_DELETE_BATCH_SIZE) do |internal_ids_chunk|
payload = { 'operation' => 'DELETE',
'record_type' => record_type,
Expand Down Expand Up @@ -162,7 +164,7 @@ def parse_json_result_from_rest(method, params, options={})

reply = nil
retryable(@retry_limit, Exception) do
reply = RestClient::Request.execute(rest_params) { |response, request, result, &block|
reply = RestClient::Request.execute(stringify(rest_params)) { |response, request, result, &block|
case response.code
when 200
response
Expand All @@ -179,6 +181,19 @@ def parse_json_result_from_rest(method, params, options={})
end
end

def stringify(data)
if data.class == Array
data.map { |value_item| stringify(value_item) }
elsif data.class == Hash
data.inject({}) do |hash, (key, value)|
hash[key.to_s] = stringify(value)
hash
end
else
data.to_s
end
end

def create_url(params)
BASE_URL + '?' + params.map { |key, value| "#{key}=#{value}" }.join('&')
end
Expand Down

0 comments on commit c924863

Please sign in to comment.