Sha256: 3478892e334378de145d604512b2e304339087738b02acfcc3f6215f4187ba4f

Contents?: true

Size: 1.58 KB

Versions: 7

Compression:

Stored size: 1.58 KB

Contents

module Pixela::Client::UserMethods
  # 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 https://docs.pixe.la/entry/post-user
  #
  # @example
  #   client.create_user(agree_terms_of_service: true, not_minor: true)
  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(default_headers).post("users", params).body
    end
  end

  # Updates the authentication token for the specified user.
  #
  # @param new_token [String]
  #
  # @return [Pixela::Response]
  #
  # @raise [Pixela::PixelaError] API is failed
  #
  # @see https://docs.pixe.la/entry/put-user
  #
  # @example
  #   client.update_user(new_token: "thisissecret")
  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

  # Deletes the specified registered user.
  #
  # @return [Pixela::Response]
  #
  # @raise [Pixela::PixelaError] API is failed
  #
  # @see https://docs.pixe.la/entry/delete-user
  #
  # @example
  #   client.delete_user
  def delete_user
    with_error_handling do
      connection.delete("users/#{username}").body
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pixela-2.0.0 lib/pixela/client/user_methods.rb
pixela-1.5.0 lib/pixela/client/user_methods.rb
pixela-1.4.2 lib/pixela/client/user_methods.rb
pixela-1.4.1 lib/pixela/client/user_methods.rb
pixela-1.4.0 lib/pixela/client/user_methods.rb
pixela-1.3.1 lib/pixela/client/user_methods.rb
pixela-1.3.0 lib/pixela/client/user_methods.rb