<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,6 @@
 unfuddle:
   subdomain: something
+  use_ssl: false
   user: yourusername
   password: yourpassword
   people:
@@ -7,5 +8,5 @@ unfuddle:
     
 repositories:
   github-unfuddle:
-    unfuddle-project-id: 1111
+    unfuddle_project_id: 1111
     
\ No newline at end of file</diff>
      <filename>config.example</filename>
    </modified>
    <modified>
      <diff>@@ -2,33 +2,78 @@ require 'rubygems'
 require 'sinatra'
 require 'json'
 require 'yaml'
+require 'net/http'
+
+CONFIG = YAML.load_file(&quot;config.yml&quot;)
 
 post '/' do
-  puts &quot;\n\n#{params[:payload]}\n\n&quot;
   push = JSON.parse(params[:payload])
   build_unfuddle_xml_from(push)
 end
 
 def build_unfuddle_xml_from(push)
-  puts push.inspect
-  config = YAML.load_file(&quot;config.yml&quot;)  
-  repository = push[&quot;repository&quot;]
-  commits = push[&quot;commits&quot;]
-  output = &quot;&quot;
+  @repository = push[&quot;repository&quot;]
+  @commits = push[&quot;commits&quot;]
+  
+  raise &quot;Must specify Unfuddle subdomain, user, and password.&quot; unless CONFIG[&quot;unfuddle&quot;][&quot;subdomain&quot;] &amp;&amp; CONFIG[&quot;unfuddle&quot;][&quot;user&quot;] &amp;&amp; CONFIG[&quot;unfuddle&quot;][&quot;password&quot;]
+  raise &quot;Could not map from GitHub project name to Unfuddle Project ID.&quot; unless unfuddle_project_id
+  
+  successes = []
   
-  commits.each do |id, commit|
+  @commits.each do |id, commit|
     timestamp = Time.parse(commit['timestamp'])
     xml = &lt;&lt;-XML
     &lt;changeset&gt;
-      #{&quot;&lt;author-id type=\&quot;integer\&quot;&gt;#{config[&quot;unfuddle&quot;][&quot;people&quot;][commit[&quot;author&quot;][&quot;email&quot;]]}&lt;/author-id&gt;&quot; if config[&quot;unfuddle&quot;][&quot;people&quot;][commit[&quot;author&quot;][&quot;email&quot;]]}
+      #{&quot;&lt;author-id type=\&quot;integer\&quot;&gt;#{unfuddle_author_id(commit)}&lt;/author-id&gt;&quot; if unfuddle_author_id(commit)}
       &lt;message&gt;#{commit[&quot;message&quot;]}
       
-[More Detail](#{commit[&quot;url&quot;]})&lt;/message&gt;
+Details: #{commit[&quot;url&quot;]}&lt;/message&gt;
       &lt;revision type=&quot;integer&quot;&gt;#{timestamp.strftime(&quot;%y%m%d%H%M&quot;)}&lt;/revision&gt;
     &lt;/changeset&gt;
     XML
     
-    output &lt;&lt; xml
+    successes &lt;&lt; post_changeset_to_unfuddle(xml)
   end
-  output
+  
+  successes.inspect
+end
+
+def post_changeset_to_unfuddle(xml)
+  http = Net::HTTP.new(&quot;#{CONFIG[&quot;unfuddle&quot;][&quot;subdomain&quot;]}.unfuddle.com&quot;, CONFIG[&quot;unfuddle&quot;][&quot;use_ssl&quot;] ? 443 : 80)
+
+  # if using ssl, then set it up
+  if CONFIG[&quot;unfuddle&quot;][&quot;use_ssl&quot;]
+    http.use_ssl = true
+    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+  end
+  
+  begin
+    path = &quot;/api/v1/projects/#{unfuddle_project_id}/changesets.xml&quot;
+    puts path.inspect
+    request = Net::HTTP::Post.new(path, {'Content-type' =&gt; 'application/xml'})
+    request.basic_auth CONFIG[&quot;unfuddle&quot;][&quot;user&quot;], CONFIG[&quot;unfuddle&quot;][&quot;password&quot;]
+    request.body = xml
+
+    puts request.inspect
+    
+    response = http.request(request)
+    
+    if response.code == &quot;201&quot;
+      return response['Location']
+    else
+      puts response.body
+      return false
+    end
+  rescue =&gt; e
+    puts e.message
+    return false
+  end
+end
+
+def unfuddle_project_id
+  CONFIG[&quot;repositories&quot;][@repository[&quot;name&quot;]][&quot;unfuddle_project_id&quot;]
+end
+
+def unfuddle_author_id(commit)
+  CONFIG[&quot;unfuddle&quot;][&quot;people&quot;][commit[&quot;author&quot;][&quot;email&quot;]]
 end
\ No newline at end of file</diff>
      <filename>github_unfuddle.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>b521099adcd81bc8729e5984eeeaede3f687acdc</id>
    </parent>
  </parents>
  <author>
    <name>Michael Bleigh</name>
    <email>michael@intridea.com</email>
  </author>
  <url>http://github.com/mbleigh/github-unfuddle/commit/300afdbbef8bc50dafe2a1da510995246530dcac</url>
  <id>300afdbbef8bc50dafe2a1da510995246530dcac</id>
  <committed-date>2008-03-24T08:28:36-07:00</committed-date>
  <authored-date>2008-03-24T08:28:36-07:00</authored-date>
  <message>Resolves #1 - Basic skeleton is now working.</message>
  <tree>cc60601f69efb7dc6b5e58f6693b2fbdc9def716</tree>
  <committer>
    <name>Michael Bleigh</name>
    <email>michael@intridea.com</email>
  </committer>
</commit>
