Skip to content

Instantly share code, notes, and snippets.

@tomohiro
Created June 24, 2011 05:53
Show Gist options
  • Save tomohiro/1044296 to your computer and use it in GitHub Desktop.
Save tomohiro/1044296 to your computer and use it in GitHub Desktop.
Redmine REST API sample
#!/usr/bin/env ruby
require 'rubygems'
require 'active_resource'
class Issue < ActiveResource::Base
self.site = 'http://localhost'
self.user = 'user'
self.password = 'password'
end
Issue.
find(:all, :params => { :project_id => 29, :query_id => 27}).
sort { |a, b| a.fixed_version.id <=> b.fixed_version.id }.
each { |i| puts "[##{i.id}] #{i.fixed_version.name} #{i.subject}" }
require 'rubygems'
require 'active_resource'
# IRC Bot Framework "Citrus" plugin
class Redmine < Citrus::Plugin
def on_privmsg(prefix, channel, message)
case message
when /#(\d+)/
notice(channel, get_issue($1))
end
end
private
class RestAPI < ActiveResource::Base
self.site = 'http://redmine.example.com'
self.user = 'user'
self.password = 'password'
end
class Project < RestAPI; end
class Issue < RestAPI; end
def get_issue id
issue = Issue.find(id)
"[#{Project.find(issue.project.id).name}] [^C4#{issue.status.name}^C] ^C5#{issue.subject}^C http://redmine.example.com/issues/#{id}"
end
end
#!/usr/bin/env ruby
require 'rubygems'
require 'active_resource'
class TimeEntry < ActiveResource::Base
self.site = 'http://localhost'
self.user = 'user'
self.password = 'password'
end
TimeEntry.
find(:all).
sort { |a, b| b.spent_on + b.user.id <=> a.spent_on + a.user.id }.
each { |e| puts "#{e.spent_on} #{e.user.name} #{e.hours}h #{e.activity.name}" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment