Class: Pickler::Tracker

Inherits:
Object
  • 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/v2'
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.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pickler/tracker.rb', line 15

def initialize(token, ssl = false)
  require 'active_support'
  # Use nokogiri when avaiable
  begin
    require 'nokogiri'
    ActiveSupport::XmlMini.backend = 'Nokogiri'
  rescue MissingSourceFile
  end
  @token = token
  @ssl = ssl
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



13
14
15
# File 'lib/pickler/tracker.rb', line 13

def token
  @token
end

Instance Method Details

#get_xml(path) ⇒ Object



67
68
69
# File 'lib/pickler/tracker.rb', line 67

def get_xml(path)
  request_xml(:get, path)
end

#httpObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/pickler/tracker.rb', line 31

def http
  unless @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



71
72
73
# File 'lib/pickler/tracker.rb', line 71

def project(id)
  Project.new(self,get_xml("/projects/#{id}")["project"])
end

#request(method, path, *args) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/pickler/tracker.rb', line 46

def request(method, path, *args)
  headers = {
    "X-TrackerToken" => @token,
    "Accept"         => "application/xml",
    "Content-type"   => "application/xml"
  }
  http # trigger require of 'net/http'
  klass = Net::HTTP.const_get(method.to_s.capitalize)
  http.request(klass.new("#{BASE_PATH}#{path}", headers), *args)
end

#request_xml(method, path, *args) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/pickler/tracker.rb', line 57

def request_xml(method, path, *args)
  response = request(method,path,*args)
  raise response.inspect if response["Content-type"].split(/; */).first != "application/xml"
  hash = Hash.from_xml(response.body)
  if hash["message"] && (response.code.to_i >= 400 || hash["success"] == "false")
    raise Error, hash["message"], caller
  end
  hash
end

#ssl?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/pickler/tracker.rb', line 27

def ssl?
  @ssl
end