class TinyGate::Client

Attributes

app_id[R]
callback_token[R]
root_url[R]

Public Class Methods

new(root_url = self.class.config.root_url, app_id = self.class.config.app_id, callback_token = self.class.config.callback_token) click to toggle source
# 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

Public Instance Methods

fetch_user(token, user_id) click to toggle source
# 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_url() click to toggle source
# File lib/tiny_gate/client.rb, line 20
def login_url
  "#{root_url}/auth/sessions/new?app_id=#{app_id}#{callback_token_params}"
end
logout_url() click to toggle source
# File lib/tiny_gate/client.rb, line 24
def logout_url
  "#{root_url}/signout"
end
signed_in?(token, user_id) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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

Private Instance Methods

auth_base_url() click to toggle source
# File lib/tiny_gate/client.rb, line 70
def auth_base_url
  "#{root_url}/auth/sessions"
end
callback_token_params() click to toggle source
# File lib/tiny_gate/client.rb, line 52
def callback_token_params
  if callback_token
    "&callback_token=#{callback_token}"
  end
end
me_url() click to toggle source
# File lib/tiny_gate/client.rb, line 66
def me_url
  "#{auth_base_url}/me"
end
switch_org_url() click to toggle source
# File lib/tiny_gate/client.rb, line 74
def switch_org_url
  "#{root_url}/auth/sessions/switch_org"
end
validate_signed_in_url() click to toggle source
# File lib/tiny_gate/client.rb, line 62
def validate_signed_in_url
  "#{auth_base_url}/signed_in"
end
validate_url() click to toggle source
# File lib/tiny_gate/client.rb, line 58
def validate_url
  "#{auth_base_url}/validate"
end