class GlimrApiClient::FindCase

TODO: rename so it follow api spec

Constants

TRIBUNAL_JURISDICTION_ID

Public Class Methods

find(case_reference, confirmation_code) click to toggle source

TODO: Case should use ‘#call(params)` directly, like everything else.

# File lib/glimr_api_client/find_case.rb, line 10
def self.find(case_reference, confirmation_code)
  new(case_reference, confirmation_code).call
end
new(case_reference, confirmation_code) click to toggle source
# File lib/glimr_api_client/find_case.rb, line 14
def initialize(case_reference, confirmation_code)
  @case_reference = case_reference
  @confirmation_code = confirmation_code
end

Public Instance Methods

call() click to toggle source
# File lib/glimr_api_client/find_case.rb, line 19
def call
  post
  self
end
fees() click to toggle source

We only care about outstanding fee liabilities, wrt what we are asking the taxpayer to pay

# File lib/glimr_api_client/find_case.rb, line 37
def fees
  unpaid_fees
end
title() click to toggle source

Case title is returned with each fee liability, rather than as a top-level attribute of the case. If there are any unpaid fee liabilities, we want to take the title from the first of these (because that is the most relevant title)

# File lib/glimr_api_client/find_case.rb, line 28
def title
  @title ||= begin
               fee = unpaid_fees.any? ? unpaid_fees.first : all_fees.first
               fee.nil? ? 'Missing Title' : fee.case_title
             end
end

Private Instance Methods

all_fees() click to toggle source
# File lib/glimr_api_client/find_case.rb, line 47
def all_fees
  @all_fees ||= response_body.fetch(:feeLiabilities).map do |fee|
    OpenStruct.new(
      glimr_id: Integer(fee.fetch(:feeLiabilityId)),
      description: fee.fetch(:onlineFeeTypeDescription),
      amount: Integer(fee.fetch(:payableWithUnclearedInPence)),
      case_title: fee.fetch(:caseTitle)
    )
  end
end
endpoint() click to toggle source
# File lib/glimr_api_client/find_case.rb, line 58
def endpoint
  '/requestcasefees'
end
re_raise_error(body) click to toggle source
Calls superclass method GlimrApiClient::Api#re_raise_error
# File lib/glimr_api_client/find_case.rb, line 62
def re_raise_error(body)
  error = body.fetch(:message, nil)
  case body.fetch(:glimrerrorcode, nil)
  when 212 # TribunalCase for CaseNumber not found
    raise NotFound, error
  when 213 # Invalid CaseNumber/CaseConfirmationCode combination
    raise InvalidCaseNumber, error
  end
  super(message: error)
end
request_body() click to toggle source
# File lib/glimr_api_client/find_case.rb, line 73
def request_body
  {
    # jurisdictionId is in the spec for this method, but doesn't actually seem to be necessary.
    # Leaving it here, just in case a requirement is added in future
    jurisdictionId: TRIBUNAL_JURISDICTION_ID,
    caseNumber: @case_reference,
    confirmationCode: @confirmation_code
  }
end
unpaid_fees() click to toggle source
# File lib/glimr_api_client/find_case.rb, line 43
def unpaid_fees
  @unpaid_fees ||= all_fees.find_all {|fee| fee.amount > 0}
end