Skip to content
Browse files

Removed errant puts.

       Fixed bug with undefined local variable redmine_url.
Added support for authentication.

[git-p4: depot-paths = "//src/omnifocus-redmine/dev/": change = 6167]
  • Loading branch information...
1 parent fb42b4b commit 8bbb2ad4f8cded22277430dd9a4f3882bb6114de @thagomizer thagomizer committed Feb 15, 2011
Showing with 47 additions and 15 deletions.
  1. +5 −0 History.txt
  2. +18 −7 README.txt
  3. +24 −8 lib/omnifocus/redmine.rb
View
5 History.txt
@@ -1,3 +1,8 @@
+=== 1.2.0 / 2011-02-15
+* Fixed a bug with a missing variable
+* Removed an errant puts
+* Added support for authentication
+
=== 1.1.0 / 2011-02-8
* Added ability to run multiple queries.
View
25 README.txt
@@ -6,21 +6,32 @@
Plugin for the omnifocus gem to provide synchronization with Redmine Issues.
+This plugin uses the Redmine REST API. It must be enabled by an adminstrator
+for the plugin to work.
+
The first time this runs it creates a yaml file in your home directory for
-the redmine url and username.
+the configuration data.
+
+ * redmine_url is required. This is the base url for the redmine repository.
+
+ * user_id is required. To find your user id login and go to the my account
+ page. Your user_id is the number at the end of the url for my account.
-The queries config is optional. If it is not included omnifocus-redmine will
-pull all open bugs assigned to the specified user.
+ * username is optional. It is used if the redmine server requires
+ authentication.
-To use a custom query or multiple queries you must include a queries parameter
-in your config.
+ * password is optional. It is used if the redmine server requires
+ authentication.
-The queries config is an array of strings. These strings will be appended onto a
-query of the form: http://your-redmine-url/issues.xml?assigned_to_id=user-id?.
+ * queries is optional. It is used for custom queries or multiple queries.
+ The queries config is an array of strings. The strings will be appended
+ to a query of the form: "http://redmine_url/issues.xml?assigned_to_id=user_id".
Example:
:user_id: 20
:redmine_url: http://redmine/
+:username: me
+:password: 1234
:queries: ["status_id=1", "status_id=2"]
== FEATURES/PROBLEMS:
View
32 lib/omnifocus/redmine.rb
@@ -1,14 +1,16 @@
module OmniFocus::Redmine
- VERSION = '1.1.0'
+ VERSION = '1.2.0'
def load_or_create_redmine_config
path = File.expand_path "~/.omnifocus-redmine.yml"
config = YAML.load(File.read(path)) rescue nil
unless config then
config = {
- :user => "Admin User",
+ :user_id => "20",
:redmine_url => "http://redmine",
+ :username => "UserName",
+ :password => "Password"
}
File.open(path, "w") { |f|
@@ -24,22 +26,36 @@ def load_or_create_redmine_config
def populate_redmine_tasks
config = load_or_create_redmine_config
redmine_url = config[:redmine_url]
- user_id = config[:user_id]
+ user_id = config[:user_id]
+ username = config[:username]
+ password = config[:password]
+
+ # Authenticate if the user name and password are defined
+ if username and password then
+ mechanize.basic_auth(username, password)
+ end
+
default_query = "#{redmine_url}/issues.xml?assigned_to_id=#{user_id}"
unless config[:queries]
- process_query_results default_query
+ process_query_results(default_query, redmine_url)
else
queries = config[:queries]
queries.each do |q|
- process_query_results "#{default_query}&#{q}"
+ process_query_results("#{default_query}&#{q}", redmine_url)
end
end
end
- def process_query_results(query)
- puts query
- mechanize.get(query)
+ def process_query_results(query, redmine_url)
+ begin
+ mechanize.get(query)
+ rescue Mechanize::ResponseCodeError => e
+ if e.response_code == "401" then
+ abort "Unauthorized. Check username and password in .omnifocus-redmine"
+ end
+ end
+
details = Nokogiri.parse(mechanize.current_page.body)
issues = details.root.xpath('//issue')

0 comments on commit 8bbb2ad

Please sign in to comment.
Something went wrong with that request. Please try again.