Class: TicketMaster::Provider::Base::Comment
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- TicketMaster::Provider::Base::Comment
- Extended by:
- Helper
- Defined in:
- lib/ticketmaster/comment.rb
Overview
The comment class
This will probably one of the most troublesome parts of creating a provider for ticketmaster since there are so many different ways comments are handled by different APIs. Keep in mind that if you do need to change/overwrite the methods, you will most likely only need to overwrite #find_by_id, #find_by_attributes, #search, and possibly #initialize as long as their parameters conform to what the find method expects.
Here are the expected attributes:
-
author
-
body
-
id
-
created_at
-
updated_at
-
ticket_id
-
project_id
Direct Known Subclasses
Constant Summary collapse
- API =
Replace with your comment’s API’s Class
nil
Instance Attribute Summary collapse
-
#system ⇒ Object
Returns the value of attribute system.
-
#system_data ⇒ Object
Returns the value of attribute system_data.
Class Method Summary collapse
-
.find(project_id, ticket_id, *options) ⇒ Object
Find comment You can also retrieve an array of all comments by not specifying any query.
-
.find_by_attributes(project_id, ticket_id, attributes = {}) ⇒ Object
Accepts an attributes hash and returns all comments matching those attributes in an array Should return all comments if the attributes hash is empty Must be defined by the provider.
-
.find_by_id(project_id, ticket_id, id) ⇒ Object
Accepts an integer id and returns the single comment instance Must be defined by the provider.
-
.first(project_id, ticket_id, *options) ⇒ Object
The first of whatever comment.
-
.last(project_id, ticket_id, *options) ⇒ Object
The last of whatever comment.
-
.search(project_id, ticket_id, options = {}, limit = 1000) ⇒ Object
This is a helper method to find.
Methods included from Helper
easy_finder, filter_string, provider_parent, search_by_attribute, search_filter, this_method
Methods included from Common
#destroy, included, #initialize, #respond_to?, #save, #update!
Instance Attribute Details
#system ⇒ Object
Returns the value of attribute system.
24 25 26 |
# File 'lib/ticketmaster/comment.rb', line 24 def system @system end |
#system_data ⇒ Object
Returns the value of attribute system_data.
24 25 26 |
# File 'lib/ticketmaster/comment.rb', line 24 def system_data @system_data end |
Class Method Details
.find(project_id, ticket_id, *options) ⇒ Object
Find comment You can also retrieve an array of all comments by not specifying any query.
-
find(<project_id>, <ticket_id>) or find(<project_id>, <ticket_id>, :all) - Returns an array of all comments
-
find(<project_id>, <ticket_id>, ##) - Returns a comment based on that id or some other primary (unique) attribute
-
find(<project_id>, <ticket_id>, [#, #, #]) - Returns many comments with these ids
-
find(<project_id>, <ticket_id>, :first, :name => ‘Project name’) - Returns the first comment based on the comment’s attribute(s)
-
find(<project_id>, <ticket_id>, :last, :name => ‘Some project’) - Returns the last comment based on the comment’s attribute(s)
-
find(<project_id>, <ticket_id>, :all, :name => ‘Test Project’) - Returns all comments based on the given attribute(s)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ticketmaster/comment.rb', line 36 def self.find(project_id, ticket_id, *) first, attributes = if first.nil? or (first == :all and attributes.nil?) self.find_by_attributes(project_id, ticket_id) elsif first.is_a? Array first.collect { |id| self.find_by_id(project_id, ticket_id, id) } elsif first == :first comments = attributes.nil? ? self.find_by_attributes(project_id, ticket_id) : self.find_by_attributes(project_id, ticket_id, attributes) comments.first elsif first == :last comments = attributes.nil? ? self.find_by_attributes(project_id, ticket_id) : self.find_by_attributes(project_id, ticket_id, attributes) comments.last elsif first == :all self.find_by_attributes(project_id, ticket_id, attributes) else self.find_by_id(project_id, ticket_id, first) end end |
.find_by_attributes(project_id, ticket_id, attributes = {}) ⇒ Object
Accepts an attributes hash and returns all comments matching those attributes in an array Should return all comments if the attributes hash is empty Must be defined by the provider
78 79 80 81 82 83 84 |
# File 'lib/ticketmaster/comment.rb', line 78 def self.find_by_attributes(project_id, ticket_id, attributes = {}) if self::API.is_a? Class self.search(project_id, ticket_id, attributes) else raise TicketMaster::Exception.new("#{self.name}::#{this_method} method must be implemented by the provider") end end |
.find_by_id(project_id, ticket_id, id) ⇒ Object
Accepts an integer id and returns the single comment instance Must be defined by the provider
67 68 69 70 71 72 73 |
# File 'lib/ticketmaster/comment.rb', line 67 def self.find_by_id(project_id, ticket_id, id) if self::API.is_a? Class self.new self::API.find(id, :params => {:project_id => project_id, :ticket_id => ticket_id}) else raise TicketMaster::Exception.new("#{self.name}::#{this_method} method must be implemented by the provider") end end |
.first(project_id, ticket_id, *options) ⇒ Object
The first of whatever comment
56 57 58 |
# File 'lib/ticketmaster/comment.rb', line 56 def self.first(project_id, ticket_id, *) self.find(project_id, ticket_id, :first, *) end |
.last(project_id, ticket_id, *options) ⇒ Object
The last of whatever comment
61 62 63 |
# File 'lib/ticketmaster/comment.rb', line 61 def self.last(project_id, ticket_id, *) self.find(project_id, ticket_id, :last, *) end |
.search(project_id, ticket_id, options = {}, limit = 1000) ⇒ Object
This is a helper method to find
87 88 89 90 91 92 93 94 |
# File 'lib/ticketmaster/comment.rb', line 87 def self.search(project_id, ticket_id, = {}, limit = 1000) if self::API.is_a? Class comments = self::API.find(:all, :params => {:project_id => project_id, :ticket_id => ticket_id}).collect { |comment| self.new comment } search_by_attribute(comments, , limit) else raise TicketMaster::Exception.new("#{self.name}::#{this_method} method must be implemented by the provider") end end |