Class: Tidas::Identity

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



6
7
8
# File 'lib/tidas/identity.rb', line 6

def app_name
  @app_name
end

#deactivatedObject (readonly)

Returns the value of attribute deactivated.



6
7
8
# File 'lib/tidas/identity.rb', line 6

def deactivated
  @deactivated
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/tidas/identity.rb', line 6

def id
  @id
end

#public_keyObject (readonly)

Returns the value of attribute public_key.



6
7
8
# File 'lib/tidas/identity.rb', line 6

def public_key
  @public_key
end

Class Method Details

.activate(attributes) ⇒ Object



71
72
73
74
# File 'lib/tidas/identity.rb', line 71

def self.activate(attributes)
  tidas_id = attributes[:tidas_id]
  Client.activate(tidas_id)
end

.deactivate(attributes) ⇒ Object



66
67
68
69
# File 'lib/tidas/identity.rb', line 66

def self.deactivate(attributes)
  tidas_id = attributes[:tidas_id]
  Client.deactivate(tidas_id)
end

.enroll(attributes) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/tidas/identity.rb', line 47

def self.enroll(attributes)
  data = attributes[:data]
  if attributes[:options] != nil
    tidas_id = attributes[:options][:tidas_id]
    overwrite = attributes[:options][:overwrite]
  end
  if overwrite && overwrite != true
    raise(ParameterError,"Overwrite may only be called as an enrollment option if the value is set to true")
  end

  Client.enroll(data, tidas_id, overwrite)
end

.get(id) ⇒ Object



13
14
15
16
# File 'lib/tidas/identity.rb', line 13

def self.get(id)
  resp = Client.get_identity(id)
  process_identity_response(resp)
end

.indexObject



8
9
10
11
# File 'lib/tidas/identity.rb', line 8

def self.index
  resp = Client.index_identities
  process_identity_response(resp)
end

.process_identity_response(resp) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/tidas/identity.rb', line 18

def self.process_identity_response(resp)
  if resp.success?
    request_identities(resp)
  else
    resp
  end
end

.request_identities(resp) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/tidas/identity.rb', line 26

def self.request_identities(resp)
  identities_data = JSON.parse(resp.data, symbolize_names: true)
  identities_array = identities_data[:identities]
  identities_array.map! do |identity_hash|
    Identity.new(
      id:identity_hash[:id],
      deactivated: identity_hash[:deactivated],
      app_name: identity_hash[:app],
      public_key: identity_hash[:public_key]
    )
  end

  if identities_array.length == 1
    out = identities_array[0]
  else
    out = identities_array
  end

  SuccessfulResult.new(message:"Search successful", data:out)
end

.validate(attributes) ⇒ Object



60
61
62
63
64
# File 'lib/tidas/identity.rb', line 60

def self.validate(attributes)
  data      = attributes[:data]
  tidas_id  = attributes[:tidas_id]
  Client.validate(data, tidas_id)
end

Instance Method Details

#to_hashObject



82
83
84
85
86
87
88
# File 'lib/tidas/identity.rb', line 82

def to_hash
  {
    id: id,
    deactivated: deactivated,
    app: app_name
  }
end

#to_hash_with_keyObject



76
77
78
79
80
# File 'lib/tidas/identity.rb', line 76

def to_hash_with_key
  hash = to_hash
  hash[:public_key] = public_key
  hash
end