Class: Shikimori::API::REST

Inherits:
Object
  • Object
show all
Defined in:
lib/shikimori/api/rest.rb

Overview

Helpers to make requests

Instance Method Summary collapse

Constructor Details

#initialize(app_name: nil, access_token: nil, refresh_token: nil, **options) ⇒ REST

Returns a new instance of REST.



7
8
9
10
11
12
13
14
15
# File 'lib/shikimori/api/rest.rb', line 7

def initialize(app_name: nil, access_token: nil, refresh_token: nil, **options)
  @app_name = app_name
  @access_token = access_token
  @refresh_token = refresh_token
  @proxy_host = options.fetch(:proxy_host, nil)
  @proxy_port = options.fetch(:proxy_port, nil)
  @proxy_user = options.fetch(:proxy_user, nil)
  @proxy_password = options.fetch(:proxy_password, nil)
end

Instance Method Details

#delete(uri, **options) ⇒ Object



32
33
34
35
# File 'lib/shikimori/api/rest.rb', line 32

def delete(uri, **options)
  response, _json = request(:delete, uri, **options)
  [Net::HTTPNoContent, Net::HTTPSuccess].any? { response.is_a?(_1) }
end

#get(uri, **options) ⇒ Object



17
18
19
20
# File 'lib/shikimori/api/rest.rb', line 17

def get(uri, **options)
  _response, json = request(:get, uri, **options)
  json
end

#post(uri, data, **options) ⇒ Object



22
23
24
25
# File 'lib/shikimori/api/rest.rb', line 22

def post(uri, data, **options)
  _response, json = request(:post, uri, data, **options)
  json
end

#put(uri, data, **options) ⇒ Object



27
28
29
30
# File 'lib/shikimori/api/rest.rb', line 27

def put(uri, data, **options)
  _response, json = request(:put, uri, data, **options)
  json
end