class Memerator::Profile

A profile is a user, but has more details. Usually, only the authenticated user can see these.

Public Class Methods

new(data, token: nil) click to toggle source

@!visibility private

# File lib/memerator/profile.rb, line 5
def initialize(data, token: nil)
  @data = data
  @token = token
end

Public Instance Methods

bio=(new_bio) click to toggle source

Update your Bio! @return [true] the success

# File lib/memerator/profile.rb, line 39
def bio=(new_bio)
  response = JSON.parse(RestClient.post("https://api.memerator.me/v1/profile/me", { "bio" => new_bio }.to_json, Authorization: @token, 'Content-Type': :json))
  @data['bio'] = new_bio
  response['success']
end
pro_expires() click to toggle source

@return [Time, nil] the time when your Pro subscription expires, if you have one

# File lib/memerator/profile.rb, line 11
def pro_expires
  Time.parse(@data['pro']['expires'])
end
pro_since() click to toggle source

@return [Time, nil] the time when your Pro subscription started, if you have one

# File lib/memerator/profile.rb, line 16
def pro_since
  Time.parse(@data['pro']['since'])
end
username=(new_username) click to toggle source

Set your username Username Requirements:

Be between 2 and 32 characters.
Not be in use
Can't be only numbers
Can't have special characters Allowed: (A-Z|a-z|0-9|_|.)

@return [true] if the username was changed @raise [ArgumentError] if the requirements are not met

# File lib/memerator/profile.rb, line 28
def username=(new_username)
  response = JSON.parse(RestClient.post("https://api.memerator.me/v1/profile/me", { "username" => new_username }.to_json, Authorization: @token, 'Content-Type': :json))
  @data['username'] = new_username
  response['success']
rescue RestClient::BadRequest => error
  why = JSON.parse(error.response.body)['error']
  raise ArgumentError, "Your username does not match the requirements! #{why}"
end