To bypass the Passenger Redmine server and access the Redmine REST API, you can create a script that communicates directly with the Redmine application running on the server. Here's a step-by-step guide to creating a Ruby script that interacts with the Redmine REST API.
Prerequisites:
- Ensure that you have Ruby installed on your server.
- Install the
rest-clientandjsongems for making HTTP requests and handling JSON responses, respectively:
gem install rest-client json
Script:
Create a file named redmine_api.rb and paste the following code:
require 'rest-client'
require 'json'
# Your Redmine API URL (e.g., http://your-redmine-server.com/api)
api_url = "http://your-redmine-server.com/api"
# Your Redmine API key (obtain it from your Redmine account settings)
api_key = "your-api-key"
# Your Redmine API username (obtain it from your Redmine account settings)
api_username = "your-api-username"
# Function to make authenticated GET requests
def get_request(path)
request = RestClient::Request.new(
method: :get,
url: api_url + path,
headers: {
'Content-Type' => 'application/json',
'Authorization' => "Token token=#{api_key}"
}
)
request.execute
end
# Function to make authenticated POST requests
def post_request(path, params)
request = RestClient::Request.new(
method: :post,
url: api_url + path,
headers: {
'Content-Type' => 'application/json',
'Authorization' => "Token token=#{api_key}"
},
payload: params.to_json
)
request.execute
end
# Example usage: list projects
puts get_request("/projects.json").body
# Example usage: create a new issue
params = {
title: "New issue",
description: "This is a new issue created programmatically.",
project_id: 1
}
puts post_request("/issues.json", params).body
Replace your-api-key and your-api-username with your actual Redmine API key and username. Also, update the api_url variable with the URL of your Redmine API.
Running the script:
Execute the script using the following command:
ruby redmine_api.rb
This script demonstrates how to make authenticated GET and POST requests to the Redmine REST API. You can modify it according to your needs and use cases.
References: