Class: MyERP::Credentials

Inherits:
Object
  • Object
show all
Defined in:
lib/myerp/credentials.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_email, api_key, options) ⇒ Credentials

Returns a new instance of Credentials.



5
6
7
# File 'lib/myerp/credentials.rb', line 5

def initialize(api_email, api_key, options)
  @api_email, @api_key, @options = api_email, api_key, options
end

Instance Attribute Details

#api_emailObject

Returns the value of attribute api_email.



3
4
5
# File 'lib/myerp/credentials.rb', line 3

def api_email
  @api_email
end

#api_keyObject

Returns the value of attribute api_key.



3
4
5
# File 'lib/myerp/credentials.rb', line 3

def api_key
  @api_key
end

#optionsObject

Returns the value of attribute options.



3
4
5
# File 'lib/myerp/credentials.rb', line 3

def options
  @options
end

Instance Method Details

#basic_authObject



13
14
15
# File 'lib/myerp/credentials.rb', line 13

def basic_auth
  Base64.encode64("#{api_email}:#{api_key}").delete("\r\n")
end

#hostObject



17
18
19
20
21
22
23
24
25
# File 'lib/myerp/credentials.rb', line 17

def host
  site = "#{@options[:protocol]}://"
  if (@options[:protocol] == 'http' && @options[:port] == 80) || (@options[:protocol] == 'https' && @options[:port] == 443)
    site += @options[:host]
  else
    site += "#{@options[:host]}:#{@options[:port]}"
  end
  site += @options[:prefix].to_s
end

#valid?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/myerp/credentials.rb', line 9

def valid?
  !api_email.nil? && !api_key.nil? && !options.nil?
end