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
# File 'lib/pickler/tracker.rb', line 15

def initialize(token, ssl = false)
  require 'active_support'
  @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



61
62
63
# File 'lib/pickler/tracker.rb', line 61

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

#httpObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pickler/tracker.rb', line 25

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



65
66
67
# File 'lib/pickler/tracker.rb', line 65

def project(id)
  Project.new(self,get_xml("/projects/#{id}")["project"])
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)
  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



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 = 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)


21
22
23
# File 'lib/pickler/tracker.rb', line 21

def ssl?
  @ssl
end