Class: StudyplusForSchoolSync::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/studyplus_for_school_sync/token.rb

Overview

Handling access token

Constant Summary collapse

END_POINT =
"/learning_material_supplier_api/v1/oauth/token"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url:, client_id:, client_secret:) ⇒ Token

Returns a new instance of Token.

Parameters:

  • base_url (String)

    API domain

  • client_id (String)

    Application ClientID

  • client_secret (String)

    Application Secret


17
18
19
20
21
22
23
24
25
26
# File 'lib/studyplus_for_school_sync/token.rb', line 17

def initialize(base_url:, client_id:, client_secret:)
  @base_url = base_url
  @client_id = client_id
  @client_secret = client_secret
  @conn = Faraday.new(headers: default_header) do |connection|
    connection.response :json
    connection.response :encoding
    connection.adapter Faraday.default_adapter
  end
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url


12
13
14
# File 'lib/studyplus_for_school_sync/token.rb', line 12

def base_url
  @base_url
end

#client_idObject (readonly)

Returns the value of attribute client_id


12
13
14
# File 'lib/studyplus_for_school_sync/token.rb', line 12

def client_id
  @client_id
end

#client_secretObject (readonly)

Returns the value of attribute client_secret


12
13
14
# File 'lib/studyplus_for_school_sync/token.rb', line 12

def client_secret
  @client_secret
end

#grant_typeObject (readonly)

Returns the value of attribute grant_type


12
13
14
# File 'lib/studyplus_for_school_sync/token.rb', line 12

def grant_type
  @grant_type
end

Instance Method Details

#create(authorization_code:, redirect_uri:) ⇒ Object

Creating a token from authorization code

Parameters:

  • authorization_code (String)

    Authorization Code

  • redirect_uri (String)

    Application Redirect URI


31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/studyplus_for_school_sync/token.rb', line 31

def create(authorization_code:, redirect_uri:)
  post(
    path: END_POINT,
    params: {
      client_id: client_id,
      client_secret: client_secret,
      redirect_uri: redirect_uri,
      grant_type: "authorization_code",
      code: authorization_code,
    }
  )
end

#refresh(refresh_token) ⇒ Object

Refresh Token

Parameters:

  • refresh_token (String)

    Refresh token obtained during token generation


46
47
48
49
50
51
52
53
54
55
56
# File 'lib/studyplus_for_school_sync/token.rb', line 46

def refresh(refresh_token)
  post(
    path: END_POINT,
    params: {
      client_id: client_id,
      client_secret: client_secret,
      grant_type: "refresh_token",
      refresh_token: refresh_token,
    }
  )
end