Class: GitHooks::Notifier::TrackerClient

Inherits:
Object
  • Object
show all
Defined in:
lib/git_hooks/notifier/tracker_client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracker_options) ⇒ TrackerClient

Returns a new instance of TrackerClient.



16
17
18
19
20
21
# File 'lib/git_hooks/notifier/tracker_client.rb', line 16

def initialize(tracker_options)
  @curl = Curl::Easy.new("http://www.pivotaltracker.com/services/v3/source_commits") do |curl| 
    curl.headers["X-TrackerToken"] = tracker_options[:api_key]
    curl.headers["Content-type"] = "application/xml"
  end
end

Instance Attribute Details

#curlObject (readonly)

Returns the value of attribute curl.



7
8
9
# File 'lib/git_hooks/notifier/tracker_client.rb', line 7

def curl
  @curl
end

Class Method Details

.deliver(options) ⇒ Object



9
10
11
12
13
14
# File 'lib/git_hooks/notifier/tracker_client.rb', line 9

def self.deliver(options)
  commits = options.delete(:commits)

  client_instance = new(options)
  client_instance.deliver(commits)
end

Instance Method Details

#create_payloads(commits, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/git_hooks/notifier/tracker_client.rb', line 29

def create_payloads(commits, &block)
  payloads = commits.map do |commit|
    <<-XML
<source_commit>
<message>#{commit.message}</message>
<author>#{commit.author.name}</author>
<commit_id>#{commit.id}</commit_id>
</source_commit>
    XML
  end
  
  payloads.each(&block)
end

#deliver(commits) ⇒ Object



23
24
25
26
27
# File 'lib/git_hooks/notifier/tracker_client.rb', line 23

def deliver(commits)
  create_payloads(commits) do |payload|
    curl.http_post(payload)
  end
end