Class: Shikimori::OAuth2::Client

Inherits:
OAuth2::Client
  • Object
show all
Defined in:
lib/shikimori/oauth2/client.rb

Overview

Client for Shikimori OAuth2

Constant Summary collapse

SCOPE_JOIN_SYMBOL =
'+'
SCOPE_JOIN_ENCODED_SYMBOL =
'%2B'

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret, options = {}, app_name: config.app_name, &block) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/shikimori/oauth2/client.rb', line 10

def initialize(
  client_id,
  client_secret,
  options = {},
  app_name: config.app_name,
  &block
)
  options = config.options.merge(options)

  @app_name = app_name

  super(client_id, client_secret, options, &block)
end

Instance Method Details

#authorize_url(params = {}) ⇒ Object



24
25
26
27
# File 'lib/shikimori/oauth2/client.rb', line 24

def authorize_url(params = {})
  # Shikimori only works with `+` sign, not encoded value
  super(params).gsub(SCOPE_JOIN_ENCODED_SYMBOL, SCOPE_JOIN_SYMBOL)
end

#configObject



36
37
38
# File 'lib/shikimori/oauth2/client.rb', line 36

def config
  @config ||= OAuth2.config
end

#get_token(params, access_token_opts = {}, extract_access_token = nil, &block) ⇒ Object



29
30
31
32
33
34
# File 'lib/shikimori/oauth2/client.rb', line 29

def get_token(params, access_token_opts = {}, extract_access_token = nil, &block)
  params[:headers] ||= {}
  params[:headers]['User-Agent'] ||= @app_name

  super(params, access_token_opts, extract_access_token, &block)
end