Class: FeedieTheFeed::FeedGrabber

Inherits:
Object
  • Object
show all
Defined in:
lib/feedie_the_feed/feed_grabber.rb

Overview

This is the main class that does all the job.

Constant Summary collapse

@@defaults =

This hash is used to store default values for things like Facebook posts limit.

{ facebook_posts_limit: 10 }

Instance Method Summary collapse

Constructor Details

#initialize(facebook_appid = nil, facebook_secret = nil, facebook_posts_limit = @@defaults[:facebook_posts_limit]) ⇒ FeedGrabber

Returns a new instance of FeedGrabber.

Raises:


31
32
33
34
35
36
# File 'lib/feedie_the_feed/feed_grabber.rb', line 31

def initialize(facebook_appid = nil, facebook_secret = nil,
               facebook_posts_limit = @@defaults[:facebook_posts_limit])
  @facebook_appid_global = facebook_appid
  @facebook_secret_global = facebook_secret
  fb_posts_limit(facebook_posts_limit)
end

Instance Method Details

#fb_posts_limit(limit) ⇒ Object

Sets global Facebook posts limit for this object.

Raises:


83
84
85
86
87
88
89
# File 'lib/feedie_the_feed/feed_grabber.rb', line 83

def fb_posts_limit(limit)
  unless limit.is_a?(Integer) && limit <= 100 && limit > 0
    raise BadFacebookPostsLimit, 'Facebook posts limit can only be an ' \
      'integer from 1 to 100'
  end
  @facebook_posts_limit_global = limit
end

#get(url, options = {}) ⇒ Array

Gets an array of hashes that are RSS or Facebook posts.

Options Hash (options):

  • :facebook_posts_limit (Integer)

    Amout of Facebook posts to get in this operation (should be in 1..100 range)

  • :facebook_appid (String)

    Facebook AppID value to be used with this operation

  • :facebook_secret (String)

    Facebook secret key value to be used with this operation

Raises:

  • (FacebookAuthorisationError)

    Exception used when Facebook authorisation fails with the given credentials

  • (BadUrl)

    Exception used when the RSS or Facebook link provided isn't a valid one

  • (BadFacebookPostsLimit)

    Exception used when Facebook posts limit is out of range or not an integer

  • (ConnectionFailed)

    Exception used when TCP connection could not be established


59
60
61
62
63
64
# File 'lib/feedie_the_feed/feed_grabber.rb', line 59

def get(url, options = {})
  get_proper_feed(url,
                  options[:facebook_posts_limit],
                  options[:facebook_appid],
                  options[:facebook_secret])
end

#reset_fb_posts_limit!Object

Resets global Facebook posts limit of this object.


73
74
75
# File 'lib/feedie_the_feed/feed_grabber.rb', line 73

def reset_fb_posts_limit!
  @facebook_posts_limit_global = @@defaults[:facebook_posts_limit]
end

#reset_keys!Object

Resets global Facebook AppID and secret key of this object.


67
68
69
70
# File 'lib/feedie_the_feed/feed_grabber.rb', line 67

def reset_keys!
  @facebook_appid_global = nil
  @facebook_secret_global = nil
end