Class: TicketMaster::Provider::Github::Ticket
- Inherits:
-
Base::Ticket
- Object
- Base::Ticket
- TicketMaster::Provider::Github::Ticket
- Defined in:
- lib/provider/ticket.rb
Overview
Ticket class for ticketmaster-github
Constant Summary collapse
- @@allowed_states =
%w{open close}
Instance Attribute Summary collapse
-
#prefix_options ⇒ Object
Returns the value of attribute prefix_options.
Class Method Summary collapse
- .find(project_id, *options) ⇒ Object
- .find_all(project_id) ⇒ Object
- .find_by_attributes(project_id, attributes = {}) ⇒ Object
- .find_by_id(project_id, number) ⇒ Object
- .open(project_id, *options) ⇒ Object
Instance Method Summary collapse
- #close ⇒ Object
- #comment!(comment) ⇒ Object
- #comments ⇒ Object
- #created_at ⇒ Object
- #id ⇒ Object
-
#initialize(*object) ⇒ Ticket
constructor
declare needed overloaded methods here.
- #reopen ⇒ Object
- #save ⇒ Object
- #updated_at ⇒ Object
Constructor Details
#initialize(*object) ⇒ Ticket
declare needed overloaded methods here
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/provider/ticket.rb', line 11 def initialize(*object) project_id = object.shift if object.first object = object.first @system_data = {:client => object} unless object.is_a? Hash hash = {:title => object.title, :created_at => object.created_at, :updated_at => object.updated_at, :number => object.number, :user => object.user, :id => object.number, :state => object.state, :html_url => object.html_url, :position => object.position, :description => object.body, :project_id => project_id} else object.merge!(:project_id => project_id) hash = object end super hash end end |
Instance Attribute Details
#prefix_options ⇒ Object
Returns the value of attribute prefix_options.
8 9 10 |
# File 'lib/provider/ticket.rb', line 8 def @prefix_options end |
Class Method Details
.find(project_id, *options) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/provider/ticket.rb', line 44 def self.find(project_id, *) if .first.empty? self.find_all(project_id) elsif [0].first.is_a? Array .first.collect { |number| self.find_by_id(project_id, number) } elsif [0].first.is_a? Hash self.find_by_attributes(project_id, [0].first) end end |
.find_all(project_id) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/provider/ticket.rb', line 59 def self.find_all(project_id) issues = [] issues += TicketMaster::Provider::Github.api.issues("#{TicketMaster::Provider::Github.login}/#{project_id}") state = 'closed' issues += TicketMaster::Provider::Github.api.issues("#{TicketMaster::Provider::Github.login}/#{project_id}", state) issues.collect { |issue| Ticket.new(project_id, issue) } end |
.find_by_attributes(project_id, attributes = {}) ⇒ Object
54 55 56 57 |
# File 'lib/provider/ticket.rb', line 54 def self.find_by_attributes(project_id, attributes = {}) issues = self.find_all(project_id) search_by_attribute(issues, attributes) end |
.find_by_id(project_id, number) ⇒ Object
40 41 42 |
# File 'lib/provider/ticket.rb', line 40 def self.find_by_id(project_id, number) self.new(project_id, TicketMaster::Provider::Github.api.issue("#{TicketMaster::Provider::Github.login}/#{project_id}", number)) end |
.open(project_id, *options) ⇒ Object
67 68 69 70 71 |
# File 'lib/provider/ticket.rb', line 67 def self.open(project_id, *) body = .first.delete(:body) title = .first.delete(:title) TicketMaster::Provider::Github.api.create_issue("#{TicketMaster::Provider::Github.login}/#{project_id}", title, body, .first) end |
Instance Method Details
#close ⇒ Object
100 101 102 |
# File 'lib/provider/ticket.rb', line 100 def close Ticket.new(project_id, TicketMaster::Provider::Github.api.close_issue("#{TicketMaster::Provider::Github.login}/#{project_id}", number)) end |
#comment!(comment) ⇒ Object
108 109 110 |
# File 'lib/provider/ticket.rb', line 108 def comment!(comment) Comment.create(project_id, number, comment) end |
#comments ⇒ Object
104 105 106 |
# File 'lib/provider/ticket.rb', line 104 def comments Comment.find(project_id, number) end |
#created_at ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/provider/ticket.rb', line 73 def created_at begin Time.parse(self[:created_at]) rescue self[:created_at] end end |
#id ⇒ Object
36 37 38 |
# File 'lib/provider/ticket.rb', line 36 def id self[:number] end |
#reopen ⇒ Object
96 97 98 |
# File 'lib/provider/ticket.rb', line 96 def reopen Ticket.new(project_id, TicketMaster::Provider::Github.api.reopen_issue("#{TicketMaster::Provider::Github.login}/#{project_id}", number)) end |
#save ⇒ Object
89 90 91 92 93 94 |
# File 'lib/provider/ticket.rb', line 89 def save t = Ticket.find_by_id(project_id, number) return false if t.title == title and t.body == body Ticket.new(project_id, TicketMaster::Provider::Github.api.update_issue("#{TicketMaster::Provider::Github.login}/#{project_id}", number, title, body)) true end |
#updated_at ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/provider/ticket.rb', line 81 def updated_at begin Time.parse(self[:updated_at]) rescue self[:updated_at] end end |