Module: NetSuite::Configuration

Extended by:
Configuration
Included in:
Configuration
Defined in:
lib/netsuite/configuration.rb

Instance Method Summary collapse

Instance Method Details

#account(account = nil) ⇒ Object



180
181
182
183
184
185
186
187
188
# File 'lib/netsuite/configuration.rb', line 180

def ( = nil)
  if 
    self. = 
  else
    attributes[:account] ||
    raise(ConfigurationError,
      '#account is a required configuration value. Please set it by calling NetSuite::Configuration.account = 1234')
  end
end

#account=(account) ⇒ Object



176
177
178
# File 'lib/netsuite/configuration.rb', line 176

def account=()
  attributes[:account] = 
end

#api_version(version = nil) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/netsuite/configuration.rb', line 26

def api_version(version = nil)
  if version
    self.api_version = version
  else
    attributes[:api_version] ||= '2011_2'
  end
end

#api_version=(version) ⇒ Object



34
35
36
# File 'lib/netsuite/configuration.rb', line 34

def api_version=(version)
  attributes[:api_version] = version
end

#attributesObject



9
10
11
# File 'lib/netsuite/configuration.rb', line 9

def attributes
  @attributes ||= {}
end

#auth_header(credentials = {}) ⇒ Object



101
102
103
104
105
106
107
108
109
110
# File 'lib/netsuite/configuration.rb', line 101

def auth_header(credentials={})
  {
    'platformMsgs:passport' => {
      'platformCore:email'    => credentials[:email] || email,
      'platformCore:password' => credentials[:password] || password,
      'platformCore:account'  => credentials[:account] || .to_s,
      'platformCore:role'     => { :@internalId => credentials[:role] || role }
    }
  }
end

#connection(params = {}, credentials = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/netsuite/configuration.rb', line 13

def connection(params={}, credentials={})
  Savon.client({
    wsdl: wsdl,
    read_timeout: read_timeout,
    namespaces: namespaces,
    soap_header: auth_header(credentials).update(soap_header),
    pretty_print_xml: true,
    logger: logger,
    log_level: log_level,
    log: !silent,   # turn off logging entirely if configured
  }.update(params))
end

#email(email = nil) ⇒ Object



152
153
154
155
156
157
158
159
160
# File 'lib/netsuite/configuration.rb', line 152

def email(email = nil)
  if email
    self.email = email
  else
    attributes[:email] ||
    raise(ConfigurationError,
      '#email is a required configuration value. Please set it by calling NetSuite::Configuration.email = "[email protected]"')
  end
end

#email=(email) ⇒ Object



148
149
150
# File 'lib/netsuite/configuration.rb', line 148

def email=(email)
  attributes[:email] = email
end

#log(path = nil) ⇒ Object



206
207
208
209
# File 'lib/netsuite/configuration.rb', line 206

def log(path = nil)
  self.log = path if path
  attributes[:log]
end

#log=(path) ⇒ Object



202
203
204
# File 'lib/netsuite/configuration.rb', line 202

def log=(path)
  attributes[:log] = path
end

#log_level(value = nil) ⇒ Object



228
229
230
231
# File 'lib/netsuite/configuration.rb', line 228

def log_level(value = nil)
  self.log_level = value || :debug
  attributes[:log_level]
end

#log_level=(value) ⇒ Object



233
234
235
# File 'lib/netsuite/configuration.rb', line 233

def log_level=(value)
  attributes[:log_level] ||= value
end

#logger(value = nil) ⇒ Object



211
212
213
214
215
216
217
# File 'lib/netsuite/configuration.rb', line 211

def logger(value = nil)
  attributes[:logger] = if value.nil?
    ::Logger.new((log && !log.empty?) ? log : $stdout)
  else
    value
  end
end

#namespacesObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/netsuite/configuration.rb', line 112

def namespaces
  {
    'xmlns:platformMsgs'   => "urn:messages_#{api_version}.platform.webservices.netsuite.com",
    'xmlns:platformCore'   => "urn:core_#{api_version}.platform.webservices.netsuite.com",
    'xmlns:platformCommon' => "urn:common_#{api_version}.platform.webservices.netsuite.com",
    'xmlns:listRel'        => "urn:relationships_#{api_version}.lists.webservices.netsuite.com",
    'xmlns:tranSales'      => "urn:sales_#{api_version}.transactions.webservices.netsuite.com",
    'xmlns:tranPurch'      => "urn:purchases_#{api_version}.transactions.webservices.netsuite.com",
    'xmlns:actSched'       => "urn:scheduling_#{api_version}.activities.webservices.netsuite.com",
    'xmlns:setupCustom'    => "urn:customization_#{api_version}.setup.webservices.netsuite.com",
    'xmlns:listAcct'       => "urn:accounting_#{api_version}.lists.webservices.netsuite.com",
    'xmlns:tranBank'       => "urn:bank_#{api_version}.transactions.webservices.netsuite.com",
    'xmlns:tranCust'       => "urn:customers_#{api_version}.transactions.webservices.netsuite.com",
    'xmlns:tranEmp'        => "urn:employees_#{api_version}.transactions.webservices.netsuite.com",
    'xmlns:tranInvt'       => "urn:inventory_#{api_version}.transactions.webservices.netsuite.com",
    'xmlns:listSupport'    => "urn:support_#{api_version}.lists.webservices.netsuite.com",
    'xmlns:tranGeneral'    => "urn:general_#{api_version}.transactions.webservices.netsuite.com",
    'xmlns:listMkt'        => "urn:marketing_#{api_version}.lists.webservices.netsuite.com",
    'xmlns:listWebsite'    => "urn:website_#{api_version}.lists.webservices.netsuite.com",
    'xmlns:fileCabinet'    => "urn:filecabinet_#{api_version}.documents.webservices.netsuite.com",
    'xmlns:listEmp'        => "urn:employees_#{api_version}.lists.webservices.netsuite.com"
  }
end

#password(password = nil) ⇒ Object



166
167
168
169
170
171
172
173
174
# File 'lib/netsuite/configuration.rb', line 166

def password(password = nil)
  if password
    self.password = password
  else
    attributes[:password] ||
    raise(ConfigurationError,
      '#password is a required configuration value. Please set it by calling NetSuite::Configuration.password = "my_pass"')
  end
end

#password=(password) ⇒ Object



162
163
164
# File 'lib/netsuite/configuration.rb', line 162

def password=(password)
  attributes[:password] = password
end

#read_timeout(timeout = nil) ⇒ Object



194
195
196
197
198
199
200
# File 'lib/netsuite/configuration.rb', line 194

def read_timeout(timeout = nil)
  if timeout
    self.read_timeout = timeout
  else
    attributes[:read_timeout] ||= 60
  end
end

#read_timeout=(timeout) ⇒ Object



190
191
192
# File 'lib/netsuite/configuration.rb', line 190

def read_timeout=(timeout)
  attributes[:read_timeout] = timeout
end

#reset!Object



5
6
7
# File 'lib/netsuite/configuration.rb', line 5

def reset!
  attributes.clear
end

#role(role = nil) ⇒ Object



140
141
142
143
144
145
146
# File 'lib/netsuite/configuration.rb', line 140

def role(role = nil)
  if role
    self.role = role
  else
    attributes[:role] ||= '3'
  end
end

#role=(role) ⇒ Object



136
137
138
# File 'lib/netsuite/configuration.rb', line 136

def role=(role)
  attributes[:role] = role
end

#sandbox(flag = nil) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/netsuite/configuration.rb', line 42

def sandbox(flag = nil)
  if flag.nil?
    attributes[:flag] ||= false
  else
    self.sandbox = flag
  end
end

#sandbox=(flag) ⇒ Object



38
39
40
# File 'lib/netsuite/configuration.rb', line 38

def sandbox=(flag)
  attributes[:flag] = flag
end

#sandbox?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/netsuite/configuration.rb', line 50

def sandbox?
  !!sandbox
end

#silent(value = nil) ⇒ Object



219
220
221
222
# File 'lib/netsuite/configuration.rb', line 219

def silent(value=nil)
  self.silent = value if value
  attributes[:silent]
end

#silent=(value) ⇒ Object



224
225
226
# File 'lib/netsuite/configuration.rb', line 224

def silent=(value)
  attributes[:silent] ||= value
end

#soap_header(headers = nil) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/netsuite/configuration.rb', line 93

def soap_header(headers = nil)
  if headers
    self.soap_header = headers
  else
    attributes[:soap_header] ||= {}
  end
end

#soap_header=(headers) ⇒ Object



89
90
91
# File 'lib/netsuite/configuration.rb', line 89

def soap_header=(headers)
  attributes[:soap_header] = headers
end

#wsdl(wsdl = nil) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/netsuite/configuration.rb', line 58

def wsdl(wsdl = nil)
  if wsdl
    self.wsdl = wsdl
  else
    if sandbox
      wsdl_path = "https://webservices.sandbox.netsuite.com/wsdl/v#{api_version}_0/netsuite.wsdl"
    else
      wsdl_path = File.expand_path("../../../wsdl/#{api_version}.wsdl", __FILE__)

      unless File.exists? wsdl_path
        wsdl_path = "https://#{wsdl_domain}/wsdl/v#{api_version}_0/netsuite.wsdl"
      end
    end

    attributes[:wsdl] ||= wsdl_path
  end
end

#wsdl=(wsdl) ⇒ Object



54
55
56
# File 'lib/netsuite/configuration.rb', line 54

def wsdl=(wsdl)
  attributes[:wsdl] = wsdl
end

#wsdl_domain(wsdl_domain = nil) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/netsuite/configuration.rb', line 76

def wsdl_domain(wsdl_domain = nil)
  if wsdl_domain
    self.wsdl_domain = wsdl_domain
  else
    # if sandbox, this parameter is ignored
    attributes[:wsdl_domain] ||= 'webservices.netsuite.com'
  end
end

#wsdl_domain=(wsdl_domain) ⇒ Object



85
86
87
# File 'lib/netsuite/configuration.rb', line 85

def wsdl_domain=(wsdl_domain)
  attributes[:wsdl_domain] = wsdl_domain
end