Class: PacerApi::Batch::CaseSearch

Inherits:
Object
  • Object
show all
Includes:
Status
Defined in:
lib/pacer_api/batch/case_search.rb

Defined Under Namespace

Classes: Download

Constant Summary collapse

SEARCH_PATH =
"cases/download"
STATUS_PATH =
"cases/download/status/%d"
DOWNLOAD_PATH =
"cases/download/%d"
DELETE_PATH =
"cases/reports/%d"
LIST_PATH =
"cases/reports"

Constants included from Status

Status::COMPLETED, Status::FAILED, Status::RUNNING, Status::WAITING

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Status

#completed?, #failed?, #running?, #waiting?

Constructor Details

#initialize(session, report_info) ⇒ CaseSearch

Returns a new instance of CaseSearch.



27
28
29
30
31
# File 'lib/pacer_api/batch/case_search.rb', line 27

def initialize(session, report_info)
  @session = session
  @report_info = report_info
  @report_id = report_info.fetch(:report_id)
end

Class Method Details

.all(session) ⇒ Object



22
23
24
25
# File 'lib/pacer_api/batch/case_search.rb', line 22

def self.all(session)
  payload = session.get(LIST_PATH)
  payload.fetch(:content).map { |doc| new(session, doc) }
end

.create(session, params) ⇒ Object



17
18
19
20
# File 'lib/pacer_api/batch/case_search.rb', line 17

def self.create(session, params)
  payload = session.post(SEARCH_PATH, params)
  new(session, payload)
end

Instance Method Details

#deleteObject



55
56
57
# File 'lib/pacer_api/batch/case_search.rb', line 55

def delete
  @session.delete(format(DELETE_PATH, @report_id))
end

#downloadObject



45
46
47
# File 'lib/pacer_api/batch/case_search.rb', line 45

def download
  Download.new(@session.get(format(DOWNLOAD_PATH, @report_id)))
end

#download_feeObject



33
34
35
# File 'lib/pacer_api/batch/case_search.rb', line 33

def download_fee
  @report_info.fetch(:download_fee, nil)
end

#download_xmlObject



49
50
51
52
53
# File 'lib/pacer_api/batch/case_search.rb', line 49

def download_xml
  @session.request(:get, format(DOWNLOAD_PATH, @report_id)) { |req|
    req.headers["Accept"] = "application/xml"
  }.body
end

#poll!Object



41
42
43
# File 'lib/pacer_api/batch/case_search.rb', line 41

def poll!
  @report_info = @session.get(format(STATUS_PATH, @report_id))
end

#record_countObject



37
38
39
# File 'lib/pacer_api/batch/case_search.rb', line 37

def record_count
  @report_info.fetch(:record_count, nil)
end

#statusObject



59
60
61
# File 'lib/pacer_api/batch/case_search.rb', line 59

def status
  @report_info.fetch(:status)
end