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



288
289
290
291
292
293
294
# File 'lib/netsuite/configuration.rb', line 288

def ( = nil)
  if 
    self. = 
  else
    attributes[:account]
  end
end

#account=(account) ⇒ Object



284
285
286
# File 'lib/netsuite/configuration.rb', line 284

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

#api_version(version = nil) ⇒ Object



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

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

#api_version=(version) ⇒ Object



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

def api_version=(version)
  if attributes[:api_version] != version
    attributes[:wsdl] = nil
    attributes[:wsdl_domain] = nil
  end

  attributes[:api_version] = version
end

#attributesObject



13
14
15
16
17
18
19
# File 'lib/netsuite/configuration.rb', line 13

def attributes
  if multi_tenant?
    Thread.current[:netsuite_gem_attributes] ||= {}
  else
    @attributes ||= {}
  end
end

#auth_header(credentials = {}) ⇒ Object



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

def auth_header(credentials={})
  if !credentials[:consumer_key].blank? || !consumer_key.blank?
    token_auth(credentials)
  else
    user_auth(credentials)
  end
end

#cache_wsdl(client) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/netsuite/configuration.rb', line 82

def cache_wsdl(client)
  # NOTE the Savon::Client doesn't pull the wsdl content upon
  # instantiation; it pulls it when it recieves the #call method.
  # If we force it to pull the wsdl here, it will duplicate the call later.
  # So, we stash the entire client and fetch just the wsdl from it after
  # it completes its call
  # For reference, see:
  # https://github.com/savonrb/savon/blob/d64925d3add33fa5531577ce9e3a28a7a93618b1/lib/savon/client.rb#L35-L37
  # https://github.com/savonrb/savon/blob/d64925d3add33fa5531577ce9e3a28a7a93618b1/lib/savon/operation.rb#L22
  wsdl_cache[wsdl] ||= client
end

#cached_wsdlObject



73
74
75
76
77
78
79
80
# File 'lib/netsuite/configuration.rb', line 73

def cached_wsdl
  cached = wsdl_cache.fetch(wsdl, nil)
  if cached.is_a? String
    cached
  elsif cached.is_a? Savon::Client
    wsdl_cache[wsdl] = cached.instance_eval { @wsdl.xml }
  end
end

#clear_wsdl_cacheObject



65
66
67
68
69
70
71
# File 'lib/netsuite/configuration.rb', line 65

def clear_wsdl_cache
  if multi_tenant?
    Thread.current[:netsuite_gem_wsdl_cache] = {}
  else
    @wsdl_cache = {}
  end
end

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/netsuite/configuration.rb', line 21

def connection(params={}, credentials={}, soap_header_extra_info={})
  client = Savon.client({
    wsdl: cached_wsdl || wsdl,
    endpoint: endpoint,
    read_timeout: read_timeout,
    open_timeout: open_timeout,
    namespaces: namespaces,
    soap_header: auth_header(credentials).update(soap_header).merge(soap_header_extra_info),
    pretty_print_xml: true,
    filters: filters,
    logger: logger,
    log_level: log_level,
    log: !silent, # turn off logging entirely if configured
  }.update(params))
  client.globals.proxy(proxy) if proxy
  cache_wsdl(client)
  return client
end

#consumer_key(consumer_key = nil) ⇒ Object



300
301
302
303
304
305
306
# File 'lib/netsuite/configuration.rb', line 300

def consumer_key(consumer_key = nil)
  if consumer_key
    self.consumer_key = consumer_key
  else
    attributes[:consumer_key]
  end
end

#consumer_key=(consumer_key) ⇒ Object



296
297
298
# File 'lib/netsuite/configuration.rb', line 296

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

#consumer_secret(consumer_secret = nil) ⇒ Object



312
313
314
315
316
317
318
# File 'lib/netsuite/configuration.rb', line 312

def consumer_secret(consumer_secret = nil)
  if consumer_secret
    self.consumer_secret = consumer_secret
  else
    attributes[:consumer_secret]
  end
end

#consumer_secret=(consumer_secret) ⇒ Object



308
309
310
# File 'lib/netsuite/configuration.rb', line 308

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

#email(email = nil) ⇒ Object



264
265
266
267
268
269
270
# File 'lib/netsuite/configuration.rb', line 264

def email(email = nil)
  if email
    self.email = email
  else
    attributes[:email]
  end
end

#email=(email) ⇒ Object



260
261
262
# File 'lib/netsuite/configuration.rb', line 260

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

#endpoint(endpoint = nil) ⇒ Object



115
116
117
118
119
120
121
# File 'lib/netsuite/configuration.rb', line 115

def endpoint(endpoint=nil)
  if endpoint
    self.endpoint = endpoint
  else
    attributes[:endpoint]
  end
end

#endpoint=(endpoint) ⇒ Object



111
112
113
# File 'lib/netsuite/configuration.rb', line 111

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

#filters(list = nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/netsuite/configuration.rb', line 40

def filters(list = nil)
  if list
    self.filters = list
  else
    attributes[:filters] ||= [
      :password,
      :email,
      :consumerKey,
      :token
    ]
  end
end

#filters=(list) ⇒ Object



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

def filters=(list)
  attributes[:filters] = list
end

#log(path = nil) ⇒ Object



372
373
374
375
# File 'lib/netsuite/configuration.rb', line 372

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

#log=(path) ⇒ Object



368
369
370
# File 'lib/netsuite/configuration.rb', line 368

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

#log_level(value = nil) ⇒ Object



401
402
403
404
405
# File 'lib/netsuite/configuration.rb', line 401

def log_level(value = nil)
  self.log_level = value if value

  attributes[:log_level] || :debug
end

#log_level=(value) ⇒ Object



407
408
409
# File 'lib/netsuite/configuration.rb', line 407

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

#logger(value = nil) ⇒ Object



377
378
379
380
381
382
383
384
385
386
# File 'lib/netsuite/configuration.rb', line 377

def logger(value = nil)
  if value.nil?
    # if passed a IO object (like StringIO) `empty?` won't exist
    valid_log = log && !(log.respond_to?(:empty?) && log.empty?)

    attributes[:logger] ||= ::Logger.new(valid_log ? log : $stdout)
  else
    attributes[:logger] = value
  end
end

#logger=(value) ⇒ Object



388
389
390
# File 'lib/netsuite/configuration.rb', line 388

def logger=(value)
  attributes[:logger] = value
end

#multi_tenant!Object



423
424
425
# File 'lib/netsuite/configuration.rb', line 423

def multi_tenant!
  @multi_tenant = true
end

#multi_tenant?Boolean

Returns:

  • (Boolean)


427
428
429
# File 'lib/netsuite/configuration.rb', line 427

def multi_tenant?
  @multi_tenant
end

#namespacesObject



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/netsuite/configuration.rb', line 223

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:commGeneral'    => "urn:communication_#{api_version}.general.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

#open_timeout(timeout = nil) ⇒ Object



360
361
362
363
364
365
366
# File 'lib/netsuite/configuration.rb', line 360

def open_timeout(timeout = nil)
  if timeout
    self.open_timeout = timeout
  else
    attributes[:open_timeout]
  end
end

#open_timeout=(timeout) ⇒ Object



356
357
358
# File 'lib/netsuite/configuration.rb', line 356

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

#password(password = nil) ⇒ Object



276
277
278
279
280
281
282
# File 'lib/netsuite/configuration.rb', line 276

def password(password = nil)
  if password
    self.password = password
  else
    attributes[:password]
  end
end

#password=(password) ⇒ Object



272
273
274
# File 'lib/netsuite/configuration.rb', line 272

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

#proxy(proxy = nil) ⇒ Object



415
416
417
418
419
420
421
# File 'lib/netsuite/configuration.rb', line 415

def proxy(proxy = nil)
  if proxy
    self.proxy = proxy
  else
    attributes[:proxy]
  end
end

#proxy=(proxy) ⇒ Object



411
412
413
# File 'lib/netsuite/configuration.rb', line 411

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

#read_timeout(timeout = nil) ⇒ Object



348
349
350
351
352
353
354
# File 'lib/netsuite/configuration.rb', line 348

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

#read_timeout=(timeout) ⇒ Object



344
345
346
# File 'lib/netsuite/configuration.rb', line 344

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

#reset!Object



5
6
7
8
9
10
11
# File 'lib/netsuite/configuration.rb', line 5

def reset!
  NetSuite::Utilities.clear_cache!

  clear_wsdl_cache

  attributes.clear
end

#role(role = nil) ⇒ Object



252
253
254
255
256
257
258
# File 'lib/netsuite/configuration.rb', line 252

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

#role=(role) ⇒ Object



248
249
250
# File 'lib/netsuite/configuration.rb', line 248

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

#sandbox(flag = nil) ⇒ Object



132
133
134
135
136
137
138
# File 'lib/netsuite/configuration.rb', line 132

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

#sandbox=(flag) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/netsuite/configuration.rb', line 123

def sandbox=(flag)
  if attributes[:sandbox] != flag
    attributes[:wsdl] = nil
    attributes[:wsdl_domain] = nil
  end

  attributes[:sandbox] = flag
end

#sandbox?Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/netsuite/configuration.rb', line 140

def sandbox?
  !!sandbox
end

#silent(value = nil) ⇒ Object



392
393
394
395
# File 'lib/netsuite/configuration.rb', line 392

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

#silent=(value) ⇒ Object



397
398
399
# File 'lib/netsuite/configuration.rb', line 397

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

#soap_header(headers = nil) ⇒ Object



188
189
190
191
192
193
194
# File 'lib/netsuite/configuration.rb', line 188

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

#soap_header=(headers) ⇒ Object



184
185
186
# File 'lib/netsuite/configuration.rb', line 184

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

#token_auth(credentials) ⇒ Object



213
214
215
216
217
218
219
220
221
# File 'lib/netsuite/configuration.rb', line 213

def token_auth(credentials)
  NetSuite::Passports::Token.new(
    credentials[:account] || ,
    credentials[:consumer_key] || consumer_key,
    credentials[:consumer_secret] || consumer_secret,
    credentials[:token_id] || token_id,
    credentials[:token_secret] || token_secret
  ).passport
end

#token_id(token_id = nil) ⇒ Object



324
325
326
327
328
329
330
# File 'lib/netsuite/configuration.rb', line 324

def token_id(token_id = nil)
  if token_id
    self.token_id = token_id
  else
    attributes[:token_id]
  end
end

#token_id=(token_id) ⇒ Object



320
321
322
# File 'lib/netsuite/configuration.rb', line 320

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

#token_secret(token_secret = nil) ⇒ Object



336
337
338
339
340
341
342
# File 'lib/netsuite/configuration.rb', line 336

def token_secret(token_secret = nil)
  if token_secret
    self.token_secret = token_secret
  else
    attributes[:token_secret]
  end
end

#token_secret=(token_secret) ⇒ Object



332
333
334
# File 'lib/netsuite/configuration.rb', line 332

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

#user_auth(credentials) ⇒ Object



204
205
206
207
208
209
210
211
# File 'lib/netsuite/configuration.rb', line 204

def user_auth(credentials)
  NetSuite::Passports::User.new(
    credentials[:account] || ,
    credentials[:email] || email,
    credentials[:password] || password,
    credentials[:role] || role
  ).passport
end

#wsdl(wsdl = nil) ⇒ Object



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

def wsdl(wsdl = nil)
  if wsdl
    self.wsdl = wsdl
  else
    attributes[:wsdl] ||= begin
      if sandbox
        "https://webservices.sandbox.netsuite.com/wsdl/v#{api_version}_0/netsuite.wsdl"
      else
        "https://#{wsdl_domain}/wsdl/v#{api_version}_0/netsuite.wsdl"
      end
    end
  end
end

#wsdl=(wsdl) ⇒ Object



144
145
146
# File 'lib/netsuite/configuration.rb', line 144

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

#wsdl_cacheObject



57
58
59
60
61
62
63
# File 'lib/netsuite/configuration.rb', line 57

def wsdl_cache
  if multi_tenant?
    Thread.current[:netsuite_gem_wsdl_cache] ||= {}
  else
    @wsdl_cache ||= {}
  end
end

#wsdl_domain(wsdl_domain = nil) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/netsuite/configuration.rb', line 162

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

#wsdl_domain=(wsdl_domain) ⇒ Object



175
176
177
178
179
180
181
182
# File 'lib/netsuite/configuration.rb', line 175

def wsdl_domain=(wsdl_domain)
  if attributes[:wsdl_domain] != wsdl_domain
    # reset full wsdl url to ensure it's regenerated with the updated `wsdl_domain` next time it's needed
    attributes[:wsdl] = nil
  end

  attributes[:wsdl_domain] = wsdl_domain
end