Class: PacerApi::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/pacer_api/authenticator.rb

Constant Summary collapse

HOSTS =
{
  production: "pacer.login.uscourts.gov",
  qa: "qa-login.uscourts.gov"
}.freeze
PATH =
"/services/cso-auth"

Instance Method Summary collapse

Constructor Details

#initialize(login_id, password, client_code: nil, environment: :production) ⇒ Authenticator

Returns a new instance of Authenticator.



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pacer_api/authenticator.rb', line 18

def initialize(
  , password, client_code: nil, environment: :production
)
  @login_id = 
  @password = password
  @client_code = client_code
  @environment = environment
  @uri = URI::HTTPS.build(
    host: HOSTS.fetch(environment),
    path: PATH
  )
end

Instance Method Details

#authenticateObject



31
32
33
34
35
36
37
38
# File 'lib/pacer_api/authenticator.rb', line 31

def authenticate
  res = Faraday.post(@uri) { |req|
    req.headers["Content-Type"] = "application/json"
    req.headers["Accept"] = "application/json"
    req.body = build_request_body
  }
  parse_response(res.body)
end