Class: Alegra::Setup

Inherits:
Object
  • Object
show all
Defined in:
lib/alegra/setup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username = nil, apikey = nil, debug = false) ⇒ Setup

Returns a new instance of Setup.

Raises:

  • (Error)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/alegra/setup.rb', line 9

def initialize(username=nil, apikey=nil, debug=false)
  @host = 'https://app.alegra.com/'
  @path = 'api/v1/'

  @debug = debug

  if not apikey
    if ENV['ALEGRA_APIKEY']
      @apikey = ENV['ALEGRA_APIKEY']
    else
      raise 'set up the ALEGRA_APIKEY environment variable'
      # apikey = read_configs
    end
  end

  if not username
    if ENV['ALEGRA_USERNAME']
      @username = ENV['ALEGRA_USERNAME']
    else
      raise 'set up the ALEGRA_USERNAME environment variable'
      # apikey = read_configs
    end
  end

  raise Error, 'You must provide a ALEGRA API key' if not apikey
  raise Error, 'You must provide a ALEGRA USERNAME' if not username
  @apikey = apikey
  @username = username
  create_token!
end

Instance Attribute Details

#apikeyObject

Returns the value of attribute apikey.



7
8
9
# File 'lib/alegra/setup.rb', line 7

def apikey
  @apikey
end

#debugObject

Returns the value of attribute debug.



7
8
9
# File 'lib/alegra/setup.rb', line 7

def debug
  @debug
end

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/alegra/setup.rb', line 7

def host
  @host
end

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/alegra/setup.rb', line 7

def path
  @path
end

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/alegra/setup.rb', line 7

def token
  @token
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/alegra/setup.rb', line 7

def username
  @username
end

Instance Method Details

#create_token!Object



40
41
42
# File 'lib/alegra/setup.rb', line 40

def create_token!
  @token = ::Base64.strict_encode64("#{@username}:#{@apikey}")
end