-
-
Save anonymous/43fee9c370274bb07173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# require 'byebug' | |
require 'httparty' | |
class Redmine | |
include HTTParty | |
base_uri '192.168.1.150' | |
end # Redmine class | |
class Project < Redmine | |
RMUSER='username' | |
RMPASS='password' | |
def create(name) | |
# create identifier from name | |
# Length between 1 and 100 characters. Only lower case letters (a-z), | |
# numbers, dashes and underscores are allowed, must start with a lower case letter. | |
# Once saved, the identifier cannot be changed. | |
identifier=name.downcase.gsub!(/\W+/, '_') # replace non-word chars with underscore | |
xml="<project><name>#{name}</name><identifier>#{identifier}</identifier></project>" | |
Redmine.post( | |
'/projects.xml', | |
:basic_auth => { | |
:username => RMUSER, | |
:password => RMPASS }, | |
:body => xml, | |
:headers => {'Content-type' => 'text/xml'} | |
) | |
end # create method | |
end # Project class | |
Redmine::Project.create("TestProject") | |
# This fails with error(s): | |
# ./Redmine.rb:39: warning: toplevel constant Project referenced by Redmine::Project | |
# ./Redmine.rb:39:in `<main>': undefined method `create' for Project:Class (NoMethodError) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment