Sha256: 1fb73d5e8bdab13104aa0687abd47ce1e93d9343d0242bcd3e55b63b836beac4

Contents?: true

Size: 886 Bytes

Versions: 7

Compression:

Stored size: 886 Bytes

Contents

# frozen_string_literal: true

class EasyPost::Services::ApiKey < EasyPost::Services::Service
  # Retrieve a list of all ApiKey objects.
  def all
    response = @client.make_request(:get, 'api_keys')

    EasyPost::InternalUtilities::Json.convert_json_to_object(response, EasyPost::Models::ApiKey)
  end

  # Retrieve a list of ApiKey objects (works for the authenticated user or a child user).
  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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
easypost-6.4.1 lib/easypost/services/api_key.rb
easypost-6.4.0 lib/easypost/services/api_key.rb
easypost-6.3.0 lib/easypost/services/api_key.rb
easypost-6.2.0 lib/easypost/services/api_key.rb
easypost-6.1.1 lib/easypost/services/api_key.rb
easypost-6.1.0 lib/easypost/services/api_key.rb
easypost-6.0.0 lib/easypost/services/api_key.rb