howlingmine-client 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ === 0.1 / 2009-10-06
2
+
3
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,13 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ examples/issues_example.rb
6
+ howlingmine_client.tmproj
7
+ lib/howlingmine.rb
8
+ lib/howlingmine/client.rb
9
+ lib/howlingmine/config.rb
10
+ lib/howlingmine/issue.rb
11
+ redmine_test_files/database.yml
12
+ redmine_test_files/redmine.db
13
+ test/issue_test.rb
data/README.txt ADDED
@@ -0,0 +1,23 @@
1
+ Howling Mine Client
2
+ ====================
3
+
4
+ AR-esque library to interface with Howling Mine Server:
5
+
6
+ http://github.com/rubiojr/howlingmine-server
7
+
8
+ Code loosely based on hoptoad notifier by Thoughbot inc.
9
+ http://github.com/thoughtbot/hoptoad_notifier
10
+
11
+
12
+ INSTALLATION
13
+ ------------
14
+
15
+ Install the rubygem from http://gemcutter.org
16
+
17
+ Requires howlingmine-server redmine plugin 0.1
18
+
19
+ EXAMPLES
20
+ -------------
21
+ see examples/ dir
22
+
23
+
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/howlingmine.rb'
6
+
7
+ Hoe.spec 'howlingmine-client' do |p|
8
+ p.version = HowlingMine::VERSION
9
+ p.developer('Sergio Rubio', 'sergio@rubio.name')
10
+ p.summary = 'Client library for the Howling Mine Server'
11
+ p.description = 'Client library for the Howling Mine Server'
12
+ p.url = 'http://github.com/rubiojr/howlingmine-client'
13
+ p.test_globs = ['test/*_test.rb']
14
+ end
15
+
16
+ # vim: syntax=Ruby
17
+
18
+ task :restore_redmine_db do
19
+ FileUtils.cp 'redmine_test_files/redmine.db','/opt/redmine-0.8/db/redmine.db'
20
+ end
@@ -0,0 +1,38 @@
1
+ require "#{File.join(File.dirname(__FILE__),'../lib/howlingmine.rb')}"
2
+
3
+ HowlingMine::Config.host = 'redmine.local'
4
+ HowlingMine::Config.port = 80 # default
5
+ HowlingMine::Config.use_ssl = false # default
6
+ HowlingMine::Config.project = 'howlingmine'
7
+ HowlingMine::Config.tracker = 'Bug' # default
8
+ HowlingMine::Config.api_key = 'OPlv8xfQmmEy0x5yHMrX'
9
+
10
+ HowlingMine::Issue.all.each do |i|
11
+ puts "-" * 40
12
+ puts "Issue ID: #{i.id}"
13
+ puts "Subject: #{i.subject}"
14
+ puts "Created On: #{i.created_on}"
15
+ puts "Last update: #{i.updated_on}"
16
+ puts "Issue status: #{i.status}"
17
+ end
18
+
19
+ issue = HowlingMine::Issue.new
20
+ issue.subject = 'issue number one'
21
+ issue.description = 'oh my, first issue'
22
+ # if an issue with the same subject exist, the default behaviour
23
+ # is to update the journal creating another comment
24
+ issue.save
25
+
26
+ # Get redmine issue #1 and update the journal
27
+ issue = HowlingMine::Issue.get 1
28
+ if issue
29
+ issue.description = 'another journal entry' # adds a comment to the issue
30
+ issue.save
31
+ end
32
+
33
+ # Get the last issue and print the last update date
34
+ issue = HowlingMine::Issue.last
35
+ if issue
36
+ puts '-' * 40
37
+ puts "Issue ##{issue.id} updated on: #{issue.updated_on.strftime '%F %H:%M'}"
38
+ end
@@ -0,0 +1,139 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>currentDocument</key>
6
+ <string>test/issue_test.rb</string>
7
+ <key>documents</key>
8
+ <array>
9
+ <dict>
10
+ <key>expanded</key>
11
+ <true/>
12
+ <key>name</key>
13
+ <string>howlingmine_client</string>
14
+ <key>regexFolderFilter</key>
15
+ <string>!.*/(\.[^/]*|CVS|_darcs|_MTN|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
16
+ <key>sourceDirectory</key>
17
+ <string></string>
18
+ </dict>
19
+ </array>
20
+ <key>fileHierarchyDrawerWidth</key>
21
+ <integer>200</integer>
22
+ <key>metaData</key>
23
+ <dict>
24
+ <key>README.txt</key>
25
+ <dict>
26
+ <key>caret</key>
27
+ <dict>
28
+ <key>column</key>
29
+ <integer>0</integer>
30
+ <key>line</key>
31
+ <integer>9</integer>
32
+ </dict>
33
+ <key>firstVisibleColumn</key>
34
+ <integer>0</integer>
35
+ <key>firstVisibleLine</key>
36
+ <integer>0</integer>
37
+ </dict>
38
+ <key>Rakefile</key>
39
+ <dict>
40
+ <key>caret</key>
41
+ <dict>
42
+ <key>column</key>
43
+ <integer>0</integer>
44
+ <key>line</key>
45
+ <integer>20</integer>
46
+ </dict>
47
+ <key>firstVisibleColumn</key>
48
+ <integer>0</integer>
49
+ <key>firstVisibleLine</key>
50
+ <integer>0</integer>
51
+ </dict>
52
+ <key>lib/howlingmine/client.rb</key>
53
+ <dict>
54
+ <key>caret</key>
55
+ <dict>
56
+ <key>column</key>
57
+ <integer>127</integer>
58
+ <key>line</key>
59
+ <integer>22</integer>
60
+ </dict>
61
+ <key>columnSelection</key>
62
+ <false/>
63
+ <key>firstVisibleColumn</key>
64
+ <integer>0</integer>
65
+ <key>firstVisibleLine</key>
66
+ <integer>0</integer>
67
+ <key>selectFrom</key>
68
+ <dict>
69
+ <key>column</key>
70
+ <integer>115</integer>
71
+ <key>line</key>
72
+ <integer>22</integer>
73
+ </dict>
74
+ <key>selectTo</key>
75
+ <dict>
76
+ <key>column</key>
77
+ <integer>127</integer>
78
+ <key>line</key>
79
+ <integer>22</integer>
80
+ </dict>
81
+ </dict>
82
+ <key>lib/howlingmine/config.rb</key>
83
+ <dict>
84
+ <key>caret</key>
85
+ <dict>
86
+ <key>column</key>
87
+ <integer>12</integer>
88
+ <key>line</key>
89
+ <integer>6</integer>
90
+ </dict>
91
+ <key>firstVisibleColumn</key>
92
+ <integer>0</integer>
93
+ <key>firstVisibleLine</key>
94
+ <integer>0</integer>
95
+ </dict>
96
+ <key>lib/howlingmine/issue.rb</key>
97
+ <dict>
98
+ <key>caret</key>
99
+ <dict>
100
+ <key>column</key>
101
+ <integer>23</integer>
102
+ <key>line</key>
103
+ <integer>33</integer>
104
+ </dict>
105
+ <key>firstVisibleColumn</key>
106
+ <integer>0</integer>
107
+ <key>firstVisibleLine</key>
108
+ <integer>48</integer>
109
+ </dict>
110
+ <key>test/issue_test.rb</key>
111
+ <dict>
112
+ <key>caret</key>
113
+ <dict>
114
+ <key>column</key>
115
+ <integer>30</integer>
116
+ <key>line</key>
117
+ <integer>106</integer>
118
+ </dict>
119
+ <key>firstVisibleColumn</key>
120
+ <integer>0</integer>
121
+ <key>firstVisibleLine</key>
122
+ <integer>0</integer>
123
+ </dict>
124
+ </dict>
125
+ <key>openDocuments</key>
126
+ <array>
127
+ <string>lib/howlingmine/issue.rb</string>
128
+ <string>test/issue_test.rb</string>
129
+ <string>Rakefile</string>
130
+ <string>lib/howlingmine/client.rb</string>
131
+ <string>README.txt</string>
132
+ <string>lib/howlingmine/config.rb</string>
133
+ </array>
134
+ <key>showFileHierarchyDrawer</key>
135
+ <true/>
136
+ <key>windowFrame</key>
137
+ <string>{{300, 77}, {660, 645}}</string>
138
+ </dict>
139
+ </plist>
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'net/https'
3
+ require 'rubygems'
4
+ require 'rest_client'
5
+ require 'pp'
6
+ require 'json'
7
+ require 'time'
8
+ require "#{File.join(File.dirname(__FILE__),'howlingmine/config')}"
9
+ require "#{File.join(File.dirname(__FILE__),'howlingmine/client')}"
10
+ require "#{File.join(File.dirname(__FILE__),'howlingmine/issue')}"
11
+
12
+ module HowlingMine
13
+ VERSION = '0.1'
14
+ end
@@ -0,0 +1,28 @@
1
+ module HowlingMine
2
+ module Client
3
+
4
+ class << self
5
+ def new_issue
6
+ post_ticket
7
+ end
8
+
9
+ def post_ticket
10
+ RestClient.post("#{HowlingMine::Config.protocol}://#{HowlingMine::Config.host}:#{HowlingMine::Config.port}/howling_mine/new_issue", HowlingMine::Config.params.merge(:api_key => HowlingMine::Config.api_key))
11
+ end
12
+
13
+ def issue_status
14
+ RestClient.post("#{HowlingMine::Config.protocol}://#{HowlingMine::Config.host}:#{HowlingMine::Config.port}/howling_mine/issue_status", :api_key => HowlingMine::Config.api_key, :issue_id => HowlingMine::Config.params[:issue_id])
15
+ end
16
+ def issues
17
+ RestClient.post("#{HowlingMine::Config.protocol}://#{HowlingMine::Config.host}:#{HowlingMine::Config.port}/howling_mine/issues", :api_key => HowlingMine::Config.api_key, :issue_id => HowlingMine::Config.params[:issue_id])
18
+ end
19
+ def projects
20
+ RestClient.post("#{HowlingMine::Config.protocol}://#{HowlingMine::Config.host}:#{HowlingMine::Config.port}/howling_mine/projects", :api_key => HowlingMine::Config.api_key, :issue_id => HowlingMine::Config.params[:issue_id])
21
+ end
22
+ def journals
23
+ RestClient.post("#{HowlingMine::Config.protocol}://#{HowlingMine::Config.host}:#{HowlingMine::Config.port}/howling_mine/journals", :api_key => HowlingMine::Config.api_key, :issue_id => HowlingMine::Config.params[:issue_id])
24
+ end
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,62 @@
1
+ module HowlingMine
2
+ class Config
3
+
4
+ attr_accessor :api_key
5
+
6
+ def self.api_key
7
+ params[:api_key]
8
+ end
9
+
10
+ def self.api_key=(k)
11
+ params[:api_key] = k
12
+ end
13
+
14
+ def self.params
15
+ @@params ||= {}
16
+ end
17
+
18
+ def self.host
19
+ @@host ||= 'localhost'
20
+ end
21
+
22
+ def self.host=(h)
23
+ @@host = h
24
+ end
25
+
26
+ def self.port=(p)
27
+ @@port = p
28
+ end
29
+
30
+ def self.port
31
+ @@port ||= 80
32
+ end
33
+
34
+ def self.use_ssl
35
+ @@use_ssl ||= false
36
+ end
37
+
38
+ def self.use_ssl=(yn)
39
+ @@use_ssl ||= yn
40
+ end
41
+
42
+ def self.project
43
+ params[:project]
44
+ end
45
+
46
+ def self.project=(p)
47
+ params[:project] = p
48
+ end
49
+
50
+ def self.protocol
51
+ use_ssl ? 'https' : 'http'
52
+ end
53
+
54
+ def self.tracker=(t)
55
+ params[:tracker] = t
56
+ end
57
+
58
+ def self.tracker
59
+ params[:tracker] ||= 'Bug'
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,92 @@
1
+ module HowlingMine
2
+ class Issue
3
+
4
+ attr_accessor :id, :subject, :description, :raw, :author
5
+ attr_writer :created_on, :updated_on
6
+
7
+ def save
8
+ client = HowlingMine::Client
9
+ params = {
10
+ :subject => subject || 'no subject',
11
+ :description => description || '',
12
+ :author => author || 'none',
13
+ #:custom_fields => {
14
+ # :foofield1 => 'field-text'
15
+ #}.to_yaml
16
+ }
17
+
18
+ HowlingMine::Config.params.merge!(params)
19
+
20
+ begin
21
+ response = client.new_issue
22
+ @id = response.to_i
23
+ return true
24
+ rescue Exception => e
25
+ return false
26
+ end
27
+ end
28
+
29
+ def self.all
30
+ project = JSON.parse(HowlingMine::Client.projects).find do |p|
31
+ p['identifier'] == HowlingMine::Config.project
32
+ end
33
+ project_id = ''
34
+ if ! project.nil?
35
+ project_id = project['id']
36
+ else
37
+ raise Exception.new("#{HowlingMine::Config.project} project not found in target Redmine")
38
+ end
39
+ issues = []
40
+ client = HowlingMine::Client
41
+ JSON.parse(client.issues).each do |i|
42
+ next if i['project_id'] != project_id
43
+ issue = Issue.new
44
+ issue.subject = i['subject']
45
+ issue.description = i['description']
46
+ issue.id = i['id'].to_i
47
+ issue.raw = i
48
+ issue.created_on = i['created_on']
49
+ issue.updated_on = i['updated_on']
50
+ if i['custom_fields']
51
+ end
52
+ issues << issue
53
+ end
54
+ issues
55
+ end
56
+
57
+ def updated_on
58
+ Time.parse @updated_on
59
+ end
60
+
61
+ def created_on
62
+ Time.parse @created_on
63
+ end
64
+
65
+ def self.first
66
+ all.first
67
+ end
68
+
69
+ def self.last
70
+ all.last
71
+ end
72
+
73
+ def status
74
+ c = HowlingMine::Client
75
+ HowlingMine::Config.params.merge!(:issue_id => id)
76
+ c.issue_status.downcase
77
+ end
78
+
79
+ def self.get(ticket_no)
80
+ all.find do |i| ticket_no.to_i == i.id end
81
+ end
82
+
83
+ def journal
84
+ client = HowlingMine::Client
85
+ params = {
86
+ :issue_id => id
87
+ }
88
+ HowlingMine::Config.params.merge! params
89
+ JSON.parse(client.journals)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,12 @@
1
+ # MySQL (default setup). Versions 4.1 and 5.0 are recommended.
2
+ #
3
+ # Get the fast C bindings:
4
+ # gem install mysql
5
+ # (on OS X: gem install mysql -- --include=/usr/local/lib)
6
+ # And be sure to use new-style password hashing:
7
+ # http://dev.mysql.com/doc/refman/5.0/en/old-client.html
8
+
9
+ production:
10
+ adapter: sqlite3
11
+ dbfile: db/redmine.db
12
+
Binary file
@@ -0,0 +1,111 @@
1
+ require 'test/unit'
2
+ require "#{File.join(File.dirname(__FILE__),'../lib/howlingmine.rb')}"
3
+
4
+ class TestIssue < Test::Unit::TestCase
5
+
6
+ def setup
7
+ FileUtils.cp 'redmine_test_files/redmine.db','/opt/redmine-0.8/db/redmine.db'
8
+ HowlingMine::Config.host = 'redmine.local'
9
+ HowlingMine::Config.port = 80 # default
10
+ HowlingMine::Config.use_ssl = false # default
11
+ HowlingMine::Config.project = 'howlingmine'
12
+ HowlingMine::Config.tracker = 'Bug' # default
13
+ HowlingMine::Config.api_key = 'FboVJFYVg84avd2dfL3Y'
14
+ end
15
+
16
+ def teardown
17
+ end
18
+
19
+ def test_api_key
20
+ HowlingMine::Config.api_key = '0'
21
+ assert_raises RestClient::RequestFailed do
22
+ HowlingMine::Issue.all
23
+ end
24
+
25
+ assert_nothing_raised do
26
+ HowlingMine::Config.api_key = 'FboVJFYVg84avd2dfL3Y'
27
+ HowlingMine::Issue.all
28
+ end
29
+ end
30
+
31
+ def test_empty_issues
32
+ assert HowlingMine::Issue.all.empty?
33
+ end
34
+
35
+ def test_subject
36
+ issue = HowlingMine::Issue.new
37
+ issue.subject = 'issue number one'
38
+ issue.save
39
+ issue = HowlingMine::Issue.get 1
40
+ issue.subject == 'issue number one'
41
+ end
42
+
43
+ def test_get
44
+ issue = HowlingMine::Issue.new
45
+ issue.subject = 'issue number one'
46
+ assert issue.save
47
+ issue = HowlingMine::Issue.get 1
48
+ assert ! issue.nil?
49
+ assert issue.subject == 'issue number one'
50
+ end
51
+
52
+ def test_new_issue
53
+ issue = HowlingMine::Issue.new
54
+ issue.subject = 'issue number one'
55
+ assert_nothing_raised do
56
+ assert issue.save
57
+ end
58
+
59
+ assert HowlingMine::Issue.all.size == 1
60
+
61
+ issue = HowlingMine::Issue.new
62
+ issue.subject = 'issue number 2'
63
+ issue.description = 'stuff'
64
+ assert issue.save
65
+ assert issue.id == 2
66
+ assert HowlingMine::Issue.all.size == 2
67
+ end
68
+
69
+ def test_last_issue
70
+ issue = HowlingMine::Issue.new
71
+ issue.subject = 'issue number one'
72
+ assert issue.save
73
+ assert issue.id == HowlingMine::Issue.last.id
74
+ assert HowlingMine::Issue.last.id == 1
75
+ end
76
+
77
+ def test_first_issue
78
+ issue = HowlingMine::Issue.new
79
+ issue.subject = 'issue number one'
80
+ assert issue.save
81
+ assert issue.id == HowlingMine::Issue.first.id
82
+ assert HowlingMine::Issue.first.id == 1
83
+ end
84
+
85
+ def test_journal
86
+ issue = HowlingMine::Issue.new
87
+ issue.subject = 'issue number 1'
88
+ issue.save
89
+ assert issue.journal.size == 0
90
+ issue.description = 'comment one'
91
+ issue.save
92
+ assert issue.journal.size == 1
93
+ end
94
+
95
+ def test_save
96
+ issue = HowlingMine::Issue.new
97
+ issue.subject = 'issue number 1'
98
+ issue.description = 'description'
99
+ assert issue.save
100
+ issue = HowlingMine::Issue.get 1
101
+ assert issue.subject == 'issue number 1'
102
+ assert issue.description == 'description'
103
+
104
+ assert_nothing_raised do
105
+ issue = HowlingMine::Issue.new
106
+ assert issue.save
107
+ assert HowlingMine::Issue.all.size == 2
108
+ end
109
+ end
110
+
111
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: howlingmine-client
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Sergio Rubio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-15 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.3
24
+ version:
25
+ description: Client library for the Howling Mine Server
26
+ email:
27
+ - sergio@rubio.name
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - Rakefile
41
+ - examples/issues_example.rb
42
+ - howlingmine_client.tmproj
43
+ - lib/howlingmine.rb
44
+ - lib/howlingmine/client.rb
45
+ - lib/howlingmine/config.rb
46
+ - lib/howlingmine/issue.rb
47
+ - redmine_test_files/database.yml
48
+ - redmine_test_files/redmine.db
49
+ - test/issue_test.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/rubiojr/howlingmine-client
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --main
57
+ - README.txt
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ requirements: []
73
+
74
+ rubyforge_project: howlingmine-client
75
+ rubygems_version: 1.3.5
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: Client library for the Howling Mine Server
79
+ test_files:
80
+ - test/issue_test.rb