Class: EasyPost::Services::ApiKey

Inherits:
Service
  • Object
show all
Defined in:
lib/easypost/services/api_key.rb

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from EasyPost::Services::Service

Instance Method Details

#allObject

Retrieve a list of all ApiKey objects.



5
6
7
8
9
# 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) ⇒ Object

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



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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