Class: TinCanApi::Agent

Inherits:
Object
  • Object
show all
Defined in:
lib/tin_can_api/agent.rb

Overview

Agent model class

Direct Known Subclasses

Group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Agent

Returns a new instance of Agent.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tin_can_api/agent.rb', line 9

def initialize(options={}, &block)
  @object_type = 'Agent'
  json = options.fetch(:json, nil)
  if json
    attributes = JSON.parse(json)
    self.name = attributes['name'] if attributes['name']
    self.mbox = attributes['mbox'] if attributes['mbox']
    self.mbox_sha1_sum = attributes['mbox_sha1sum'] if attributes['mbox_sha1sum']
    self.open_id = attributes['openid'] if attributes['openid']
    self. = AgentAccount.new(json: attributes['account'].to_json) if attributes['account']
  else
    self.name = options.fetch(:name, nil)
    self.mbox = options.fetch(:mbox, nil)
    self.mbox_sha1_sum = options.fetch(:mbox_sha1_sum, nil)
    self.open_id = options.fetch(:open_id, nil)
    self. = options.fetch(:account, nil)

    if block_given?
      block[self]
    end
  end
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



7
8
9
# File 'lib/tin_can_api/agent.rb', line 7

def 
  @account
end

#mboxObject

Returns the value of attribute mbox.



7
8
9
# File 'lib/tin_can_api/agent.rb', line 7

def mbox
  @mbox
end

#mbox_sha1_sumObject

Returns the value of attribute mbox_sha1_sum.



7
8
9
# File 'lib/tin_can_api/agent.rb', line 7

def mbox_sha1_sum
  @mbox_sha1_sum
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/tin_can_api/agent.rb', line 7

def name
  @name
end

#object_typeObject

Returns the value of attribute object_type.



7
8
9
# File 'lib/tin_can_api/agent.rb', line 7

def object_type
  @object_type
end

#open_idObject

Returns the value of attribute open_id.



7
8
9
# File 'lib/tin_can_api/agent.rb', line 7

def open_id
  @open_id
end

Instance Method Details

#serialize(version) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/tin_can_api/agent.rb', line 32

def serialize(version)
  node = {}
  node['objectType'] = object_type
  node['name'] = name if name
  node['mbox'] = mbox if mbox
  node['mbox_sha1sum'] = mbox_sha1_sum if mbox_sha1_sum
  node['openid'] = open_id if open_id
  node['account'] = .serialize(version) if 
  node
end