netsuite 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +8 -8
  2. data/README.md +32 -0
  3. data/lib/netsuite.rb +5 -1
  4. data/lib/netsuite/actions/add.rb +4 -4
  5. data/lib/netsuite/actions/delete.rb +7 -7
  6. data/lib/netsuite/actions/get.rb +5 -5
  7. data/lib/netsuite/actions/get_list.rb +24 -11
  8. data/lib/netsuite/actions/get_select_value.rb +5 -5
  9. data/lib/netsuite/actions/initialize.rb +5 -5
  10. data/lib/netsuite/actions/login.rb +33 -0
  11. data/lib/netsuite/actions/search.rb +5 -5
  12. data/lib/netsuite/actions/update.rb +5 -5
  13. data/lib/netsuite/actions/upsert.rb +4 -4
  14. data/lib/netsuite/configuration.rb +9 -9
  15. data/lib/netsuite/records/account.rb +1 -1
  16. data/lib/netsuite/records/custom_field_list.rb +2 -0
  17. data/lib/netsuite/records/custom_record.rb +1 -1
  18. data/lib/netsuite/records/customer.rb +9 -6
  19. data/lib/netsuite/records/deposit.rb +2 -2
  20. data/lib/netsuite/records/deposit_cash_back.rb +42 -0
  21. data/lib/netsuite/records/deposit_cash_back_list.rb +32 -0
  22. data/lib/netsuite/records/deposit_other.rb +45 -0
  23. data/lib/netsuite/records/deposit_other_list.rb +32 -0
  24. data/lib/netsuite/records/item_fulfillment.rb +7 -1
  25. data/lib/netsuite/records/item_fulfillment_item.rb +1 -1
  26. data/lib/netsuite/records/item_fulfillment_package_list.rb +22 -1
  27. data/lib/netsuite/records/sales_order.rb +1 -1
  28. data/lib/netsuite/records/service_sale_item.rb +1 -1
  29. data/lib/netsuite/support/requests.rb +5 -4
  30. data/lib/netsuite/version.rb +1 -1
  31. data/netsuite.gemspec +1 -1
  32. data/spec/netsuite/actions/add_spec.rb +5 -5
  33. data/spec/netsuite/actions/delete_spec.rb +2 -2
  34. data/spec/netsuite/actions/get_spec.rb +4 -4
  35. data/spec/netsuite/actions/initialize_spec.rb +2 -2
  36. data/spec/netsuite/actions/search_spec.rb +6 -6
  37. data/spec/netsuite/actions/update_spec.rb +4 -4
  38. data/spec/netsuite/actions/upsert_spec.rb +5 -5
  39. data/spec/netsuite/records/account_spec.rb +6 -6
  40. data/spec/netsuite/records/accounting_period_spec.rb +6 -6
  41. data/spec/netsuite/records/classification_spec.rb +4 -4
  42. data/spec/netsuite/records/credit_memo_spec.rb +8 -8
  43. data/spec/netsuite/records/custom_field_list_spec.rb +10 -0
  44. data/spec/netsuite/records/custom_field_spec.rb +1 -1
  45. data/spec/netsuite/records/custom_record_ref_spec.rb +1 -1
  46. data/spec/netsuite/records/custom_record_spec.rb +6 -6
  47. data/spec/netsuite/records/custom_record_type_spec.rb +6 -6
  48. data/spec/netsuite/records/customer_payment_spec.rb +9 -9
  49. data/spec/netsuite/records/customer_refund_spec.rb +8 -8
  50. data/spec/netsuite/records/customer_spec.rb +10 -10
  51. data/spec/netsuite/records/department_spec.rb +6 -6
  52. data/spec/netsuite/records/deposit_spec.rb +10 -10
  53. data/spec/netsuite/records/inventory_item_spec.rb +6 -6
  54. data/spec/netsuite/records/invoice_spec.rb +8 -8
  55. data/spec/netsuite/records/item_fulfillment_package_list_spec.rb +27 -0
  56. data/spec/netsuite/records/item_fulfillment_spec.rb +49 -0
  57. data/spec/netsuite/records/job_spec.rb +8 -8
  58. data/spec/netsuite/records/journal_entry_spec.rb +6 -6
  59. data/spec/netsuite/records/location_spec.rb +2 -2
  60. data/spec/netsuite/records/non_inventory_sale_item_spec.rb +6 -6
  61. data/spec/netsuite/records/payment_method_spec.rb +2 -2
  62. data/spec/netsuite/records/rev_rec_template_spec.rb +2 -2
  63. data/spec/netsuite/records/sales_order_spec.rb +9 -9
  64. data/spec/netsuite/records/service_sale_item_spec.rb +6 -6
  65. data/spec/netsuite/records/support_case_spec.rb +8 -8
  66. data/spec/netsuite/records/term_spec.rb +6 -6
  67. data/spec/netsuite/support/actions_spec.rb +1 -1
  68. data/spec/netsuite/support/attributes_spec.rb +1 -1
  69. data/spec/spec_helper.rb +1 -1
  70. metadata +13 -5
  71. data/lib/netsuite/actions/search_more_with_id.rb +0 -107
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTRlZDk0NGYwODZlOTA3OGZmMGQ2MDllMTdmNDNlZDI5YmY4ODNjYw==
4
+ ZTRiNTZiNjNmNzNhNDY0NzNiYWEwYTBmZmI4MWI3MzA3YTM5N2Q4Nw==
5
5
  data.tar.gz: !binary |-
6
- ZTA3YTgyYTE5ZDAxNWUyY2ZiNmViODlmNGE1NTY4MjFlY2U2OGI5Ng==
6
+ ZTdlZTI4Njc5MDlmN2ViNThiMDNjY2Q4ZGE4ZjZkM2JiZGUwNDc0Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZWI1MDEyYWRjNmY3YzNlYWY2ZmUzNDlkNjYzZDgyNGI1YzA5OTg5ZjA0YzQ2
10
- N2I3YzUzNDU3NGRjYjA2NjQ0MjZmMWY4ZmNjYTc0MzM4N2UxNjVlMWExZWUy
11
- ODUwYzBjM2QzNTI1NGZkNDZiNWM1ODE5M2FmZGVkNWYwNWU0NmQ=
9
+ NWVkYjczN2Q2ODA0ZTcxMmJmMTlhN2ZhNTg1MmY0Nzc2NGE0MmZhZDJmZWUz
10
+ ZmE4YWJlZWIxMDQ1NDhjZWVlYjNmYjI3OTdhYjQyNmQxOTUzMWJiYjFlNWFj
11
+ NmQ3YmU0OTMzOTdhYmI2NzkxMDVjZjE5ZjQ1ZGY2OTE0NzE4ZGU=
12
12
  data.tar.gz: !binary |-
13
- OTI5Mzc5MWE1NTg1YjUxZWUzYjhlMWIxYmNiZjZkMmVmODUxNDMzOGFkMTg0
14
- OGFmZjc5NmMyOGNhZGE0NzJlZTVkYjU2ZWU5YTQwMWYwNmU2NjU2NmExYWNl
15
- NDAwZWNmMzk2ZTEzOWM3ZWRhOWJjODg4OTljN2ZkMzU4ZmYwM2Y=
13
+ NzUzMGVkMDg2ZTQxOTdmMWI3ZWU3ZjgzZWJiMDlmYzQ4M2QzZmFiZWEyZGYw
14
+ N2ZkZDgwNWUwNzU1MmVhZDRhZjQwYjhkOGU2OTUzMzY1YWYzMGFlMzMwZWRh
15
+ MDhjYjRlMzZlY2MzMTVhZTg5YWVlNDgyYTFiN2NiZGQxZDVhMTA=
data/README.md CHANGED
@@ -33,6 +33,9 @@ bundle exec rspec
33
33
  ## Usage
34
34
 
35
35
  ### Configuration
36
+
37
+ Not sure how to find your account id? Search for "web service preferences" in the NetSuite global search.
38
+
36
39
  ```ruby
37
40
  NetSuite.configure do
38
41
  reset!
@@ -274,4 +277,33 @@ contact = NetSuite::Records::Contact.get(12345)
274
277
  contact.custom_field_list.custentity_alistfield = { internal_id: 1 }
275
278
  contact.custom_field_list.custentity_abooleanfield = true
276
279
  contact.update(custom_field_list: contact.custom_field_list)
280
+
281
+ # the getList operation
282
+ NetSuite::Records::CustomRecord.get_list(
283
+ # netsuite internalIDs
284
+ list: [1,2,3],
285
+ # only needed for a custom record
286
+ type_id: 1234
287
+ ).each do |record|
288
+ # do your thing...
289
+ end
290
+
291
+ # getting a custom record
292
+ record = NetSuite::Records::CustomRecord.get(
293
+ # custom record type
294
+ type_id: 10,
295
+ # reference to instance of the custom record type
296
+ internal_id: 100
297
+ )
298
+
299
+ # adding a custom record
300
+ record = NetSuite::Records::CustomRecord.new
301
+ record.rec_type = NetSuite::Records::CustomRecord.new(internal_id: 10)
302
+ record.custom_field_list.custrecord_locationstate = "New Jersey"
303
+ record.add
304
+
305
+ # updating a custom record
306
+ record = NetSuite::Records::CustomRecord.new(internal_id: 100)
307
+ record.custom_field_list.custrecord_locationstate = "New Jersey"
308
+ record.update(custom_field_list: record.custom_field_list, rec_type: NetSuite::Records::CustomRecord.new(internal_id: 10))
277
309
  ```
@@ -44,7 +44,7 @@ module NetSuite
44
44
  autoload :Update, 'netsuite/actions/update'
45
45
  autoload :Upsert, 'netsuite/actions/upsert'
46
46
  autoload :Search, 'netsuite/actions/search'
47
- autoload :SearchMoreWithId, 'netsuite/actions/search_more_with_id'
47
+ autoload :Login, 'netsuite/actions/login'
48
48
  end
49
49
 
50
50
  module Records
@@ -84,6 +84,10 @@ module NetSuite
84
84
  autoload :Deposit, 'netsuite/records/deposit'
85
85
  autoload :DepositPayment, 'netsuite/records/deposit_payment'
86
86
  autoload :DepositPaymentList, 'netsuite/records/deposit_payment_list'
87
+ autoload :DepositOther, 'netsuite/records/deposit_other'
88
+ autoload :DepositOtherList, 'netsuite/records/deposit_other_list'
89
+ autoload :DepositCashBack, 'netsuite/records/deposit_cash_back'
90
+ autoload :DepositCashBackList, 'netsuite/records/deposit_cash_back_list'
87
91
  autoload :Duration, 'netsuite/records/duration'
88
92
  autoload :InventoryItem, 'netsuite/records/inventory_item'
89
93
  autoload :Invoice, 'netsuite/records/invoice'
@@ -11,8 +11,8 @@ module NetSuite
11
11
 
12
12
  private
13
13
 
14
- def request
15
- NetSuite::Configuration.connection.call :add, :message => request_body
14
+ def request(credentials={})
15
+ NetSuite::Configuration.connection({}, credentials).call(:add, :message => request_body)
16
16
  end
17
17
 
18
18
  # <soap:Body>
@@ -70,8 +70,8 @@ module NetSuite
70
70
  end
71
71
 
72
72
  module Support
73
- def add
74
- response = NetSuite::Actions::Add.call(self)
73
+ def add(credentials={})
74
+ response = NetSuite::Actions::Add.call([self], credentials)
75
75
 
76
76
  @errors = response.errors
77
77
 
@@ -10,13 +10,13 @@ module NetSuite
10
10
 
11
11
  private
12
12
 
13
- def request
13
+ def request(credentials={})
14
14
  NetSuite::Configuration.connection(
15
- namespaces: {
15
+ {namespaces: {
16
16
  'xmlns:platformMsgs' => "urn:messages_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
17
17
  'xmlns:platformCore' => "urn:core_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com"
18
- },
19
- ).call :delete, :message => request_body
18
+ }}, credentials
19
+ ).call :delete, message: request_body
20
20
  end
21
21
 
22
22
  def soap_type
@@ -65,11 +65,11 @@ module NetSuite
65
65
  end
66
66
 
67
67
  module Support
68
- def delete(options = {})
68
+ def delete(options = {}, credentials={})
69
69
  response = if options.empty?
70
- NetSuite::Actions::Delete.call(self)
70
+ NetSuite::Actions::Delete.call([self], credentials)
71
71
  else
72
- NetSuite::Actions::Delete.call(self, options)
72
+ NetSuite::Actions::Delete.call([self, options], credentials)
73
73
  end
74
74
  response.success?
75
75
  end
@@ -10,12 +10,12 @@ module NetSuite
10
10
 
11
11
  private
12
12
 
13
- def request
13
+ def request(credentials={})
14
14
  NetSuite::Configuration.connection(
15
- namespaces: {
15
+ {namespaces: {
16
16
  'xmlns:platformMsgs' => "urn:messages_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
17
17
  'xmlns:platformCore' => "urn:core_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com"
18
- },
18
+ }}, credentials
19
19
  ).call :get, message: request_body
20
20
  end
21
21
 
@@ -63,10 +63,10 @@ module NetSuite
63
63
 
64
64
  module ClassMethods
65
65
 
66
- def get(options = {})
66
+ def get(options = {}, credentials = {})
67
67
  options = { :internal_id => options } unless options.is_a?(Hash)
68
68
 
69
- response = NetSuite::Actions::Get.call(self, options)
69
+ response = NetSuite::Actions::Get.call([self, options], credentials)
70
70
  if response.success?
71
71
  new(response.body)
72
72
  else
@@ -10,29 +10,42 @@ module NetSuite
10
10
 
11
11
  private
12
12
 
13
- def request
14
- NetSuite::Configuration.connection.call :get_list, :message => request_body
13
+ def request(credentials={})
14
+ NetSuite::Configuration.connection({}, credentials).call(:get_list, :message => request_body)
15
15
  end
16
16
 
17
17
  def request_body
18
- if @options[:type_id]
18
+ # list of all netsuite types; useful for debugging
19
+ # https://webservices.netsuite.com/xsd/platform/v2014_1_0/coreTypes.xsd
20
+
21
+ list = @options.is_a?(Hash) ? @options[:list] : @options
22
+
23
+ formatted_list = if @options[:type_id]
19
24
  type = @options[:type_id]
20
25
  record_type = 'platformCore:CustomRecordRef'
26
+
27
+ list.map do |internal_id|
28
+ {
29
+ '@internalId' => internal_id,
30
+ '@typeId' => type,
31
+ '@xsi:type' => record_type
32
+ }
33
+ end
21
34
  else
22
35
  type = @klass.to_s.split('::').last.lower_camelcase
23
36
  record_type = 'platformCore:RecordRef'
24
- end
25
37
 
26
- list = @options.is_a?(Hash) ? @options[:list] : @options
27
-
28
- {
29
- baseRef: list.map do |internal_id|
38
+ list.map do |internal_id|
30
39
  {
31
40
  '@internalId' => internal_id,
32
- '@typeId' => type,
41
+ '@type' => type,
33
42
  '@xsi:type' => record_type
34
43
  }
35
44
  end
45
+ end
46
+
47
+ {
48
+ baseRef: formatted_list
36
49
  }
37
50
  end
38
51
 
@@ -59,8 +72,8 @@ module NetSuite
59
72
  end
60
73
 
61
74
  module ClassMethods
62
- def get_list(options = { })
63
- response = NetSuite::Actions::GetList.call(self, options)
75
+ def get_list(options = { }, credentials={})
76
+ response = NetSuite::Actions::GetList.call([self, options], credentials)
64
77
 
65
78
  if response.success?
66
79
  response.body.map do |record|
@@ -10,12 +10,12 @@ module NetSuite
10
10
 
11
11
  private
12
12
 
13
- def request
13
+ def request(credentials={})
14
14
  NetSuite::Configuration.connection(
15
- namespaces: {
15
+ {namespaces: {
16
16
  'xmlns:platformMsgs' => "urn:messages_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
17
17
  'xmlns:platformCore' => "urn:core_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com"
18
- },
18
+ }}, credentials
19
19
  ).call :get_select_value, :message => @options
20
20
  end
21
21
 
@@ -39,13 +39,13 @@ module NetSuite
39
39
 
40
40
  module ClassMethods
41
41
 
42
- def get_select_value(options = {})
42
+ def get_select_value(options = {}, credentials={})
43
43
  message = {
44
44
  pageIndex: (options.delete(:pageIndex) || 1),
45
45
  fieldDescription: field_description(options)
46
46
  }
47
47
 
48
- response = NetSuite::Actions::GetSelectValue.call(self, message)
48
+ response = NetSuite::Actions::GetSelectValue.call([self, message], credentials)
49
49
 
50
50
  if response.success?
51
51
  new(response.body)
@@ -8,13 +8,13 @@ module NetSuite
8
8
  @object = object
9
9
  end
10
10
 
11
- def request
11
+ def request(credentials={})
12
12
  NetSuite::Configuration.connection(
13
- namespaces: {
13
+ {namespaces: {
14
14
  'xmlns:platformMsgs' => "urn:messages_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
15
15
  'xmlns:platformCore' => "urn:core_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
16
16
  'xmlns:platformCoreTyp' => "urn:types.core_#{NetSuite::Configuration.api_version}.platform.webservices.netsuite.com",
17
- },
17
+ }}, credentials
18
18
  ).call :initialize, :message => request_body
19
19
  end
20
20
 
@@ -64,8 +64,8 @@ module NetSuite
64
64
 
65
65
  module ClassMethods
66
66
 
67
- def initialize(object)
68
- response = NetSuite::Actions::Initialize.call(self, object)
67
+ def initialize(object, credentials={})
68
+ response = NetSuite::Actions::Initialize.call([self, object], credentials)
69
69
  if response.success?
70
70
  new(response.body)
71
71
  else
@@ -0,0 +1,33 @@
1
+ module NetSuite
2
+ module Actions
3
+ class Login
4
+
5
+ def self.call(credentials)
6
+ passport = NetSuite::Configuration.auth_header.dup
7
+ passport['platformMsgs:passport']['platformCore:email'] = credentials[:email] || ''
8
+ passport['platformMsgs:passport']['platformCore:password'] = credentials[:password] || ''
9
+
10
+ begin
11
+ response = NetSuite::Configuration.connection(soap_header: {}).call :login, message: passport
12
+ rescue Savon::SOAPFault => e
13
+ error_details = e.to_hash[:fault]
14
+
15
+ return NetSuite::Response.new(
16
+ success: false,
17
+ errors: [ NetSuite::Error.new(
18
+ code: error_details[:detail][:invalid_credentials_fault][:code],
19
+ message: error_details[:faultstring]
20
+ )],
21
+ body: error_details
22
+ )
23
+ end
24
+
25
+ NetSuite::Response.new(
26
+ success: response.to_hash[:login_response][:session_response][:status][:@is_success] == 'true',
27
+ body: response.to_hash[:login_response][:session_response][:base_ref]
28
+ )
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -17,11 +17,11 @@ module NetSuite
17
17
  end
18
18
 
19
19
  private
20
- def request
20
+ def request(credentials={})
21
21
  # https://system.netsuite.com/help/helpcenter/en_US/Output/Help/SuiteCloudCustomizationScriptingWebServices/SuiteTalkWebServices/SettingSearchPreferences.html
22
22
  # https://webservices.netsuite.com/xsd/platform/v2012_2_0/messages.xsd
23
- preferences = NetSuite::Configuration.auth_header
24
- preferences = preferences.merge(
23
+
24
+ preferences = NetSuite::Configuration.auth_header(credentials).update(
25
25
  (@options.delete(:preferences) || {}).inject({'platformMsgs:SearchPreferences' => {}}) do |h, (k, v)|
26
26
  h['platformMsgs:SearchPreferences'][k.to_s.lower_camelcase] = v
27
27
  h
@@ -228,8 +228,8 @@ module NetSuite
228
228
  end
229
229
 
230
230
  module ClassMethods
231
- def search(options = { })
232
- response = NetSuite::Actions::Search.call(self, options)
231
+ def search(options = { }, credentials={})
232
+ response = NetSuite::Actions::Search.call([self, options], credentials)
233
233
 
234
234
  if response.success?
235
235
  NetSuite::Support::SearchResult.new(response, self)
@@ -8,8 +8,8 @@ module NetSuite
8
8
  @attributes = attributes
9
9
  end
10
10
 
11
- def request
12
- NetSuite::Configuration.connection.call :update, :message => request_body
11
+ def request(credentials={})
12
+ NetSuite::Configuration.connection({}, credentials).call :update, :message => request_body
13
13
  end
14
14
 
15
15
  # <platformMsgs:update>
@@ -32,7 +32,7 @@ module NetSuite
32
32
  if updated_record.respond_to?(:external_id) && updated_record.external_id
33
33
  hash['platformMsgs:record']['@platformMsgs:externalId'] = updated_record.external_id
34
34
  end
35
-
35
+
36
36
  hash
37
37
  end
38
38
 
@@ -53,10 +53,10 @@ module NetSuite
53
53
  end
54
54
 
55
55
  module Support
56
- def update(options = {})
56
+ def update(options = {}, credentials={})
57
57
  options.merge!(:internal_id => internal_id) if respond_to?(:internal_id) && internal_id
58
58
  options.merge!(:external_id => external_id) if respond_to?(:external_id) && external_id
59
- response = NetSuite::Actions::Update.call(self.class, options)
59
+ response = NetSuite::Actions::Update.call([self.class, options], credentials)
60
60
  response.success?
61
61
  end
62
62
  end
@@ -11,8 +11,8 @@ module NetSuite
11
11
 
12
12
  private
13
13
 
14
- def request
15
- NetSuite::Configuration.connection.call :upsert, :message => request_body
14
+ def request(credentials={})
15
+ NetSuite::Configuration.connection({}, credentials).call :upsert, :message => request_body
16
16
  end
17
17
 
18
18
  # <soap:Body>
@@ -70,8 +70,8 @@ module NetSuite
70
70
  end
71
71
 
72
72
  module Support
73
- def upsert
74
- response = NetSuite::Actions::Upsert.call(self)
73
+ def upsert(credentials={})
74
+ response = NetSuite::Actions::Upsert.call([self], credentials)
75
75
 
76
76
  @errors = response.errors
77
77
 
@@ -10,16 +10,16 @@ module NetSuite
10
10
  @attributes ||= {}
11
11
  end
12
12
 
13
- def connection(params = {})
13
+ def connection(params={}, credentials={})
14
14
  Savon.client({
15
15
  wsdl: wsdl,
16
16
  read_timeout: read_timeout,
17
17
  namespaces: namespaces,
18
- soap_header: auth_header,
18
+ soap_header: auth_header(credentials),
19
19
  pretty_print_xml: true,
20
20
  logger: logger,
21
21
  log_level: log_level,
22
- }.merge(params))
22
+ }.update(params))
23
23
  end
24
24
 
25
25
  def api_version(version = nil)
@@ -65,13 +65,13 @@ module NetSuite
65
65
  end
66
66
  end
67
67
 
68
- def auth_header
69
- attributes[:auth_header] ||= {
68
+ def auth_header(credentials={})
69
+ {
70
70
  'platformMsgs:passport' => {
71
- 'platformCore:email' => email,
72
- 'platformCore:password' => password,
73
- 'platformCore:account' => account.to_s,
74
- 'platformCore:role' => { :'@type' => 'role', :@internalId => role }
71
+ 'platformCore:email' => credentials[:email] || email,
72
+ 'platformCore:password' => credentials[:password] || password,
73
+ 'platformCore:account' => credentials[:account] || account.to_s,
74
+ 'platformCore:role' => { :@internalId => credentials[:role] || role }
75
75
  }
76
76
  }
77
77
  end