Class: ListCordRB::GetBots

Inherits:
Object
  • Object
show all
Defined in:
lib/listcordrb/getbots.rb

Overview

Stats and stuff, ya know.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query, sort = 'votes', limit = 1, page = 1) ⇒ GetBots

Initialize the get bots

Parameters:

  • query (String)

    Name of the bot.

  • sort (String) (defaults to: 'votes')

    Type of sort, can be votes, servers, newest, or invites, default votes.

  • limit (Integer) (defaults to: 1)

    amount of bots to return. Max 10, default 1.

  • page (Integer) (defaults to: 1)

    page of bots, takes limit and mulitplies by this.



8
9
10
11
12
13
14
15
# File 'lib/listcordrb/getbots.rb', line 8

def initialize(query, sort = 'votes', limit = 1, page = 1)
  @query = query
  @sort = sort
  @limit = limit
  @page = page
  url = "https://listcord.com/api/bots/#{sort}/#{limit}/#{page * limit - 1}"
  @data = JSON.parse(RestClient.get(url, params: { q: query }))
end

Instance Attribute Details

#dataObject (readonly) Also known as: to_s

Returns data in raw json form.

Returns:

  • data in raw json form.



18
19
20
# File 'lib/listcordrb/getbots.rb', line 18

def data
  @data
end

#limitObject (readonly)

Returns the original limit.

Returns:

  • the original limit.



29
30
31
# File 'lib/listcordrb/getbots.rb', line 29

def limit
  @limit
end

#pageObject (readonly)

Returns the original page.

Returns:

  • the original page.



32
33
34
# File 'lib/listcordrb/getbots.rb', line 32

def page
  @page
end

#queryObject (readonly)

Returns the original query.

Returns:

  • the original query.



23
24
25
# File 'lib/listcordrb/getbots.rb', line 23

def query
  @query
end

#sortObject (readonly)

Returns the original sort method.

Returns:

  • the original sort method.



26
27
28
# File 'lib/listcordrb/getbots.rb', line 26

def sort
  @sort
end

Instance Method Details

#firstInteger

Returns the ID of the first bot.

Returns:

  • (Integer)

    the ID of the first bot



40
41
42
# File 'lib/listcordrb/getbots.rb', line 40

def first
  @data[0].to_i
end

#nextObject

Go to the next page of bots



35
36
37
# File 'lib/listcordrb/getbots.rb', line 35

def next
  ListCordRB::GetBots.new(@query, @sort, @limit, @page + 1)
end