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) ⇒ REST

Returns a new instance of REST.



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

def initialize(app_name: nil, access_token: nil, refresh_token: nil)
  @app_name = app_name
  @access_token = access_token
  @refresh_token = refresh_token
end

Instance Method Details

#delete(uri, **options) ⇒ Object



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

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

#get(uri, **options) ⇒ Object



13
14
15
16
# File 'lib/shikimori/api/rest.rb', line 13

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

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



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

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

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



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

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