Class: Caseflow::Service

Inherits:
Common::Client::Base show all
Includes:
Common::Client::Concerns::Monitoring, SentryLogging
Defined in:
lib/caseflow/service.rb

Overview

Proxy Service for appeals in Caseflow.

Examples:

Create a service and fetching caseflow for a user

caseflow_response = Caseflow::Service.new.get_appeals(user)

Constant Summary collapse

STATSD_KEY_PREFIX =
'api.appeals'
CASEFLOW_V2_API_PATH =
'/api/v2/appeals'
CASEFLOW_V3_API_PATH =
'/api/v3/decision_reviews'
DEFAULT_HEADERS =
{ 'Authorization' => "Token token=#{Settings.caseflow.app_token}" }.freeze

Instance Method Summary collapse

Methods included from Common::Client::Concerns::Monitoring

#increment, #increment_failure, #increment_total, #with_monitoring

Methods included from SentryLogging

#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger, #set_sentry_metadata

Methods inherited from Common::Client::Base

#config, configuration, #connection, #delete, #get, #perform, #post, #put, #raise_backend_exception, #raise_not_authenticated, #request, #sanitize_headers!, #service_name

Instance Method Details

#authorized_perform(method, path, params, additional_headers = nil, options = nil) ⇒ Object (private)



98
99
100
# File 'lib/caseflow/service.rb', line 98

def authorized_perform(method, path, params, additional_headers = nil, options = nil)
  perform(method, path, params, DEFAULT_HEADERS.merge(additional_headers || {}), options)
end

#create_higher_level_review(body) ⇒ Hash

Create a HLR in Caseflow.

Parameters:

  • body (Hash)

    The HLR’s attributes.

Returns:

  • (Hash)

    Response object.



79
80
81
82
83
# File 'lib/caseflow/service.rb', line 79

def create_higher_level_review(body)
  with_monitoring do
    authorized_perform(:post, "#{CASEFLOW_V3_API_PATH}/higher_level_reviews", body)
  end
end

#get_appeals(user, additional_headers = {}) ⇒ Caseflow::Responses::Caseflow

Returns caseflow data for a user by their SSN.

Parameters:

  • user (User)

    The user object, usually the ‘@current_user` from a controller.

  • additional_headers (Hash) (defaults to: {})

    Any additional HTTP headers you want to include in the request.

Returns:



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/caseflow/service.rb', line 31

def get_appeals(user, additional_headers = {})
  with_monitoring do
    response = authorized_perform(
      :get,
      CASEFLOW_V2_API_PATH,
      {},
      additional_headers.merge('ssn' => user.ssn)
    )
    Caseflow::Responses::Caseflow.new(response.body, response.status)
  end
end

#get_contestable_issues(headers:, benefit_type:, decision_review_type:) ⇒ Hash

Returns contestable issues for a veteran.

Parameters:

  • headers (Hash)

    Headers to include.

  • decision_review_type (String)

    The type of decision review (appeals (nod), higher_level_reviews, etc)

Returns:

  • (Hash)

    Response object.



62
63
64
65
66
67
68
69
70
71
# File 'lib/caseflow/service.rb', line 62

def get_contestable_issues(headers:, benefit_type:, decision_review_type:)
  with_monitoring do
    authorized_perform(
      :get,
      "#{CASEFLOW_V3_API_PATH}/#{decision_review_type}/contestable_issues/#{benefit_type}".chomp('/'),
      {},
      headers
    )
  end
end

#get_legacy_appeals(headers:) ⇒ Object

Returns caseflow data for a user via their SSN or file_number passed as headers



44
45
46
47
48
49
50
51
52
53
# File 'lib/caseflow/service.rb', line 44

def get_legacy_appeals(headers:)
  with_monitoring do
    authorized_perform(
      :get,
      "#{CASEFLOW_V3_API_PATH}/legacy_appeals".chomp('/'),
      {},
      headers
    )
  end
end

#healthcheckFaraday::Response

Pings the Caseflow health check endpoint.

Returns:

  • (Faraday::Response)

    Faraday response instance.



90
91
92
93
94
# File 'lib/caseflow/service.rb', line 90

def healthcheck
  with_monitoring do
    perform(:get, '/health-check', nil)
  end
end