netsuite 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ Autotest.add_hook :initialize do |at|
2
+ at.clear_mappings
3
+
4
+ at.add_mapping %r%/^lib/(.*)\.rb$% do |_, m|
5
+ possible = File.basename(m[1])
6
+ files_matching %r%^spec/.*(#{possible}_spec)\.rb$%
7
+ end
8
+
9
+ at.add_mapping(%r%^spec/.*\_spec.rb$%) {|filename, _| filename }
10
+ end
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in netsuite.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2011 Ryan Moran
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Netsuite
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'netsuite'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install netsuite
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc 'Run specs'
9
+ RSpec::Core::RakeTask.new do |t|
10
+ t.pattern = './spec/**/*_spec.rb'
11
+ end
12
+
13
+ desc 'Generate code coverage'
14
+ RSpec::Core::RakeTask.new(:coverage) do |t|
15
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
16
+ t.rcov = true
17
+ t.rcov_opts = ['--exclude', 'spec']
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'netsuite/configuration'
2
+ require 'netsuite/errors'
3
+ require 'netsuite/response'
4
+ require 'netsuite/version'
5
+
6
+ # ACTIONS
7
+ require 'netsuite/actions/customer/get'
8
+
9
+ # MODELS
10
+ require 'netsuite/models/customer'
11
+
12
+ module NetSuite
13
+
14
+ def self.configure(&block)
15
+ NetSuite::Configuration.instance_eval(&block)
16
+ end
17
+
18
+ end
@@ -0,0 +1,70 @@
1
+ module NetSuite
2
+ module Actions
3
+ module Customer
4
+ class Get
5
+
6
+ def initialize(id)
7
+ @id = id
8
+ end
9
+
10
+ def self.call(id)
11
+ new(id).call
12
+ end
13
+
14
+ def call
15
+ @response = request
16
+ build_response
17
+ end
18
+
19
+ private
20
+
21
+ def request
22
+ connection.request :platformMsgs, :get do
23
+ soap.namespaces['xmlns:platformMsgs'] = 'urn:messages_2011_2.platform.webservices.netsuite.com'
24
+ soap.namespaces['xmlns:platformCore'] = 'urn:core_2011_2.platform.webservices.netsuite.com'
25
+ soap.header = auth_header
26
+ soap.body = request_body
27
+ end
28
+ end
29
+
30
+ def connection
31
+ NetSuite::Configuration.connection
32
+ end
33
+
34
+ def auth_header
35
+ NetSuite::Configuration.auth_header
36
+ end
37
+
38
+ def request_body
39
+ {
40
+ 'platformMsgs:baseRef' => {},
41
+ :attributes! => {
42
+ 'platformMsgs:baseRef' => {
43
+ :internalId => @id,
44
+ :type => 'customer',
45
+ 'xsi:type' => 'platformCore:RecordRef'
46
+ }
47
+ }
48
+ }
49
+ end
50
+
51
+ def build_response
52
+ NetSuite::Response.new(:success => success?, :body => response_body)
53
+ end
54
+
55
+ def success?
56
+ @success ||= response_hash[:status][:@is_success] == 'true'
57
+ end
58
+
59
+ def response_body
60
+ @response_body ||= response_hash[:record]
61
+ end
62
+
63
+ def response_hash
64
+ @response_hash = @response[:get_response][:read_response]
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,74 @@
1
+ module NetSuite
2
+ module Configuration
3
+ extend self
4
+
5
+ def reset!
6
+ attributes.clear
7
+ end
8
+
9
+ def attributes
10
+ @attributes ||= {}
11
+ end
12
+
13
+ def connection
14
+ attributes[:connection] ||= Savon::Client.new(self.wsdl)
15
+ end
16
+
17
+ def wsdl
18
+ attributes[:wsdl] ||= File.expand_path('../../../wsdl/2011_02.wsdl', __FILE__)
19
+ end
20
+
21
+ def auth_header
22
+ attributes[:auth_header] ||= {
23
+ 'platformMsgs:passport' => {
24
+ 'platformCore:email' => email,
25
+ 'platformCore:password' => password,
26
+ 'platformCore:account' => account.to_s
27
+ }
28
+ }
29
+ end
30
+
31
+ def email=(email)
32
+ attributes[:email] = email
33
+ end
34
+
35
+ def email(email = nil)
36
+ if email
37
+ self.email = email
38
+ else
39
+ attributes[:email] ||
40
+ raise(NetSuite::ConfigurationError,
41
+ '#email is a required configuration value. Please set it by calling NetSuite::Configuration.email = "me@example.com"')
42
+ end
43
+ end
44
+
45
+ def password=(password)
46
+ attributes[:password] = password
47
+ end
48
+
49
+ def password(password = nil)
50
+ if password
51
+ self.password = password
52
+ else
53
+ attributes[:password] ||
54
+ raise(NetSuite::ConfigurationError,
55
+ '#password is a required configuration value. Please set it by calling NetSuite::Configuration.password = "my_pass"')
56
+ end
57
+ end
58
+
59
+ def account=(account)
60
+ attributes[:account] = account
61
+ end
62
+
63
+ def account(account = nil)
64
+ if account
65
+ self.account = account
66
+ else
67
+ attributes[:account] ||
68
+ raise(NetSuite::ConfigurationError,
69
+ '#account is a required configuration value. Please set it by calling NetSuite::Configuration.account = 1234')
70
+ end
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,4 @@
1
+ module NetSuite
2
+ class RecordNotFound < StandardError; end
3
+ class ConfigurationError < StandardError; end
4
+ end
@@ -0,0 +1,22 @@
1
+ module NetSuite
2
+ class Customer
3
+
4
+ def initialize(attributes = {})
5
+ @attributes = attributes
6
+ end
7
+
8
+ def self.get(id)
9
+ response = NetSuite::Actions::Customer::Get.call(id)
10
+ if response.success?
11
+ new(response.body)
12
+ else
13
+ raise RecordNotFound, "#{self} with ID=#{id} could not be found"
14
+ end
15
+ end
16
+
17
+ def is_person
18
+ @attributes[:is_person]
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module NetSuite
2
+ class Response
3
+ attr_accessor :body
4
+
5
+ def initialize(attributes = {})
6
+ @success = attributes[:success]
7
+ @body = attributes[:body]
8
+ end
9
+
10
+ def success!
11
+ @success = true
12
+ end
13
+
14
+ def success?
15
+ @success
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Netsuite
2
+ VERSION = '0.0.2'
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/netsuite/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Ryan Moran']
6
+ gem.email = ['ryan.moran@gmail.com']
7
+ gem.description = %q{NetSuite SuiteTalk API Wrapper}
8
+ gem.summary = %q{NetSuite SuiteTalk API Wrapper}
9
+ gem.homepage = 'https://github.com/RevolutionPrep/netsuite'
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = 'netsuite'
15
+ gem.require_paths = ['lib']
16
+ gem.version = Netsuite::VERSION
17
+
18
+ gem.add_dependency 'savon', '0.9.7'
19
+
20
+ gem.add_development_dependency 'rspec', '2.7.0'
21
+ gem.add_development_dependency 'autotest-standalone', '4.5.9'
22
+ gem.add_development_dependency 'savon_spec', '0.1.6'
23
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Actions::Customer::Get do
4
+
5
+ before do
6
+ savon.expects(:get).with({
7
+ 'platformMsgs:baseRef' => {},
8
+ :attributes! => {
9
+ 'platformMsgs:baseRef' => {
10
+ :internalId => 1,
11
+ :type => 'customer',
12
+ 'xsi:type' => 'platformCore:RecordRef'
13
+ }
14
+ }
15
+ }).returns(:get_customer)
16
+ end
17
+
18
+ it 'makes a valid request to the NetSuite API' do
19
+ NetSuite::Actions::Customer::Get.call(1)
20
+ end
21
+
22
+ it 'returns a valid Response object' do
23
+ response = NetSuite::Actions::Customer::Get.call(1)
24
+ response.should be_kind_of(NetSuite::Response)
25
+ end
26
+
27
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Configuration do
4
+ let(:config) { NetSuite::Configuration }
5
+
6
+ before do
7
+ config.reset!
8
+ end
9
+
10
+ describe '#reset!' do
11
+ it 'clears the attributes hash' do
12
+ config.attributes[:blah] = 'something'
13
+ config.attributes.should_not be_empty
14
+ config.reset!
15
+ config.attributes.should be_empty
16
+ end
17
+ end
18
+
19
+ describe '#connection' do
20
+ it 'returns a Savon::Client object that allows requests to the service' do
21
+ config.connection.should be_kind_of(Savon::Client)
22
+ end
23
+ end
24
+
25
+ describe '#wsdl' do
26
+ it 'returns a path to the WSDL to use for the API' do
27
+ config.wsdl.should match(/.*\/netsuite\/wsdl\/2011_02\.wsdl/)
28
+ end
29
+ end
30
+
31
+ describe '#auth_header' do
32
+ before do
33
+ config.email = 'user@example.com'
34
+ config.password = 'myPassword'
35
+ config.account = 1234
36
+ end
37
+
38
+ it 'returns a hash representation of the authentication header' do
39
+ config.auth_header.should eql({
40
+ 'platformMsgs:passport' => {
41
+ 'platformCore:email' => 'user@example.com',
42
+ 'platformCore:password' => 'myPassword',
43
+ 'platformCore:account' => '1234'
44
+ }
45
+ })
46
+ end
47
+ end
48
+
49
+ describe '#email' do
50
+ context 'when the email has been set' do
51
+ before do
52
+ config.email = 'test@example.com'
53
+ end
54
+
55
+ it 'returns the email' do
56
+ config.email.should eql('test@example.com')
57
+ end
58
+ end
59
+
60
+ context 'when the email has not been set' do
61
+ it 'raises a ConfigurationError' do
62
+ lambda {
63
+ config.email
64
+ }.should raise_error(NetSuite::ConfigurationError,
65
+ '#email is a required configuration value. Please set it by calling NetSuite::Configuration.email = "me@example.com"')
66
+ end
67
+ end
68
+ end
69
+
70
+ describe '#password' do
71
+ context 'when the password has been set' do
72
+ before do
73
+ config.password = 'password'
74
+ end
75
+
76
+ it 'returns the password' do
77
+ config.password.should eql('password')
78
+ end
79
+ end
80
+
81
+ context 'when the password has not been set' do
82
+ it 'raises a ConfigurationError' do
83
+ lambda {
84
+ config.password
85
+ }.should raise_error(NetSuite::ConfigurationError,
86
+ '#password is a required configuration value. Please set it by calling NetSuite::Configuration.password = "my_pass"')
87
+ end
88
+ end
89
+ end
90
+
91
+ describe '#account' do
92
+ context 'when the account has been set' do
93
+ before do
94
+ config.account = 4321
95
+ end
96
+
97
+ it 'returns the account' do
98
+ config.account.should eql(4321)
99
+ end
100
+ end
101
+
102
+ context 'when the account has not been set' do
103
+ it 'raises a ConfigurationError' do
104
+ lambda {
105
+ config.account
106
+ }.should raise_error(NetSuite::ConfigurationError,
107
+ '#account is a required configuration value. Please set it by calling NetSuite::Configuration.account = 1234')
108
+ end
109
+ end
110
+ end
111
+
112
+ end