Class: Memerator::Profile

Inherits:
User
  • Object
show all
Defined in:
lib/memerator/profile.rb

Overview

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

Instance Method Summary collapse

Methods inherited from User

#bio, #followers, #following, #id, #joined, #link, #memes, #pro?, #staff?, #translator?, #username, #verified?

Instance Method Details

#bio=(new_bio) ⇒ true

Update your Bio!

Returns:

  • (true)

    the success


39
40
41
42
43
# 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_expiresTime?

Returns the time when your Pro subscription expires, if you have one.

Returns:

  • (Time, nil)

    the time when your Pro subscription expires, if you have one


11
12
13
# File 'lib/memerator/profile.rb', line 11

def pro_expires
  Time.parse(@data['pro']['expires'])
end

#pro_sinceTime?

Returns the time when your Pro subscription started, if you have one.

Returns:

  • (Time, nil)

    the time when your Pro subscription started, if you have one


16
17
18
# File 'lib/memerator/profile.rb', line 16

def pro_since
  Time.parse(@data['pro']['since'])
end

#username=(new_username) ⇒ true

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|_|.)

Returns:

  • (true)

    if the username was changed

Raises:

  • (ArgumentError)

    if the requirements are not met


28
29
30
31
32
33
34
35
# 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