netsuite 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjcyMjQzYWViZjVhMTVhZjJjODQyMzYxYTAwNTYyMDhmMTBjMmJjZA==
4
+ YjY3MzQ4ZTcwOTU2YjM1YzE1YmFkMWVjMGI3YmE0NWMzNWFmYzE2Zg==
5
5
  data.tar.gz: !binary |-
6
- MThjNDBjNzc1MzkwZDhkODhlNmRiMjM5NjlhZDg3ZWIxZDA2NjJlNA==
6
+ NzgzZTEyNjNhYTVmNjMwZjIyNDc2YmU2ZjhjZTRlNGVmYzk4NmI1Mw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDUwZWUzYmMzNGMxNDJiMDQyODdjNGVjNzRiMTFkY2IxN2JiYTgwM2ZmNDQw
10
- MzZiZjUwOGU3NGI5ZTM4MGJiMzg1ODYwOTU0MTQyOWZlY2M4YTQzOWM3ZmU1
11
- YWViNDE1MjFlNmQ5OTIwYzFkNDhhMGJjZmY1ZDE1NGQwMTg4MTE=
9
+ Mzc1ZDMwMzFjMzhkNzQxMmIyZmYzNmY5ZGQzN2I5NWM2MmU0YTBmYTcwZTM4
10
+ Y2Q3OGExNTlmMDYyNTNmZWI0YThkMzk2YzZlNjk2ZDA1ODk4ZjNmNTFiZDlm
11
+ MmY5ODY5MGVhOTAzZDAxZTcxODczNzc1NmVhYmFiYWM3ZTFhYTk=
12
12
  data.tar.gz: !binary |-
13
- MjQxNTlkMmVhODZhMjlkYTRiZTQxNzU5ZDE2NzhiZDk4ZjRlOTQ4OTM3NWU5
14
- NWMzY2U3MTc1NTExYjZlZTVmZGI0ZjAwOGY1ZWMzMmU1YTQ4YWJhMGIyZDdh
15
- OWU5NDc0MDU5MGQwMDVjN2ZiYTk5NjhiM2ZkNGJlNjY1Y2I5OTM=
13
+ ODUzZjFhMGVjMGY2MjhmYzdiMTU5NGZmYmRhYzhkOWEwZDhjMWU3NTVmZGJh
14
+ OTU1YjlhMTg4YzQ3ZGMyNWQzOTFmYWFjZDMwZjYzZDcxMWYyMGVjNzY1OTU5
15
+ NmEwNjk0NjgyOTg1ZDJlNDk1ZDc1ZGViYTM1YTc3OTEzZjFlZjc=
@@ -194,7 +194,7 @@ module NetSuite
194
194
  def self.configure_from_env(&block)
195
195
  NetSuite.configure do
196
196
  reset!
197
-
197
+
198
198
  email ENV['NETSUITE_EMAIL'] unless ENV['NETSUITE_EMAIL'].nil?
199
199
  password ENV['NETSUITE_PASSWORD'] unless ENV['NETSUITE_PASSWORD'].nil?
200
200
  account ENV['NETSUITE_ACCOUNT'] unless ENV['NETSUITE_ACCOUNT'].nil?
@@ -223,14 +223,10 @@ module NetSuite
223
223
  @success ||= search_result[:status][:@is_success] == 'true'
224
224
  end
225
225
 
226
- # TODO need to figure out a way for the user to access this
227
- def errors
228
- error_obj = response_hash[:status][:status_detail]
229
- error_obj = [error_obj] if error_obj.class == Hash
230
- error_obj.map do |error|
231
- NetSuite::Error.new(error)
226
+ protected
227
+ def method_name
228
+
232
229
  end
233
- end
234
230
 
235
231
  module Support
236
232
  def self.included(base)
@@ -10,13 +10,11 @@ module NetSuite
10
10
  when Array
11
11
  attributes[:custom_field].each { |custom_field| extract_custom_field(custom_field) }
12
12
  end
13
-
13
+
14
14
  @custom_fields_assoc = Hash.new
15
15
  custom_fields.each do |custom_field|
16
- reference_id = custom_field.script_id || custom_field.internal_id
17
-
18
16
  # not all custom fields have an id; https://github.com/NetSweet/netsuite/issues/182
19
- if reference_id
17
+ if reference_id = custom_field.send(reference_id_type)
20
18
  @custom_fields_assoc[reference_id.to_sym] = custom_field
21
19
  end
22
20
  end
@@ -27,7 +25,7 @@ module NetSuite
27
25
  end
28
26
 
29
27
  def delete_custom_field(field)
30
- custom_fields.delete_if { |c| c.internal_id.to_sym == field }
28
+ custom_fields.delete_if { |c| c.send(reference_id_type).to_sym == field }
31
29
  @custom_fields_assoc.delete(field)
32
30
  end
33
31
 
@@ -38,7 +36,7 @@ module NetSuite
38
36
  def custom_fields_by_type(type)
39
37
  custom_fields.select { |field| field.type == "platformCore:#{type}" }
40
38
  end
41
-
39
+
42
40
  def method_missing(sym, *args, &block)
43
41
  # read custom field if already set
44
42
  if @custom_fields_assoc.include?(sym)
@@ -93,6 +91,10 @@ module NetSuite
93
91
  end
94
92
 
95
93
  private
94
+ def reference_id_type
95
+ @reference_id_type ||= Configuration.api_version >= '2013_2' ? :script_id : :internal_id
96
+ end
97
+
96
98
  def extract_custom_field(custom_field_data)
97
99
  # TODO this seems brittle, but might sufficient, watch out for this if something breaks
98
100
  if custom_field_data[:"@xsi:type"] == "platformCore:SelectCustomFieldRef"
@@ -102,7 +104,7 @@ module NetSuite
102
104
  custom_fields << CustomField.new(custom_field_data)
103
105
  end
104
106
 
105
- def create_custom_field(internal_id, field_value)
107
+ def create_custom_field(reference_id, field_value)
106
108
  # all custom fields need types; infer type based on class sniffing
107
109
  field_type = case
108
110
  when field_value.is_a?(Array)
@@ -123,7 +125,7 @@ module NetSuite
123
125
  # TODO seems like DateTime doesn't need the iso8601 call
124
126
  # not sure if this is specific to my env though
125
127
 
126
- custom_field_value = case
128
+ custom_field_value = case
127
129
  when field_value.is_a?(Hash)
128
130
  CustomRecordRef.new(field_value)
129
131
  when field_value.is_a?(Date)
@@ -146,13 +148,13 @@ module NetSuite
146
148
  end
147
149
 
148
150
  custom_field = CustomField.new(
149
- internal_id: internal_id,
150
- value: custom_field_value,
151
- type: "#{record_namespace}:#{field_type}"
151
+ reference_id_type => reference_id,
152
+ :value => custom_field_value,
153
+ :type => "#{record_namespace}:#{field_type}"
152
154
  )
153
155
 
154
156
  custom_fields << custom_field
155
- @custom_fields_assoc[internal_id.to_sym] = custom_field
157
+ @custom_fields_assoc[reference_id.to_sym] = custom_field
156
158
  end
157
159
  end
158
160
  end
@@ -24,6 +24,10 @@ module NetSuite
24
24
  attr_reader :internal_id
25
25
  attr_accessor :external_id
26
26
 
27
+ def self.search_class_name
28
+ 'Employee'
29
+ end
30
+
27
31
  end
28
32
  end
29
33
  end
@@ -7,7 +7,7 @@ module NetSuite
7
7
  include Support::Actions
8
8
  include Namespaces::TranSales
9
9
 
10
- actions :get, :get_list, :initialize, :add, :delete, :upsert, :search
10
+ actions :get, :get_list, :initialize, :add, :update, :delete, :upsert, :search
11
11
 
12
12
  fields :balance, :bill_address,
13
13
  :billing_schedule, :contrib_pct, :created_date, :currency_name, :custom_field_list,
@@ -3,6 +3,7 @@ module NetSuite
3
3
  class Location
4
4
  include Support::Fields
5
5
  include Support::RecordRefs
6
+ include Support::Records
6
7
  include Support::Actions
7
8
  include Namespaces::ListAcct
8
9
 
@@ -20,7 +20,7 @@ module NetSuite
20
20
  def initialize(response, result_class)
21
21
  @result_class = result_class
22
22
  @response = response
23
-
23
+
24
24
  @total_records = response.body[:total_records].to_i
25
25
  @total_pages = response.body[:total_pages].to_i
26
26
  @current_page = response.body[:page_index].to_i
@@ -48,7 +48,7 @@ module NetSuite
48
48
  next if search_group.to_s.start_with?('@')
49
49
 
50
50
  record[search_group].each_pair do |k, v|
51
- # all return values of joined searchs are wrapped in a <SearchValue/>
51
+ # all return values are wrapped in a <SearchValue/>
52
52
  # extract the value from <SearchValue/> to make results easier to work with
53
53
 
54
54
  if v.is_a?(Hash) && v.has_key?(:search_value)
@@ -63,7 +63,6 @@ module NetSuite
63
63
  end
64
64
 
65
65
  result_wrapper = result_class.new(record.delete(:basic))
66
- # TODO if custom record search the type id should be copied over
67
66
  result_wrapper.search_joins = record
68
67
  results << result_wrapper
69
68
  end
@@ -98,4 +97,4 @@ module NetSuite
98
97
 
99
98
  end
100
99
  end
101
- end
100
+ end
@@ -1,3 +1,3 @@
1
1
  module Netsuite
2
- VERSION = '0.4.3'
2
+ VERSION = '0.4.4'
3
3
  end
@@ -7,31 +7,77 @@ describe NetSuite::Records::CustomFieldList do
7
7
  expect(list.custom_fields).to be_kind_of(Array)
8
8
  end
9
9
 
10
- context 'writing convience methods' do
11
- it "should create a custom field entry when none exists" do
12
- list.custrecord_somefield = 'a value'
13
- expect(list.custom_fields.size).to eq(1)
14
- expect(list.custom_fields.first.value).to eq('a value')
15
- expect(list.custom_fields.first.type).to eq('platformCore:StringCustomFieldRef')
16
- end
10
+ context 'custom field internalId-to-scriptId transition at WSDL 2013_2:' do
11
+ before(:context) { @reset = NetSuite::Configuration.api_version }
12
+ after(:context) { NetSuite::Configuration.api_version = @reset }
17
13
 
18
- it "should handle date custom field creation" do
19
- list.custrecord_somefield = Date.parse("12/12/2012")
20
- expect(list.custom_fields.first.value).to eq('2012-12-12T00:00:00+00:00')
21
- end
14
+ transition_version = '2013_2'
22
15
 
23
- it "should handle datetime custom field creation" do
24
- list.custrecord_somefield = DateTime.parse("12/12/2012 10:05am")
25
- expect(list.custom_fields.first.value).to eq('2012-12-12T10:05:00+00:00')
26
- end
16
+ ['2012_2', '2013_2', '2014_2'].each do |version|
17
+
18
+ comparison = ['==', '>', '<'][version <=> transition_version]
19
+
20
+ context "when WSDL version #{comparison} #{transition_version}," do
21
+ before { NetSuite::Configuration.api_version = version }
22
+
23
+ context 'convenience methods' do
24
+ reference_id_type = version < transition_version ? :internal_id : :script_id
25
+
26
+ it "should create a custom field entry when none exists" do
27
+ list.some_custom_field = 'a value'
28
+
29
+ expect(list.custom_fields.size).to eq(1)
30
+ expect(list.custom_fields.first.value).to eq('a value')
31
+ expect(list.custom_fields.first.type).to eq('platformCore:StringCustomFieldRef')
32
+ end
33
+
34
+ it "should set #{reference_id_type} to method name when creating a custom field" do
35
+ list.some_custom_field = 'a value'
36
+
37
+ expect(list.some_custom_field.send(reference_id_type)).to eq('some_custom_field')
38
+ end
39
+
40
+ it "should update a custom field's value when one exists" do
41
+ list.existing_custom_field = 'old value'
42
+ list.existing_custom_field = 'new value'
43
+
44
+ expect(list.existing_custom_field.value).to eq('new value')
45
+ end
46
+
47
+ it "should handle date custom field creation" do
48
+ list.some_custom_field = Date.parse("12/12/2012")
49
+
50
+ expect(list.custom_fields.first.value).to eq('2012-12-12T00:00:00+00:00')
51
+ end
52
+
53
+ it "should handle datetime custom field creation" do
54
+ list.some_custom_field = DateTime.parse("12/12/2012 10:05am")
55
+
56
+ expect(list.custom_fields.first.value).to eq('2012-12-12T10:05:00+00:00')
57
+ end
58
+
59
+ it "should convert a list of numbers into a list of custom field refs" do
60
+ list.some_custom_field = [1,2]
61
+
62
+ expect(list.custom_fields.first.type).to eq('platformCore:MultiSelectCustomFieldRef')
63
+ expect(list.custom_fields.first.value.map(&:to_record)).to eql([
64
+ NetSuite::Records::CustomRecordRef.new(:internal_id => 1),
65
+ NetSuite::Records::CustomRecordRef.new(:internal_id => 2)
66
+ ].map(&:to_record))
67
+ end
68
+
69
+ it "should return custom field record when entry exists" do
70
+ list.existing_custom_field = 'a value'
71
+
72
+ expect(list.existing_custom_field).to be_a(NetSuite::Records::CustomField)
73
+ expect(list.existing_custom_field.value).to eq('a value')
74
+ end
27
75
 
28
- it "should convert a list of numbers into a list of custom field refs" do
29
- list.custrecord_somefield = [1,2]
30
- expect(list.custom_fields.first.type).to eq('platformCore:MultiSelectCustomFieldRef')
31
- expect(list.custom_fields.first.value.map(&:to_record)).to eql([
32
- NetSuite::Records::CustomRecordRef.new(:internal_id => 1),
33
- NetSuite::Records::CustomRecordRef.new(:internal_id => 2)
34
- ].map(&:to_record))
76
+ it "should raise an error if custom field entry does not exist" do
77
+ expect{ list.nonexisting_custom_field }.to raise_error
78
+ end
79
+ end
80
+ end
35
81
  end
36
82
  end
37
83
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsuite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Moran
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-08-12 00:00:00.000000000 Z
12
+ date: 2015-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: savon