Module: NekosLife::API

Defined in:
lib/nekos/api.rb

Overview

Main API functions

Constant Summary collapse

BASE =
'https://nekos.life/api/v2'.freeze

Class Method Summary collapse

Class Method Details

.get(endpoint) ⇒ Hash

Requests an endpoint

Parameters:

  • endpoint (String)

    the endpoint

Returns:

  • (Hash)

    the response given in JSON



33
34
35
36
37
38
# File 'lib/nekos/api.rb', line 33

def get(endpoint)
  request(
    :get,
    "#{BASE}/#{endpoint}"
  )
end

.img(type) ⇒ Hash

Requests an image

Parameters:

  • type (String)

    the image type

Returns:

  • (Hash)

    the response given in JSON



23
24
25
26
27
28
# File 'lib/nekos/api.rb', line 23

def img(type)
  request(
    :get,
    "#{BASE}/img/#{type}"
  )
end

.request(type, *attributes) ⇒ Hash

Request an endpoint easily

Returns:

  • (Hash)

    the response given in JSON



14
15
16
17
18
# File 'lib/nekos/api.rb', line 14

def request(type, *attributes)
  parse_json(RestClient.send(type, *attributes))
rescue RuntimeError => e
  raise e
end