activenetsuite 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.gemtest +0 -0
  3. data/.rspec +1 -0
  4. data/CHANGELOG +0 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +51 -0
  7. data/History.txt +3 -0
  8. data/Manifest.txt +60 -0
  9. data/README.rdoc +14 -0
  10. data/Rakefile +14 -0
  11. data/activenetsuite.gemspec +30 -0
  12. data/lib/activenetsuite.rb +30 -0
  13. data/lib/activenetsuite/accounting/account.rb +11 -0
  14. data/lib/activenetsuite/accounting/non_inventory_sale_item.rb +10 -0
  15. data/lib/activenetsuite/core/custom_field_list.rb +7 -0
  16. data/lib/activenetsuite/core/custom_field_ref.rb +8 -0
  17. data/lib/activenetsuite/core/deleted_record.rb +10 -0
  18. data/lib/activenetsuite/core/get_deleted_result.rb +13 -0
  19. data/lib/activenetsuite/core/record.rb +254 -0
  20. data/lib/activenetsuite/core/record_ref.rb +35 -0
  21. data/lib/activenetsuite/core/search_record.rb +97 -0
  22. data/lib/activenetsuite/core/search_result.rb +12 -0
  23. data/lib/activenetsuite/core/status.rb +50 -0
  24. data/lib/activenetsuite/helpers/client.rb +135 -0
  25. data/lib/activenetsuite/helpers/error.rb +7 -0
  26. data/lib/activenetsuite/helpers/method_inflector.rb +78 -0
  27. data/lib/activenetsuite/helpers/response_methods.rb +21 -0
  28. data/lib/activenetsuite/helpers/search_response_methods.rb +62 -0
  29. data/lib/activenetsuite/messages/add_response.rb +8 -0
  30. data/lib/activenetsuite/messages/delete_list_response.rb +19 -0
  31. data/lib/activenetsuite/messages/delete_response.rb +8 -0
  32. data/lib/activenetsuite/messages/get_deleted_response.rb +23 -0
  33. data/lib/activenetsuite/messages/get_deleted_result.rb +21 -0
  34. data/lib/activenetsuite/messages/get_response.rb +13 -0
  35. data/lib/activenetsuite/messages/read_response.rb +7 -0
  36. data/lib/activenetsuite/messages/search_more_with_id_response.rb +8 -0
  37. data/lib/activenetsuite/messages/search_response.rb +8 -0
  38. data/lib/activenetsuite/messages/update_response.rb +8 -0
  39. data/lib/activenetsuite/messages/write_response.rb +16 -0
  40. data/lib/activenetsuite/relationships/partner.rb +18 -0
  41. data/lib/activenetsuite/relationships/vendor.rb +14 -0
  42. data/lib/activenetsuite/sales/cash_refund.rb +12 -0
  43. data/lib/activenetsuite/sales/cash_sale.rb +12 -0
  44. data/lib/activenetsuite/soap/NetSuiteServiceClient.rb +978 -0
  45. data/lib/activenetsuite/soap/default.rb +68163 -0
  46. data/lib/activenetsuite/soap/defaultDriver.rb +419 -0
  47. data/lib/activenetsuite/soap/defaultMappingRegistry.rb +62549 -0
  48. data/lib/activenetsuite/version.rb +3 -0
  49. data/spec/lib/activenetsuite/accounting/non_inventory_sale_item_spec.rb +9 -0
  50. data/spec/lib/activenetsuite/core/record_ref_spec.rb +56 -0
  51. data/spec/lib/activenetsuite/core/record_spec.rb +298 -0
  52. data/spec/lib/activenetsuite/core/search_record_spec.rb +50 -0
  53. data/spec/lib/activenetsuite/core/search_result_spec.rb +26 -0
  54. data/spec/lib/activenetsuite/helpers/client_spec.rb +115 -0
  55. data/spec/lib/activenetsuite/helpers/method_inflector_spec.rb +85 -0
  56. data/spec/lib/activenetsuite/helpers/search_response_methods_spec.rb +50 -0
  57. data/spec/lib/activenetsuite/messages/search_response_spec.rb +5 -0
  58. data/spec/lib/activenetsuite/relationships/partner_spec.rb +22 -0
  59. data/spec/lib/activenetsuite/relationships/vendor_spec.rb +14 -0
  60. data/spec/lib/activenetsuite/sales/cash_refund_spec.rb +10 -0
  61. data/spec/lib/activenetsuite/sales/cash_sale_spec.rb +10 -0
  62. data/spec/spec_helper.rb +17 -0
  63. metadata +138 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a62dd9969f9d4657bdfc588da6e306fbc7576f74
4
+ data.tar.gz: 5d04379601512749b16b41172683bba9a6109a7d
5
+ SHA512:
6
+ metadata.gz: 2a515203251fb8d571b292666a460a3bcf6247a55bb9265e8f23c1def95448ceb0695ca7c2bcd38fd4a5b1b683d978285847034c3d11037833e5a3930497b76d
7
+ data.tar.gz: ca01938b4ef81e185963d287d8d7d568c951d94909da3c5b1ee1f5d8c21749b0cd4423fb4b68ea49fc51e4ec1a8d80f63a0eabd63c236d2a682b2c4ac6804c7d
data/.gemtest ADDED
File without changes
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/CHANGELOG ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in asdf.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,51 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ activenetsuite (0.1.0)
5
+ active_support (~> 3.0)
6
+ hoe (~> 3.8)
7
+ soap4r-ruby1.9 (~> 2.0.5)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ active_support (3.0.0)
13
+ activesupport (= 3.0.0)
14
+ activesupport (3.0.0)
15
+ addressable (2.3.5)
16
+ crack (0.4.2)
17
+ safe_yaml (~> 1.0.0)
18
+ diff-lcs (1.2.5)
19
+ docile (1.1.3)
20
+ hoe (3.8.1)
21
+ rake (>= 0.8, < 11.0)
22
+ multi_json (1.8.4)
23
+ rake (10.1.1)
24
+ rspec (2.14.1)
25
+ rspec-core (~> 2.14.0)
26
+ rspec-expectations (~> 2.14.0)
27
+ rspec-mocks (~> 2.14.0)
28
+ rspec-core (2.14.7)
29
+ rspec-expectations (2.14.5)
30
+ diff-lcs (>= 1.1.3, < 2.0)
31
+ rspec-mocks (2.14.5)
32
+ safe_yaml (1.0.1)
33
+ simplecov (0.8.2)
34
+ docile (~> 1.1.0)
35
+ multi_json
36
+ simplecov-html (~> 0.8.0)
37
+ simplecov-html (0.8.0)
38
+ soap4r-ruby1.9 (2.0.5)
39
+ webmock (1.17.2)
40
+ addressable (>= 2.2.7)
41
+ crack (>= 0.3.2)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ activenetsuite!
48
+ hoe (~> 3.8)
49
+ rspec (~> 2.14)
50
+ simplecov (~> 0.8)
51
+ webmock (~> 1.17)
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ === 0.1.0 / 2014-02-05
2
+
3
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,60 @@
1
+ .rspec
2
+ CHANGELOG
3
+ Gemfile
4
+ Gemfile.lock
5
+ History.txt
6
+ Manifest.txt
7
+ README.rdoc
8
+ Rakefile
9
+ activenetsuite.gemspec
10
+ lib/activenetsuite.rb
11
+ lib/activenetsuite/accounting/account.rb
12
+ lib/activenetsuite/accounting/non_inventory_sale_item.rb
13
+ lib/activenetsuite/core/custom_field_list.rb
14
+ lib/activenetsuite/core/custom_field_ref.rb
15
+ lib/activenetsuite/core/deleted_record.rb
16
+ lib/activenetsuite/core/get_deleted_result.rb
17
+ lib/activenetsuite/core/record.rb
18
+ lib/activenetsuite/core/record_ref.rb
19
+ lib/activenetsuite/core/search_record.rb
20
+ lib/activenetsuite/core/search_result.rb
21
+ lib/activenetsuite/core/status.rb
22
+ lib/activenetsuite/helpers/client.rb
23
+ lib/activenetsuite/helpers/error.rb
24
+ lib/activenetsuite/helpers/method_inflector.rb
25
+ lib/activenetsuite/helpers/response_methods.rb
26
+ lib/activenetsuite/helpers/search_response_methods.rb
27
+ lib/activenetsuite/messages/add_response.rb
28
+ lib/activenetsuite/messages/delete_list_response.rb
29
+ lib/activenetsuite/messages/delete_response.rb
30
+ lib/activenetsuite/messages/get_deleted_response.rb
31
+ lib/activenetsuite/messages/get_deleted_result.rb
32
+ lib/activenetsuite/messages/get_response.rb
33
+ lib/activenetsuite/messages/read_response.rb
34
+ lib/activenetsuite/messages/search_more_with_id_response.rb
35
+ lib/activenetsuite/messages/search_response.rb
36
+ lib/activenetsuite/messages/update_response.rb
37
+ lib/activenetsuite/messages/write_response.rb
38
+ lib/activenetsuite/relationships/partner.rb
39
+ lib/activenetsuite/relationships/vendor.rb
40
+ lib/activenetsuite/sales/cash_refund.rb
41
+ lib/activenetsuite/sales/cash_sale.rb
42
+ lib/activenetsuite/soap/NetSuiteServiceClient.rb
43
+ lib/activenetsuite/soap/default.rb
44
+ lib/activenetsuite/soap/defaultDriver.rb
45
+ lib/activenetsuite/soap/defaultMappingRegistry.rb
46
+ lib/activenetsuite/version.rb
47
+ spec/lib/activenetsuite/accounting/non_inventory_sale_item_spec.rb
48
+ spec/lib/activenetsuite/core/record_ref_spec.rb
49
+ spec/lib/activenetsuite/core/record_spec.rb
50
+ spec/lib/activenetsuite/core/search_record_spec.rb
51
+ spec/lib/activenetsuite/core/search_result_spec.rb
52
+ spec/lib/activenetsuite/helpers/client_spec.rb
53
+ spec/lib/activenetsuite/helpers/method_inflector_spec.rb
54
+ spec/lib/activenetsuite/helpers/search_response_methods_spec.rb
55
+ spec/lib/activenetsuite/messages/search_response_spec.rb
56
+ spec/lib/activenetsuite/relationships/partner_spec.rb
57
+ spec/lib/activenetsuite/relationships/vendor_spec.rb
58
+ spec/lib/activenetsuite/sales/cash_refund_spec.rb
59
+ spec/lib/activenetsuite/sales/cash_sale_spec.rb
60
+ spec/spec_helper.rb
data/README.rdoc ADDED
@@ -0,0 +1,14 @@
1
+ = ActiveNetsuite
2
+
3
+ https://github.com/smazhara/activenetsuite
4
+
5
+ NetSuite Object Mapper
6
+
7
+ == Description
8
+
9
+ Netsuite Object Mapper.
10
+
11
+
12
+ == LICENSE:
13
+
14
+ ActiveNetsuite is released under the [MIT License](http://www.opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
4
+ require 'activenetsuite/version'
5
+
6
+ Hoe.plugin :gemspec
7
+ Hoe.plugin :git
8
+
9
+ Hoe.spec 'activenetsuite' do
10
+ developer 'Stan Mazhara', 'akmegran@gmail.com'
11
+ license 'MIT'
12
+ version = ActiveNetsuite::VERSION
13
+ end
14
+
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'activenetsuite'
5
+ s.version = '0.1.0'
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
8
+ s.authors = ['Stan Mazhara']
9
+ s.date = '2014-02-05'
10
+ s.description = 'Netsuite Object Mapper.'
11
+ s.email = ['akmegran@gmail.com']
12
+ s.extra_rdoc_files = ['History.txt', 'Manifest.txt', 'README.rdoc']
13
+ s.files = `git ls-files`.split("\n")
14
+ s.homepage = 'https://github.com/smazhara/activenetsuite'
15
+ s.licenses = ['MIT']
16
+ s.rdoc_options = ['--main', 'README.rdoc']
17
+ s.require_paths = ['lib']
18
+ s.rubyforge_project = 'activenetsuite'
19
+ s.rubygems_version = '2.0.3'
20
+ s.summary = 'Netsuite Object Mapper.'
21
+
22
+ s.add_development_dependency 'hoe', ['~> 3.8']
23
+ s.add_development_dependency 'rspec', ['~> 2.14']
24
+ s.add_development_dependency 'simplecov', ['~> 0.8']
25
+ s.add_development_dependency 'webmock', ['~> 1.17']
26
+
27
+ s.add_dependency 'hoe', ['~> 3.8']
28
+ s.add_dependency 'soap4r-ruby1.9', ['~> 2.0.5']
29
+ s.add_dependency 'active_support', ['~> 3.0']
30
+ end
@@ -0,0 +1,30 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/activenetsuite')
2
+
3
+ require 'rubygems'
4
+ gem 'soap4r-ruby1.9'
5
+
6
+ require 'active_support/inflector'
7
+ require 'forwardable'
8
+
9
+ module NetSuite
10
+ $:.unshift(File.dirname(__FILE__) + '/activenetsuite/soap')
11
+ require 'soap/default'
12
+ require 'soap/defaultDriver'
13
+ require 'soap/defaultMappingRegistry'
14
+ require 'NetSuiteServiceClient'
15
+ $:.shift
16
+
17
+ Dir.chdir(File.dirname(__FILE__) + '/activenetsuite') do
18
+ Dir[*%w(
19
+ helpers/*.rb
20
+ accounting/*.rb
21
+ core/*.rb
22
+ messages/*.rb
23
+ relationships/*.rb
24
+ sales/*.rb
25
+ )].each do |file|
26
+ require file
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,11 @@
1
+ module ActiveNetsuite
2
+
3
+ class Account < Record
4
+ def income_account
5
+ incomeAccount.type = 'account'
6
+ incomeAccount
7
+ end
8
+ end
9
+
10
+ end
11
+
@@ -0,0 +1,10 @@
1
+ module ActiveNetsuite
2
+
3
+ class NonInventorySaleItem < ActiveNetsuite::Record
4
+ def self.basic_search_class
5
+ ActiveNetsuite::ItemSearchBasic
6
+ end
7
+ end
8
+
9
+ end
10
+
@@ -0,0 +1,7 @@
1
+ module ActiveNetsuite
2
+
3
+ class CustomFieldList
4
+ end
5
+
6
+ end
7
+
@@ -0,0 +1,8 @@
1
+ module ActiveNetsuite
2
+
3
+ class CustomFieldRef
4
+ include MethodInflector
5
+ end
6
+
7
+ end
8
+
@@ -0,0 +1,10 @@
1
+ module ActiveNetsuite
2
+
3
+ class DeletedRecord
4
+ include MethodInflector
5
+
6
+ alias_method :ref, :record
7
+ end
8
+
9
+ end
10
+
@@ -0,0 +1,13 @@
1
+ module ActiveNetsuite
2
+
3
+ class GetDeletedResult
4
+ extend Forwardable
5
+
6
+ def_delegators :status, :success?, :code, :message
7
+
8
+ def records
9
+ deletedRecordList
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,254 @@
1
+ module ActiveNetsuite
2
+
3
+ class Record
4
+ include MethodInflector
5
+
6
+ def to_s
7
+ instance_variables.
8
+ map do |var|
9
+ [var, instance_variable_get(var)]
10
+ end.
11
+ select do |var, val|
12
+ val
13
+ end
14
+ end
15
+
16
+ class << self
17
+ def client
18
+ @@client
19
+ end
20
+
21
+ def client=(client)
22
+ @@client = client
23
+ end
24
+
25
+ def type
26
+ type = to_s.split('::').last
27
+ type[0,1].downcase + type[1..-1]
28
+ end
29
+
30
+ def find_by_internal_id(id)
31
+ find_by_id(internal_id: id)
32
+ end
33
+
34
+ def find(id)
35
+ find_by_id(internal_id: id) or raise_not_found_error(internal_id: id)
36
+ end
37
+ alias_method :get, :find
38
+
39
+ def find_by_external_id(id)
40
+ find_by_id(external_id: id)
41
+ end
42
+
43
+ def find_by_id(args)
44
+ client.get(ref(args)).record
45
+ end
46
+
47
+ def basic_search_class
48
+ "::#{to_s}SearchBasic".constantize
49
+ end
50
+
51
+ def search(search = basic_search_class.new)
52
+ case search
53
+ when SearchRecord
54
+ client.search(search)
55
+ when SearchResponse
56
+ client.search_next(search, search.page_index + 1)
57
+ when SearchMoreWithIdResponse
58
+ client.search_next(search, search.page_index + 1)
59
+ else
60
+ raise "Unrecognized search:#{search}"
61
+ end
62
+ end
63
+
64
+ def search_next(search_result, page_index)
65
+ client.search_next(search, page_index)
66
+ end
67
+
68
+ def where(*args)
69
+ search.where(*args)
70
+ end
71
+
72
+ def find_by(*args)
73
+ search.find_by(*args)
74
+ end
75
+
76
+ def all
77
+ search.response
78
+ end
79
+
80
+ def inactive
81
+ search.inactive
82
+ end
83
+
84
+ def active
85
+ search.active
86
+ end
87
+
88
+ def delete(objects)
89
+ objects = [objects] unless objects.respond_to?(:map)
90
+ client.delete_list(refs(objects))
91
+ end
92
+
93
+ def update(records)
94
+ records = [records] unless records.respond_to?(:map)
95
+ client.update_list(records)
96
+ end
97
+
98
+ def deleted(op, val)
99
+ op = ('ActiveNetsuite::SearchDateFieldOperator::' + op.to_s.camelize).constantize
100
+ val = ('ActiveNetsuite::SearchDate::' + val.to_s.camelize).constantize
101
+ search_value = SearchDateField.new
102
+ search_value.xmlattr_operator = op
103
+ search_value.predefinedSearchValue = val
104
+
105
+ search_type = SearchEnumMultiSelectField.new
106
+ search_type.xmlattr_operator = SearchEnumMultiSelectFieldOperator::AnyOf
107
+ search_type.searchValue = type
108
+
109
+ get_deleted_filter = GetDeletedFilter.new(search_value, search_type)
110
+ client.get_deleted(get_deleted_filter)
111
+ end
112
+
113
+ def ref(arg)
114
+ ref = RecordRef.new
115
+ ref.type = type
116
+ arg = {internal_id: arg} unless arg.is_a?(Hash)
117
+ ref.internal_id = arg[:internal_id]
118
+ ref.external_id = arg[:external_id]
119
+ ref
120
+ end
121
+
122
+ def raise_not_found_error(arg)
123
+ raise NotFoundError, not_found_error_message(ref(arg))
124
+ end
125
+
126
+ private
127
+
128
+ def search
129
+ search = basic_search_class.new
130
+ search.record_class = self
131
+ search
132
+ end
133
+
134
+ def refs(objects)
135
+ objects.map do |object|
136
+ case object
137
+ when RecordRef
138
+ object
139
+ when Record
140
+ object.ref
141
+ when String, Integer
142
+ ref(object)
143
+ end
144
+ end
145
+ end
146
+
147
+ def not_found_error_message(ref)
148
+ "type: #{ref.type}, internal_id: #{ref.internal_id}, " \
149
+ "external_id: #{ref.external_id}"
150
+ end
151
+ end
152
+
153
+ def add
154
+ res = client.add(self)
155
+ if res.success?
156
+ self.internal_id = res.internal_id
157
+ end
158
+ res
159
+ end
160
+
161
+ def update
162
+ client.update(self)
163
+ end
164
+
165
+ def delete
166
+ res = client.delete(ref)
167
+ if res.success?
168
+ self.internal_id = nil
169
+ end
170
+ res
171
+ end
172
+
173
+ def client
174
+ self.class.client
175
+ end
176
+
177
+ def load
178
+ return self if loaded?
179
+
180
+ record = find_by_id
181
+ record.getters.each do |getter|
182
+ send :"#{getter}=", record.send(getter)
183
+ end
184
+ @loaded = true
185
+ self
186
+ end
187
+
188
+ def loaded?
189
+ !!@loaded
190
+ end
191
+
192
+ def active?
193
+ !inactive?
194
+ end
195
+
196
+ def active=(value)
197
+ self.is_inactive = !value
198
+ end
199
+
200
+ def inactive=(value)
201
+ self.is_inactive = !!value
202
+ end
203
+
204
+ def activate
205
+ self.active = true
206
+ self
207
+ end
208
+
209
+ def inactivate
210
+ self.active = false
211
+ self
212
+ end
213
+
214
+ def ref
215
+ self.class.ref(internal_id)
216
+ end
217
+
218
+ def setters
219
+ public_methods(false).grep(/=$/)
220
+ end
221
+
222
+ def getters
223
+ setters.map(&:to_s).map(&:chop).map(&:to_sym)
224
+ end
225
+
226
+ private
227
+
228
+ def raise_not_found_error
229
+ self.class.raise_not_found_error(ref)
230
+ end
231
+
232
+ def not_found_error_message
233
+ self.class.not_found_error_message(ref)
234
+ end
235
+
236
+ def find_by_id
237
+ by_internal_id || by_external_id or raise_not_found_error
238
+ end
239
+
240
+ def by_internal_id
241
+ self.class.find_by_internal_id(internal_id) if internal_id
242
+ end
243
+
244
+ def by_external_id
245
+ self.class.find_by_external_id(external_id) if external_id
246
+ end
247
+
248
+ def type
249
+ self.class.type
250
+ end
251
+ end
252
+
253
+ end
254
+