Class: TyphoeusTrackerConnector

Inherits:
Object
  • Object
show all
Defined in:
lib/typhoeus_tracker_connector.rb

Instance Method Summary collapse

Constructor Details

#initialize(project_ids = [], tracker_token) ⇒ TyphoeusTrackerConnector

Returns a new instance of TyphoeusTrackerConnector.



6
7
8
9
10
# File 'lib/typhoeus_tracker_connector.rb', line 6

def initialize(project_ids = [], tracker_token)
  @hydra = Typhoeus::Hydra.new
  @project_ids = project_ids
  @token = tracker_token
end

Instance Method Details

#details_for(stories) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/typhoeus_tracker_connector.rb', line 12

def details_for(stories)
  stories_qs = stories.join(',')
  requests = []
  projects.each do |id, name|
    request = Typhoeus::Request.new(
        "http://www.pivotaltracker.com/services/v3/projects/#{id}/stories?filter=id:#{stories_qs}&includedone:true",
        headers: {'X-TrackerToken' => @token})

    request.on_complete do |response|
      doc = Nokogiri::XML(response.body)

      {}.tap do |h|
        doc.xpath('//stories/story').map do |e|
          h[e.xpath('id').text] = [name, e.xpath('current_state').text.to_sym]
        end
      end
    end

    requests << request
    @hydra.queue request
  end
  @hydra.run

  requests.inject({}) { |acc, r| acc.merge(r.handled_response) }
end