Project

General

Profile

Actions

Rest api with ruby » History » Revision 4

« Previous | Revision 4/15 (diff) | Next »
Eric Davis, 2010-10-21 06:26
Added a note about the RedmineClient gem


Using the REST API with Ruby

Redmine REST API follows the Rails's RESTful conventions, so using it with ActiveResource is pretty straightforward.

ActiveResource

Here is a simple ruby script that demonstrates how to use the Redmine REST API:

require 'rubygems'
require 'active_resource'

# Issue model on the client side
class Issue < ActiveResource::Base
  self.site = 'http://redmine.server/'
  self.user = 'foo'
  self.password = 'bar'
end

# Retrieving issues
issues = Issue.find(:all)
puts issues.first.subject

# Retrieving an issue
issue = Issue.find(1)
puts issue.description
puts issue.author.name

# Creating an issue
issue = Issue.new(
  :subject => 'REST API',
  :assigned_to_id => 1,
  :project_id => 1,
  :custom_field_values => {'2' => 'Fixed'}
)
if issue.save
  puts issue.id
else
  puts issue.errors.full_messages
end

# Updating an issue
issue = Issue.find(1)
issue.subject = 'REST API'
issue.save

# Deleting an issue
issue = Issue.find(1)
issue.destroy

RedmineClient gem

Eric Davis has created a gem that has ActiveResource wrappers for Redmine's API. See his post Redmine Client - Access the Redmine API in Ruby for more details and an example.

Updated by Eric Davis about 14 years ago · 4 revisions