Skip to content

Commit

Permalink
actions are now dynamically defined in modules that are then included
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmoran committed Jan 23, 2012
1 parent 3a7ebb3 commit 167d090
Show file tree
Hide file tree
Showing 19 changed files with 134 additions and 215 deletions.
3 changes: 1 addition & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ end

desc 'Generate code coverage'
RSpec::Core::RakeTask.new(:coverage) do |t|
t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
t.rcov = true
t.rcov_opts = ['--exclude', 'spec']
t.rcov_opts = ['--exclude', '/gems/,spec']
end
1 change: 1 addition & 0 deletions lib/netsuite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Namespaces
end

module Support
autoload :Actions, 'netsuite/support/actions'
autoload :Attributes, 'netsuite/support/attributes'
autoload :Fields, 'netsuite/support/fields'
autoload :RecordRefs, 'netsuite/support/record_refs'
Expand Down
12 changes: 3 additions & 9 deletions lib/netsuite/records/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module Records
class Account
include Support::Fields
include Support::RecordRefs
include Support::Actions

actions :get

fields :acct_name, :acct_number, :acct_type, :cash_flow_rate, :cur_doc_num, :description, :eliminate, :exchange_rate,
:general_rate, :include_children, :inventory, :is_inactive, :opening_balance, :revalue, :tran_date
Expand All @@ -18,15 +21,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end

def self.get(options = {})
response = Actions::Get.call(self, options)
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
end
end

end
end
end
12 changes: 3 additions & 9 deletions lib/netsuite/records/classification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module NetSuite
module Records
class Classification
include Support::Fields
include Support::Actions

actions :get

fields :name, :include_children, :is_inactive, :class_translation_list, :subsidiary_list, :custom_field_list

Expand All @@ -14,15 +17,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end

def self.get(options = {})
response = Actions::Get.call(self, options)
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
end
end

end
end
end
26 changes: 3 additions & 23 deletions lib/netsuite/records/credit_memo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class CreditMemo
include Support::Fields
include Support::RecordRefs
include Support::Records
include Support::Actions
include Namespaces::TranCust

actions :get, :add, :initialize

fields :alt_handling_cost, :alt_shipping_cost, :amount_paid, :amount_remaining, :auto_apply, :balance,
:bill_address, :contrib_pct, :created_date, :currency_name, :deferred_revenue, :discount_rate, :email,
:est_gross_profit, :est_gross_profit_percent, :exchange_rate, :exclude_commission, :fax, :gift_cert_applied,
Expand All @@ -31,29 +34,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end

def self.get(options = {})
response = Actions::Get.call(self, options)
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
end
end

def self.initialize(object)
response = Actions::Initialize.call(self, object)
if response.success?
new(response.body)
else
raise InitializationError, "#{self}.initialize with #{object} failed."
end
end

def add
response = Actions::Add.call(self)
response.success?
end

end
end
end
16 changes: 5 additions & 11 deletions lib/netsuite/records/custom_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class CustomRecord
include Support::Fields
include Support::RecordRefs
include Support::Records
include Support::Actions
include Namespaces::SetupCustom

actions :get, :add

fields :allow_attachments, :allow_inline_editing, :allow_numbering_override, :allow_quick_search, :created,
:custom_record_id, :description, :disclaimer, :enabl_email_merge, :enable_numbering, :include_name,
:is_available_offline, :is_inactive, :is_numbering_updateable, :is_ordered, :last_modified, :name,
Expand All @@ -28,17 +31,8 @@ def initialize(attributes = {})

def self.get(options = {})
options.merge!(:type_id => type_id) unless options[:type_id]
response = Actions::Get.call(self, options.merge!(:custom => true))
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
end
end

def add
response = Actions::Add.call(self)
response.success?
options.merge!(:custom => true)
super(options)
end

def self.type_id(id = nil)
Expand Down
12 changes: 3 additions & 9 deletions lib/netsuite/records/custom_record_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ module Records
class CustomRecordType
include Support::Fields
include Support::RecordRefs
include Support::Actions

actions :get

fields :allow_attachments, :allow_inline_editing, :allow_numbering_override, :allow_quick_search, :description,
:disclaimer, :enable_mail_merge, :enable_numbering, :include_name, :is_available_offline, :is_inactive,
Expand All @@ -22,15 +25,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end

def self.get(options = {})
response = Actions::Get.call(self, options)
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
end
end

end
end
end
17 changes: 3 additions & 14 deletions lib/netsuite/records/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class Customer
include Support::Fields
include Support::RecordRefs
include Support::Records
include Support::Actions
include Namespaces::ListRel

actions :get, :add

fields :access_role, :account_number, :aging, :alt_email, :alt_name, :alt_phone, :bill_pay,
:buying_reason, :buying_time_frame, :campaign_category, :category, :click_stream, :comments, :company_name,
:consol_aging, :consol_days_overdue, :contact_roles_list, :contrib_pct, :credit_cards_list, :credit_hold_override,
Expand Down Expand Up @@ -38,20 +41,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end

def self.get(options = {})
response = Actions::Get.call(self, options)
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
end
end

def add
response = Actions::Add.call(self)
response.success?
end

end
end
end
26 changes: 3 additions & 23 deletions lib/netsuite/records/customer_payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class CustomerPayment
include Support::Fields
include Support::RecordRefs
include Support::Records
include Support::Actions
include Namespaces::TranCust

actions :get, :initialize, :add

fields :auth_code, :auto_apply, :cc_approved, :cc_avs_street_match, :cc_avs_zip_match,
:cc_expire_date, :cc_name, :cc_number, :cc_security_code, :cc_security_code_match, :cc_street, :cc_zip_code,
:charge_it, :check_num, :created_date, :currency_name, :debit_card_issue_no, :exchange_rate, :ignore_avs,
Expand All @@ -28,29 +31,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end

def self.get(options = {})
response = Actions::Get.call(self, options)
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
end
end

def self.initialize(object)
response = Actions::Initialize.call(self, object)
if response.success?
new(response.body)
else
raise InitializationError, "#{self}.initialize with #{object} failed."
end
end

def add
response = Actions::Add.call(self)
response.success?
end

end
end
end
26 changes: 3 additions & 23 deletions lib/netsuite/records/customer_refund.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class CustomerRefund
include Support::Fields
include Support::RecordRefs
include Support::Records
include Support::Actions
include Namespaces::TranCust

actions :get, :initialize, :add

fields :address, :balance, :cc_approved, :cc_expire_date, :cc_name, :cc_number, :cc_street, :cc_zip_code, :charge_it,
:created_date, :currency_name, :debit_card_issue_no, :exchange_rate, :last_modified_date, :memo, :pn_ref_num, :status,
:to_be_printed, :tran_date, :tran_id, :valid_from
Expand All @@ -23,29 +26,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end

def self.get(options = {})
response = Actions::Get.call(self, options)
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
end
end

def self.initialize(object)
response = Actions::Initialize.call(self, object)
if response.success?
new(response.body)
else
raise InitializationError, "#{self}.initialize with #{object} failed."
end
end

def add
response = Actions::Add.call(self)
response.success?
end

end
end
end
17 changes: 3 additions & 14 deletions lib/netsuite/records/inventory_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class InventoryItem
include Support::Fields
include Support::RecordRefs
include Support::Records
include Support::Actions
include Namespaces::ListAcct

actions :get, :add

fields :auto_lead_time, :auto_preferred_stock_level, :auto_reorder_point, :available_to_partners, :average_cost,
:copy_description, :cost, :cost_estimate, :cost_estimate_type, :cost_estimate_units, :cost_units, :costing_method,
:costing_method_display, :country_of_manufacture, :created_date, :currency, :date_converted_to_inv,
Expand Down Expand Up @@ -46,20 +49,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end

def self.get(options = {})
response = Actions::Get.call(self, options)
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
end
end

def add
response = Actions::Add.call(self)
response.success?
end

end
end
end
26 changes: 3 additions & 23 deletions lib/netsuite/records/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class Invoice
include Support::Fields
include Support::RecordRefs
include Support::Records
include Support::Actions
include Namespaces::TranSales

actions :get, :initialize, :add

fields :alt_handling_cost, :alt_shipping_cost, :balance, :bill_address,
:billing_schedule, :contrib_pct, :created_date, :created_from, :currency_name, :custom_field_list,
:deferred_revenue, :department, :discount_amount, :discount_date, :discount_item, :discount_rate,
Expand Down Expand Up @@ -45,29 +48,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end

def self.get(options = {})
response = Actions::Get.call(self, options)
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
end
end

def self.initialize(object)
response = Actions::Initialize.call(self, object)
if response.success?
new(response.body)
else
raise InitializationError, "#{self}.initialize with #{object} failed."
end
end

def add
response = Actions::Add.call(self)
response.success?
end

end
end
end
17 changes: 3 additions & 14 deletions lib/netsuite/records/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ class Job
include Support::Fields
include Support::RecordRefs
include Support::Records
include Support::Actions
include Namespaces::ListRel

actions :get, :add

fields :account_number, :allocate_payroll_expenses, :allow_all_resources_for_tasks, :allow_expenses, :allow_time,
:alt_name, :alt_phone, :bill_pay, :calculated_end_date, :calculated_end_date_baseline, :comments, :company_name,
:date_created, :default_address, :email, :email_preference, :end_date, :entity_id, :estimated_cost,
Expand All @@ -32,20 +35,6 @@ def initialize(attributes = {})
initialize_from_attributes_hash(attributes)
end

def self.get(options = {})
response = Actions::Get.call(self, options)
if response.success?
new(response.body)
else
raise RecordNotFound, "#{self} with OPTIONS=#{options.inspect} could not be found"
end
end

def add
response = Actions::Add.call(self)
response.success?
end

end
end
end
Loading

0 comments on commit 167d090

Please sign in to comment.