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

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit da06a74
Author: James Christie <[email protected]>
Date:   Wed Dec 19 11:29:31 2012 -0600

    Add ability to fetch a list of records by a list of ids in a single request

    commit 9330c79ef90d3d3559491faf156232a72bce2882
    Author: James Christie <[email protected]>
    Date:   Wed Dec 19 11:26:52 2012 -0600

        Fix bug with RESTlet not properly concatenating results

    commit 880a1d8d5d0dccb00cb90dce570fbeff0dbe7e15
    Author: James Christie <[email protected]>
    Date:   Wed Dec 19 11:19:56 2012 -0600

        Flatten return values somewhat

    commit cc47a74207e1972b3936382c4ca1ee9ca1b8f680
    Author: James Christie <[email protected]>
    Date:   Wed Dec 19 11:15:15 2012 -0600

        Add opetional var to disable de-Array-ing of single item returns

    commit dc4895a5a1f46d0164ad09c308268fe52bfb9002
    Author: James Christie <[email protected]>
    Date:   Wed Dec 19 11:08:52 2012 -0600

        Assign payload object to request

    commit 6a0383f9af88515669f4e26c1b9119241c802c0d
    Author: James Christie <[email protected]>
    Date:   Wed Dec 19 11:06:18 2012 -0600

        Correct deploy id

    commit ec89b6e9c10f70090e049bf84b202c05f47a7d64
    Author: James Christie <[email protected]>
    Date:   Wed Dec 19 11:01:21 2012 -0600

        Convert get_record method to a POST request

    commit 195da062393634aca1ce1ec2e04dfa1b140dd617
    Author: James Christie <[email protected]>
    Date:   Wed Dec 19 10:58:03 2012 -0600

        Bump script and deploy ids to the new restlet deployment

    commit c765b82dd7862a33b56be19aecdf37a06e8823e0
    Author: James Christie <[email protected]>
    Date:   Wed Dec 19 10:52:55 2012 -0600

        Update get_record method to support a list of multiple ids and properly batch the request

    commit 61908dbcd76643032c1a09ea97f6f6604cac45f0
    Author: James Christie <[email protected]>
    Date:   Wed Dec 19 10:46:53 2012 -0600

        Update RESTlet script to support fetching a list of record ids

commit 4bda276
Merge: d3086ae b1e0f1a
Author: James Christie <[email protected]>
Date:   Wed Nov 14 11:58:19 2012 -0600

    Merge branch 'master' into development

    Conflicts:
    	lib/restlets/rest.js

commit d3086ae
Author: James Christie <[email protected]>
Date:   Mon Oct 29 22:38:12 2012 -0500

    tentative declaration of matching field for a list of line items on a given sublist field

commit ce9ac98
Merge: e57624a f96d218
Author: James Christie <[email protected]>
Date:   Mon Oct 29 14:46:01 2012 -0500

    Merge branch 'master' into development

commit e57624a
Author: James Christie <[email protected]>
Date:   Sun Oct 28 22:05:59 2012 -0500

    bugfixes for transformation line item handling

commit e0d1c86
Author: James Christie <[email protected]>
Date:   Sun Oct 28 20:40:33 2012 -0500

    removed some more old code

commit d39f1f2
Author: James Christie <[email protected]>
Date:   Sun Oct 28 20:39:00 2012 -0500

    removed iteration from previous version of the transform operation

commit e506a0b
Author: James Christie <[email protected]>
Date:   Sun Oct 28 20:24:27 2012 -0500

    full line item operation coverage on record transformations
  • Loading branch information
James Christie committed Dec 19, 2012
1 parent b1e0f1a commit e8b38bc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
43 changes: 27 additions & 16 deletions lib/netsuite-rest-client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
require 'json'
require 'uri'

BASE_URL = "https://rest.netsuite.com/app/site/hosting/restlet.nl"
DEFAULT_SCRIPT_ID = 12
DEFAULT_DEPLOY_ID = 1
DEFAULT_SEARCH_BATCH_SIZE = 1000
DEFAULT_RETRY_LIMIT = 5
DEFAULT_REQUEST_TIMEOUT = -1
DEFAULT_UPSERT_BATCH_SIZE = 40
DEFAULT_DELETE_BATCH_SIZE = 60
DEFAULT_TRANSFORM_BATCH_SIZE = 10
BASE_URL = "https://rest.netsuite.com/app/site/hosting/restlet.nl"
DEFAULT_SCRIPT_ID = 13
DEFAULT_DEPLOY_ID = 1
DEFAULT_GET_RECORD_BATCH_SIZE = 10000
DEFAULT_SEARCH_BATCH_SIZE = 1000
DEFAULT_RETRY_LIMIT = 5
DEFAULT_REQUEST_TIMEOUT = -1
DEFAULT_UPSERT_BATCH_SIZE = 40
DEFAULT_DELETE_BATCH_SIZE = 60
DEFAULT_TRANSFORM_BATCH_SIZE = 10

module Netsuite
class Client
Expand All @@ -36,7 +37,8 @@ def initialize(account_id, login, password, role_id, options={})
@script_id = options[:rest_script_id] || DEFAULT_SCRIPT_ID
@deploy_id = options[:rest_deploy_id] || DEFAULT_DEPLOY_ID

@search_batch_size = options[:search_batch_size] || DEFAULT_SEARCH_BATCH_SIZE
@get_record_batch_size = options[:get_record_batch_size] || DEFAULT_GET_RECORD_BATCH_SIZE
@search_batch_size = options[:search_batch_size] || DEFAULT_SEARCH_BATCH_SIZE

@retry_limit = options[:retry_limit] || DEFAULT_RETRY_LIMIT
end
Expand All @@ -50,14 +52,23 @@ def initialize_record(record_type)
parse_json_result_from_rest(:get, params)
end

def get_record(record_type, internal_id)
def get_record(record_type, internal_id_list, return_array_on_single=false)
internal_id_list = Array(internal_id_list).uniq

params = { 'script' => @script_id,
'deploy' => @deploy_id,
'operation' => 'LOAD',
'record_type' => record_type,
'internal_id' => internal_id }
'deploy' => @deploy_id }

parse_json_result_from_rest(:get, params)
payload = { 'operation' => 'LOAD',
'record_type' => record_type }

results = []
internal_id_list.each_slice(@get_record_batch_size) do |id_chunk|
payload['internal_id_list'] = id_chunk
results += parse_json_result_from_rest(:post, params, :payload=>payload)
end

results = results.first if results.length == 1 && !return_array_on_single
results
end

def search_records(record_type, search_filters, return_columns, options={})
Expand Down
24 changes: 18 additions & 6 deletions lib/restlets/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var OPERATIONS = { 'CREATE': { 'function': 'initializeRecord',
'access': 'GET',
'baseGovernance': 10 },
'LOAD': { 'function': 'loadRecord',
'access': 'GET',
'access': 'POST',
'baseGovernance': 10 },
'SAVED': { 'function': 'getSavedSearch',
'access': 'GET',
Expand Down Expand Up @@ -156,15 +156,27 @@ function loadRecord(request) {
/*
* Description: Retrieves a single record based on query fields
* Params:
* recordType: String matching a record type
* internalId: String matching the internal id of a record
* request['record_type']: String matching a record type
* request['internal_id_list']: Array of Strings matching the internal ids of multiple records
*
* Return: Record of given type with given id
*/
var recordType = request.record_type;
var internalId = request.internal_id;
var recordType = request['record_type'];
var internalIdList = request['internal_id_list'];
var recordList = [];

for(var index = 0; index < internalIdList.length; index++) {
recordId = internalIdList[index];

try {
recordList.push(nlapiLoadRecord(recordType, recordId));
}
catch(load_exception) {
recordList.push(formatException(load_exception));
}
}

return(nlapiLoadRecord(recordType, internalId));
return(recordList);
}

function searchRecords(request) {
Expand Down

0 comments on commit e8b38bc

Please sign in to comment.