Class: FeedieTheFeed::FeedGrabber
- Inherits:
-
Object
- Object
- FeedieTheFeed::FeedGrabber
- Defined in:
- lib/feedie_the_feed/feed_grabber.rb
Overview
This is the main class that does all the job.
Instance Method Summary collapse
-
#fb_appid_and_secret_key(facebook_appid, facebook_secret) ⇒ Object
Sets Facebook AppID and secret key for this object.
-
#fb_posts_limit(limit) ⇒ Object
Sets global Facebook posts limit for this object.
-
#get(url, options = {}) ⇒ Array
Gets an array of hashes that are RSS or Facebook posts.
-
#initialize(options = {}) ⇒ FeedGrabber
constructor
Returns a new instance of FeedGrabber.
-
#reset_fb_appid_and_secret_key! ⇒ Object
Resets global Facebook AppID and secret key of this object.
-
#reset_fb_posts_limit! ⇒ Object
Resets global Facebook posts limit of this object.
Constructor Details
#initialize(options = {}) ⇒ FeedGrabber
Returns a new instance of FeedGrabber.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/feedie_the_feed/feed_grabber.rb', line 31 def initialize( = {}) # This hash is used to store default values for things like Facebook posts # limit. @defaults = { facebook_posts_limit: 10 } @facebook_appid_global = [:facebook_appid] @facebook_secret_global = [:facebook_secret] fb_posts_limit( [:facebook_posts_limit] || @defaults[:facebook_posts_limit] ) end |
Instance Method Details
#fb_appid_and_secret_key(facebook_appid, facebook_secret) ⇒ Object
Sets Facebook AppID and secret key for this object.
86 87 88 89 90 91 92 93 94 95 |
# File 'lib/feedie_the_feed/feed_grabber.rb', line 86 def fb_appid_and_secret_key(facebook_appid, facebook_secret) if facebook_appid.is_a?(String) && facebook_secret.is_a?(String) @facebook_appid_global = facebook_appid @facebook_secret_global = facebook_secret else raise BadFacebookAppIDAndSecretKey, 'Facebook AppID and secret key ' \ 'must be strings (input classes: ' \ "#{facebook_appid.class} and #{facebook_secret.class})" end end |
#fb_posts_limit(limit) ⇒ Object
Sets global Facebook posts limit for this object.
108 109 110 111 |
# File 'lib/feedie_the_feed/feed_grabber.rb', line 108 def fb_posts_limit(limit) valid_facebook_posts_limit?(limit) @facebook_posts_limit_global = limit end |
#get(url, options = {}) ⇒ Array
Gets an array of hashes that are RSS or Facebook posts.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/feedie_the_feed/feed_grabber.rb', line 63 def get(url, = {}) url = sanitise_web_url(url) if facebook_url?(url) get_facebook_feed(url, ) else get_rss_feed(url) end rescue Faraday::ConnectionFailed => e raise ConnectionFailed, e end |
#reset_fb_appid_and_secret_key! ⇒ Object
Resets global Facebook AppID and secret key of this object.
75 76 77 78 |
# File 'lib/feedie_the_feed/feed_grabber.rb', line 75 def reset_fb_appid_and_secret_key! @facebook_appid_global = nil @facebook_secret_global = nil end |
#reset_fb_posts_limit! ⇒ Object
Resets global Facebook posts limit of this object.
98 99 100 |
# File 'lib/feedie_the_feed/feed_grabber.rb', line 98 def reset_fb_posts_limit! @facebook_posts_limit_global = @defaults[:facebook_posts_limit] end |