Class: GetToWork::Service::PivotalTracker
Instance Method Summary
collapse
display_name, #display_name, #initialize, #keychain, #name, #save_config, #update_keychain, #yaml_key
Instance Method Details
#api_client ⇒ Object
52
53
54
|
# File 'lib/get_to_work/service/pivotal_tracker.rb', line 52
def api_client
@api_client ||= TrackerApi::Client.new(token: api_token)
end
|
#api_token ⇒ Object
48
49
50
|
# File 'lib/get_to_work/service/pivotal_tracker.rb', line 48
def api_token
@api_token ||= authenticate_with_keychain
end
|
#authenticate(username:, password:, subdomain:) ⇒ Object
33
34
35
36
|
# File 'lib/get_to_work/service/pivotal_tracker.rb', line 33
def authenticate(username:, password:, subdomain:)
token = get_auth_token(user: username, pass: password)
set_client_token(token)
end
|
#authenticate_with_keychain ⇒ Object
38
39
40
41
42
|
# File 'lib/get_to_work/service/pivotal_tracker.rb', line 38
def authenticate_with_keychain
if keychain
set_client_token(keychain.password)
end
end
|
#get_auth_token(user:, pass:) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/get_to_work/service/pivotal_tracker.rb', line 11
def get_auth_token(user:, pass:)
uri = URI("https://www.pivotaltracker.com/services/v3/tokens/active")
req = Net::HTTP::Get.new(uri)
req.basic_auth user, pass
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(req)
end
case res
when Net::HTTPUnauthorized
raise Service::UnauthorizedError
else
res
end
xml = Nokogiri::XML(res.body)
xml.xpath("//guid").first.text
end
|
#get_projects ⇒ Object
60
61
62
63
64
|
# File 'lib/get_to_work/service/pivotal_tracker.rb', line 60
def get_projects
api_client.projects.sort do |x, y|
x[:name] <=> y[:name]
end
end
|
#projects ⇒ Object
56
57
58
|
# File 'lib/get_to_work/service/pivotal_tracker.rb', line 56
def projects
@projects ||= get_projects
end
|
#set_client_token(token) ⇒ Object
44
45
46
|
# File 'lib/get_to_work/service/pivotal_tracker.rb', line 44
def set_client_token(token)
@api_token = token
end
|
#story(story_id) ⇒ Object
66
67
68
|
# File 'lib/get_to_work/service/pivotal_tracker.rb', line 66
def story(story_id)
api_client.project(@project_id).story(story_id)
end
|