ticketmaster-lighthouse 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/provider/comment.rb +69 -0
- data/lib/provider/lighthouse.rb +6 -29
- data/lib/provider/project.rb +2 -93
- data/lib/provider/ticket.rb +90 -78
- data/lib/ticketmaster-lighthouse.rb +1 -1
- data/ticketmaster-lighthouse.gemspec +3 -2
- metadata +6 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module TicketMaster::Provider
|
2
|
+
module Lighthouse
|
3
|
+
# The comment class for ticketmaster-lighthouse
|
4
|
+
#
|
5
|
+
# Due to the way lighthouse handles tickets, comments aren't really comments, but
|
6
|
+
# versions of the ticket.
|
7
|
+
#
|
8
|
+
# * author => user_name (read-only)
|
9
|
+
# * body => description
|
10
|
+
# * id => position in the versions array (set by the initializer)
|
11
|
+
# * created_at
|
12
|
+
# * updated_at
|
13
|
+
# * ticket_id => number (read-only)
|
14
|
+
# * project_id => (set by the initializer)
|
15
|
+
class Comment < TicketMaster::Provider::Base::Comment
|
16
|
+
API = LighthouseAPI::Ticket
|
17
|
+
|
18
|
+
# A custom find_by_id
|
19
|
+
# The "comment" id is it's index in the versions array. An id of 0 therefore exists and
|
20
|
+
# should be the first ticket (original)
|
21
|
+
def self.find_by_id(project_id, ticket_id, id)
|
22
|
+
self.new LighthouseAPI::Ticket.find(ticket_id, :params => {:project_id => project_id}), id
|
23
|
+
end
|
24
|
+
|
25
|
+
# A custom find_by_attributes
|
26
|
+
#
|
27
|
+
def self.find_by_attributes(project_id, ticket_id, attributes = {})
|
28
|
+
result = self.search(project_id, ticket_id, attributes)
|
29
|
+
result[0].collect do |comment|
|
30
|
+
self.new(result[1], index_of(result[1].versions, comment))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# The Array#index method doesn't work for the versions...
|
35
|
+
# because it seems they're all equal.
|
36
|
+
def self.index_of(versions, needle)
|
37
|
+
result = nil
|
38
|
+
versions.each_with_index do |version, index|
|
39
|
+
result = index if version.attributes == needle.attributes
|
40
|
+
end
|
41
|
+
result
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(ticket, id)
|
45
|
+
@system_data ||= {}
|
46
|
+
@system_data[:ticket] = @system_data[:client] = ticket
|
47
|
+
@system_data[:version] = ticket.versions[id]
|
48
|
+
self.project_id = ticket.prefix_options[:project_id]
|
49
|
+
self.id = id
|
50
|
+
super(@system_data[:version].attributes)
|
51
|
+
end
|
52
|
+
|
53
|
+
# A custom searcher
|
54
|
+
#
|
55
|
+
# It returns a custom result because we need the original ticket to make a comment.
|
56
|
+
def self.search(project_id, ticket_id, options = {}, limit = 1000)
|
57
|
+
ticket = LighthouseAPI::Ticket.find(ticket_id, :params => {:project_id => project_id})
|
58
|
+
comments = ticket.versions
|
59
|
+
[search_by_attribute(comments, options, limit), ticket]
|
60
|
+
end
|
61
|
+
|
62
|
+
# The author's name
|
63
|
+
def author
|
64
|
+
user_name
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/provider/lighthouse.rb
CHANGED
@@ -2,6 +2,8 @@ module TicketMaster::Provider
|
|
2
2
|
# This is the Lighthouse Provider for ticketmaster
|
3
3
|
module Lighthouse
|
4
4
|
include TicketMaster::Provider::Base
|
5
|
+
PROJECT_API = LighthouseAPI::Project
|
6
|
+
TICKET_API = LighthouseAPI::Ticket
|
5
7
|
|
6
8
|
# This is for cases when you want to instantiate using TicketMaster::Provider::Lighthouse.new(auth)
|
7
9
|
def self.new(auth = {})
|
@@ -27,19 +29,13 @@ module TicketMaster::Provider
|
|
27
29
|
# end up using whatever the previous instantiated object's account info is.
|
28
30
|
def projects(*options)
|
29
31
|
authorize
|
30
|
-
|
31
|
-
Project.find(*options)
|
32
|
-
else
|
33
|
-
Project.find(:all)
|
34
|
-
end
|
35
|
-
set_master_data(projects)
|
32
|
+
super(*options)
|
36
33
|
end
|
37
34
|
|
38
35
|
# The project
|
39
36
|
def project(*options)
|
40
37
|
authorize
|
41
|
-
|
42
|
-
Project
|
38
|
+
super(*options)
|
43
39
|
end
|
44
40
|
|
45
41
|
# The tickets
|
@@ -55,33 +51,14 @@ module TicketMaster::Provider
|
|
55
51
|
# the first project is.
|
56
52
|
def tickets(*options)
|
57
53
|
authorize
|
58
|
-
|
59
|
-
tickets = if arg.nil?
|
60
|
-
Ticket.find
|
61
|
-
elsif arg.is_a?(Fixnum)
|
62
|
-
Ticket.find(:all, :params => {:project_id => arg})
|
63
|
-
elsif arg.is_a?(Hash)
|
64
|
-
Ticket.find(:all, :params => arg) if arg.is_a?(Hash)
|
65
|
-
else
|
66
|
-
[]
|
67
|
-
end
|
68
|
-
set_master_data(tickets)
|
54
|
+
super(*options)
|
69
55
|
end
|
70
56
|
|
71
57
|
# the ticket
|
72
58
|
def ticket(*options)
|
73
59
|
authorize
|
74
|
-
|
75
|
-
Ticket
|
60
|
+
super(*options)
|
76
61
|
end
|
77
62
|
|
78
|
-
def set_master_data(data)
|
79
|
-
if data.is_a?(Array)
|
80
|
-
data.collect! { |p| p.system_data.merge!(:master => self); p }
|
81
|
-
else
|
82
|
-
data.system_data.merge!(:master => self)
|
83
|
-
end
|
84
|
-
data
|
85
|
-
end
|
86
63
|
end
|
87
64
|
end
|
data/lib/provider/project.rb
CHANGED
@@ -4,102 +4,11 @@ module TicketMaster::Provider
|
|
4
4
|
#
|
5
5
|
#
|
6
6
|
class Project < TicketMaster::Provider::Base::Project
|
7
|
-
# The finder method
|
8
|
-
#
|
9
|
-
# It accepts all the find functionalities defined by ticketmaster
|
10
|
-
#
|
11
|
-
# + find() and find(:all) - Returns all projects on the account
|
12
|
-
# + find(<project_id>) - Returns the project based on the id
|
13
|
-
# + find(:first, :name => <project_name>) - Returns the first project based on the attribute
|
14
|
-
# + find(:name => <project name>) - Returns all projects based on the attribute
|
15
7
|
attr_accessor :prefix_options
|
16
|
-
|
17
|
-
first = options.shift
|
18
|
-
if first.nil? or first == :all
|
19
|
-
LighthouseAPI::Project.find(:all).collect do |p|
|
20
|
-
self.new p
|
21
|
-
end
|
22
|
-
elsif first.is_a?(Fixnum)
|
23
|
-
self.new LighthouseAPI::Project.find(first)
|
24
|
-
elsif first == :first
|
25
|
-
self.new self.search(options.shift || {}, 1).first
|
26
|
-
elsif first.is_a?(Hash)
|
27
|
-
self.search(first).collect { |p| self.new p }
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
# This is a helper method to find
|
32
|
-
def self.search(options = {}, limit = 1000)
|
33
|
-
projects = LighthouseAPI::Project.find(:all)
|
34
|
-
projects.find_all do |p|
|
35
|
-
options.keys.reduce(true) do |memo, key|
|
36
|
-
p.send(key) == options[key] and (limit-=1) >= 0
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Create a project
|
42
|
-
def self.create(*options)
|
43
|
-
project = LighthouseAPI::Project.new(options.shift)
|
44
|
-
project.save
|
45
|
-
self.new project
|
46
|
-
end
|
47
|
-
|
48
|
-
# The initializer
|
49
|
-
#
|
50
|
-
# A side effect of Hashie causes prefix_options to become an instance of TicketMaster::Provider::Lighthouse::Project
|
51
|
-
def initialize(*options)
|
52
|
-
@system = :lighthouse
|
53
|
-
@system_data = {}
|
54
|
-
first = options.shift
|
55
|
-
if first.is_a?(LighthouseAPI::Project)
|
56
|
-
@system_data[:client] = first
|
57
|
-
@prefix_options = first.prefix_options
|
58
|
-
super(first.attributes)
|
59
|
-
else
|
60
|
-
super(first)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# All tickets for this project
|
65
|
-
def tickets(*options)
|
66
|
-
if options.length == 0
|
67
|
-
Ticket.find(:project_id => self.id)
|
68
|
-
else
|
69
|
-
first = options.first
|
70
|
-
if first.is_a?(Fixnum)
|
71
|
-
[Ticket.find(first, {:project_id => self.id})]
|
72
|
-
else
|
73
|
-
Ticket.find({:project_id => self.id}.merge(:q => options.first))
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
# The ticket finder
|
79
|
-
# returns only one ticket
|
80
|
-
def ticket(*options)
|
81
|
-
first = options.shift
|
82
|
-
if first.nil?
|
83
|
-
return Ticket
|
84
|
-
elsif first.is_a?(Fixnum)
|
85
|
-
return Ticket.find(first, :project_id => self.id)
|
86
|
-
else
|
87
|
-
Ticket.find(:first, {:project_id => self.id}.merge(:q => first))
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
# Save this project
|
92
|
-
def save
|
93
|
-
lighthouse = @system_data[:client]
|
94
|
-
lighthouse.attributes.each do |k, v|
|
95
|
-
lighthouse.send(k + '=', self.send(k)) if self.send(k) != v
|
96
|
-
end
|
97
|
-
lighthouse.save
|
98
|
-
end
|
99
|
-
|
8
|
+
API = LighthouseAPI::Project
|
100
9
|
# Delete this project
|
101
10
|
def destroy
|
102
|
-
result =
|
11
|
+
result = super
|
103
12
|
result.is_a?(Net::HTTPOK)
|
104
13
|
end
|
105
14
|
|
data/lib/provider/ticket.rb
CHANGED
@@ -1,102 +1,114 @@
|
|
1
1
|
module TicketMaster::Provider
|
2
2
|
module Lighthouse
|
3
3
|
# Ticket class for ticketmaster-lighthouse
|
4
|
+
#
|
5
|
+
# Due to the way Lighthouse stores tickets, we actually end up creating a new ticket version
|
6
|
+
# every time we edit tickets. Their api FAQ states these attributes as the only editable ones(?):
|
7
|
+
#
|
8
|
+
# * title
|
9
|
+
# * body - follows the same formatting rules.
|
10
|
+
# * state - Can be any one of these: new, open, resolved, hold, invalid. Optional, set to open by default for new tickets.
|
11
|
+
# * assigned-user-id - optional
|
12
|
+
# * milestone-id - optional
|
13
|
+
# * tag - space or comma delimited list of tags
|
14
|
+
#
|
15
|
+
# We had to remap things a bit since lighthouse doesn't name things as ticketmaster specifies.
|
16
|
+
#
|
17
|
+
# * id => number (read-only)
|
18
|
+
# * status => state
|
19
|
+
# * resolution => ticket.latest_body
|
20
|
+
# * description => ticket.original_body (setting a new description creates a new body)
|
21
|
+
# * assignee => assigned_user_name (read-only)
|
22
|
+
# * requestor => creator_name (read-only)
|
23
|
+
# * project_id => prefix_options[:project_id]
|
24
|
+
# * priority
|
25
|
+
# * title
|
26
|
+
# * created_at
|
27
|
+
# * updated_at
|
28
|
+
|
4
29
|
class Ticket < TicketMaster::Provider::Base::Ticket
|
5
30
|
@@allowed_states = ['new', 'open', 'resolved', 'hold', 'invalid']
|
6
31
|
attr_accessor :prefix_options
|
32
|
+
API = LighthouseAPI::Ticket
|
33
|
+
COMMENT = Lighthouse::Comment
|
7
34
|
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# It tries to implement all the ticketmaster calls, but since the project id is required as the
|
11
|
-
# parent key, it doesnt really make sense to call find(:all) or find(##)
|
12
|
-
#
|
13
|
-
# * find(:all) - Returns an array of all tickets
|
14
|
-
# * find(##, ##) - Returns a ticket based on that id or some other primary (unique) attribute
|
15
|
-
# * find(:first, :summary => 'Ticket title') - Returns a ticket based on the ticket's attributes
|
16
|
-
# * find(:summary => 'Test Ticket') - Returns all tickets based on the given attributes
|
17
|
-
def self.find(*options)
|
18
|
-
first = options.shift
|
19
|
-
if first.nil? or first == :all
|
20
|
-
tickets = []
|
21
|
-
LighthouseAPI::Project.find(:all).each do |p|
|
22
|
-
tickets |= p.tickets
|
23
|
-
end
|
24
|
-
tickets.collect { |t| self.new t }
|
25
|
-
elsif first.is_a?(Fixnum)
|
26
|
-
second = options.shift
|
27
|
-
if second.is_a?(Fixnum)
|
28
|
-
self.new LighthouseAPI::Ticket.find(first, :params => { :project_id => second })
|
29
|
-
elsif second.is_a?(Hash)
|
30
|
-
self.new LighthouseAPI::Ticket.find(first, :params => qize(second))
|
31
|
-
end
|
32
|
-
elsif first == :first
|
33
|
-
self.new self.search(options.shift, 1).first
|
34
|
-
elsif first.is_a?(Hash)
|
35
|
-
self.search(first).collect do |t| self.new t end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
35
|
+
# This is to get the ticket id
|
36
|
+
# We can't set ids, so there's no 'id=' method.
|
39
37
|
def id
|
40
38
|
@system_data[:client].number
|
41
39
|
end
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
41
|
+
# This is to get the status, mapped to state
|
42
|
+
def status
|
43
|
+
state
|
44
|
+
end
|
45
|
+
|
46
|
+
# This is to set the status, mapped to state
|
47
|
+
def status=(stat)
|
48
|
+
stat = state unless @@allowed_states.include?(stat)
|
49
|
+
state = stat
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get the resolution, mapped to latest_body
|
53
|
+
def resolution
|
54
|
+
latest_body
|
55
|
+
end
|
56
|
+
|
57
|
+
# Set the resolution...also sets state to resolved
|
58
|
+
def resolution=(res)
|
59
|
+
state = 'resolved'
|
60
|
+
body = res
|
61
|
+
end
|
62
|
+
|
63
|
+
# Get the description, mapped to original_body
|
64
|
+
def description
|
65
|
+
original_body
|
66
|
+
end
|
67
|
+
|
68
|
+
# Set the description, mapped to body, which actually does a comment
|
69
|
+
def description=(desc)
|
70
|
+
body = desc
|
71
|
+
end
|
72
|
+
|
73
|
+
# Get the assigned person's name
|
74
|
+
def assignee
|
75
|
+
assigned_user_name
|
53
76
|
end
|
54
77
|
|
55
|
-
#
|
56
|
-
def
|
57
|
-
|
58
|
-
tickets.find_all do |t|
|
59
|
-
options.keys.reduce(true) do |memo, key|
|
60
|
-
t.send(key) == options[key] and (limit-=1) > 0
|
61
|
-
end
|
62
|
-
end
|
78
|
+
# Get the requestor's name
|
79
|
+
def requestor
|
80
|
+
creator_name
|
63
81
|
end
|
64
82
|
|
65
|
-
#
|
66
|
-
def
|
67
|
-
|
68
|
-
@system_data = {}
|
69
|
-
first = options.shift
|
70
|
-
if first.is_a?(LighthouseAPI::Ticket)
|
71
|
-
@system_data[:client] = first
|
72
|
-
@prefix_options = first.prefix_options
|
73
|
-
super(first.attributes)
|
74
|
-
else
|
75
|
-
super(first)
|
76
|
-
end
|
83
|
+
# Get the project id
|
84
|
+
def project_id
|
85
|
+
prefix_options[:project_id]
|
77
86
|
end
|
78
87
|
|
79
|
-
#
|
80
|
-
def
|
81
|
-
|
82
|
-
|
83
|
-
new_ticket.send(k + '=', v)
|
84
|
-
end
|
85
|
-
new_ticket.save
|
86
|
-
self.new new_ticket
|
88
|
+
# Set the body
|
89
|
+
def body=(bod)
|
90
|
+
@system_data[:client].body = nil
|
91
|
+
super(bod)
|
87
92
|
end
|
88
93
|
|
89
|
-
#
|
90
|
-
def
|
91
|
-
|
92
|
-
self.
|
93
|
-
|
94
|
-
|
95
|
-
|
94
|
+
# Tags, a little helper for the ticket tagging
|
95
|
+
def tags
|
96
|
+
return @tags if @tags
|
97
|
+
tagz = self.tag.split(/([\w\d]+)|"([\w \d]+)"/)
|
98
|
+
tagz.delete(' ')
|
99
|
+
tagz.delete('')
|
100
|
+
@tags = tagz
|
96
101
|
end
|
97
102
|
|
98
|
-
|
99
|
-
|
103
|
+
# Gotta unset the body attribute...otherwise every save ends up using that body
|
104
|
+
def save
|
105
|
+
tag = @tags.reduce([]) do |mem, t|
|
106
|
+
t = "\"#{t}\"" if t.include?(' ')
|
107
|
+
mem << t
|
108
|
+
end.join(' ') if @tags
|
109
|
+
super
|
110
|
+
body = nil
|
111
|
+
@system_data[:client].body = nil
|
100
112
|
end
|
101
113
|
|
102
114
|
# The closer
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ticketmaster-lighthouse}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Hong"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-07-02}
|
13
13
|
s.description = %q{Allows ticketmaster to interact with Lighthouse's issue tracking system.}
|
14
14
|
s.email = %q{hong.quach@abigfisch.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/lighthouse/LICENSE",
|
27
27
|
"lib/lighthouse/README.markdown",
|
28
28
|
"lib/lighthouse/lighthouse-api.rb",
|
29
|
+
"lib/provider/comment.rb",
|
29
30
|
"lib/provider/lighthouse.rb",
|
30
31
|
"lib/provider/project.rb",
|
31
32
|
"lib/provider/ticket.rb",
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ticketmaster-lighthouse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Hong
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-07-02 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/lighthouse/LICENSE
|
118
118
|
- lib/lighthouse/README.markdown
|
119
119
|
- lib/lighthouse/lighthouse-api.rb
|
120
|
+
- lib/provider/comment.rb
|
120
121
|
- lib/provider/lighthouse.rb
|
121
122
|
- lib/provider/project.rb
|
122
123
|
- lib/provider/ticket.rb
|