Class: Mintsoft::AuthClient::AuthResource

Inherits:
Object
  • Object
show all
Defined in:
lib/mintsoft/auth_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ AuthResource

Returns a new instance of AuthResource.



37
38
39
# File 'lib/mintsoft/auth_client.rb', line 37

def initialize(client)
  @client = client
end

Instance Method Details

#authenticate(username, password) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mintsoft/auth_client.rb', line 41

def authenticate(username, password)
  validate_credentials!(username, password)

  response = @client.connection.post("/api/auth") do |req|
    req.body = {
      username: username,
      password: password
    }
  end

  if response.success?
    # the response body is like "\"xxxx-xx-xxxx\""
    if response.body.start_with?('"') && response.body.end_with?('"')
      response.body.gsub(/^["']|["']$/, "")
    else
      response.body
    end
  else
    handle_error_response(response)
  end
end