Module: DDAPI::API

Defined in:
lib/dd-api/api.rb

Overview

List of methods representing endpoints in Discord Dungeons’s API

Constant Summary collapse

APIBASE =

The base URL of the Discord Dungeons REST API.

'http://api.discorddungeons.me'.freeze
RESBASE =

The base URL of the Discord Dungeons Alternate Resources.

'https://res.discorddungeons.me/images'.freeze

Class Method Summary collapse

Class Method Details

.all_guild_items(app) ⇒ Object



70
71
72
# File 'lib/dd-api/api.rb', line 70

def all_guild_items(app)
  get('all/gitems', app)['data']
end

.all_guilds(app) ⇒ Object



58
59
60
# File 'lib/dd-api/api.rb', line 58

def all_guilds(app)
  get('all/guilds', app)['data']
end

.all_items(app) ⇒ Object



66
67
68
# File 'lib/dd-api/api.rb', line 66

def all_items(app)
  get('all/items', app)['data']
end

.all_users(app) ⇒ Object



62
63
64
# File 'lib/dd-api/api.rb', line 62

def all_users(app)
  get('all/users', app)['data']
end

.api_baseString

Returns the currently used API base URL.

Returns:

  • (String)

    the currently used API base URL.



16
17
18
# File 'lib/dd-api/api.rb', line 16

def api_base
  APIBASE
end

.get(endpoint, app) ⇒ Object



38
39
40
# File 'lib/dd-api/api.rb', line 38

def get(endpoint, app)
  JSON.parse(RestClient.get("#{api_base}/"+endpoint, :'X-Api-Key' => app.api_key, :'User-Agent' => app.user_agent))
end

.get_guild(app, id) ⇒ Object



46
47
48
# File 'lib/dd-api/api.rb', line 46

def get_guild(app, id)
  get('guild/'+id, app)['data']
end

.get_guild_item(app, id) ⇒ Object



54
55
56
# File 'lib/dd-api/api.rb', line 54

def get_guild_item(app, id)
  get('gitem/'+id, app)['data']
end

.get_item(app, id) ⇒ Object



50
51
52
# File 'lib/dd-api/api.rb', line 50

def get_item(app, id)
  get('item/'+id, app)['data']
end

.get_user(app, id) ⇒ Object



42
43
44
# File 'lib/dd-api/api.rb', line 42

def get_user(app, id)
  get('user/'+id.to_s, app)['user']
end

.guild_icon_url(icon) ⇒ Object

Make an item image URL from the item image



30
31
32
# File 'lib/dd-api/api.rb', line 30

def guild_icon_url(icon)
  "#{res_base}/twemoji/"+icon.gsub(/\u0026#x/, "").gsub(/[;]/, "").gsub(/\u0026amp/, "-").downcase+".png"
end

.image_url(image) ⇒ Object

Make an item image URL from the item image



26
27
28
# File 'lib/dd-api/api.rb', line 26

def image_url(image)
  "#{res_base}/#{image}"
end

.res_baseString

Returns the currently used resource base URL.

Returns:

  • (String)

    the currently used resource base URL.



21
22
23
# File 'lib/dd-api/api.rb', line 21

def res_base
  RESBASE
end

.rget(endpoint, api_key, user_agent) ⇒ Object



34
35
36
# File 'lib/dd-api/api.rb', line 34

def rget(endpoint, api_key, user_agent)
  JSON.parse(RestClient.get("#{api_base}/"+endpoint, :'X-Api-Key' => api_key, :'User-Agent' => user_agent))
end