netsuite 0.0.16 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,8 +3,9 @@ module NetSuite
3
3
  class Update
4
4
  include Support::Requests
5
5
 
6
- def initialize(obj = nil)
7
- @obj = obj
6
+ def initialize(klass, attributes)
7
+ @klass = klass
8
+ @attributes = attributes
8
9
  end
9
10
 
10
11
  def request
@@ -27,22 +28,26 @@ module NetSuite
27
28
  # </platformMsgs:update>
28
29
  def request_body
29
30
  hash = {
30
- 'platformMsgs:record' => @obj.to_record,
31
+ 'platformMsgs:record' => updated_record.to_record,
31
32
  :attributes! => {
32
33
  'platformMsgs:record' => {
33
- 'xsi:type' => @obj.record_type
34
+ 'xsi:type' => updated_record.record_type
34
35
  }
35
36
  }
36
37
  }
37
- if @obj.respond_to?(:internal_id) && @obj.internal_id
38
- hash[:attributes!]['platformMsgs:record']['platformMsgs:internalId'] = @obj.internal_id
38
+ if updated_record.respond_to?(:internal_id) && updated_record.internal_id
39
+ hash[:attributes!]['platformMsgs:record']['platformMsgs:internalId'] = updated_record.internal_id
39
40
  end
40
- if @obj.respond_to?(:external_id) && @obj.external_id
41
- hash[:attributes!]['platformMsgs:record']['platformMsgs:externalId'] = @obj.external_id
41
+ if updated_record.respond_to?(:external_id) && updated_record.external_id
42
+ hash[:attributes!]['platformMsgs:record']['platformMsgs:externalId'] = updated_record.external_id
42
43
  end
43
44
  hash
44
45
  end
45
46
 
47
+ def updated_record
48
+ @updated_record ||= @klass.new(@attributes)
49
+ end
50
+
46
51
  def success?
47
52
  @success ||= response_hash[:status][:@is_success] == 'true'
48
53
  end
@@ -1,4 +1,5 @@
1
1
  module NetSuite
2
2
  class RecordNotFound < StandardError; end
3
+ class InitializationError < StandardError; end
3
4
  class ConfigurationError < StandardError; end
4
5
  end
@@ -9,7 +9,6 @@ module NetSuite
9
9
  def initialize(attributes = {})
10
10
  @internal_id = attributes.delete(:internal_id) || attributes.delete(:@internal_id)
11
11
  @type = attributes.delete(:type) || attributes.delete(:"@xsi:type")
12
- @type = @type.split(':').last if @type
13
12
  self.attributes = attributes
14
13
  end
15
14
 
@@ -20,11 +19,16 @@ module NetSuite
20
19
  hash[kname] = v
21
20
  hash
22
21
  end
23
- hash_rec["#{record_namespace}:internalId"] = internal_id if internal_id
24
- hash_rec["#{record_namespace}:type"] = type if type
25
22
  hash_rec
26
23
  end
27
24
 
25
+ def attributes!
26
+ attr_hash = {}
27
+ attr_hash['internalId'] = internal_id if internal_id
28
+ attr_hash['xsi:type'] = type if type
29
+ attr_hash
30
+ end
31
+
28
32
  end
29
33
  end
30
34
  end
@@ -17,7 +17,14 @@ module NetSuite
17
17
  end
18
18
 
19
19
  def to_record
20
- { "#{record_namespace}:customField" => custom_fields.map(&:to_record) }
20
+ custom_fields.map do |custom_field|
21
+ {
22
+ "#{record_namespace}:customField" => custom_field.to_record,
23
+ :attributes! => {
24
+ "#{record_namespace}:customField" => custom_field.attributes!
25
+ }
26
+ }
27
+ end
21
28
  end
22
29
 
23
30
  end
@@ -41,11 +41,19 @@ module NetSuite
41
41
  end
42
42
 
43
43
  def transaction_bill_address=(attrs)
44
- attributes[:transaction_bill_address] = BillAddress.new(attrs)
44
+ attributes[:transaction_bill_address] = attrs.kind_of?(BillAddress) ? attrs : BillAddress.new(attrs)
45
+ end
46
+
47
+ def transaction_bill_address
48
+ attributes[:transaction_bill_address] ||= BillAddress.new
45
49
  end
46
50
 
47
51
  def transaction_ship_address=(attrs)
48
- attributes[:transaction_ship_address] = ShipAddress.new(attrs)
52
+ attributes[:transaction_ship_address] = attrs.kind_of?(ShipAddress) ? attrs : ShipAddress.new(attrs)
53
+ end
54
+
55
+ def transaction_ship_address
56
+ attributes[:transaction_ship_address] ||= ShipAddress.new
49
57
  end
50
58
 
51
59
  def item_list
@@ -57,7 +65,7 @@ module NetSuite
57
65
  end
58
66
 
59
67
  def custom_field_list=(attrs)
60
- attributes[:custom_field_list] = CustomFieldList.new(attrs)
68
+ attributes[:custom_field_list] = attrs.kind_of?(CustomFieldList) ? attrs : CustomFieldList.new(attrs)
61
69
  end
62
70
 
63
71
  def self.get(options = {})
@@ -74,7 +82,7 @@ module NetSuite
74
82
  if response.success?
75
83
  new(response.body)
76
84
  else
77
- raise RecordNotFound, "#{self} with ID=#{id} could not be found"
85
+ raise InitializationError, "#{self}.initialize with #{customer} failed."
78
86
  end
79
87
  end
80
88
 
@@ -1,3 +1,3 @@
1
1
  module Netsuite
2
- VERSION = '0.0.16'
2
+ VERSION = '0.0.17'
3
3
  end
@@ -3,9 +3,8 @@ require 'spec_helper'
3
3
  describe NetSuite::Actions::Update do
4
4
 
5
5
  context 'Customer' do
6
- let(:customer) do
7
- NetSuite::Records::Customer.new(:entity_id => 'Shutter Fly', :company_name => 'Shutter Fly, Inc.')
8
- end
6
+ let(:customer) { NetSuite::Records::Customer.new }
7
+ let(:attributes) { { :entity_id => 'Shutter Fly', :company_name => 'Shutter Fly, Inc.' } }
9
8
 
10
9
  before do
11
10
  savon.expects(:update).with({
@@ -22,23 +21,21 @@ describe NetSuite::Actions::Update do
22
21
  end
23
22
 
24
23
  it 'makes a valid request to the NetSuite API' do
25
- NetSuite::Actions::Update.call(customer)
24
+ NetSuite::Actions::Update.call(NetSuite::Records::Customer, attributes)
26
25
  end
27
26
 
28
27
  it 'returns a valid Response object' do
29
- response = NetSuite::Actions::Update.call(customer)
28
+ response = NetSuite::Actions::Update.call(NetSuite::Records::Customer, attributes)
30
29
  response.should be_kind_of(NetSuite::Response)
31
30
  response.should be_success
32
31
  end
33
32
  end
34
33
 
35
34
  context 'Invoice' do
36
- let(:invoice) do
37
- NetSuite::Records::Invoice.new(:source => 'Google', :total => 100.0)
38
- end
35
+ let(:invoice) { NetSuite::Records::Invoice.new }
36
+ let(:attributes) { { :source => 'Google', :total => 100.0 } }
39
37
 
40
38
  before do
41
- pending
42
39
  savon.expects(:update).with({
43
40
  'platformMsgs:record' => {
44
41
  'listRel:source' => 'Google',
@@ -53,11 +50,11 @@ describe NetSuite::Actions::Update do
53
50
  end
54
51
 
55
52
  it 'makes a valid request to the NetSuite API' do
56
- NetSuite::Actions::Update.call(invoice)
53
+ NetSuite::Actions::Update.call(NetSuite::Records::Invoice, attributes)
57
54
  end
58
55
 
59
56
  it 'returns a valid Response object' do
60
- response = NetSuite::Actions::Update.call(invoice)
57
+ response = NetSuite::Actions::Update.call(NetSuite::Records::Invoice, attributes)
61
58
  response.should be_kind_of(NetSuite::Response)
62
59
  response.should be_success
63
60
  end
@@ -44,7 +44,7 @@ describe NetSuite::Records::CustomRecord do
44
44
  lambda {
45
45
  NetSuite::Records::CustomRecord.get(:external_id => 1)
46
46
  }.should raise_error(NetSuite::RecordNotFound,
47
- /NetSuite::Records::CustomRecord with OPTIONS={(.*)} could not be found/)
47
+ /NetSuite::Records::CustomRecord with OPTIONS=(.*) could not be found/)
48
48
  end
49
49
  end
50
50
  end
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
3
+ <soapenv:Header>
4
+ <platformMsgs:documentInfo xmlns:platformMsgs="urn:messages_2011_2.platform.webservices.netsuite.com">
5
+ <platformMsgs:nsId>WEBSERVICES_3392464_011320126577605972140734119_7ceea51ae8ee</platformMsgs:nsId>
6
+ </platformMsgs:documentInfo>
7
+ </soapenv:Header>
8
+ <soapenv:Body>
9
+ <updateResponse xmlns="urn:messages_2011_2.platform.webservices.netsuite.com">
10
+ <writeResponse>
11
+ <platformCore:status isSuccess="true" xmlns:platformCore="urn:core_2011_2.platform.webservices.netsuite.com"/>
12
+ <baseRef internalId="439" externalId="2187" type="invoice" xsi:type="platformCore:RecordRef" xmlns:platformCore="urn:core_2011_2.platform.webservices.netsuite.com"/>
13
+ </writeResponse>
14
+ </updateResponse>
15
+ </soapenv:Body>
16
+ </soapenv:Envelope>
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsuite
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 61
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 16
10
- version: 0.0.16
9
+ - 17
10
+ version: 0.0.17
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Moran
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-13 00:00:00 Z
18
+ date: 2012-01-14 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: savon