Class: NetsuiteApi::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/netsuite_api/base.rb

Direct Known Subclasses

Contact, CreditMemo, Customer, Invoice, Payment, Vendor, VendorBill

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(netsuite_host: nil, netsuite_pdf_host: nil, account_id: nil, consumer_key: nil, token: nil, token_secret: nil, consumer_secret: nil) ⇒ Base

Returns a new instance of Base.



10
11
12
13
14
15
16
17
18
# File 'lib/netsuite_api/base.rb', line 10

def initialize(netsuite_host: nil, netsuite_pdf_host: nil, account_id: nil, consumer_key: nil, token: nil, token_secret: nil, consumer_secret: nil)
  @netsuite_host = netsuite_host || ENV['NETSUITE_HOST']
  @netsuite_pdf_host = netsuite_pdf_host || ENV['NETSUITE_PDF_HOST']
  @account_id =  || ENV['NETSUITE_ACCOUNT_ID']
  @consumer_key = consumer_key || ENV['NETSUITE_CONSUMER_KEY']
  @token = token || ENV['NETSUITE_TOKEN']
  @token_secret = token_secret || ENV['NETSUITE_TOKEN_SECRET']
  @consumer_secret = consumer_secret || ENV['NETSUITE_CONSUMER_SECRET']
end

Instance Attribute Details

#account_idObject (readonly)

Returns the value of attribute account_id.



8
9
10
# File 'lib/netsuite_api/base.rb', line 8

def 
  @account_id
end

#consumer_keyObject (readonly)

Returns the value of attribute consumer_key.



8
9
10
# File 'lib/netsuite_api/base.rb', line 8

def consumer_key
  @consumer_key
end

#netsuite_hostObject (readonly)

Returns the value of attribute netsuite_host.



8
9
10
# File 'lib/netsuite_api/base.rb', line 8

def netsuite_host
  @netsuite_host
end

#tokenObject (readonly)

Returns the value of attribute token.



8
9
10
# File 'lib/netsuite_api/base.rb', line 8

def token
  @token
end

Instance Method Details

#request(url, query_params: nil, host_type: :netsuite_host, body: nil, method: :get, headers: {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/netsuite_api/base.rb', line 20

def request(url, query_params: nil, host_type: :netsuite_host, body: nil, method: :get, headers: {})
  host = host_options[host_type]
  connection(host).send(method) do |req|
    req.url full_url(url, query_params)
    req.headers["Authorization"] = authorization_header(url, method, query_params, host: host)
    req.headers["Content-Type"] = "application/json"
    req.headers.merge!(headers)
    req.body = JSON.dump(body) if body
  end
end