Class: VRE::Service

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

Direct Known Subclasses

Ch31Form

Instance Method Summary collapse

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

#with_monitoring

Methods inherited from Common::Client::Base

configuration, #raise_backend_exception

Methods included from SentryLogging

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

Instance Method Details

#get_tokenHash

Makes call to VRE and retrieves a token. Token is valid for 3 minutes so we just fire this on every api call

Returns:

  • (Hash)

    the student’s address



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vre/service.rb', line 15

def get_token
  with_monitoring do
    conn = Faraday.new(
      "#{Settings.veteran_readiness_and_employment.auth_endpoint}?grant_type=client_credentials",
      headers: { 'Authorization' => "Basic #{Settings.veteran_readiness_and_employment.credentials}" }
    )

    request = conn.post
    JSON.parse(request.body)['access_token']
  end
end

#request_headersObject



38
39
40
41
42
# File 'lib/vre/service.rb', line 38

def request_headers
  {
    Authorization: "Bearer #{get_token}"
  }
end

#send_to_vre(payload:) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/vre/service.rb', line 27

def send_to_vre(payload:)
  with_monitoring do
    perform(
      :post,
      end_point,
      payload,
      request_headers
    ) # see lib/common/client/base.rb#L94
  end
end