Class: Pickler::Tracker
- Inherits:
-
Object
show all
- Defined in:
- lib/pickler/tracker.rb,
lib/pickler/tracker/note.rb,
lib/pickler/tracker/story.rb,
lib/pickler/tracker/project.rb,
lib/pickler/tracker/iteration.rb
Defined Under Namespace
Classes: Abstract, Error, Iteration, Note, Project, Story
Constant Summary
collapse
- ADDRESS =
'www.pivotaltracker.com'
- BASE_PATH =
'/services/v3'
- SEARCH_KEYS =
%w(label type state requester owner mywork id includedone)
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(token, ssl = false) ⇒ Tracker
Returns a new instance of Tracker.
16
17
18
19
|
# File 'lib/pickler/tracker.rb', line 16
def initialize(token, ssl = false)
@token = token
@ssl = ssl
end
|
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
14
15
16
|
# File 'lib/pickler/tracker.rb', line 14
def token
@token
end
|
Instance Method Details
#get_xml(path) ⇒ Object
61
62
63
|
# File 'lib/pickler/tracker.rb', line 61
def get_xml(path)
request_xml(:get, path)
end
|
#http ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/pickler/tracker.rb', line 25
def http
unless defined?(@http)
if ssl?
require 'net/https'
@http = Net::HTTP.new(ADDRESS, Net::HTTP.https_default_port)
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@http.use_ssl = true
else
require 'net/http'
@http = Net::HTTP.new(ADDRESS)
end
end
@http
end
|
#project(id) ⇒ Object
65
66
67
|
# File 'lib/pickler/tracker.rb', line 65
def project(id)
Project.new(self, lambda { get_xml("/projects/#{id}")["project"] }, id)
end
|
#request(method, path, *args) ⇒ Object
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/pickler/tracker.rb', line 40
def request(method, path, *args)
= {
"X-TrackerToken" => @token,
"Accept" => "application/xml",
"Content-type" => "application/xml"
}
http klass = Net::HTTP.const_get(method.to_s.capitalize)
http.request(klass.new("#{BASE_PATH}#{path}", ), *args)
end
|
#request_xml(method, path, *args) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/pickler/tracker.rb', line 51
def request_xml(method, path, *args)
response = request(method,path,*args)
raise response.inspect if response["Content-type"].split(/; */).first != "application/xml"
hash = Crack::XML.parse(response.body)
if hash["message"] && (response.code.to_i >= 400 || hash["success"] == "false")
raise Error, hash["message"], caller
end
hash
end
|
#ssl? ⇒ Boolean
21
22
23
|
# File 'lib/pickler/tracker.rb', line 21
def ssl?
@ssl
end
|