Class: LedgerSync::Adaptors::NetSuite::Adaptor

Inherits:
Adaptor
  • Object
show all
Defined in:
lib/ledger_sync/adaptors/netsuite/adaptor.rb

Constant Summary collapse

HEADERS =
{
  # 'Accept' => 'application/schema+json'
}.freeze
WRITE_HEADERS =
{
  'Accept' => '*/*',
  'Content-Type' => 'application/json'
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Adaptor

#adaptor_configuration, #base_module, base_module, base_operation_module_for, config, #ledger_attributes_to_save, #parse_operation_error, #searcher_for?, #searcher_klass_for, #url_for, url_for

Methods included from Validatable

#valid?, #validate, #validate_or_fail

Constructor Details

#initialize(account_id:, consumer_key:, consumer_secret:, token_id:, token_secret:) ⇒ Adaptor

Returns a new instance of Adaptor.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 24

def initialize(
  account_id:,
  consumer_key:,
  consumer_secret:,
  token_id:,
  token_secret:
)
  @account_id = 
  @consumer_key = consumer_key
  @consumer_secret = consumer_secret
  @token_id = token_id
  @token_secret = token_secret
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



18
19
20
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 18

def 
  @account_id
end

#consumer_keyObject (readonly)

Returns the value of attribute consumer_key.



18
19
20
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 18

def consumer_key
  @consumer_key
end

#consumer_secretObject (readonly)

Returns the value of attribute consumer_secret.



18
19
20
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 18

def consumer_secret
  @consumer_secret
end

#token_idObject (readonly)

Returns the value of attribute token_id.



18
19
20
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 18

def token_id
  @token_id
end

#token_secretObject (readonly)

Returns the value of attribute token_secret.



18
19
20
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 18

def token_secret
  @token_secret
end

Class Method Details

.ledger_attributes_to_saveObject



80
81
82
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 80

def self.ledger_attributes_to_save
  %i[]
end

.new_from_env(**override) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 84

def self.new_from_env(**override)
  new(
    {
      account_id: ENV.fetch('NETSUITE_ACCOUNT_ID', nil),
      consumer_key: ENV.fetch('NETSUITE_CONSUMER_KEY', nil),
      consumer_secret: ENV.fetch('NETSUITE_CONSUMER_SECRET', nil),
      token_id: ENV.fetch('NETSUITE_TOKEN_ID', nil),
      token_secret: ENV.fetch('NETSUITE_TOKEN_SECRET', nil)
    }.merge(override)
  )
end

Instance Method Details

#account_id_for_oauthObject



38
39
40
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 38

def 
  .split('-sb').join('_SB')
end

#account_id_for_urlObject



42
43
44
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 42

def 
  .split('_SB').join('-sb')
end

#api_base_urlObject



46
47
48
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 46

def api_base_url
  @api_base_url ||= "https://#{api_host}/rest/platform/v1"
end

#api_hostObject



50
51
52
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 50

def api_host
  @api_host ||= "#{}.suitetalk.api.netsuite.com"
end

#delete(**keywords) ⇒ Object



54
55
56
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 54

def delete(**keywords)
  request(keywords.merge(method: :delete))
end

#get(**keywords) ⇒ Object



58
59
60
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 58

def get(**keywords)
  request(keywords.merge(method: :get))
end

#patch(headers: {}, **keywords) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 62

def patch(headers: {}, **keywords)
  request(
    keywords.merge(
      headers: WRITE_HEADERS.merge(headers),
      method: :patch
    )
  )
end

#post(headers: {}, **keywords) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/ledger_sync/adaptors/netsuite/adaptor.rb', line 71

def post(headers: {}, **keywords)
  request(
    keywords.merge(
      headers: WRITE_HEADERS.merge(headers),
      method: :post
    )
  )
end