Class: TinyGate::Client

Inherits:
Object
  • Object
show all
Extended by:
Dry::Configurable
Defined in:
lib/tiny_gate/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(root_url = self.class.config.root_url, app_id = self.class.config.app_id, callback_token = self.class.config.callback_token) ⇒ Client

Returns a new instance of Client.



14
15
16
17
18
# File 'lib/tiny_gate/client.rb', line 14

def initialize(root_url = self.class.config.root_url, app_id = self.class.config.app_id, callback_token = self.class.config.callback_token)
  @root_url = root_url
  @app_id = app_id
  @callback_token = callback_token
end

Instance Method Details

#fetch_user(token, user_id) ⇒ Object



38
39
40
41
# File 'lib/tiny_gate/client.rb', line 38

def fetch_user(token, user_id)
  response = HTTP.post(me_url, json: {user_id: user_id, token: token, app_id: app_id})
  Types::SessionResponse.new(response)
end

#login_urlObject



20
21
22
# File 'lib/tiny_gate/client.rb', line 20

def 
  "#{root_url}/auth/sessions/new?app_id=#{app_id}#{callback_token_params}"
end

#logout_urlObject



24
25
26
# File 'lib/tiny_gate/client.rb', line 24

def logout_url
  "#{root_url}/signout"
end

#signed_in?(token, user_id) ⇒ Boolean

Returns:



33
34
35
36
# File 'lib/tiny_gate/client.rb', line 33

def signed_in?(token, user_id)
  response = HTTP.post(validate_signed_in_url, json: {user_id: user_id, token: token, app_id: app_id})
  response.status == 200
end

#switch_org(token, organization_id, user_id) ⇒ Object



43
44
45
46
# File 'lib/tiny_gate/client.rb', line 43

def switch_org(token, organization_id, user_id)
  response = HTTP.post(switch_org_url, json: {token: token, organization_id: organization_id, user_id: user_id, app_id: app_id})
  Types::SwitchOrgResponse.new(response).new_token_url
end

#validate(payload) ⇒ Object



28
29
30
31
# File 'lib/tiny_gate/client.rb', line 28

def validate(payload)
  response = HTTP.post(validate_url, json: payload.merge(app_id: app_id))
  Types::SessionResponse.new(response)
end