netsuite 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec CHANGED
@@ -1 +1,2 @@
1
1
  --color
2
+ --order rand
data/lib/netsuite.rb CHANGED
@@ -8,6 +8,7 @@ require 'netsuite/attribute_support'
8
8
  require 'netsuite/field_support'
9
9
  require 'netsuite/record_support'
10
10
  require 'netsuite/savon_support'
11
+ require 'netsuite/record_ref_support'
11
12
 
12
13
  # ACTIONS
13
14
  require 'netsuite/actions/add'
@@ -18,6 +19,7 @@ require 'netsuite/actions/initialize'
18
19
  require 'netsuite/records/customer'
19
20
  require 'netsuite/records/customer_addressbook_list'
20
21
  require 'netsuite/records/invoice'
22
+ require 'netsuite/records/record_ref'
21
23
 
22
24
  module NetSuite
23
25
 
@@ -0,0 +1,30 @@
1
+ module NetSuite
2
+ module RecordRefSupport
3
+
4
+ def self.included(base)
5
+ base.extend(ClassMethods)
6
+ end
7
+
8
+ module ClassMethods
9
+
10
+ def record_refs(*names)
11
+ names.each do |name|
12
+ record_ref name
13
+ end
14
+ end
15
+
16
+ def record_ref(name)
17
+ name_sym = name.to_sym
18
+ define_method "#{name}=" do |attrs|
19
+ attributes[name_sym] = NetSuite::Records::RecordRef.new(attrs)
20
+ end
21
+
22
+ define_method name_sym do
23
+ attributes[name_sym]
24
+ end
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+ end
@@ -3,12 +3,13 @@ module NetSuite
3
3
  class Customer
4
4
  include FieldSupport
5
5
  include RecordSupport
6
+ include RecordRefSupport
6
7
 
7
8
  fields :access_role, :account_number, :addressbook_list, :aging, :alt_email, :alt_name, :alt_phone, :balance, :bill_pay,
8
9
  :buying_reason, :buying_time_frame, :campaign_category, :category, :click_stream, :comments, :company_name,
9
10
  :consol_aging, :consol_balance, :consol_days_overdue, :consol_deposit_balance, :consol_overdue_balance,
10
11
  :consol_unbilled_orders, :contact_roles_list, :contrib_pct, :credit_cards_list, :credit_hold_override, :credit_limit,
11
- :currency, :currency_list, :custom_field_list, :custom_form, :date_created, :days_overdue, :default_address,
12
+ :currency, :currency_list, :custom_field_list, :date_created, :days_overdue, :default_address,
12
13
  :deposit_balance, :download_list, :email, :email_preference, :email_transactions, :end_date, :entity_id, :entity_status,
13
14
  :estimated_budget, :fax, :fax_transactions, :first_name, :first_visit, :give_access, :global_subscription_status,
14
15
  :group_pricing_list, :home_phone, :image, :is_budget_approved, :is_inactive, :is_person, :item_pricing_list, :keywords,
@@ -21,6 +22,8 @@ module NetSuite
21
22
  :territory, :third_party_acct, :third_party_country, :third_party_zipcode, :title, :unbilled_orders, :url,
22
23
  :vat_reg_number, :visits, :web_lead
23
24
 
25
+ record_refs :custom_form, :entity_status
26
+
24
27
  attr_reader :internal_id, :external_id
25
28
 
26
29
  def initialize(attributes = {})
@@ -29,8 +32,8 @@ module NetSuite
29
32
  initialize_from_attributes_hash(attributes)
30
33
  end
31
34
 
32
- def addressbook_list=(attributes_or_record)
33
- attributes[:addressbook_list] = NetSuite::Records::CustomerAddressbookList.new(attributes_or_record)
35
+ def addressbook_list=(attrs)
36
+ attributes[:addressbook_list] = CustomerAddressbookList.new(attrs)
34
37
  end
35
38
 
36
39
  def self.get(id)
@@ -3,11 +3,12 @@ module NetSuite
3
3
  class Invoice
4
4
  include FieldSupport
5
5
  include RecordSupport
6
+ include RecordRefSupport
6
7
 
7
- fields :account, :alt_handling_cost, :alt_shipping_cost, :amount_paid, :amount_remaining, :balance, :bill_address,
8
- :bill_address_list, :billing_schedule, :contrib_pct, :created_date, :created_from, :currency_name, :custom_field_list,
9
- :custom_form, :deferred_revenue, :department, :discount_amount, :discount_date, :discount_item, :discount_rate,
10
- :discount_total, :due_date, :email, :end_date, :entity, :est_gross_profit, :est_gross_profit_percent, :exchange_rate,
8
+ fields :alt_handling_cost, :alt_shipping_cost, :amount_paid, :amount_remaining, :balance, :bill_address,
9
+ :billing_schedule, :contrib_pct, :created_date, :created_from, :currency_name, :custom_field_list,
10
+ :deferred_revenue, :department, :discount_amount, :discount_date, :discount_item, :discount_rate,
11
+ :discount_total, :due_date, :email, :end_date, :est_gross_profit, :est_gross_profit_percent, :exchange_rate,
11
12
  :exclude_commission, :exp_cost_disc_amount, :exp_cost_disc_print, :exp_cost_disc_rate, :exp_cost_disc_tax_1_amt,
12
13
  :exp_cost_disc_taxable, :exp_cost_discount, :exp_cost_list, :exp_cost_tax_code, :exp_cost_tax_rate_1,
13
14
  :exp_cost_tax_rate_2, :fax, :fob, :gift_cert_applied, :gift_cert_redemption_list, :handling_cost, :handling_tax_1_rate,
@@ -15,9 +16,9 @@ module NetSuite
15
16
  :item_cost_disc_rate, :item_cost_disc_tax_1_amt, :item_cost_disc_taxable, :item_cost_discount, :item_cost_list,
16
17
  :item_cost_tax_code, :item_cost_tax_rate_1, :item_cost_tax_rate_2, :item_list, :job, :klass, :last_modified_date,
17
18
  :lead_source, :linked_tracking_numbers, :location, :memo, :message, :message_sel, :on_credit_hold, :opportunity,
18
- :other_ref_name, :partner, :partners_list, :posting_period, :promo_code, :recognized_revenue, :rev_rec_end_date,
19
+ :other_ref_name, :partner, :partners_list, :promo_code, :recognized_revenue, :rev_rec_end_date,
19
20
  :rev_rec_on_rev_commitment, :rev_rec_schedule, :rev_rec_start_date, :revenue_status, :sales_effective_date,
20
- :sales_group, :sales_rep, :sales_team_list, :ship_address, :ship_address_list, :ship_date, :ship_group_list,
21
+ :sales_group, :sales_rep, :sales_team_list, :ship_address, :ship_date, :ship_group_list,
21
22
  :ship_method, :shipping_cost, :shipping_tax_1_rate, :shipping_tax_2_rate, :shipping_tax_code, :source, :start_date,
22
23
  :status, :sub_total, :subsidiary, :sync_partner_teams, :sync_sales_teams, :tax_2_total, :tax_item, :tax_rate,
23
24
  :tax_total, :terms, :time_disc_amount, :time_disc_print, :time_disc_rate, :time_disc_tax_1_amt, :time_disc_taxable,
@@ -25,6 +26,10 @@ module NetSuite
25
26
  :to_be_printed, :total, :total_cost_estimate, :tracking_numbers, :tran_date, :tran_id, :tran_is_vsoe_bundle,
26
27
  :transaction_bill_address, :transaction_ship_address, :vat_reg_num, :vsoe_auto_calc
27
28
 
29
+ attr_reader :internal_id, :external_id
30
+
31
+ record_refs :account, :bill_address_list, :custom_form, :entity, :posting_period, :ship_address_list
32
+
28
33
  def initialize(attributes = {})
29
34
  @internal_id = attributes.delete(:internal_id)
30
35
  @external_id = attributes.delete(:external_id)
@@ -0,0 +1,27 @@
1
+ module NetSuite
2
+ module Records
3
+ class RecordRef
4
+ include AttributeSupport
5
+
6
+ attr_reader :internal_id
7
+
8
+ def initialize(attributes_or_record = {})
9
+ case attributes_or_record
10
+ when Hash
11
+ attributes_or_record.delete(:"@xmlns:platform_core")
12
+ @internal_id = attributes_or_record.delete(:internal_id) || attributes_or_record.delete(:@internal_id)
13
+ @attributes = attributes_or_record
14
+ end
15
+ end
16
+
17
+ def method_missing(m, *args, &block)
18
+ if attributes.keys.map(&:to_sym).include?(m.to_sym)
19
+ attributes[m.to_sym]
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module Netsuite
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
data/netsuite.gemspec CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency 'savon', '0.9.7'
19
19
 
20
- gem.add_development_dependency 'rspec', '2.7.0'
20
+ gem.add_development_dependency 'rspec', '2.8.0'
21
21
  gem.add_development_dependency 'autotest-standalone', '4.5.9'
22
22
  gem.add_development_dependency 'savon_spec', '0.1.6'
23
23
  end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::RecordRefSupport do
4
+ pending
5
+ end
@@ -9,8 +9,8 @@ describe NetSuite::Records::Customer do
9
9
  :buying_reason, :buying_time_frame, :campaign_category, :category, :click_stream, :comments, :company_name,
10
10
  :consol_aging, :consol_balance, :consol_days_overdue, :consol_deposit_balance, :consol_overdue_balance,
11
11
  :consol_unbilled_orders, :contact_roles_list, :contrib_pct, :credit_cards_list, :credit_hold_override, :credit_limit,
12
- :currency, :currency_list, :custom_field_list, :custom_form, :date_created, :days_overdue, :default_address,
13
- :deposit_balance, :download_list, :email, :email_preference, :email_transactions, :end_date, :entity_id, :entity_status,
12
+ :currency, :currency_list, :custom_field_list, :date_created, :days_overdue, :default_address,
13
+ :deposit_balance, :download_list, :email, :email_preference, :email_transactions, :end_date, :entity_id,
14
14
  :estimated_budget, :fax, :fax_transactions, :first_name, :first_visit, :give_access, :global_subscription_status,
15
15
  :group_pricing_list, :home_phone, :image, :is_budget_approved, :is_inactive, :is_person, :item_pricing_list, :keywords,
16
16
  :language, :last_modified, :last_name, :last_page_visited, :last_visit, :lead_source, :middle_name, :mobile_phone,
@@ -46,6 +46,30 @@ describe NetSuite::Records::Customer do
46
46
  customer.addressbook_list.should be_kind_of(NetSuite::Records::CustomerAddressbookList)
47
47
  end
48
48
 
49
+ describe 'RecordRefs' do
50
+ describe 'custom_form' do
51
+ it 'builds a RecordRef for this field' do
52
+ customer.custom_form = {
53
+ :@internal_id => '3',
54
+ :"@xmlns:platform_core" => 'urn:core_2011_2.platform.webservices.netsuite.com',
55
+ :name => 'RP Customer Form'
56
+ }
57
+ customer.custom_form.should be_kind_of(NetSuite::Records::RecordRef)
58
+ end
59
+ end
60
+
61
+ describe 'entity_status' do
62
+ it 'builds a RecordRef for this field' do
63
+ customer.entity_status = {
64
+ :@internal_id => '13',
65
+ :"@xmlns:platform_core" => 'urn:core_2011_2.platform.webservices.netsuite.com',
66
+ :name => 'CUSTOMER-Closed Won'
67
+ }
68
+ customer.entity_status.should be_kind_of(NetSuite::Records::RecordRef)
69
+ end
70
+ end
71
+ end
72
+
49
73
  describe '.get' do
50
74
  context 'when the response is successful' do
51
75
  let(:response) { NetSuite::Response.new(:success => true, :body => { :is_person => true }) }
@@ -7,14 +7,14 @@ describe NetSuite::Records::Invoice do
7
7
 
8
8
  it 'has all the right fields' do
9
9
  [
10
- :created_date, :last_modified_date, :custom_form, :entity, :tran_date, :tran_id, :source, :created_from, :posting_period,
10
+ :created_date, :last_modified_date, :tran_date, :tran_id, :source, :created_from,
11
11
  :opportunity, :department, :klass, :terms, :location, :subsidiary, :due_date, :discount_date, :discount_amount, :sales_rep,
12
12
  :contrib_pct, :partner, :lead_source, :start_date, :end_date, :other_ref_name, :memo, :sales_effective_date,
13
13
  :exclude_commission, :total_cost_estimate, :est_gross_profit, :est_gross_profit_percent, :rev_rec_schedule,
14
- :rev_rec_start_date, :rev_rec_end_date, :amount_paid, :amount_remaining, :balance, :account, :on_credit_hold,
14
+ :rev_rec_start_date, :rev_rec_end_date, :amount_paid, :amount_remaining, :balance, :on_credit_hold,
15
15
  :exchange_rate, :currency_name, :promo_code, :discount_item, :discount_rate, :is_taxable, :tax_item, :tax_rate,
16
- :to_be_printed, :to_be_emailed, :to_be_faxed, :fax, :message_sel, :message, :transaction_bill_address, :bill_address_list,
17
- :bill_address, :transaction_ship_address, :ship_address_list, :ship_address, :fob, :ship_date, :ship_method, :shipping_cost,
16
+ :to_be_printed, :to_be_emailed, :to_be_faxed, :fax, :message_sel, :message, :transaction_bill_address,
17
+ :bill_address, :transaction_ship_address, :ship_address, :fob, :ship_date, :ship_method, :shipping_cost,
18
18
  :shipping_tax_1_rate, :shipping_tax_2_rate, :shipping_tax_code, :handling_tax_code, :handling_tax_1_rate, :handling_cost,
19
19
  :handling_tax_2_rate, :tracking_numbers, :linked_tracking_numbers, :sales_group, :sub_total, :revenue_status,
20
20
  :recognized_revenue, :deferred_revenue, :rev_rec_on_rev_commitment, :sync_sales_teams, :discount_total, :tax_total,
@@ -48,6 +48,74 @@ describe NetSuite::Records::Invoice do
48
48
  end
49
49
  end
50
50
 
51
+ describe 'RecordRefs' do
52
+ describe 'account' do
53
+ it 'creates a RecordRef for this attribute' do
54
+ invoice.account = {
55
+ :@internal_id => '123',
56
+ :"@xmlns:platform_core" => 'urn:core_2011_2.platform.webservices.netsuite.com',
57
+ :name => '1100 Accounts Receivable'
58
+ }
59
+ invoice.account.should be_kind_of(NetSuite::Records::RecordRef)
60
+ end
61
+ end
62
+
63
+ describe 'bill_address_list' do
64
+ it 'creates a RecordRef for this attribute' do
65
+ invoice.bill_address_list = {
66
+ :@internal_id => '567',
67
+ :"@xmlns:platform_core" => 'urn:core_2011_2.platform.webservices.netsuite.com',
68
+ :name => '123 Happy Lane'
69
+ }
70
+ invoice.bill_address_list.should be_kind_of(NetSuite::Records::RecordRef)
71
+ end
72
+ end
73
+
74
+ describe 'custom_form' do
75
+ it 'creates a RecordRef for this attribute' do
76
+ invoice.custom_form = {
77
+ :@internal_id => '101',
78
+ :"@xmlns:platform_core" => 'urn:core_2011_2.platform.webservices.netsuite.com',
79
+ :name => 'RP Test Product Invoice'
80
+ }
81
+ invoice.custom_form.should be_kind_of(NetSuite::Records::RecordRef)
82
+ end
83
+ end
84
+
85
+ describe 'entity' do
86
+ it 'creates a RecordRef for this attribute' do
87
+ invoice.entity = {
88
+ :@internal_id => '988',
89
+ :"@xmlns:platform_core" => 'urn:core_2011_2.platform.webservices.netsuite.com',
90
+ :name => '100157 Shutter Fly'
91
+ }
92
+ invoice.entity.should be_kind_of(NetSuite::Records::RecordRef)
93
+ end
94
+ end
95
+
96
+ describe 'posting_period' do
97
+ it 'creates a RecordRef for this attribute' do
98
+ invoice.posting_period = {
99
+ :@internal_id => '20',
100
+ :"@xmlns:platform_core" => 'urn:core_2011_2.platform.webservices.netsuite.com',
101
+ :name => 'Jan 2012'
102
+ }
103
+ invoice.posting_period.should be_kind_of(NetSuite::Records::RecordRef)
104
+ end
105
+ end
106
+
107
+ describe 'ship_address_list' do
108
+ it 'creates a RecordRef for this attribute' do
109
+ invoice.ship_address_list = {
110
+ :@internal_id => '567',
111
+ :"@xmlns:platform_core" => 'urn:core_2011_2.platform.webservices.netsuite.com',
112
+ :name => '123 Happy Lane'
113
+ }
114
+ invoice.ship_address_list.should be_kind_of(NetSuite::Records::RecordRef)
115
+ end
116
+ end
117
+ end
118
+
51
119
  describe '#add' do
52
120
  let(:test_data) { { :email => 'test@example.com', :fax => '1234567890' } }
53
121
 
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::RecordRef do
4
+ let(:record_ref) { NetSuite::Records::RecordRef.new }
5
+
6
+ describe 'internal_id' do
7
+ context 'when passing in as plain attribute to initialize' do
8
+ it 'correctly sets the internal_id' do
9
+ record_ref = NetSuite::Records::RecordRef.new(:internal_id => '1')
10
+ record_ref.internal_id.should eql('1')
11
+ end
12
+ end
13
+
14
+ context 'when passing in as swirly attributes to initialize' do
15
+ it 'correctly sets the internal_id' do
16
+ record_ref = NetSuite::Records::RecordRef.new(:@internal_id => '2')
17
+ record_ref.internal_id.should eql('2')
18
+ end
19
+ end
20
+
21
+ context 'when not passed in as an attribute to initialize' do
22
+ it 'does not set an internal_id' do
23
+ record_ref = NetSuite::Records::RecordRef.new
24
+ record_ref.internal_id.should be_nil
25
+ end
26
+ end
27
+
28
+ it 'has no public internal_id setter' do
29
+ record_ref.should_not respond_to(:internal_id=)
30
+ end
31
+ end
32
+
33
+ describe 'attributes' do
34
+ let(:record_ref) do
35
+ NetSuite::Records::RecordRef.new(
36
+ :name => 'This is a record_ref',
37
+ :banana => 'for monkeys'
38
+ )
39
+ end
40
+
41
+ context 'readers' do
42
+ it 'can take on arbitrary attributes into itself on initialization' do
43
+ record_ref.name.should eql('This is a record_ref')
44
+ record_ref.banana.should eql('for monkeys')
45
+ end
46
+ end
47
+ end
48
+
49
+ describe 'untouchables' do
50
+ let(:record_ref) do
51
+ NetSuite::Records::RecordRef.new(
52
+ :"@xmlns:platform_core" => 'something'
53
+ )
54
+ end
55
+
56
+ it 'ignores untouchable attributes' do
57
+ record_ref.instance_variable_get('@attributes').keys.should_not include(:"@xmlns:platform_core")
58
+ end
59
+ end
60
+
61
+ end
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
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-04 00:00:00 Z
18
+ date: 2012-01-06 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: savon
@@ -41,12 +41,12 @@ dependencies:
41
41
  requirements:
42
42
  - - "="
43
43
  - !ruby/object:Gem::Version
44
- hash: 19
44
+ hash: 47
45
45
  segments:
46
46
  - 2
47
- - 7
47
+ - 8
48
48
  - 0
49
- version: 2.7.0
49
+ version: 2.8.0
50
50
  type: :development
51
51
  version_requirements: *id002
52
52
  - !ruby/object:Gem::Dependency
@@ -107,10 +107,12 @@ files:
107
107
  - lib/netsuite/configuration.rb
108
108
  - lib/netsuite/errors.rb
109
109
  - lib/netsuite/field_support.rb
110
+ - lib/netsuite/record_ref_support.rb
110
111
  - lib/netsuite/record_support.rb
111
112
  - lib/netsuite/records/customer.rb
112
113
  - lib/netsuite/records/customer_addressbook_list.rb
113
114
  - lib/netsuite/records/invoice.rb
115
+ - lib/netsuite/records/record_ref.rb
114
116
  - lib/netsuite/response.rb
115
117
  - lib/netsuite/savon_support.rb
116
118
  - lib/netsuite/version.rb
@@ -121,10 +123,12 @@ files:
121
123
  - spec/netsuite/attribute_support_spec.rb
122
124
  - spec/netsuite/configuration_spec.rb
123
125
  - spec/netsuite/field_support_spec.rb
126
+ - spec/netsuite/record_ref_support_spec.rb
124
127
  - spec/netsuite/record_support_spec.rb
125
128
  - spec/netsuite/records/customer_addressbook_list_spec.rb
126
129
  - spec/netsuite/records/customer_spec.rb
127
130
  - spec/netsuite/records/invoice_spec.rb
131
+ - spec/netsuite/records/record_ref_spec.rb
128
132
  - spec/netsuite/response_spec.rb
129
133
  - spec/netsuite/savon_support_spec.rb
130
134
  - spec/netsuite_spec.rb
@@ -177,10 +181,12 @@ test_files:
177
181
  - spec/netsuite/attribute_support_spec.rb
178
182
  - spec/netsuite/configuration_spec.rb
179
183
  - spec/netsuite/field_support_spec.rb
184
+ - spec/netsuite/record_ref_support_spec.rb
180
185
  - spec/netsuite/record_support_spec.rb
181
186
  - spec/netsuite/records/customer_addressbook_list_spec.rb
182
187
  - spec/netsuite/records/customer_spec.rb
183
188
  - spec/netsuite/records/invoice_spec.rb
189
+ - spec/netsuite/records/record_ref_spec.rb
184
190
  - spec/netsuite/response_spec.rb
185
191
  - spec/netsuite/savon_support_spec.rb
186
192
  - spec/netsuite_spec.rb