class EasyPost::Services::ApiKey

Public Instance Methods

all() click to toggle source

Retrieve a list of all ApiKey objects.

# File lib/easypost/services/api_key.rb, line 5
def all
  response = @client.make_request(:get, 'api_keys')

  EasyPost::InternalUtilities::Json.convert_json_to_object(response, EasyPost::Models::ApiKey)
end
retrieve_api_keys_for_user(id) click to toggle source

Retrieve a list of ApiKey objects (works for the authenticated user or a child user).

# File lib/easypost/services/api_key.rb, line 12
def retrieve_api_keys_for_user(id)
  api_keys = all

  if api_keys.id == id
    # This function was called on the authenticated user
    return api_keys.keys
  end

  # This function was called on a child user (authenticated as parent, only return this child user's details).
  api_keys.children.each do |child|
    if child.id == id
      return child.keys
    end
  end

  raise EasyPost::Errors::FilteringError.new(EasyPost::Constants::NO_USER_FOUND)
end