Class: ADN::Recipes::BroadcastMessageBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/adn/recipes/broadcast_message_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) {|_self| ... } ⇒ BroadcastMessageBuilder

Returns a new instance of BroadcastMessageBuilder.

Yields:

  • (_self)

Yield Parameters:



10
11
12
13
14
15
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 10

def initialize(params = {})
  if params.respond_to? :each_pair
    params.each_pair { |k, v| send("#{k}=", v) if respond_to?("#{k}=") }
  end
  yield self if block_given?
end

Instance Attribute Details

#attachmentObject

Returns the value of attribute attachment.



6
7
8
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 6

def attachment
  @attachment
end

#channel_idObject

Returns the value of attribute channel_id.



6
7
8
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 6

def channel_id
  @channel_id
end

#headlineObject

Returns the value of attribute headline.



6
7
8
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 6

def headline
  @headline
end

Returns the value of attribute parse_links.



6
7
8
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 6

def parse_links
  @parse_links
end

Returns the value of attribute parse_markdown_links.



6
7
8
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 6

def parse_markdown_links
  @parse_markdown_links
end

#photoObject

Returns the value of attribute photo.



6
7
8
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 6

def photo
  @photo
end

Returns the value of attribute read_more_link.



6
7
8
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 6

def read_more_link
  @read_more_link
end

#textObject

Returns the value of attribute text.



6
7
8
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 6

def text
  @text
end

Instance Method Details

#annotationsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 17

def annotations
  annotations = [
    {
      type: 'net.app.core.broadcast.message.metadata',
      value: {
        subject: self.headline
      }
    }
  ]

  if self.read_more_link
    annotations << {
      type: 'net.app.core.crosspost',
      value: {
        canonical_url: self.read_more_link
      }
    }
  end

  annotations
end

#messageObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 39

def message
  {
    annotations: self.annotations,
    text: self.text,
    machine_only: (not self.text),
    entities: {
      parse_links: (self.parse_links or self.parse_markdown_links),
      parse_markdown_links: !!self.parse_markdown_links
    }
  }
end

#sendObject



51
52
53
# File 'lib/adn/recipes/broadcast_message_builder.rb', line 51

def send
  Message.new ADN::API::Message.create(self.channel_id, self.message)["data"]
end