Class: Stratagem::Authentication

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/stratagem/authentication.rb

Constant Summary collapse

FILENAME =
'.stratagem'

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.



10
11
12
# File 'lib/stratagem/authentication.rb', line 10

def project
  @project
end

#tokenObject (readonly)

Returns the value of attribute token.



10
11
12
# File 'lib/stratagem/authentication.rb', line 10

def token
  @token
end

Instance Method Details

#base_urlObject



28
29
30
31
# File 'lib/stratagem/authentication.rb', line 28

def base_url
  protocol = Stratagem.ssl? ? 'https' : 'http'
  "#{protocol}://#{Stratagem.domain}"
end

#credentialsObject



37
38
39
# File 'lib/stratagem/authentication.rb', line 37

def credentials
  @credentials ||= load_credentials  
end

#project_urlObject



33
34
35
# File 'lib/stratagem/authentication.rb', line 33

def project_url
  "#{base_url}/projects/#{credentials[:project]}?auth_token=#{credentials[:token]}"
end

#store_credentials(token, project) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/stratagem/authentication.rb', line 12

def store_credentials(token, project)
  File.open(FILENAME, 'w') do |f|
    f.puts token
    f.puts project
  end
  reload_credentials
end

#urlObject



20
21
22
23
24
25
26
# File 'lib/stratagem/authentication.rb', line 20

def url
  if (credentials.nil?)
    base_url+"/project_links/new"
  else
    base_url+"/project_links/validate/#{credentials[:project]}?auth_token=#{credentials[:token]}"
  end
end