Permalink
Browse files

apparently I forgot to commit. for a while

  • Loading branch information...
1 parent 27c1ee4 commit 5caf4990379ce02964ad49d2ab03660dc2b2f4bf @josephholsten committed Jan 27, 2011
View
@@ -0,0 +1,7 @@
+require "rake/testtask"
+Rake::TestTask.new do |test|
+ test.test_files = Dir['test/**/*_test.rb']
+ test.verbose = true
+end
+
+task :default => :test
View
@@ -13,12 +13,12 @@ $:.unshift lib_path unless $:.include? lib_path
require 'rest_client'
require 'nokogiri'
-require 'active_support/time'
-require 'active_support/core_ext/object/returning'
require 'active_support/core_ext/hash/slice'
-require 'hash_with_append'
+require 'streamy'
-Date::DATE_FORMATS[:long_sans_year] = "%B %e"
+# Replace These
+PIVOTAL_TOKEN = '00000000000000000000000000000000'
+GITHUB_TOKEN = {:login => 'jappleseed', :token => '00000000000000000000000000000000'}
class Projects < Thor
def initialize(*args)
@@ -27,46 +27,57 @@ class Projects < Thor
end
desc "tracker", "get tracker data"
def tracker
- acts = for_subj("Joseph Holsten")
- puts render(acts)
+ user = PivotalTracker::Service.new(PIVOTAL_TOKEN).
+ project('30500').
+ user("Joseph Holsten")
+ puts render(user.activities)
end
+ desc 'github', "get github commits"
+ def github
+ cmts = cmts_for_author "Joseph Anthony Pasquale Holsten"
+ puts render_github(cmts)
+ end
+
+
no_tasks do
- def req(uri)
- token = 'dc5a8bb8ea76ac8363eb80fbf5ae4c42'
- response = RestClient.get uri, 'X-TrackerToken' => token
- Nokogiri::XML(response.body)
- end
- def activities
- project_id = '30500'
- uri = "http://www.pivotaltracker.com/services/v3/projects/#{project_id}/activities?limit=100"
+ def cmts_for_author(author)
+ uri = 'https://github.com/api/v2/xml/commits/list/mobicentric/mobicentric/master'
+ resp = RestClient.post uri, GITHUB_TOKEN
+ commits = Nokogiri::XML(resp.body).search('/commits/commit')
+ cmts = {}
+ commits.each do |commit|
+ next unless commit.at('author name').text == author
- doc = req uri
- activities = doc.search('/activities/activity')
+ time = Time.parse(commit.at('authored-date').text)
+ date = time.to_date
+ cmt = {
+ :author => commit.at('author name').text,
+ :url => commit.at('url').text,
+ :time => time.to_s(:time),
+ :desc => commit.at('message').text.lines.first.strip
+ }
+ cmts[date] ||= []
+ cmts[date].unshift(cmt)
+ end
+ cmts
end
- def for_subj(subj)
- returning({}) do |acts|
- activities.each do |a|
- next unless (author = a.at('author').text) == subj
- date, act = make_act(a, subj)
- acts[date] ||= []
- acts[date].unshift(act)
+ def render_github(cmts)
+ out = StringIO.new
+ cmts.keys.sort.each do |day|
+ out.puts day.to_s(:long_sans_year)
+ commits = cmts[day].sort_by{|s| s[:time] }
+ out.puts "\nCommits"
+ commits.each do |s|
+ out.puts "#{s[:time]} <a href=\"#{s[:url]}\">#{s[:desc]}</a>"
end
+ out.puts "\n\n"
end
+ out.rewind
+ out.read
end
- def make_act(activity, subj)
- time = Time.parse(activity.at('occurred_at').text)
- url = activity.at('stories story url').text
- @stories[url] ||= req(url).at('story')
- act = {
- :desc => activity.at('description').text.gsub(/^#{subj} /,''),
- :author => activity.at('author').text,
- :time => time.to_s(:time),
- :url => @stories[url].at('url').text,
- :name => @stories[url].at('name').text
- }
- [time.to_date, act]
- end
+
+
def render(activities)
out = StringIO.new
activities.keys.sort.each do |day|
View
@@ -0,0 +1 @@
+require 'streamy/pivotal_tracker'
@@ -0,0 +1,2 @@
+require 'streamy/campfire/room'
+require 'streamy/campfire/service'
@@ -0,0 +1,22 @@
+require 'rest_client'
+require 'nokogiri'
+require 'active_support/core_ext/object/returning'
+require 'active_support/core_ext/hash/keys'
+
+module Campfire
+ class Room
+ attr_accessor :service, :id
+ # path = '/room/#{id}/transcript.xml'
+ def initialize(id, service)
+ @id = id
+ @service = service
+ end
+ def uri
+ @service.uri.merge "/room/#{id}"
+ end
+
+ def resource
+ RestClient.get(uri.to_s).body
+ end
+ end
+end
@@ -0,0 +1,53 @@
+require 'rest_client'
+require 'nokogiri'
+require 'active_support/core_ext/object/returning'
+require 'streamy/campfire/room'
+
+module Campfire
+ class Service
+ attr_accessor :token, :subdomain, :secure
+ # takes a hash for :token, :subdomain, and :secure
+ # :token should have the API token for your account
+ # :subdomain should be the subdomain for the campfire service
+ # :secure should be set to true if the campfire service uses https
+ def initialize(token, subdomain, secure = false)
+ @token = token
+ @subdomain = subdomain
+ @secure = secure
+ end
+ def secure?
+ @secure
+ end
+ def uri
+ scheme = @secure ? 'https' : 'http'
+ URI::Generic.build :scheme => scheme,
+ :host => @subdomain + '.campfirenow.com',
+ :userinfo => @token
+ end
+ def resource
+ RestClient.get(uri.to_s).body
+ end
+ def rooms
+ Rooms.new(self)
+ end
+ end
+
+ class Rooms
+ attr_accessor :service
+ def initialize(service)
+ @service = service
+ end
+ def uri
+ @service.uri.merge '/rooms'
+ end
+ def resource
+ RestClient.get(uri.to_s).body
+ end
+ def doc
+ Nokogiri::XML(resource)
+ end
+ def room_ids
+ doc.search('/rooms/room/id').map{|id| id.text.to_i}
+ end
+ end
+end
@@ -0,0 +1,78 @@
+require 'rest_client'
+require 'nokogiri'
+require 'active_support/core_ext/object/returning'
+require 'active_support/time'
+require 'hash_with_append'
+
+Date::DATE_FORMATS[:long_sans_year] = "%B %e"
+
+module PivotalTracker
+ class Service
+ attr_accessor :token
+ def initialize(token)
+ @token = token
+ end
+ def req(uri)
+ response = RestClient.get uri, 'X-TrackerToken' => @token
+ Nokogiri::XML(response.body)
+ end
+ def project(id)
+ Project.new(id, self)
+ end
+ end
+ class Project
+ attr_accessor :project, :svc
+ def initialize(project, svc)
+ @project = project
+ @svc = svc
+ end
+ def activity_doc
+ uri = "http://www.pivotaltracker.com/services/v3/projects/#{@project}/activities?limit=100"
+ @svc.req uri
+ end
+ def activities
+ activity_doc.search('/activities/activity')
+ end
+ def user(name)
+ User.new(name, self)
+ end
+ end
+ class User
+ attr_accessor :user, :svc, :project
+ def initialize(user,project)
+ @user = user
+ @svc = project.svc
+ @project = project
+ @stories = {}
+ end
+ def activities
+ returning({}) do |acts|
+ @project.activities.each do |a|
+ next unless (a.at('author').text) == user
+ date, act = self.make_act(a, user)
+ acts[date] ||= []
+ acts[date].unshift(act)
+ end
+ end
+ end
+
+ def make_act(activity, subj)
+ time = Time.parse(activity.at('occurred_at').text)
+ url = activity.at('stories story url').text
+ @stories[url] ||= @svc.req(url).at('story')
+ act = {
+ :desc => activity.at('description').text.gsub(/^#{subj} /,''),
+ :author => activity.at('author').text,
+ :time => time.to_s(:time),
+ :url => @stories[url].at('url').text,
+ :name => @stories[url].at('name').text
+ }
+ [time.to_date, act]
+ end
+ end
+ class Activity
+ def self.parse(xml)
+ raise "write me"
+ end
+ end
+end
@@ -0,0 +1,50 @@
+#!/usr/bin/env ruby
+$:.unshift File.expand_path('..',__FILE__)
+require 'test_helper'
+require 'test/unit'
+require 'streamy/campfire'
+
+class CampfireRoomTest < Test::Unit::TestCase
+ def setup
+ @service = Campfire::Service.new 'foo', 'bar', true
+ @room = Campfire::Room.new(20356, @service)
+ end
+
+ def test_should_set_id
+ assert_equal 20356, @room.id
+ end
+
+ def test_should_set_service
+ assert_equal @service, @room.service
+ end
+
+ def test_should_get_uri
+ assert_equal 'https://foo@bar.campfirenow.com/room/20356', @room.uri.to_s
+ end
+end
+
+class CampfireRoomLiveTest < Test::Unit::TestCase
+ def setup
+ @service = Campfire::Service.new '6538bc6e0104c939699458c1e30a552d1cb1a779', 'josephholsten'
+ @room = Campfire::Room.new(20356, @service)
+ end
+ def test_should_get_resource
+ expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<room>\n <created-at type=\"datetime\">2006-04-28T12:43:31Z</created-at>\n <id type=\"integer\">20356</id>\n <membership-limit type=\"integer\">4</membership-limit>\n <name>Private</name>\n <topic nil=\"true\"></topic>\n <updated-at type=\"datetime\">2007-02-10T23:00:35Z</updated-at>\n <open-to-guests type=\"boolean\">true</open-to-guests>\n <full type=\"boolean\">false</full>\n <active-token-value>cb812</active-token-value>\n <users type=\"array\"/>\n</room>\n"
+ assert_equal expected, @room.resource
+end
+end
+
+
+<?xml version="1.0" encoding="UTF-8"?>
+<room>
+ <created-at type="datetime">2006-04-28T12:43:31Z</created-at>
+ <id type="integer">20356</id>
+ <membership-limit type="integer">4</membership-limit>
+ <name>Private</name>
+ <topic nil="true"></topic>
+ <updated-at type="datetime">2007-02-10T23:00:35Z</updated-at>
+ <open-to-guests type="boolean">true</open-to-guests>
+ <full type="boolean">false</full>
+ <active-token-value>cb812</active-token-value>
+ <users type="array"/>
+</room>
@@ -0,0 +1,26 @@
+$:.unshift File.expand_path('..',__FILE__)
+require 'test_helper'
+require 'test/unit'
+require 'streamy/campfire'
+
+class CampfireRoomsLiveTest < Test::Unit::TestCase
+ def setup
+ @service = Campfire::Service.new '6538bc6e0104c939699458c1e30a552d1cb1a779', 'josephholsten'
+ end
+ def test_should_get_uri
+ uri = @service.rooms.uri.to_s
+ # resp = RestClient.get uri
+ # expected = ''
+ # assert_equal expected, resp.body # @service.resource
+ assert_equal 'http://6538bc6e0104c939699458c1e30a552d1cb1a779@josephholsten.campfirenow.com/rooms', uri
+ end
+
+ def test_should_get_doc
+ doc = @service.rooms.doc
+ assert_equal 'rooms', doc.root.name
+ end
+ def test_should_get_room_ids
+ ids = @service.rooms.room_ids
+ assert_equal [20356, 255613], ids
+ end
+end
Oops, something went wrong.

0 comments on commit 5caf499

Please sign in to comment.