Class: Contentful::Social::FacebookHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/contentful/social/facebook_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(facebook_config, contentful_client, webhook) ⇒ FacebookHandler

Returns a new instance of FacebookHandler.



8
9
10
11
12
13
14
15
# File 'lib/contentful/social/facebook_handler.rb', line 8

def initialize(facebook_config, contentful_client, webhook)
  @template = facebook_config.template
  @post_to = facebook_config.post_to || 'me'

  @webhook = webhook
  @contentful = contentful_client
  @facebook = create_facebook_client(facebook_config)
end

Instance Attribute Details

#contentfulObject (readonly)

Returns the value of attribute contentful.



6
7
8
# File 'lib/contentful/social/facebook_handler.rb', line 6

def contentful
  @contentful
end

#facebookObject (readonly)

Returns the value of attribute facebook.



6
7
8
# File 'lib/contentful/social/facebook_handler.rb', line 6

def facebook
  @facebook
end

#templateObject (readonly)

Returns the value of attribute template.



6
7
8
# File 'lib/contentful/social/facebook_handler.rb', line 6

def template
  @template
end

#webhookObject (readonly)

Returns the value of attribute webhook.



6
7
8
# File 'lib/contentful/social/facebook_handler.rb', line 6

def webhook
  @webhook
end

Instance Method Details

#postObject



17
18
19
20
21
22
23
24
25
# File 'lib/contentful/social/facebook_handler.rb', line 17

def post
  body = ::Contentful::Social::Template.new(
    contentful,
    webhook,
    template
  ).render

  facebook.put_connections(@post_to, 'feed', message: body)
end