module Pixela::Client::UserMethods

Public Instance Methods

create_user(agree_terms_of_service:, not_minor:) click to toggle source

Create a new Pixela user.

@param agree_terms_of_service [Boolean] @param not_minor [Boolean]

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/post-user

@example

client.create_user(agree_terms_of_service: true, not_minor: true)
# File lib/pixela/client/user_methods.rb, line 15
def create_user(agree_terms_of_service:, not_minor:)
  params = {
    token:               token,
    username:            username,
    agreeTermsOfService: to_boolean_string(agree_terms_of_service),
    notMinor:            to_boolean_string(not_minor),
  }

  with_error_handling do
    connection(request_headers: default_headers).post("users", params).body
  end
end
delete_user() click to toggle source

Deletes the specified registered user.

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/delete-user

@example

client.delete_user
# File lib/pixela/client/user_methods.rb, line 65
def delete_user
  with_error_handling do
    connection.delete("users/#{username}").body
  end
end
update_user(new_token:) click to toggle source

Updates the authentication token for the specified user.

@param new_token [String]

@return [Pixela::Response]

@raise [Pixela::PixelaError] API is failed

@see docs.pixe.la/entry/put-user

@example

client.update_user(new_token: "thisissecret")
# File lib/pixela/client/user_methods.rb, line 40
def update_user(new_token:)
  params = {
    newToken: new_token,
  }

  response =
    with_error_handling do
      connection.put("users/#{username}", params).body
    end

  @token = new_token

  response
end