unfuddler 0.0.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
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 The Hybrid Group
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.md ADDED
@@ -0,0 +1,27 @@
1
+ # Unfuddler
2
+
3
+ Unfuddler is a simple Ruby API to Unfuddle's projects and tickets. Primarily made for [ticketmaster](http://github.com/Sirupsen/ticketmaster).
4
+
5
+ ## Usage
6
+
7
+ Unfuddler.authenticate(:username => "john", :password => "seekrit", :subdomain => "johnscompany")
8
+ # Project#find returns all projects, fetching last element from array with Array#last
9
+ project = Unfuddler.project.find.last
10
+ # Fetch all new tickets where the status is new
11
+ new_tickets = project.tickets.find(:status => "new")
12
+ # Close ticket with a resolution
13
+ new_tickets.first.close!(:resolution => "fixed", :description => "I fixed it!")
14
+
15
+ ## Note on Patches/Pull Requests
16
+
17
+ * Fork the project.
18
+ * Make your feature addition or bug fix.
19
+ * Add tests for it. This is important so I don't break it in a
20
+ future version unintentionally.
21
+ * Commit, do not mess with rakefile, version, or history.
22
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
23
+ * Send me a pull request. Bonus points for topic branches.
24
+
25
+ ## Copyright
26
+
27
+ Copyright (c) 2010 [Hybrid Group](http://hybridgroup.com). See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "unfuddler"
8
+ gem.summary = %Q{Provides a simple Ruby API to Unfuddle.}
9
+ gem.description = %Q{Provides a simple Ruby API to Unfuddle.}
10
+ gem.email = "sirup@sirupsen.dk"
11
+ gem.homepage = "http://github.com/Sirupsen/unfuddler"
12
+ gem.authors = ["Sirupsen"]
13
+ gem.add_development_dependency "shoulda", ">= 0"
14
+ gem.add_dependency "hashie", ">= 0.2.0"
15
+ gem.add_dependency "crack", ">= 0.1.6"
16
+ gem.add_dependency "activesupport", ">= 2.3.5"
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ require 'rake/testtask'
24
+ Rake::TestTask.new(:test) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.pattern = 'test/**/test_*.rb'
27
+ test.verbose = true
28
+ end
29
+
30
+ begin
31
+ require 'rcov/rcovtask'
32
+ Rcov::RcovTask.new do |test|
33
+ test.libs << 'test'
34
+ test.pattern = 'test/**/test_*.rb'
35
+ test.verbose = true
36
+ end
37
+ rescue LoadError
38
+ task :rcov do
39
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
40
+ end
41
+ end
42
+
43
+ task :test => :check_dependencies
44
+
45
+ task :default => :test
46
+
47
+ require 'rake/rdoctask'
48
+ Rake::RDocTask.new do |rdoc|
49
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "unfuddler #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('lib/**/*.rb')
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/lib/unfuddler.rb ADDED
@@ -0,0 +1,146 @@
1
+ %w{
2
+ hashie
3
+ net/http
4
+ crack/xml
5
+ active_support
6
+ active_support/core_ext/hash
7
+ }.each {|lib| require lib}
8
+
9
+
10
+ module Unfuddler
11
+ class << self
12
+ attr_accessor :username, :password, :subdomain, :http
13
+
14
+ def authenticate(info)
15
+ @username, @password, @subdomain = info[:username], info[:password], info[:subdomain]
16
+ @http = Net::HTTP.new("#{@subdomain}.unfuddle.com", 80)
17
+ end
18
+
19
+ def request(type, url, data = nil)
20
+ request = eval("Net::HTTP::#{type.capitalize}").new("/api/v1/#{url}", {'Content-type' => "application/xml"})
21
+ request.basic_auth @username, @password
22
+
23
+ request.body = data if data
24
+ handle_response(@http.request(request))
25
+ end
26
+
27
+ def handle_response(response)
28
+ valid_codes = [201, 200, 302]
29
+ raise "Server returned response code: " + response.code unless valid_codes.include?(response.code.to_i)
30
+ Crack::XML.parse(response.body)
31
+ end
32
+
33
+ [:get, :put, :post, :delete].each do |method|
34
+ define_method(method) do |url, data = nil|
35
+ request(method, url, data)
36
+ end
37
+ end
38
+ end
39
+
40
+ class Project < Hashie::Mash
41
+ def self.find
42
+ projects = []
43
+ Unfuddler.get("projects.xml")["projects"].each do |project|
44
+ projects << Project.new(project)
45
+ end
46
+ projects
47
+ end
48
+
49
+ def tickets(argument = nil)
50
+ Ticket.find(self.id, argument)
51
+ end
52
+
53
+ def ticket
54
+ Ticket::Interacter.new(self.id)
55
+ end
56
+ end
57
+
58
+ class Ticket < Hashie::Mash
59
+ # Find tickets associated with a project.
60
+ #
61
+ # Required argument is project_id, which is the id
62
+ # of the project to search for tickets.
63
+ #
64
+ # Optional argument is argument, which searches the tickets
65
+ # to match the keys in the argument. e.g.
66
+ # Ticket.find(:status => "new")
67
+ # Returns all tickets with status "new"
68
+ def self.find(project_id, arguments = nil)
69
+ tickets = []
70
+ Unfuddler.get("projects/#{project_id}/tickets.xml")["tickets"].each do |project|
71
+ tickets << Ticket.new(project)
72
+ end
73
+
74
+ if arguments
75
+ specified_tickets = []
76
+
77
+ # Check each ticket if all the expected values pass, return all
78
+ # tickets where everything passes in an array
79
+ tickets.each do |ticket|
80
+ matches = 0
81
+ arguments.each_pair do |method, expected_value|
82
+ matches += 1 if ticket.send(method) == expected_value
83
+ end
84
+
85
+ specified_tickets << ticket if matches == arguments.length
86
+ end
87
+
88
+ return specified_tickets
89
+ end
90
+
91
+ tickets
92
+ end
93
+
94
+ # Save ticket
95
+ #
96
+ # Optional argument is what to update if the ticket object is not altered
97
+ def save(update = nil)
98
+ update = self.to_hash.to_xml(:root => "ticket") unless update
99
+ Unfuddler.put("projects/#{self.project_id}/tickets/#{self.id}", update)
100
+ end
101
+
102
+ # Create a ticket
103
+ #
104
+ # Optional argument is project_id
105
+ def create(project_id = nil)
106
+ ticket = self.to_hash.to_xml(:root => "ticket")
107
+ Unfuddler.post("projects/#{project_id or self.project_id}/tickets", ticket)
108
+ end
109
+
110
+ [:closed!, :new!, :unaccepted!, :reassigned!, :reopened!, :accepted!, :resolved!].each do |method|
111
+ # Fix method names, e.g. #reassigned! => #reassign!
112
+ length = method[0..-3] if method == :closed!
113
+ length = method[0..-2] if [:new!, :resolved!].include?(method)
114
+
115
+ define_method((length || method[0..-4]) + "!") do |resolution|
116
+ name = method[0..-2] # No "!"
117
+ update = {:status => name}
118
+
119
+ if resolution
120
+ # The API wants resolution-description for a resolutions description,
121
+ # to make it more user-friendly, we convert this automatically
122
+ resolution[:"resolution-description"] = resolution.delete(:description)
123
+ update.merge!(resolution)
124
+ end
125
+
126
+ update = update.to_xml(:root => "ticket")
127
+ save(update)
128
+ end
129
+ end
130
+
131
+ def delete
132
+ Unfuddler.delete("projects/#{self.project_id}/tickets/#{self.id}")
133
+ end
134
+
135
+ class Interacter
136
+ def initialize(project_id)
137
+ @project_id = project_id
138
+ end
139
+
140
+ def create(ticket = {})
141
+ ticket = Ticket.new(ticket)
142
+ ticket.create(@project_id)
143
+ end
144
+ end
145
+ end
146
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'unfuddler'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,25 @@
1
+ require 'helper'
2
+
3
+ class TestUnfuddler < Test::Unit::TestCase
4
+ context "an Unfuddler project instance" do
5
+ setup do
6
+ Unfuddler.authenticate(:username => "simon", :password => "WT00op", :subdomain => "ticketmaster")
7
+ @project = Unfuddler::Project.find.first
8
+ end
9
+
10
+ should "find a ticket" do
11
+ ticket = @project.tickets.first
12
+ assert ticket.is_a?(Unfuddler::Ticket)
13
+ end
14
+
15
+ should "be able to create a ticket" do
16
+ # Should return an empty hash on success
17
+ assert @project.ticket.create(:priority => "3", :description => "This is a test ticket made by Unfuddler", :summary => "Test Ticket").empty?
18
+ end
19
+
20
+ should "be able to delete the newly created ticket, which should be the last one" do
21
+ # Should return an empty hash on success
22
+ assert @project.tickets.last.delete.empty?
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unfuddler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Sirupsen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-05-23 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: hashie
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 0
46
+ - 2
47
+ - 0
48
+ version: 0.2.0
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: crack
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 23
60
+ segments:
61
+ - 0
62
+ - 1
63
+ - 6
64
+ version: 0.1.6
65
+ type: :runtime
66
+ version_requirements: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: activesupport
69
+ prerelease: false
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 9
76
+ segments:
77
+ - 2
78
+ - 3
79
+ - 5
80
+ version: 2.3.5
81
+ type: :runtime
82
+ version_requirements: *id004
83
+ description: Provides a simple Ruby API to Unfuddle.
84
+ email: sirup@sirupsen.dk
85
+ executables: []
86
+
87
+ extensions: []
88
+
89
+ extra_rdoc_files:
90
+ - LICENSE
91
+ - README.md
92
+ files:
93
+ - .document
94
+ - .gitignore
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - VERSION
99
+ - lib/unfuddler.rb
100
+ - test/helper.rb
101
+ - test/test_unfuddler.rb
102
+ has_rdoc: true
103
+ homepage: http://github.com/Sirupsen/unfuddler
104
+ licenses: []
105
+
106
+ post_install_message:
107
+ rdoc_options:
108
+ - --charset=UTF-8
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ version: "0"
129
+ requirements: []
130
+
131
+ rubyforge_project:
132
+ rubygems_version: 1.3.7
133
+ signing_key:
134
+ specification_version: 3
135
+ summary: Provides a simple Ruby API to Unfuddle.
136
+ test_files:
137
+ - test/helper.rb
138
+ - test/test_unfuddler.rb