Class: Glitch_Auth

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

Overview

This class builds a url that can be used to authenticate with the API for Glitch, the game (www.glitch.com).

Instance Method Summary (collapse)

Constructor Details

- (Glitch_Auth) initialize(token, redirect_uri)

Default constructor.

Parameters:

  • token (String)

    the API token associated with the client's API key

  • redirect_uri (String)

    the callback URL associated with the client's API key



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/glitch_auth.rb', line 9

def initialize(token, redirect_uri)

	# unique to glitch
	@path = 'https://api.glitch.com/oauth2/authorize'
	
	# unique to client
	@token = token	
	@redirect_uri = redirect_uri

	# default option values
	response_type('code')
	scope('identity')
	state('hello-world')

end

Instance Method Details

- (Object) redirect_uri(value)

Parameters:

  • value (String)

    a string specifying the redirect_uri already associated with this client's API key.



32
33
34
# File 'lib/glitch_auth.rb', line 32

def redirect_uri(value)
	@redirect_uri = value
end

- (Object) response_type(value)

Parameters:

  • value (String)

    a string specifying the response_type required. Must be either 'code' or 'token'.



37
38
39
40
41
42
43
# File 'lib/glitch_auth.rb', line 37

def response_type(value)
	if (value == 'code' || value == 'token') 								
		@response_type = value
	else
		raise ArgumentError, 'Invalid response type.'
	end	
end

- (Object) scope(value)

Parameters:

  • value (String)

    a string specifying the scope of the request. Must be either 'identity', 'read' or 'write'.



46
47
48
49
50
51
52
# File 'lib/glitch_auth.rb', line 46

def scope(value)	
	if (value == 'identity' || value == 'read' || value == 'write') 								
		@scope = value
	else
		raise ArgumentError, 'Invalid scope.'
	end
end

- (Object) state(value)

Parameters:

  • value (String)

    a string specifying the state.



55
56
57
# File 'lib/glitch_auth.rb', line 55

def state(value)
	@state = value
end

- (Object) token(value)

Parameters:

  • value (String)

    a string specifying the token already associated with this client's API key.



27
28
29
# File 'lib/glitch_auth.rb', line 27

def token(value)
	@token = value
end

- (String) uri

A URI for authenticating with Glitch, customised as per the settings specified

Returns:

  • (String)

    a URI for authenticating with Glitch, customised as per the settings specified



60
61
62
# File 'lib/glitch_auth.rb', line 60

def uri
	"#{@path}?response_type=#{@response_type}&client_id=#{@token}&redirect_uri=#{@redirect_uri}&scope=#{@scope}&state=#{@state}"		
end