Class: Cic::Report

Inherits:
ActiveCic::Base show all
Defined in:
lib/cic/report.rb

Constant Summary

Constants inherited from ActiveCic::Base

ActiveCic::Base::BASE_URL

Instance Attribute Summary collapse

Attributes inherited from ActiveCic::Base

#attributes, #raw_attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveCic::Base

all, #method_missing

Constructor Details

#initialize(hash) ⇒ Report

Returns a new instance of Report.



8
9
10
# File 'lib/cic/report.rb', line 8

def initialize(hash)
  super(hash)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveCic::Base

Instance Attribute Details

#ticket_idObject (readonly)

Returns the value of attribute ticket_id.



6
7
8
# File 'lib/cic/report.rb', line 6

def ticket_id
  @ticket_id
end

Class Method Details

.find(ticket) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/cic/report.rb', line 12

def self.find(ticket)
  response = self.get("/reports.json")
  if response.success?
    report_hash = response.parsed_response["reports"].select { |report| report['ticket'] == ticket }.first
    report_hash ? self.new(report_hash) : nil
   else
    raise_exception(response.code, response.body)
  end
end

.where(params = {}) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/cic/report.rb', line 32

def self.where(params = {})
  response = self.get("/reports.json", query: params)
  if response.success?
    response.parsed_response['reports'].map { |report_hash| self.new(report_hash) }
   else
    raise_exception(response.code, response.body)
  end
end

Instance Method Details

#saveObject



22
23
24
25
26
27
28
29
30
# File 'lib/cic/report.rb', line 22

def save
  response = self.class.post("/reports.json", body: self.raw_attributes )
  if response.success?
    @ticket_id = response.parsed_response["reports"]["ticket"]
    true #POST always finds its way...
  else
    false
  end
end