Class: IdnSdkRuby::Com::Nbos::Capi::Modules::Identity::V0::ModuleTokenApiModel

Inherits:
BasicActiveModel
  • Object
show all
Defined in:
lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsed_response = nil) ⇒ ModuleTokenApiModel



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 13

def initialize(parsed_response = nil)
  if !parsed_response.nil?
    @username = parsed_response['username']
    @clientId = parsed_response['clientId']
    @tokenType = parsed_response['tokenType']
    @token = parsed_response['token']
    @expiration = parsed_response['expiration']
    @expired = parsed_response['expired']
    @tenantId = parsed_response['tenantId']
    @uuid = parsed_response['member']['uuid'] if parsed_response['member'].present?
    @modules = add_modules(parsed_response['modules']) if parsed_response['modules'].present?
    @authorities = add_authorities(parsed_response['authorities']) if parsed_response['authorities'].present?
  end
end

Instance Attribute Details

#authoritiesObject

Returns the value of attribute authorities.



9
10
11
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 9

def authorities
  @authorities
end

#clientIdObject

Returns the value of attribute clientId.



9
10
11
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 9

def clientId
  @clientId
end

#expirationObject

Returns the value of attribute expiration.



9
10
11
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 9

def expiration
  @expiration
end

#expiredObject

Returns the value of attribute expired.



9
10
11
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 9

def expired
  @expired
end

#messageObject

Returns the value of attribute message.



9
10
11
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 9

def message
  @message
end

#modulesObject

Returns the value of attribute modules.



9
10
11
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 9

def modules
  @modules
end

#tenantIdObject

Returns the value of attribute tenantId.



9
10
11
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 9

def tenantId
  @tenantId
end

#tokenObject

Returns the value of attribute token.



9
10
11
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 9

def token
  @token
end

#tokenTypeObject

Returns the value of attribute tokenType.



9
10
11
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 9

def tokenType
  @tokenType
end

#usernameObject

Returns the value of attribute username.



9
10
11
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 9

def username
  @username
end

#uuidObject

Returns the value of attribute uuid.



9
10
11
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 9

def uuid
  @uuid
end

Instance Method Details

#add_authorities(authorities) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 50

def add_authorities(authorities)
  @authorities = []
  if authorities.size > 0
    authorities.each do |at|
      auth = IdnSdkRuby::Com::Nbos::Capi::Modules::Core::V0::AuthorityApiModel.new(at["uAuthorityName"], at["displayName"], at["description"])
      @authorities << auth
    end
  end
end

#add_errors(json_response) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 88

def add_errors(json_response)
  json_response["errors"].each do |e|
    property_name = e['propertyName']
    msg = e['message']
    self.errors[property_name] << msg
  end
end

#add_messages(json_response) ⇒ Object



96
97
98
99
100
101
102
103
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 96

def add_messages(json_response)
  if json_response["message"].present?
    @message = json_response["message"]
  elsif json_response["error"].present?
    @message = json_response["error"]
  end

end

#add_modules(modules) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 28

def add_modules(modules)
  @modules = []
  if modules.size > 0
    modules.each do |m|
      mod = IdnSdkRuby::Com::Nbos::Capi::Modules::Core::V0::ModuleApiModel.new(m["uuid"], m["name"])
      @modules << mod
    end
  end
end

#as_json(options = {}) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 105

def as_json(options={})
  {
      username: @username,
      clientId: @clientId,
      tokenType: @tokenType,
      token: @token,
      expiration: @expiration,
      expired: @expired,
      tenantId: @tenantId,
      modules: @modules,
      uuid: @uuid
  }
end

#get_authoritiesObject



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 60

def get_authorities
  if self.authorities.present?
    ms = []
    self.authorities.each do |m|
      ms << m["uAuthorityName"]
    end
    ms
  else
    []
  end
end

#get_modulesObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 38

def get_modules
  if self.modules.present?
    ms = []
    self.modules.each do |m|
      ms << m["name"]
    end
    ms
  else
    []
  end
end

#has_authorities?Boolean



80
81
82
83
84
85
86
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 80

def has_authorities?
  if self.authorities.present?
    true
  else
    false
  end
end

#is_member?Boolean



72
73
74
75
76
77
78
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 72

def is_member?
  if self.uuid.present?
    true
  else
    false
  end
end

#to_json(*options) ⇒ Object



119
120
121
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 119

def to_json(*options)
  as_json(*options).to_json(*options)
end

#to_sObject



123
124
125
# File 'lib/idn_sdk_ruby/com/nbos/capi/modules/identity/v0/module_token_api_model.rb', line 123

def to_s
  to_json
end