Class: Contentful::Social::Config

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

Constant Summary collapse

DEFAULT_PORT =
34123
DEFAULT_ENDPOINT =
'/social'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Config

Returns a new instance of Config.



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

def initialize(config = {})
  @config = Hashie::Mash.new(config)

  @config.port = (ENV.key?('PORT') ? ENV['PORT'].to_i : DEFAULT_PORT) unless @config.port?
  @config.endpoint = DEFAULT_ENDPOINT unless @config.endpoint?

  fail 'Contentful Access Token not Configured' unless contentful_configured?
  fail 'No Social Media Configured' unless twitter_configured? || facebook_configured?
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/contentful/social/config.rb', line 10

def config
  @config
end

Class Method Details

.load(path) ⇒ Object



12
13
14
# File 'lib/contentful/social/config.rb', line 12

def self.load(path)
  new(Hashie::Mash.load(path))
end

Instance Method Details

#contentful_configured?Boolean

Returns:

  • (Boolean)


61
62
63
64
# File 'lib/contentful/social/config.rb', line 61

def contentful_configured?
  contentful? &&
    contentful.all? { |space_id, access_token| access_token }
end

#endpointObject



30
31
32
# File 'lib/contentful/social/config.rb', line 30

def endpoint
  @config.endpoint
end

#facebook_configured?Boolean

Returns:

  • (Boolean)


55
56
57
58
59
# File 'lib/contentful/social/config.rb', line 55

def facebook_configured?
  facebook? &&
    facebook.template? &&
    facebook.access_token? # && facebook.app_secret? # not required
end

#portObject



26
27
28
# File 'lib/contentful/social/config.rb', line 26

def port
  @config.port
end

#twitter_configured?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
53
# File 'lib/contentful/social/config.rb', line 46

def twitter_configured?
  twitter? &&
    twitter.template? &&
    twitter.access_token? &&
    twitter.access_token_secret? &&
    twitter.consumer_key? &&
    twitter.consumer_secret?
end