redminer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'json'
7
+
8
+ # Add dependencies to develop your gem here.
9
+ # Include everything needed to run rake, tests, features, etc.
10
+ group :development do
11
+ gem "shoulda", ">= 0"
12
+ gem "rdoc", "~> 3.12"
13
+ gem "bundler", "~> 1.0.0"
14
+ gem "jeweler", "~> 1.8.3"
15
+ gem "rcov", ">= 0"
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 insoul
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = redminer
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to redminer
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 insoul. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "redminer"
18
+ gem.homepage = "http://github.com/insoul/redminer"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Redmine rest api client}
21
+ gem.description = %Q{Redmine rest api client}
22
+ gem.email = "insoul@thinkreals.com"
23
+ gem.authors = ["insoul"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "redminer #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/lib/redminer.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'yaml'
5
+ require 'redminer/base'
6
+ require 'redminer/issue'
7
+
@@ -0,0 +1,46 @@
1
+ module Redminer
2
+ class Base
3
+ attr_accessor :server, :access_key
4
+
5
+ def initialize(host, port, access_key)
6
+ @server = Net::HTTP.new(host, port)
7
+ @access_key = access_key
8
+ end
9
+
10
+ def request(path, params = nil, obj = Net::HTTP::Get)
11
+ req = obj.new(path)
12
+ req.add_field('X-Redmine-API-Key', access_key)
13
+ req.body = hash_to_querystring(params) if not params.nil? and not params.empty?
14
+ begin
15
+ if block_given?
16
+ yield server.request(req)
17
+ else
18
+ server.request(req).body
19
+ end
20
+ rescue Timeout::Error
21
+ raise "#{host}:#{port} does not respond"
22
+ end
23
+ end
24
+
25
+ def hash_to_querystring(hash)
26
+ hash.keys.inject('') do |query_string, key|
27
+ value = case hash[key]
28
+ when Hash then hash[key].to_json
29
+ else hash[key].to_s
30
+ end
31
+ query_string << '&' unless key == hash.keys.first
32
+ query_string << "#{URI.encode(key.to_s)}=#{URI.encode(value)}"
33
+ end
34
+ end
35
+
36
+ def get(path, params = nil, &block); request(path, params, &block) end
37
+ def put(path, params = nil, &block); request(path, params, Net::HTTP::Put, &block) end
38
+ def post(path, params = nil, &block); request(path, params, Net::HTTP::Post, &block) end
39
+ def delete(path, params = nil, &block); request(path, params, Net::HTTP::Delete, &block) end
40
+
41
+ def issue(issue_key = nil)
42
+ Redminer::Issue.new(self, issue_key)
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,56 @@
1
+ module Redminer
2
+ class Issue < Redminer::Base
3
+ attr_reader :base, :id
4
+ attr_accessor :author, :project
5
+ attr_accessor :tracker, :status, :priority, :category
6
+ attr_accessor :subject, :description
7
+ attr_accessor :start_date, :due_date
8
+ attr_accessor :created_on, :updated_on
9
+
10
+ def initialize(base, id = nil)
11
+ @base = base
12
+ unless id.nil?
13
+ @id = id
14
+ retrieve
15
+ end
16
+ end
17
+
18
+ def retrieve
19
+ response = base.get("/issues/#{id}.json")
20
+ raise "#{id} issue does not exists" if response.nil?
21
+ origin = JSON.parse(response)["issue"]
22
+ origin.each_pair { |k, v|
23
+ if respond_to?("#{k}=")
24
+ send("#{k}=", v)
25
+ end
26
+ }
27
+ self
28
+ end
29
+
30
+ def self.exists?(id)
31
+ (self.new(id) and true) rescue false
32
+ end
33
+
34
+ def sync
35
+ (@id.nil? ? create : update)
36
+ end
37
+
38
+ def craete
39
+ params = {
40
+ :subject => @subject,
41
+ :description => @description,
42
+ :project => @project
43
+ }
44
+ base.post("/issues.json", params)
45
+ end
46
+ def update(note = nil)
47
+ params = {
48
+ :subject => @subject,
49
+ :description => @description,
50
+ :project => @project
51
+ }
52
+ params.merge!(:notes => note) unless note.nil?
53
+ base.put("/issues/#{id}.json", params)
54
+ end
55
+ end
56
+ end
data/redminer.gemspec ADDED
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "redminer"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["insoul"]
12
+ s.date = "2012-04-05"
13
+ s.description = "Redmine rest api client"
14
+ s.email = "insoul@thinkreals.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/redminer.rb",
27
+ "lib/redminer/base.rb",
28
+ "lib/redminer/issue.rb",
29
+ "redminer.gemspec",
30
+ "test/helper.rb",
31
+ "test/test_redminer.rb"
32
+ ]
33
+ s.homepage = "http://github.com/insoul/redminer"
34
+ s.licenses = ["MIT"]
35
+ s.require_paths = ["lib"]
36
+ s.rubygems_version = "1.8.17"
37
+ s.summary = "Redmine rest api client"
38
+
39
+ if s.respond_to? :specification_version then
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
43
+ s.add_runtime_dependency(%q<json>, [">= 0"])
44
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
45
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
46
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
48
+ s.add_development_dependency(%q<rcov>, [">= 0"])
49
+ else
50
+ s.add_dependency(%q<json>, [">= 0"])
51
+ s.add_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
53
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
55
+ s.add_dependency(%q<rcov>, [">= 0"])
56
+ end
57
+ else
58
+ s.add_dependency(%q<json>, [">= 0"])
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
63
+ s.add_dependency(%q<rcov>, [">= 0"])
64
+ end
65
+ end
66
+
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'redminer'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestRedminer < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redminer
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - insoul
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-05 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ name: json
31
+ prerelease: false
32
+ type: :runtime
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ hash: 3
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ name: shoulda
45
+ prerelease: false
46
+ type: :development
47
+ requirement: *id002
48
+ - !ruby/object:Gem::Dependency
49
+ version_requirements: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ hash: 31
55
+ segments:
56
+ - 3
57
+ - 12
58
+ version: "3.12"
59
+ name: rdoc
60
+ prerelease: false
61
+ type: :development
62
+ requirement: *id003
63
+ - !ruby/object:Gem::Dependency
64
+ version_requirements: &id004 !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ hash: 23
70
+ segments:
71
+ - 1
72
+ - 0
73
+ - 0
74
+ version: 1.0.0
75
+ name: bundler
76
+ prerelease: false
77
+ type: :development
78
+ requirement: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ version_requirements: &id005 !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ hash: 49
86
+ segments:
87
+ - 1
88
+ - 8
89
+ - 3
90
+ version: 1.8.3
91
+ name: jeweler
92
+ prerelease: false
93
+ type: :development
94
+ requirement: *id005
95
+ - !ruby/object:Gem::Dependency
96
+ version_requirements: &id006 !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ hash: 3
102
+ segments:
103
+ - 0
104
+ version: "0"
105
+ name: rcov
106
+ prerelease: false
107
+ type: :development
108
+ requirement: *id006
109
+ description: Redmine rest api client
110
+ email: insoul@thinkreals.com
111
+ executables: []
112
+
113
+ extensions: []
114
+
115
+ extra_rdoc_files:
116
+ - LICENSE.txt
117
+ - README.rdoc
118
+ files:
119
+ - .document
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.rdoc
123
+ - Rakefile
124
+ - VERSION
125
+ - lib/redminer.rb
126
+ - lib/redminer/base.rb
127
+ - lib/redminer/issue.rb
128
+ - redminer.gemspec
129
+ - test/helper.rb
130
+ - test/test_redminer.rb
131
+ homepage: http://github.com/insoul/redminer
132
+ licenses:
133
+ - MIT
134
+ post_install_message:
135
+ rdoc_options: []
136
+
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 3
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ hash: 3
154
+ segments:
155
+ - 0
156
+ version: "0"
157
+ requirements: []
158
+
159
+ rubyforge_project:
160
+ rubygems_version: 1.8.17
161
+ signing_key:
162
+ specification_version: 3
163
+ summary: Redmine rest api client
164
+ test_files: []
165
+