Class: OmniAuth::ExpressoV3::AuthClient

Inherits:
Object
  • Object
show all
Defined in:
lib/omniauth-expressov3/expressov3_auth_client.rb

Defined Under Namespace

Classes: AuthenticationError, ConnectionError, MissingArgumentsError

Constant Summary collapse

SERVICE_URL =
"https://expressobr.serpro.gov.br"
VALID_ADAPTER_CONFIGURATION_KEYS =
[:service_url]

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AuthClient

Returns a new instance of AuthClient.



14
15
16
17
18
# File 'lib/omniauth-expressov3/expressov3_auth_client.rb', line 14

def initialize(options={})
  service_url = options['service_url'] || SERVICE_URL
  @debug = options['debug'] || options[:debug]
  @json_tine = JSONRPCTineConnection.new service_url, @debug
end

Instance Method Details

#authenticate(username, password) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/omniauth-expressov3/expressov3_auth_client.rb', line 25

def authenticate(username, password)
  validate_arguments(username, password)
  auth_params = {"username" => username,"password" => password}

  @json_tine.send 'Tinebase.login', auth_params

  # check if user is authenticated,  raises an authentication if not
  (@json_tine.result)
  #return user data
  build_struct @json_tine.result
end

#closeObject



57
58
59
# File 'lib/omniauth-expressov3/expressov3_auth_client.rb', line 57

def close
  @json_tine.close if @json_tine
end

#get_user_data(args = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/omniauth-expressov3/expressov3_auth_client.rb', line 42

def get_user_data args={}
  #request to get user data
  @json_tine.send 'Tinebase.getAllRegistryData', args

  # hash with user data
  build_struct :keys => @json_tine.result['keys'],
      :currentAccount => @json_tine.result['Tinebase']['currentAccount'],
      :userContact    => @json_tine.result['Tinebase']['userContact'],
      :expressoAccount    => @json_tine.result['Expressomail']['accounts']['results'][0]
end

#last_raw_dataObject



53
54
55
# File 'lib/omniauth-expressov3/expressov3_auth_client.rb', line 53

def last_raw_data
  @json_tine.last_body
end

#send(method, args = {}) ⇒ Object



20
21
22
23
# File 'lib/omniauth-expressov3/expressov3_auth_client.rb', line 20

def send(method_name, args={})
  @json_tine.send(method_name, args)
  @json_tine.result
end