Module: DList::User::Actions

Included in:
Client
Defined in:
lib/dblista/user/actions.rb

Overview

User client - actions

Instance Method Summary collapse

Instance Method Details

#add(body, type = 'bot') ⇒ Boolean

Adds bot/server to DList

Parameters:

  • body (Hash)

    raw body to send

  • type (Symbol) (defaults to: 'bot')

    type of entity (bot/server)

Returns:

  • (Boolean)

    true if operation succeded

Raises:



13
14
15
16
17
18
19
# File 'lib/dblista/user/actions.rb', line 13

def add(body, type = 'bot')
  raise DList::Error, DList::Errors::BODY_HASH unless body.is_a?(Hash)
  raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)

  DList._post("/#{type}s", body, @token)
  true
end

#delete(id, type = :bot) ⇒ Boolean

Deletes bot/server from DList

Parameters:

  • id (Integer)

    entity ID

  • type (Symbol) (defaults to: :bot)

    type of entity (bot/server)

Returns:

  • (Boolean)

    true if operation succeded

Raises:



39
40
41
42
43
44
45
# File 'lib/dblista/user/actions.rb', line 39

def delete(id, type = :bot)
  DList._validate_id id
  raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)

  DList._delete("/#{type}s/#{id}", nil, @token)
  true
end

#edit(body, type = :bot) ⇒ Boolean

Edits bot/server in DList

Parameters:

  • body (Hash)

    raw body to send

  • type (Symbol) (defaults to: :bot)

    type of entity (bot/server)

Returns:

  • (Boolean)

    true if operation succeded

Raises:



26
27
28
29
30
31
32
# File 'lib/dblista/user/actions.rb', line 26

def edit(body, type = :bot)
  raise DList::Error, DList::Errors::BODY_HASH unless body.is_a?(Hash)
  raise DList::Error, DList::Errors::TYPE_NOT_ALLOWED unless DList::User::Client::ALLOWED_TYPES.include?(type)

  DList._put("/#{type}s", body, @token)
  true
end

#generate_token(id) ⇒ Hash

Generates token for bot

Parameters:

  • id (Integer)

    bot ID

Returns:

  • (Hash)

    raw data from DList



66
67
68
69
# File 'lib/dblista/user/actions.rb', line 66

def generate_token(id)
  DList._validate_id id
  DList._get("/bots/stats/#{id}?token=#{@token}")
end

#manage_user(id, banned = false, premium = 0) ⇒ Boolean

Manages user (bans or adds premium) Available only for DList staff

Parameters:

  • id (Integer)

    user ID

  • banned (Boolean) (defaults to: false)

    user ban status

  • premium (Integer) (defaults to: 0)

    days for premium

Returns:

  • (Boolean)

    true if operation succeded



54
55
56
57
58
59
60
# File 'lib/dblista/user/actions.rb', line 54

def manage_user(id, banned = false, premium = 0)
  DList._post("/users/#{id}/manage", {
                  premium: premium,
                  ban: banned
                }, @token)
  true
end

#reset_token(id) ⇒ Hash

Resets token for bot

Parameters:

  • id (Integer)

    bot ID

Returns:

  • (Hash)

    raw data from DList



75
76
77
78
# File 'lib/dblista/user/actions.rb', line 75

def reset_token(id)
  DList._validate_id id
  DList._post("/bots/stats/#{id}/reset", nil, @token)
end