Class: TicketMaster::Provider::Rally::Ticket
- Inherits:
-
Base::Ticket
- Object
- Base::Ticket
- TicketMaster::Provider::Rally::Ticket
- Defined in:
- lib/provider/ticket.rb
Overview
Ticket class for ticketmaster-rally
Remaps
id => oid title => name requestor => submitted_by resolution => schedule_state status => state created_at => creation_date updated_at => last_update_date
assignee => owner
Class Method Summary collapse
- .create(*options) ⇒ Object
-
.find_by_attributes(project_id, attributes = {}) ⇒ Object
Accepts a project id and attributes hash and returns all tickets matching the project and those attributes in an array Should return all project tickets if the attributes hash is empty.
- .find_by_id(project_id, id) ⇒ Object
-
.search(project_id, options = {}, limit = 1000) ⇒ Object
This is a helper method to find.
Instance Method Summary collapse
- #created_at ⇒ Object
-
#id ⇒ Object
Rally REST API aliases String and Fixnum :to_q :to_s However, it does not alias Bignum If a ID is a Bignum, the API will throw undefined method Because of this, we pass all IDs to API as strings Ticketmaster specs set IDs as integers, so coerce type on get.
- #id=(id) ⇒ Object
-
#initialize(*object) ⇒ Ticket
constructor
A new instance of Ticket.
- #save ⇒ Object
- #updated_at ⇒ Object
- #updated_at=(last_update_date) ⇒ Object
Constructor Details
#initialize(*object) ⇒ Ticket
Returns a new instance of Ticket.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/provider/ticket.rb', line 17 def initialize(*object) if object.first args = object ticket = args.shift project_id = args.shift @system_data = {:client => ticket} hash = { :oid => ticket.oid, :project_id => project_id, # Rally symbol for Tasks and Defects # :hierarchical_requirement, :defect or :task (:artifact for all) :type_as_symbol => ticket.type_as_symbol, :title => ticket.name, :description => ticket.description, :requestor => ticket.submitted_by, :resolution => ticket.schedule_state, :status => ticket.state, :created_at => ticket.creation_date, :updated_at => ticket.last_update_date } # Rally optional attributes hash[:assignee] = ticket.owner if ticket.owner # From Rally Web Services API Documentation v1.21 # Allowed values for Defect.Priority: "", # "Resolve Immediately", # "High Attention", # "Normal", # "Low" # When "" Rally Ruby REST API returns <Priority>None</Priority> # Unless API returns allowed value, don't set priority hash[:priority] = ticket.priority unless ticket.priority == "None" super(hash) end end |
Class Method Details
.create(*options) ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/provider/ticket.rb', line 109 def self.create(*) = .shift project = self.rally_project([:project_id]) ticket = self.to_rally_object() ticket[:project] = project # Not sure about making the defect the default here, thoughts? new_type = [:type_as_symbol] || :defect new_ticket = TicketMaster::Provider::Rally.rally.create(new_type, ticket) self.new new_ticket end |
.find_by_attributes(project_id, attributes = {}) ⇒ Object
Accepts a project id and attributes hash and returns all tickets matching the project and those attributes in an array Should return all project tickets if the attributes hash is empty
88 89 90 |
# File 'lib/provider/ticket.rb', line 88 def self.find_by_attributes(project_id, attributes = {}) self.search(project_id, attributes) end |
.find_by_id(project_id, id) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/provider/ticket.rb', line 77 def self.find_by_id(project_id, id) project = self.rally_project(project_id) # Rally Ruby REST API expects IDs as strings # For id.to_s see note on Project::id query_result = TicketMaster::Provider::Rally.rally.find(:artifact, :fetch => true, :project => project) { equal :object_i_d, id.to_s } self.new query_result.first, project_id end |
.search(project_id, options = {}, limit = 1000) ⇒ Object
This is a helper method to find
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/provider/ticket.rb', line 93 def self.search(project_id, = {}, limit = 1000) project = self.rally_project(project_id) search_type = .delete(:type_as_symbol) || :artifact # Convert Ticketmaster hash keys to Rally hash keys for Rally query params query_parameters = self.to_rally_query_parameters() query_result = TicketMaster::Provider::Rally.rally.find_all(search_type, :project => project){ query_parameters.each do |key, value| equal key, value end } tickets = query_result.collect do |ticket| self.new ticket, project_id end search_by_attribute(tickets, , limit) end |
Instance Method Details
#created_at ⇒ Object
52 53 54 |
# File 'lib/provider/ticket.rb', line 52 def created_at Time.parse(self[:created_at]) end |
#id ⇒ Object
Rally REST API aliases String and Fixnum :to_q :to_s However, it does not alias Bignum If a ID is a Bignum, the API will throw undefined method Because of this, we pass all IDs to API as strings Ticketmaster specs set IDs as integers, so coerce type on get
65 66 67 |
# File 'lib/provider/ticket.rb', line 65 def id self[:oid].to_i end |
#id=(id) ⇒ Object
69 70 71 |
# File 'lib/provider/ticket.rb', line 69 def id=(id) self[:oid] = id.to_s end |
#save ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/provider/ticket.rb', line 120 def save if self[:oid].empty? @system_data[:client].save! else ticket = self.class.to_rally_object(self) ticket_updated = @system_data[:client].update(ticket) # Update Ticketmaster Ticket object updated_at attribute self.updated_at = ticket_updated.last_update_date end end |
#updated_at ⇒ Object
56 57 58 |
# File 'lib/provider/ticket.rb', line 56 def updated_at Time.parse(self[:updated_at]) end |
#updated_at=(last_update_date) ⇒ Object
73 74 75 |
# File 'lib/provider/ticket.rb', line 73 def updated_at=(last_update_date) self[:updated_at] = Time.parse(last_update_date) end |