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



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

def base_url
  subdomain = credentials ? credentials[:account] : 'www' 
  "https://#{subdomain}.stratagemapp.com"
end

#credentialsObject



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

def credentials
  @credentials ||= load_credentials  
end

#project_urlObject



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

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

#store_credentials(account, token, project) ⇒ Object



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

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

#urlObject



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

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