feedie_the_feed 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f50a2f884fa7b2cc27447dba1f67d2111a12edc9
4
- data.tar.gz: b4be442cf52a973cfb7176ac885467a8fbbcbd7d
3
+ metadata.gz: 1902638b99d250f6b9af85dbcc2f20e177b246f9
4
+ data.tar.gz: f8f95a0b6ad6ad12b3ede181df0784cf2314e27a
5
5
  SHA512:
6
- metadata.gz: 4a9b029ebbda614af096c801077f0894a5120fd1e6d5eb21fc0c60a2cba71e8f359a0ab1e26c478a251bf5a2eea252d4c12d672cf7c454e4f103802680c39934
7
- data.tar.gz: 9aa4488e8010c2ff6a55582d62a1024d76c6c8922c844f39409e6b133a9b2a63231058f86a12ba10eb5684c80257b925f9ac6b34b1ef7ce9cf4c98c25e2ce101
6
+ metadata.gz: '098a225782d3e05b6e2a10ef51da41696037646abfa9ff6d0e875dab86e8d27d8591f44ab7c3179e0eaf167fe0917d1d8a72727eb89f64b6f780a096c1f0f8d6'
7
+ data.tar.gz: 3c195f611068f7409fa9c605bc2b1ff2d54769b153cd9643524c0546bccd946564f94944fb23d0b47cea89ca863f92b6225b1098beb4053bbe730ab70bf356e7
data/LICENSE CHANGED
@@ -1,13 +1,21 @@
1
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
2
- Version 2, December 2004
1
+ MIT License
3
2
 
4
- Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
3
+ Copyright (c) 2017 Oleg Larkin
5
4
 
6
- Everyone is permitted to copy and distribute verbatim or modified
7
- copies of this license document, and changing it is allowed as long
8
- as the name is changed.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
9
11
 
10
- DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
11
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
12
14
 
13
- 0. You just DO WHAT THE FUCK YOU WANT TO.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,5 +1,182 @@
1
+ [![Build Status](https://travis-ci.org/krabique48/feedie_the_feed.svg?branch=master)](https://travis-ci.org/krabique48/feedie_the_feed)
2
+
1
3
  # Feedie The Feed
2
- under development... coming soon...
3
4
 
4
- ## If you feel adventurous...
5
- ...just check `try_me.rb` out, it's quite self-explanatory.
5
+ Hi! My name is Feedie The Feed. I'm a Ruby gem that enables you to aggregate RSS and Facebook pages feed with one entry point, wooop! Just feed me the link and I'll go get them for you, master! Rawr!
6
+
7
+ ## Technology
8
+
9
+ I should work on Ruby 2.2 and over. I'm built with great help from
10
+ these cool gems:
11
+ * [feedjira](https://github.com/feedjira/feedjira) - for RSS feed
12
+ * [koala](https://github.com/arsduo/koala) - for the Facebook API
13
+ * [public_suffix](https://github.com/weppos/publicsuffix-ruby) - for parsing the links
14
+ * [nesty](https://github.com/skorks/nesty) - for cute nested exceptions
15
+
16
+ ## Getting Started
17
+
18
+ ### Installing
19
+
20
+ You can just
21
+
22
+ ```
23
+ gem install feedie_the_feed
24
+ ```
25
+
26
+ and you're good to go! Although it may contain a slightly older version, so you can clone me (oh the 21st century), if you feel adventurous!
27
+
28
+ ```
29
+ git clone git@github.com:krabique48/feedie_the_feed.git
30
+ ```
31
+
32
+ ### Running the tests
33
+
34
+ Just run RSpec and watch it go green! But you'll have to clone the repo for that, since tests aren't included in the gem.
35
+
36
+ ```
37
+ rspec spec/*
38
+ ```
39
+
40
+ ### Documentation
41
+
42
+ Have my bro YARD generate the documentation for you
43
+
44
+ ```
45
+ yard doc
46
+ ```
47
+
48
+ Or just visit http://www.rubydoc.info/gems/feedie_the_feed/ for that matter.
49
+
50
+ ## How to use
51
+
52
+ ### try_me.rb
53
+
54
+ You can check `try_me.rb` out, it's quite self-explanatory.
55
+
56
+ ### RSS
57
+
58
+ Very simple, create FeedieTheFeed::FeedGrabber object and use it's get method with a URL as a parameter:
59
+
60
+ ```
61
+ @feed_grabber = FeedieTheFeed::FeedGrabber.new
62
+ feed = @feed_grabber.get(
63
+ 'https://raw.githubusercontent.com/krabique48/' \
64
+ 'feedie_the_feed/master/rss_test_sample'
65
+ )
66
+ ```
67
+
68
+ (return format is explained below)
69
+
70
+ ### Facebook
71
+
72
+ To use the gem with Facebook you'll have to use your Facebook AppID and Facebook secret key.The simplest way to provide those is to just have them in your environment variables as FACEBOOK_APPID and FACEBOOK_SECRET. This way, all you have to do is create a new instance of the FeedieTheFeed::FeedGrabber class and call it's get method with a URL to a Facebook page as a parameter.
73
+
74
+ ```
75
+ @feed_grabber = FeedieTheFeed::FeedGrabber.new
76
+ @feed_grabber.get('https://www.facebook.com/PokerGP')
77
+ ```
78
+
79
+ #### Facebook credentials priorities
80
+
81
+ Facebook AppID and secret key follow a priority rule:
82
+
83
+ ```
84
+ get method parameters > object values > environment variables
85
+ ```
86
+
87
+ So, you can also provide the Facebook credentials as parameters in the get method:
88
+
89
+ ```
90
+ @feed_grabber = FeedieTheFeed::FeedGrabber.new
91
+ @feed_grabber.get(
92
+ 'https://www.facebook.com/PokerGP',
93
+ facebook_appid: '123',
94
+ facebook_secret: '123'
95
+ )
96
+ ```
97
+
98
+ Or during object creation:
99
+
100
+ ```
101
+ @feed_grabber = FeedieTheFeed::FeedGrabber.new(
102
+ facebook_appid: '123',
103
+ facebook_secret: '123'
104
+ )
105
+ @feed_grabber.get('https://www.facebook.com/PokerGP')
106
+ ```
107
+
108
+ #### Facebook posts limit
109
+
110
+ You can also set the amount of posts you want to get, similarily to Facebook credentials (it also follows the same priority rule):
111
+
112
+ ```
113
+ @feed_grabber = FeedieTheFeed::FeedGrabber.new(facebook_posts_limit: 50)
114
+ ```
115
+
116
+ or
117
+
118
+ ```
119
+ @feed_grabber.get(some_url, facebook_posts_limit: 50)
120
+ ```
121
+
122
+ and if you don't provide it at all, it shall default to 10.
123
+
124
+ ### Output format
125
+
126
+ So the `get` method returns an **array of hashes**, where each hash is either a Facebook page post or an RSS entry.
127
+
128
+ #### Hash keys
129
+
130
+ ##### Facebook
131
+
132
+ Facebook hashes would always have these keys:
133
+
134
+ ```
135
+ 'entry_id'
136
+ 'url'
137
+ 'published'
138
+ ```
139
+
140
+ plus some additional ones that may not always be there, due to the nature of Facebook posts:
141
+
142
+ ```
143
+ 'title'
144
+ 'summary'
145
+ 'image'
146
+ ```
147
+
148
+ ##### RSS
149
+
150
+ With RSS, the only two keys that would be there no matter what are `entry_id` and `url`, due to the nature of RSS. Although, most of the time, some other keys will also be present:
151
+
152
+ ```
153
+ 'entry_id'
154
+ 'title'
155
+ 'summary'
156
+ 'url'
157
+ 'published'
158
+ 'image'
159
+ ```
160
+
161
+ ### Other utility methods
162
+
163
+ #### fb_appid_and_secret_key(facebook_appid, facebook_secret)
164
+
165
+ `fb_appid_and_secret_key(facebook_appid, facebook_secret)` is used to set the Facebook credentials for the object.
166
+
167
+ #### reset_fb_appid_and_secret_key!
168
+
169
+ `reset_fb_appid_and_secret_key!` is used to reset the Facebook credentials for the object.
170
+
171
+ #### fb_posts_limit(limit)
172
+
173
+ `fb_posts_limit(limit)` is used to set the object's Facebook posts limit (should be an integer from 1 to 100).
174
+
175
+ #### reset_fb_posts_limit!
176
+
177
+ `reset_fb_posts_limit!` is used to reset the object's Facebook posts limit.
178
+
179
+ ## Authors
180
+
181
+ * **Oleg Larkin** - *Initial work* -
182
+ [krabique48](https://github.com/krabique48) (krabique48@gmail.com)
@@ -1,4 +1,5 @@
1
1
  require 'feedie_the_feed/feed_grabber'
2
2
 
3
+ # This is the main namespace of the gem
3
4
  module FeedieTheFeed
4
5
  end
@@ -0,0 +1,27 @@
1
+ require 'nesty'
2
+
3
+ module FeedieTheFeed
4
+ # Exception used by other exceptions to enable nested exceptions with
5
+ # 'nesty' gem by inheriting the included Nesty::NestedError
6
+ class Error < StandardError
7
+ include Nesty::NestedError
8
+ end
9
+
10
+ # Exception used when Facebook authorisation fails with the given credentials
11
+ class FacebookAuthorisationError < Error; end
12
+
13
+ # Exception used when the RSS or Facebook link provided isn't a valid one
14
+ class BadUrl < Error; end
15
+
16
+ # Exception used when Facebook posts limit is out of range or not an integer
17
+ class BadFacebookPostsLimit < Error; end
18
+
19
+ # Exception used when TCP connection could not be established
20
+ class ConnectionFailed < Error; end
21
+
22
+ # Exception used when a Facebook page name provided doesn't seem to exist
23
+ class BadFacebookPageName < Error; end
24
+
25
+ # Exception used when trying to set non-string Facebook AppID and secret key
26
+ class BadFacebookAppIDAndSecretKey < Error; end
27
+ end
@@ -0,0 +1,84 @@
1
+ require 'koala'
2
+
3
+ require 'feedie_the_feed/exceptions'
4
+
5
+ require 'feedie_the_feed/helper_extensions/string'
6
+
7
+ module FeedieTheFeed
8
+ # This module handles Facebook queries
9
+ module Facebook
10
+ private
11
+
12
+ def valid_facebook_posts_limit?(limit)
13
+ if limit.is_a?(Integer) && limit <= 100 && limit > 0
14
+ limit
15
+ else
16
+ raise BadFacebookPostsLimit, 'Facebook posts limit can only be an ' \
17
+ 'integer from 1 to 100'
18
+ end
19
+ end
20
+
21
+ def sanitized_facebook_posts_limit(facebook_posts_limit)
22
+ if facebook_posts_limit
23
+ valid_facebook_posts_limit?(facebook_posts_limit)
24
+ else
25
+ @defaults[:facebook_posts_limit]
26
+ end
27
+ end
28
+
29
+ def get_facebook_feed(url, options)
30
+ facebook_appid = options[:facebook_appid] || @facebook_appid_global
31
+ facebook_secret = options[:facebook_secret] || @facebook_secret_global
32
+ facebook_posts_limit =
33
+ sanitized_facebook_posts_limit(options[:facebook_posts_limit])
34
+
35
+ authorise_facebook(facebook_appid, facebook_secret)
36
+ posts = facebook_api_query(url, facebook_posts_limit)
37
+ formalize_fb_feed_array(posts.to_a)
38
+ end
39
+
40
+ def facebook_api_query(url, facebook_posts_limit)
41
+ @fb_graph_api.get_connection(
42
+ get_fb_page_name(url),
43
+ 'posts',
44
+ limit: facebook_posts_limit, # max 100
45
+ fields: %w[message id from type picture link created_time]
46
+ )
47
+ rescue Koala::Facebook::ClientError => e
48
+ raise BadFacebookPageName.new("A Facebook page with that name doesn't " \
49
+ "seem to exist. (name: #{get_fb_page_name(url)})", e)
50
+ end
51
+
52
+ def authorise_facebook(facebook_appid, facebook_secret)
53
+ facebook_appid ||= ENV['FACEBOOK_APPID']
54
+ facebook_secret ||= ENV['FACEBOOK_SECRET']
55
+ oauth = Koala::Facebook::OAuth.new(facebook_appid, facebook_secret)
56
+
57
+ begin
58
+ access_token = oauth.get_app_access_token
59
+ rescue Koala::Facebook::OAuthTokenRequestError => e
60
+ raise FacebookAuthorisationError.new('Failing to authorise with ' \
61
+ 'given Facebook appid and Facebook secret key.', e)
62
+ end
63
+
64
+ @fb_graph_api = Koala::Facebook::API.new(access_token)
65
+ end
66
+
67
+ def get_fb_page_name(url)
68
+ URI.parse(url).path.match(
69
+ %r{\A/([^/]*)}
70
+ )[1]
71
+ end
72
+
73
+ def formalize_fb_feed_array(array)
74
+ array.each do |hash|
75
+ hash['entry_id'] = hash.delete('id')
76
+ hash['summary'] = hash.delete('message')
77
+ hash['title'] = hash['summary'].truncate(80) if hash['summary']
78
+ hash['url'] = hash.delete('link')
79
+ hash['published'] = Time.parse(hash.delete('created_time'))
80
+ hash['image'] = hash.delete('picture')
81
+ end
82
+ end
83
+ end
84
+ end
@@ -1,110 +1,128 @@
1
- # WorldsBestRssAndFBParser::Feed.execute "http://abcnews.go.com/abcnews/topstories"
2
- # WorldsBestRssAndFBParser::Feed.execute "https://www.facebook.com/leagueoflegends/"
3
-
4
- #FACEBOOK_APPID="458198461180322"
5
- #FACEBOOK_SECRET="f256365f32d5cea44316ecfcda203d99"
6
-
7
- #facebook_appid="458198461180322"
8
- #facebook_secret="f256365f32d5cea44316ecfcda203d99"
9
-
10
- require 'feedjira'
11
- require 'koala'
12
1
  require 'uri'
13
2
  require 'public_suffix'
14
3
 
4
+ require 'feedie_the_feed/exceptions'
5
+
6
+ require 'feedie_the_feed/facebook'
7
+ require 'feedie_the_feed/rss'
8
+
15
9
  module FeedieTheFeed
10
+ # This is the main class that does all the job.
16
11
  class FeedGrabber
17
-
18
- # Stops feedjira spamming in console when there is no last modified time field in an rss feed
19
- Feedjira.logger.level = Logger::FATAL
20
-
21
- def initialize(facebook_appid=nil, facebook_secret=nil)
22
- @facebook_appid = facebook_appid
23
- @facebook_secret = facebook_secret
24
- end
25
-
26
- def get(url, facebook_appid=nil, facebook_secret=nil)
27
- set_facebook_credentials(facebook_appid, facebook_secret) if facebook_appid && facebook_secret
28
- validate_url_and_start(url)
29
- end
12
+ include FeedieTheFeed::Facebook
13
+ include FeedieTheFeed::RSS
30
14
 
31
- private
32
-
33
- def set_facebook_credentials(facebook_appid, facebook_secret)
34
- @facebook_appid = facebook_appid
35
- @facebook_secret = facebook_secret
15
+ # Stops feedjira spamming in console when there is no last modified time
16
+ # field in an rss feed
17
+ Feedjira.logger.level = Logger::FATAL
18
+
19
+ # Returns a new instance of FeedGrabber.
20
+ #
21
+ # @param options [Hash] The options to use for the FeedGrabber constructor
22
+ # @option options [String] :facebook_appid The Facebook AppID to be used
23
+ # globally in this object
24
+ # @option options [String] :facebook_secret The Facebook secret key to be
25
+ # used globally in this object
26
+ # @option options [Integer] :facebook_posts_limit The amount of Facebook
27
+ # posts to get by default (should be in 1..100)
28
+ #
29
+ # @raise [BadFacebookPostsLimit] Exception used when Facebook posts limit is
30
+ # out of range or not an integer
31
+ def initialize(options = {})
32
+ # This hash is used to store default values for things like Facebook posts
33
+ # limit.
34
+ @defaults = { facebook_posts_limit: 10 }
35
+ @facebook_appid_global = options[:facebook_appid]
36
+ @facebook_secret_global = options[:facebook_secret]
37
+ fb_posts_limit(
38
+ options[:facebook_posts_limit] || @defaults[:facebook_posts_limit]
39
+ )
36
40
  end
37
-
38
- def validate_url_and_start(url)
39
- if url =~ /\A#{URI::regexp(['http', 'https'])}\z/
40
- get_proper_feed(url)
41
+
42
+ # Gets an array of hashes that are RSS or Facebook posts.
43
+ #
44
+ # @param url [String] The URL to be used as the feed source
45
+ # @param options [Hash] The options to use for the get method
46
+ # @option options [Integer] :facebook_posts_limit Amout of Facebook posts
47
+ # to get in this operation (should be in 1..100 range)
48
+ # @option options [String] :facebook_appid Facebook AppID value to be used
49
+ # with this operation
50
+ # @option options [String] :facebook_secret Facebook secret key value to be
51
+ # used with this operation
52
+ #
53
+ # @raise [FacebookAuthorisationError] Exception used when Facebook
54
+ # authorisation fails with the given credentials
55
+ # @raise [BadUrl] Exception used when the RSS or Facebook link provided
56
+ # isn't a valid one
57
+ # @raise [BadFacebookPostsLimit] Exception used when Facebook posts limit is
58
+ # out of range or not an integer
59
+ # @raise [ConnectionFailed] Exception used when TCP connection could not be
60
+ # established
61
+ #
62
+ # @return [Array] The array of hashes of RSS entries or Facebook posts
63
+ def get(url, options = {})
64
+ url = sanitise_web_url(url)
65
+ if facebook_url?(url)
66
+ get_facebook_feed(url, options)
41
67
  else
42
- p "Bad url." #GOTA THROW EXCEPTION
43
- end
44
- end
45
-
46
- def get_proper_feed(url)
47
- is_facebook_url?(url) ? get_facebook_feed(url) : get_rss_feed(url)
68
+ get_rss_feed(url)
69
+ end
70
+ rescue Faraday::ConnectionFailed => e
71
+ raise ConnectionFailed, e
48
72
  end
49
-
50
- def is_facebook_url?(url)
51
- uri = URI.parse(url)
52
- PublicSuffix.parse(uri.host).domain == 'facebook.com'
73
+
74
+ # Resets global Facebook AppID and secret key of this object.
75
+ def reset_fb_appid_and_secret_key!
76
+ @facebook_appid_global = nil
77
+ @facebook_secret_global = nil
53
78
  end
54
-
55
- def get_facebook_feed(url)
56
- authorize_facebook
57
- posts = @fb_graph_api.get_connection(get_fb_page_name(url), 'posts', {
58
- limit: 10, # max 100
59
- fields: ['message', 'id', 'from', 'type', 'picture', 'link', 'created_time']
60
- })
61
- formalize_fb_feed_array(posts.to_a)
79
+
80
+ # Sets Facebook AppID and secret key for this object.
81
+ #
82
+ # @param facebook_appid [String] Facebook AppID to set to this object
83
+ # @param facebook_secret [String] Facebook secret key to set to this object
84
+ # @raise [BadFacebookAppIDAndSecretKey] Exception used when trying
85
+ # to set non-string Facebook AppID and secret key
86
+ def fb_appid_and_secret_key(facebook_appid, facebook_secret)
87
+ if facebook_appid.is_a?(String) && facebook_secret.is_a?(String)
88
+ @facebook_appid_global = facebook_appid
89
+ @facebook_secret_global = facebook_secret
90
+ else
91
+ raise BadFacebookAppIDAndSecretKey, 'Facebook AppID and secret key ' \
92
+ 'must be strings (input classes: ' \
93
+ "#{facebook_appid.class} and #{facebook_secret.class})"
94
+ end
62
95
  end
63
-
64
- def authorize_facebook
65
- @facebook_appid ||= ENV['FACEBOOK_APPID']
66
- @facebook_secret ||= ENV['FACEBOOK_SECRET']
67
- oauth = Koala::Facebook::OAuth.new(@facebook_appid, @facebook_secret)
68
- access_token = oauth.get_app_access_token
69
- @fb_graph_api = Koala::Facebook::API.new(access_token)
96
+
97
+ # Resets global Facebook posts limit of this object.
98
+ def reset_fb_posts_limit!
99
+ @facebook_posts_limit_global = @defaults[:facebook_posts_limit]
70
100
  end
71
-
72
- def get_fb_page_name(url)
73
- URI.parse(url).path.match(/\A\/([^\/]*)/)[1]
101
+
102
+ # Sets global Facebook posts limit for this object.
103
+ #
104
+ # @param limit [Integer] The number of posts to get on Facebook queries
105
+ # (should be in 1..100 range)
106
+ # @raise [BadFacebookPostsLimit] Exception used when Facebook posts limit is
107
+ # out of range or not an integer
108
+ def fb_posts_limit(limit)
109
+ valid_facebook_posts_limit?(limit)
110
+ @facebook_posts_limit_global = limit
74
111
  end
75
112
 
76
- def truncate(text, options = {})
77
- return text unless text.length > options[:length]
78
-
79
- omission = options[:omission] || "..."
80
- length_with_room_for_omission = options[:length] - omission.length
81
- stop = \
82
- if options[:separator]
83
- text.rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission
84
- else
85
- length_with_room_for_omission
86
- end
87
-
88
- "#{text[0, stop]}#{omission}"
113
+ private
114
+
115
+ def sanitise_web_url(url)
116
+ url = "https://#{url}" unless url =~ %r{\A(http|https)://}
117
+ url
89
118
  end
90
-
91
- def formalize_fb_feed_array(array)
92
- array.each do |hash|
93
- hash['entry_id'] = hash.delete 'id'
94
- hash['summary'] = hash.delete 'message'
95
- hash['title'] = truncate(hash['summary'], length: 80, separator: ' ') if hash['summary']
96
- hash['url'] = hash.delete 'link'
97
- hash['published'] = Time.parse hash.delete('created_time')
98
- hash['image'] = hash.delete 'picture'
99
- end
100
- end
101
-
102
- def get_rss_feed(url)
103
- feed = Feedjira::Feed.fetch_and_parse url
104
- feed.entries.map! do |entry|
105
- entry.to_h
106
- end
119
+
120
+ def facebook_url?(url)
121
+ uri = URI.parse(url)
122
+ PublicSuffix.parse(uri.host).domain == 'facebook.com'
123
+ rescue PublicSuffix::DomainInvalid => e
124
+ raise BadUrl.new("The url provided doesn't seem to be valid. " \
125
+ "(url: #{url})", e)
107
126
  end
108
-
109
127
  end
110
128
  end
@@ -0,0 +1,24 @@
1
+ # This class extends String with some helper methods, like truncate.
2
+ class String
3
+ # Mimics core functionality of RoR String's truncate method, by cutting
4
+ # a string to a certain length, while adding '...' to the end and making
5
+ # sure it won't cut in the middle of a word, just on a space.
6
+ #
7
+ # The original RoR truncate method can be found here: goo.gl/unjyZm
8
+ # Copyright (c) 2005-2017 David Heinemeier Hansson
9
+ # MIT licence: https://github.com/rails/rails/blob/master/MIT-LICENSE
10
+ # (pls, don't sue me)
11
+ #
12
+ # @param truncate_at [Integer] The desired length to cut the string to
13
+ # @return [String] The truncated string
14
+ def truncate(truncate_at)
15
+ return dup unless length > truncate_at
16
+
17
+ omission = '...'
18
+ length_with_room_for_omission = truncate_at - omission.length
19
+ stop = rindex(' ', length_with_room_for_omission) ||
20
+ length_with_room_for_omission
21
+
22
+ "#{self[0, stop]}#{omission}"
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require 'feedjira'
2
+
3
+ require 'feedie_the_feed/exceptions'
4
+
5
+ module FeedieTheFeed
6
+ # This module handles RSS queries
7
+ module RSS
8
+ private
9
+
10
+ def get_rss_feed(url)
11
+ feedjira_feed = Feedjira::Feed.fetch_and_parse(url)
12
+ feed = feedjira_feed.entries.map!(&:to_h)
13
+ sanitise_feed(feed)
14
+ rescue Feedjira::NoParserAvailable => e
15
+ raise BadUrl.new("The url provided doesn't seem to contain any feed. " \
16
+ "(url: #{url})", e)
17
+ end
18
+
19
+ def sanitise_feed(feed)
20
+ feed.each do |entry|
21
+ entry['entry_id'] = entry['url'] if entry['entry_id'].nil?
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,4 @@
1
1
  module FeedieTheFeed
2
- VERSION = '0.0.1'
2
+ # Current version of the gem
3
+ VERSION = '0.2.0'.freeze
3
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: feedie_the_feed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry Wisdom
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-07 00:00:00.000000000 Z
11
+ date: 2017-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: feedjira
@@ -16,42 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.1.2
19
+ version: '2.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.1.2
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: koala
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.0.0
33
+ version: '3.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.0.0
40
+ version: '3.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: public_suffix
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.0.0
47
+ version: '3.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.0
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nesty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.7'
55
83
  description: A feed posts aggregator for rss and facebook pages
56
84
  email:
57
85
  - krabique48@gmail.com
@@ -62,11 +90,15 @@ files:
62
90
  - LICENSE
63
91
  - README.md
64
92
  - lib/feedie_the_feed.rb
93
+ - lib/feedie_the_feed/exceptions.rb
94
+ - lib/feedie_the_feed/facebook.rb
65
95
  - lib/feedie_the_feed/feed_grabber.rb
96
+ - lib/feedie_the_feed/helper_extensions/string.rb
97
+ - lib/feedie_the_feed/rss.rb
66
98
  - lib/feedie_the_feed/version.rb
67
99
  homepage: https://github.com/krabique48/feedie_the_feed
68
100
  licenses:
69
- - WTFPL
101
+ - MIT
70
102
  metadata: {}
71
103
  post_install_message:
72
104
  rdoc_options: []
@@ -76,7 +108,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
108
  requirements:
77
109
  - - ">="
78
110
  - !ruby/object:Gem::Version
79
- version: 2.4.2
111
+ version: '2.2'
80
112
  required_rubygems_version: !ruby/object:Gem::Requirement
81
113
  requirements:
82
114
  - - ">="