Module: StrawberryAPI::Client::ApiKeys

Included in:
StrawberryAPI::Client
Defined in:
lib/strawberry_api/client/api_keys.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at



9
10
11
# File 'lib/strawberry_api/client/api_keys.rb', line 9

def created_at
  @created_at
end

#idObject

Returns the value of attribute id



5
6
7
# File 'lib/strawberry_api/client/api_keys.rb', line 5

def id
  @id
end

#keyObject

Returns the value of attribute key



8
9
10
# File 'lib/strawberry_api/client/api_keys.rb', line 8

def key
  @key
end

#nameObject

Returns the value of attribute name



7
8
9
# File 'lib/strawberry_api/client/api_keys.rb', line 7

def name
  @name
end

#updated_atObject

Returns the value of attribute updated_at



10
11
12
# File 'lib/strawberry_api/client/api_keys.rb', line 10

def updated_at
  @updated_at
end

#user_idObject

Returns the value of attribute user_id



6
7
8
# File 'lib/strawberry_api/client/api_keys.rb', line 6

def user_id
  @user_id
end

Instance Method Details

#api_key(user_id:) ⇒ Array<StrawberryAPI::ApiKey>

Fetches user API keys

Parameters:

  • user_id (Integer)

    Strawberry user id

Returns:



18
19
20
21
22
# File 'lib/strawberry_api/client/api_keys.rb', line 18

def api_key(user_id:)
  get("/users/#{user_id}/api_keys").parse['api_keys']&.map do |api_key|
    ApiKey.new(api_key)
  end
end

#create_api_key(user_id:, name:) ⇒ ApiKey

Creates user API key

Parameters:

  • user_id (Integer)

    Strawberry user id

  • name (String)

    Name of the API key to create

Returns:

  • (ApiKey)

    The created user API key



31
32
33
34
# File 'lib/strawberry_api/client/api_keys.rb', line 31

def create_api_key(user_id:, name:)
  data = post("/users/#{user_id}/api_keys", body: {name: name}.to_json).parse['api_key']
  data.nil? ? nil : ApiKey.new(data)
end

#delete_api_key(user_id:, api_key_id:) ⇒ Boolean

Deletes user API key

Parameters:

  • user_id (Integer)

    Strawberry user id

  • api_key_id (Integer)

    Id of the API key to delete

Returns:

  • (Boolean)

    Success



43
44
45
# File 'lib/strawberry_api/client/api_keys.rb', line 43

def delete_api_key(user_id:, api_key_id:)
  delete("/users/#{user_id}/api_keys/#{api_key_id}").success?
end