Class: Tessera::Ticket
- Inherits:
-
Object
- Object
- Tessera::Ticket
- Defined in:
- lib/tessera/ticket.rb
Class Method Summary collapse
-
.create(params) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
-
.find(ticket_id) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength.
-
.where(params) ⇒ Object
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(result) ⇒ Ticket
constructor
A new instance of Ticket.
- #ticket_ids ⇒ Object
- #tickets ⇒ Object
Constructor Details
#initialize(result) ⇒ Ticket
Returns a new instance of Ticket.
54 55 56 |
# File 'lib/tessera/ticket.rb', line 54 def initialize(result) @result = result end |
Class Method Details
.create(params) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tessera/ticket.rb', line 34 def create(params) ticket = Tessera::Otrs::Ticket.new(params[:ticket]).to_hash article = Tessera::Otrs::Article.new(params[:article]).to_hash = if params[:attachment] && params[:attachment].is_a?(Hash) Tessera::Otrs::Attachment.new(params[:attachment]).to_hash elsif params[:attachment] && params[:attachment].is_a?(Array) params[:attachment].map do |a| Tessera::Otrs::Attachment.new(a).to_hash end end body = { Ticket: ticket } body = body.merge(Article: article) body = body.merge(Attachment: ) if Tessera::Api::TicketCreate.call(body) end |
.find(ticket_id) ⇒ Object
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/tessera/ticket.rb', line 6 def find(ticket_id) ticket = if ticket_id.is_a? Array ::Tessera::Api::TicketList.call(ticket_id) else ::Tessera::Api::TicketGet.call(ticket_id) end if ticket['Error'] raise TicketNotFound.new(ticket['Error']['ErrorMessage'], ticket['Error']['ErrorCode']) elsif ticket['Ticket'] && ticket['Ticket'].count > 1 ticket['Ticket'].map do |ticket_json| ::Tessera::Model::Ticket.new(ticket_json) end else ::Tessera::Model::Ticket.new(ticket['Ticket'].first) end end |
.where(params) ⇒ Object
rubocop:enable Metrics/MethodLength rubocop:enable Metrics/AbcSize
26 27 28 29 30 |
# File 'lib/tessera/ticket.rb', line 26 def where(params) result = Tessera::Api::TicketSearch.call(params) ticket_ids = result['TicketID'] ? result['TicketID'] : [] new(ticket_ids) end |
Instance Method Details
#count ⇒ Object
58 59 60 |
# File 'lib/tessera/ticket.rb', line 58 def count @result.size end |
#ticket_ids ⇒ Object
62 63 64 |
# File 'lib/tessera/ticket.rb', line 62 def ticket_ids @result.map(&:to_i) end |