Class: VAProfile::Models::CommunicationItem

Inherits:
CommunicationBase show all
Defined in:
lib/va_profile/models/communication_item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#communication_channelObject

Returns the value of attribute communication_channel.



10
11
12
# File 'lib/va_profile/models/communication_item.rb', line 10

def communication_channel
  @communication_channel
end

#communication_channelsObject

Returns the value of attribute communication_channels.



9
10
11
# File 'lib/va_profile/models/communication_item.rb', line 9

def communication_channels
  @communication_channels
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'lib/va_profile/models/communication_item.rb', line 9

def id
  @id
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/va_profile/models/communication_item.rb', line 9

def name
  @name
end

Class Method Details

.create_from_api(communication_res, permission_res) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/va_profile/models/communication_item.rb', line 16

def self.create_from_api(communication_res, permission_res)
  new(
    id: communication_res['communication_item_id'],
    name: communication_res['common_name'],
    communication_channels: communication_res['communication_item_channels'].map do |communication_item_channel|
      communication_channel = communication_item_channel['communication_channel']

      VAProfile::Models::CommunicationChannel.create_from_api(
        communication_channel,
        communication_res['communication_item_id'],
        communication_item_channel['default_send_indicator'],
        permission_res
      )
    end
  )
end

Instance Method Details

#http_verbObject



42
43
44
# File 'lib/va_profile/models/communication_item.rb', line 42

def http_verb
  communication_channel.communication_permission.id.present? ? :put : :post
end

#in_json(va_profile_id) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/va_profile/models/communication_item.rb', line 46

def in_json(va_profile_id)
  {
    bio: {
      allowed: communication_channel.communication_permission.allowed,
      communicationChannelId: communication_channel.id,
      communicationItemId: id,
      vaProfileId: va_profile_id.to_i,
      sourceDate: Time.zone.now.iso8601
    }.merge(lambda do
      communication_permission = communication_channel.communication_permission

      if communication_permission.id.present?
        { communicationPermissionId: communication_permission.id }
      else
        {}
      end
    end.call)
  }.to_json
end