europeana-feeds 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d9a7075f9d0c77924c0395d5325d2a891e2b144a
4
+ data.tar.gz: 6ea5219936aa46fff0cb57fa3fde0b5e9740d6db
5
+ SHA512:
6
+ metadata.gz: efac98301d7bcc1613b6d7936adafdbd90fd6d77e3add1fbecccac4feda3dc3eec1a83eb117ef7f47dafeffc126a51e76807e3216cbb2826594d270a1ec67fb0
7
+ data.tar.gz: 2446e62d49b2b3f7085a6cacc970567f2c534bdb73213e99c5b75fb1ce63ff20ad16da9db2c67cdb4bf276119d8939b613c43718af5731c3587388bfb22fb3e2
data/.rubocop.yml ADDED
@@ -0,0 +1,250 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'vendor/**/*'
4
+ - 'db/schema.rb'
5
+ - 'spec/dummy/**/*'
6
+ UseCache: false
7
+ TargetRubyVersion: 2.3
8
+ Style/CollectionMethods:
9
+ Description: Preferred collection methods.
10
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size
11
+ Enabled: true
12
+ PreferredMethods:
13
+ collect: map
14
+ collect!: map!
15
+ find: detect
16
+ find_all: select
17
+ reduce: inject
18
+ Metrics/BlockLength:
19
+ Exclude:
20
+ - 'Rakefile'
21
+ - '**/*.rake'
22
+ - 'spec/**/*.rb'
23
+ Layout/DotPosition:
24
+ Description: Checks the position of the dot in multi-line method calls.
25
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains
26
+ Enabled: true
27
+ EnforcedStyle: trailing
28
+ SupportedStyles:
29
+ - leading
30
+ - trailing
31
+ Naming/FileName:
32
+ Description: Use snake_case for source file names.
33
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files
34
+ Enabled: false
35
+ Exclude: []
36
+ Style/GuardClause:
37
+ Description: Check for conditionals that can be replaced with guard clauses
38
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals
39
+ Enabled: false
40
+ MinBodyLength: 1
41
+ Style/IfUnlessModifier:
42
+ Description: Favor modifier if/unless usage when you have a single-line body.
43
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier
44
+ Enabled: false
45
+ MaxLineLength: 80
46
+ Style/OptionHash:
47
+ Description: Don't use option hashes when you can use keyword arguments.
48
+ Enabled: false
49
+ Style/PercentLiteralDelimiters:
50
+ Description: Use `%`-literal delimiters consistently
51
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces
52
+ Enabled: false
53
+ PreferredDelimiters:
54
+ "%": "()"
55
+ "%i": "()"
56
+ "%q": "()"
57
+ "%Q": "()"
58
+ "%r": "{}"
59
+ "%s": "()"
60
+ "%w": "()"
61
+ "%W": "()"
62
+ "%x": "()"
63
+ Naming/PredicateName:
64
+ Description: Check the names of predicate methods.
65
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark
66
+ Enabled: true
67
+ NamePrefix:
68
+ - is_
69
+ - has_
70
+ - have_
71
+ NamePrefixBlacklist:
72
+ - is_
73
+ Exclude:
74
+ - spec/**/*
75
+ Style/RaiseArgs:
76
+ Description: Checks the arguments passed to raise/fail.
77
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages
78
+ Enabled: false
79
+ EnforcedStyle: exploded
80
+ SupportedStyles:
81
+ - compact
82
+ - exploded
83
+ Style/SignalException:
84
+ Description: Checks for proper usage of fail and raise.
85
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method
86
+ Enabled: false
87
+ EnforcedStyle: semantic
88
+ SupportedStyles:
89
+ - only_raise
90
+ - only_fail
91
+ - semantic
92
+ Style/SingleLineBlockParams:
93
+ Description: Enforces the names of some block params.
94
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks
95
+ Enabled: false
96
+ Methods:
97
+ - reduce:
98
+ - a
99
+ - e
100
+ - inject:
101
+ - a
102
+ - e
103
+ Style/SingleLineMethods:
104
+ Description: Avoid single-line methods.
105
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods
106
+ Enabled: false
107
+ AllowIfMethodIsEmpty: true
108
+ Style/StringLiterals:
109
+ Description: Checks if uses of quotes match the configured preference.
110
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals
111
+ Enabled: true
112
+ EnforcedStyle: single_quotes
113
+ SupportedStyles:
114
+ - single_quotes
115
+ - double_quotes
116
+ Style/StringLiteralsInInterpolation:
117
+ Description: Checks if uses of quotes inside expressions in interpolated strings
118
+ match the configured preference.
119
+ Enabled: true
120
+ EnforcedStyle: single_quotes
121
+ SupportedStyles:
122
+ - single_quotes
123
+ - double_quotes
124
+ Style/TrailingCommaInArguments:
125
+ Description: 'Checks for trailing comma in argument lists.'
126
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
127
+ Enabled: false
128
+ EnforcedStyleForMultiline: no_comma
129
+ Style/TrailingCommaInLiteral:
130
+ Description: 'Checks for trailing comma in array and hash literals.'
131
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
132
+ Enabled: false
133
+ EnforcedStyleForMultiline: no_comma
134
+ Metrics/AbcSize:
135
+ Description: A calculated magnitude based on number of assignments, branches, and
136
+ conditions.
137
+ Enabled: false
138
+ Max: 15
139
+ Metrics/ClassLength:
140
+ Description: Avoid classes longer than 100 lines of code.
141
+ Enabled: false
142
+ CountComments: false
143
+ Max: 100
144
+ Metrics/LineLength:
145
+ Description: Limit lines to max 140 characters
146
+ Max: 140
147
+ AllowHeredoc: true
148
+ AllowURI: true
149
+ URISchemes:
150
+ - http
151
+ - https
152
+ Metrics/ModuleLength:
153
+ CountComments: false
154
+ Max: 100
155
+ Description: Avoid modules longer than 100 lines of code.
156
+ Enabled: false
157
+ Metrics/CyclomaticComplexity:
158
+ Description: A complexity metric that is strongly correlated to the number of test
159
+ cases needed to validate a method.
160
+ Enabled: false
161
+ Max: 6
162
+ Metrics/MethodLength:
163
+ Description: Avoid methods longer than 10 lines of code.
164
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods
165
+ Enabled: false
166
+ CountComments: false
167
+ Max: 10
168
+ Metrics/ParameterLists:
169
+ Description: Avoid parameter lists longer than three or four parameters.
170
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params
171
+ Enabled: false
172
+ Max: 5
173
+ CountKeywordArgs: true
174
+ Metrics/PerceivedComplexity:
175
+ Description: A complexity metric geared towards measuring complexity for a human
176
+ reader.
177
+ Enabled: false
178
+ Max: 7
179
+ Lint/AssignmentInCondition:
180
+ Description: Don't use assignment in conditions.
181
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition
182
+ Enabled: false
183
+ AllowSafeAssignment: true
184
+ Style/InlineComment:
185
+ Description: Avoid inline comments.
186
+ Enabled: false
187
+ Naming/AccessorMethodName:
188
+ Description: Check the naming of accessor methods for get_/set_.
189
+ Enabled: false
190
+ Style/Alias:
191
+ Description: Use alias_method instead of alias.
192
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method
193
+ Enabled: false
194
+ Style/Documentation:
195
+ Description: Document classes and non-namespace modules.
196
+ Enabled: false
197
+ Style/DoubleNegation:
198
+ Description: Checks for uses of double negation (!!).
199
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang
200
+ Enabled: false
201
+ Style/EachWithObject:
202
+ Description: Prefer `each_with_object` over `inject` or `reduce`.
203
+ Enabled: false
204
+ Style/EmptyLiteral:
205
+ Description: Prefer literals to Array.new/Hash.new/String.new.
206
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash
207
+ Enabled: false
208
+ Style/ModuleFunction:
209
+ Description: Checks for usage of `extend self` in modules.
210
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function
211
+ Enabled: false
212
+ Style/OneLineConditional:
213
+ Description: Favor the ternary operator(?:) over if/then/else/end constructs.
214
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator
215
+ Enabled: false
216
+ Style/PerlBackrefs:
217
+ Description: Avoid Perl-style regex back references.
218
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers
219
+ Enabled: false
220
+ Style/Send:
221
+ Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send`
222
+ may overlap with existing methods.
223
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send
224
+ Enabled: false
225
+ Style/SpecialGlobalVars:
226
+ Description: Avoid Perl-style global variables.
227
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms
228
+ Enabled: false
229
+ Style/VariableInterpolation:
230
+ Description: Don't interpolate global, instance and class variables directly in
231
+ strings.
232
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate
233
+ Enabled: false
234
+ Style/WhenThen:
235
+ Description: Use when x then ... for one-line cases.
236
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases
237
+ Enabled: false
238
+ Lint/EachWithObjectArgument:
239
+ Description: Check for immutable argument given to each_with_object.
240
+ Enabled: true
241
+ Lint/HandleExceptions:
242
+ Description: Don't suppress exception.
243
+ StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions
244
+ Enabled: false
245
+ Lint/LiteralInCondition:
246
+ Description: Checks of literals used in conditions.
247
+ Enabled: false
248
+ Lint/LiteralInInterpolation:
249
+ Description: Checks for literals used in interpolation.
250
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in europeana-feeds.gemspec
8
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,119 @@
1
+ # European Union Public Licence v. 1.1
2
+ EUPL © the European Community 2007
3
+
4
+ This European Union Public Licence (the “EUPL”) applies to the Work or Software (as defined below) which is provided under the terms of this Licence. Any use of the Work, other than as authorised under this Licence is prohibited (to the extent such use is covered by a right of the copyright holder of the Work).
5
+ The Original Work is provided under the terms of this Licence when the Licensor (as defined below) has placed the following notice immediately following the copyright notice for the Original Work:
6
+
7
+ Licensed under the EUPL v.1.1
8
+
9
+ or has expressed by any other mean his willingness to license under the EUPL.
10
+
11
+ ## 1. Definitions
12
+ In this Licence, the following terms have the following meaning:
13
+ - *The Licence*: this Licence.
14
+ - *The Original Work or the Software*: the software distributed and/or communicated by the Licensor under this Licence, available as Source Code and also as Executable Code as the case may be.
15
+ - *Derivative Works*: the works or software that could be created by the Licensee, based upon the Original Work or modifications thereof. This Licence does not define the extent of modification or dependence on the Original Work required in order to classify a work as a Derivative Work; this extent is determined by copyright law applicable in the country mentioned in Article 15.
16
+ - *The Work*: the Original Work and/or its Derivative Works.
17
+ - *The Source Code*: the human-readable form of the Work which is the most convenient for people to study and modify.
18
+ - *The Executable Code*: any code which has generally been compiled and which is meant to be interpreted by a computer as a program.
19
+ - *The Licensor*: the natural or legal person that distributes and/or communicates the Work under the Licence.
20
+ - *Contributor(s)*: any natural or legal person who modifies the Work under the Licence, or otherwise contributes to the creation of a Derivative Work.
21
+ - *The Licensee* or “*You*”: any natural or legal person who makes any usage of the Software under the terms of the Licence.
22
+ - *Distribution and/or Communication*: any act of selling, giving, lending, renting, distributing, communicating, transmitting, or otherwise making available, on-line or off-line, copies of the Work or providing access to its essential functionalities at the disposal of any other natural or legal person.
23
+
24
+ ## 2. Scope of the rights granted by the Licence
25
+ The Licensor hereby grants You a world-wide, royalty-free, non-exclusive, sub- licensable licence to do the following, for the duration of copyright vested in the Original Work:
26
+ - use the Work in any circumstance and for all usage,
27
+ - reproduce the Work,
28
+ - modify the Original Work, and make Derivative Works based upon the Work,
29
+ - communicate to the public, including the right to make available or display the Work or copies thereof to the public and perform publicly, as the case may be, the Work,
30
+ - distribute the Work or copies thereof,
31
+ - lend and rent the Work or copies thereof,
32
+ - sub-license rights in the Work or copies thereof.
33
+
34
+ Those rights can be exercised on any media, supports and formats, whether now known or later invented, as far as the applicable law permits so.
35
+
36
+ In the countries where moral rights apply, the Licensor waives his right to exercise his moral right to the extent allowed by law in order to make effective the licence of the economic rights here above listed.
37
+
38
+ The Licensor grants to the Licensee royalty-free, non exclusive usage rights to any patents held by the Licensor, to the extent necessary to make use of the rights granted on the Work under this Licence.
39
+
40
+ ## 3. Communication of the Source Code
41
+ The Licensor may provide the Work either in its Source Code form, or as Executable Code. If the Work is provided as Executable Code, the Licensor provides in addition a machine-readable copy of the Source Code of the Work along with each copy of the Work that the Licensor distributes or indicates, in a notice following the copyright notice attached to the Work, a repository where the Source Code is easily and freely accessible for as long as the Licensor continues to distribute and/or communicate the Work.
42
+
43
+ ## 4. Limitations on copyright
44
+ Nothing in this Licence is intended to deprive the Licensee of the benefits from any exception or limitation to the exclusive rights of the rights owners in the Original Work or Software, of the exhaustion of those rights or of other applicable limitations thereto.
45
+
46
+ ## 5. Obligations of the Licensee
47
+ The grant of the rights mentioned above is subject to some restrictions and obligations imposed on the Licensee. Those obligations are the following:
48
+
49
+ **Attribution right**: the Licensee shall keep intact all copyright, patent or trademarks notices and all notices that refer to the Licence and to the disclaimer of warranties. The Licensee must include a copy of such notices and a copy of the Licence with every copy of the Work he/she distributes and/or communicates. The Licensee must cause any Derivative Work to carry prominent notices stating that the Work has been modified and the date of modification.
50
+
51
+ **Copyleft clause**: If the Licensee distributes and/or communicates copies of the Original Works or Derivative Works based upon the Original Work, this Distribution and/or Communication will be done under the terms of this Licence or of a later version of this Licence unless the Original Work is expressly distributed only under this version of the Licence. The Licensee (becoming Licensor) cannot offer or impose any additional terms or conditions on the Work or Derivative Work that alter or restrict the terms of the Licence.
52
+
53
+ **Compatibility clause**: If the Licensee Distributes and/or Communicates Derivative Works or copies thereof based upon both the Original Work and another work licensed under a Compatible Licence, this Distribution and/or Communication can be done under the terms of this Compatible Licence. For the sake of this clause, “Compatible Licence” refers to the licences listed in the appendix attached to this Licence. Should the Licensee’s obligations under the Compatible Licence conflict with his/her obligations under this Licence, the obligations of the Compatible Licence shall prevail.
54
+
55
+ **Provision of Source Code**: When distributing and/or communicating copies of the Work, the Licensee will provide a machine-readable copy of the Source Code or indicate a repository where this Source will be easily and freely available for as long as the Licensee continues to distribute and/or communicate the Work.
56
+
57
+ **Legal Protection**: This Licence does not grant permission to use the trade names, trademarks, service marks, or names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the copyright notice.
58
+
59
+ ## 6. Chain of Authorship
60
+ The original Licensor warrants that the copyright in the Original Work granted hereunder is owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence.
61
+
62
+ Each Contributor warrants that the copyright in the modifications he/she brings to the Work are owned by him/her or licensed to him/her and that he/she has the power and authority to grant the Licence.
63
+
64
+ Each time You accept the Licence, the original Licensor and subsequent Contributors grant You a licence to their contributions to the Work, under the terms of this Licence.
65
+
66
+ ## 7. Disclaimer of Warranty
67
+ The Work is a work in progress, which is continuously improved by numerous contributors. It is not a finished work and may therefore contain defects or “bugs” inherent to this type of software development.
68
+
69
+ For the above reason, the Work is provided under the Licence on an “as is” basis and without warranties of any kind concerning the Work, including without limitation merchantability, fitness for a particular purpose, absence of defects or errors, accuracy, non-infringement of intellectual property rights other than copyright as stated in Article 6 of this Licence.
70
+
71
+ This disclaimer of warranty is an essential part of the Licence and a condition for the grant of any rights to the Work.
72
+
73
+ ## 8. Disclaimer of Liability
74
+ Except in the cases of wilful misconduct or damages directly caused to natural persons, the Licensor will in no event be liable for any direct or indirect, material or moral, damages of any kind, arising out of the Licence or of the use of the Work, including without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, loss of data or any commercial damage, even if the Licensor has been advised of the possibility of such damage. However, the Licensor will be liable under statutory product liability laws as far such laws apply to the Work.
75
+
76
+ ## 9. Additional agreements
77
+ While distributing the Original Work or Derivative Works, You may choose to conclude an additional agreement to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or services consistent with this Licence. However, in accepting such obligations, You may act only on your own behalf and on your sole responsibility, not on behalf of the original Licensor or any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against such Contributor by the fact You have accepted any such warranty or additional liability.
78
+ 
79
+ ## 10. Acceptance of the Licence
80
+ The provisions of this Licence can be accepted by clicking on an icon “I agree” placed under the bottom of a window displaying the text of this Licence or by affirming consent in any other similar way, in accordance with the rules of applicable law. Clicking on that icon indicates your clear and irrevocable acceptance of this Licence and all of its terms and conditions.
81
+
82
+ Similarly, you irrevocably accept this Licence and all of its terms and conditions by exercising any rights granted to You by Article 2 of this Licence, such as the use of the Work, the creation by You of a Derivative Work or the Distribution and/or Communication by You of the Work or copies thereof.
83
+
84
+ ## 11. Information to the public
85
+ In case of any Distribution and/or Communication of the Work by means of electronic communication by You (for example, by offering to download the Work from a remote location) the distribution channel or media (for example, a website) must at least provide to the public the information requested by the applicable law regarding the Licensor, the Licence and the way it may be accessible, concluded, stored and reproduced by the Licensee.
86
+
87
+ ## 12. Termination of the Licence
88
+ The Licence and the rights granted hereunder will terminate automatically upon any breach by the Licensee of the terms of the Licence.
89
+
90
+ Such a termination will not terminate the licences of any person who has received the Work from the Licensee under the Licence, provided such persons remain in full compliance with the Licence.
91
+
92
+ ## 13. Miscellaneous
93
+ Without prejudice of Article 9 above, the Licence represents the complete agreement between the Parties as to the Work licensed hereunder.
94
+
95
+ If any provision of the Licence is invalid or unenforceable under applicable law, this will not affect the validity or enforceability of the Licence as a whole. Such provision will be construed and/or reformed so as necessary to make it valid and enforceable.
96
+
97
+ The European Commission may publish other linguistic versions and/or new versions of this Licence, so far this is required and reasonable, without reducing the scope of the rights granted by the Licence. New versions of the Licence will be published with a unique version number.
98
+
99
+ All linguistic versions of this Licence, approved by the European Commission, have identical value. Parties can take advantage of the linguistic version of their choice.
100
+ 
101
+ ## 14. Jurisdiction
102
+ Any litigation resulting from the interpretation of this License, arising between the European Commission, as a Licensor, and any Licensee, will be subject to the jurisdiction of the Court of Justice of the European Communities, as laid down in article 238 of the Treaty establishing the European Community.
103
+
104
+ Any litigation arising between Parties, other than the European Commission, and resulting from the interpretation of this License, will be subject to the exclusive jurisdiction of the competent court where the Licensor resides or conducts its primary business.
105
+
106
+ ## 15. Applicable Law
107
+ This Licence shall be governed by the law of the European Union country where the Licensor resides or has his registered office.
108
+
109
+ This licence shall be governed by the Belgian law if:
110
+
111
+ - a litigation arises between the European Commission, as a Licensor, and any Licensee;
112
+ - the Licensor, other than the European Commission, has no residence or registered office inside a European Union country.
113
+
114
+ ## Appendix
115
+ “Compatible Licences” according to article 5 EUPL are:
116
+ - *GNU General Public License (GNU GPL) v. 2 - Open Software License (OSL) v. 2.1, v. 3.0*
117
+ - *Common Public License v. 1.0*
118
+ - *Eclipse Public License v. 1.0*
119
+ - *Cecill v. 2.0*
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ # europeana-feeds
2
+
3
+ [![Build Status](https://travis-ci.org/europeana/europeana-feeds.svg?branch=develop)](https://travis-ci.org/europeana/europeana-feeds) [![Code Climate](https://codeclimate.com/github/europeana/europeana-feeds/badges/gpa.svg)](https://codeclimate.com/github/europeana/europeana-feeds)
4
+
5
+ Rails Engine to retrieve and manage cached versions of RSS feeds.
6
+
7
+ ## Usage
8
+
9
+ Simply add "europeana-feeds" to your Rails app's Gemfile and `bundle`.
10
+
11
+ ## License
12
+ Licensed under the EUPL V.1.1.
13
+
14
+ For full details, see [LICENSE.md](LICENSE.md).
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Europeana
4
+ module Feeds
5
+ module FeedHelper
6
+ def feed_entries(url)
7
+ feed = cached_feed(url)
8
+ feed.present? ? feed.entries : []
9
+ end
10
+
11
+ def cached_feed(url)
12
+ @cached_feeds ||= {}
13
+ @cached_feeds[url] ||= begin
14
+ Rails.cache.fetch("feed/#{url}")
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Europeana
4
+ module Feeds
5
+ class FetchJob < ActiveJob::Base
6
+ queue_as :feeds
7
+
8
+ def perform(url)
9
+ @url = url
10
+
11
+ @feed = ::Feedjira::Feed.fetch_and_parse(@url)
12
+
13
+ feed_cache_key = "feed/#{@url}"
14
+ cached_feed = Rails.cache.fetch(feed_cache_key)
15
+
16
+ if cached_feed.blank? || cached_feed.last_modified != @feed.last_modified
17
+ Rails.cache.write(feed_cache_key, @feed)
18
+ @updated = true
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Europeana
4
+ module Feeds
5
+ ##
6
+ # Models an image extracted from a remote RSS feed
7
+ class FeedEntryImage
8
+ # Methods of `[Feedjira::Parser::RSSEntry]` feed entry to inspect for image
9
+ # URLs
10
+ ENTRY_ELEMENTS = %i(summary content).freeze
11
+
12
+ # HTML tag and attribute pairs to inspect for image URLs
13
+ TAGS_ATTRS = [
14
+ { tag: :img, attr: :src },
15
+ { tag: :video, attr: :poster }
16
+ ].freeze
17
+
18
+ # @param feed_entry [Feedjira::Parser::RSSEntry]
19
+ def initialize(feed_entry)
20
+ @feed_entry = feed_entry
21
+ end
22
+
23
+ def url
24
+ @url ||= find_url_in_feed_entry
25
+ end
26
+
27
+ protected
28
+
29
+ def find_url_in_feed_entry
30
+ # first check for attached images
31
+ return @feed_entry.image if @feed_entry.image
32
+
33
+ TAGS_ATTRS.each do |tag_attr|
34
+ url = first_url_attr(tag_attr[:tag], tag_attr[:attr])
35
+ return url unless url.nil?
36
+ end
37
+ nil
38
+ end
39
+
40
+ def element_html(element_name)
41
+ Nokogiri::HTML(@feed_entry.send(element_name))
42
+ end
43
+
44
+ def first_tag_in_element(element_name, tag_name)
45
+ element_html(element_name).css(tag_name).first
46
+ end
47
+
48
+ def first_attr_on_element(element_name, tag_name, attr_name)
49
+ first_tag = first_tag_in_element(element_name, tag_name)
50
+ first_tag.nil? ? nil : first_tag[attr_name]
51
+ end
52
+
53
+ def first_url_attr_on_element(element_name, tag_name, attr_name)
54
+ attr_value = first_attr_on_element(element_name, tag_name, attr_name)
55
+ attr_value.present? && attr_value =~ %r{\Ahttps?://} ? attr_value : nil
56
+ end
57
+
58
+ def first_url_attr(tag_name, attr_name)
59
+ ENTRY_ELEMENTS.each do |element_name|
60
+ url_attr = first_url_attr_on_element(element_name, tag_name, attr_name)
61
+ return url_attr unless url_attr.nil?
62
+ end
63
+ nil
64
+ end
65
+ end
66
+ end
67
+ end
data/bin/console ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'irb'
6
+ require 'irb/completion' # easy tab completion
7
+ require 'bundler/setup'
8
+ require 'europeana/feeds'
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+
13
+ # (If you use this, don't forget to add pry to your Gemfile!)
14
+ # require 'pry'
15
+ # Pry.start
16
+
17
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ #!/usr/bin/env bash
4
+ set -euo pipefail
5
+ IFS=$'\n\t'
6
+ set -vx
7
+
8
+ bundle install
9
+
10
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Europeana
4
+ module Feeds
5
+ class Engine < Rails::Engine
6
+ isolate_namespace Europeana::Feeds
7
+
8
+ engine_name 'europeana_feeds'
9
+
10
+ config.generators do |g|
11
+ g.test_framework :rspec
12
+ end
13
+
14
+ config.autoload_paths += %W(
15
+ #{config.root}
16
+ )
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Europeana
4
+ module Feeds
5
+ VERSION = '0.0.1'
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_job'
4
+ require 'feedjira'
5
+ require 'rails'
6
+ require 'europeana/feeds/engine'
7
+
8
+ module Europeana
9
+ module Feeds
10
+ autoload :FetchJob, 'europeana/feeds/fetch_job'
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,196 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: europeana-feeds
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lutz Biedinger
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: feedjira
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.15'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.15'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.50.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.50.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.3'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.3'
139
+ - !ruby/object:Gem::Dependency
140
+ name: coveralls
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.7.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.7.1
153
+ description: Rails Engine to retrieve and cache rss feeds
154
+ email:
155
+ - lutz.biedinger@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".rubocop.yml"
161
+ - Gemfile
162
+ - LICENSE.md
163
+ - README.md
164
+ - app/helpers/europeana/feeds/feed_helper.rb
165
+ - app/jobs/europeana/feeds/fetch_job.rb
166
+ - app/models/europeana/feeds/feed_entry_image.rb
167
+ - bin/console
168
+ - bin/setup
169
+ - lib/europeana/feeds.rb
170
+ - lib/europeana/feeds/engine.rb
171
+ - lib/europeana/feeds/version.rb
172
+ homepage: https://github.org/europeana/europeana-feeds
173
+ licenses:
174
+ - EUPL-1.1
175
+ metadata: {}
176
+ post_install_message:
177
+ rdoc_options: []
178
+ require_paths:
179
+ - lib
180
+ required_ruby_version: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - ">="
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ requirements: []
191
+ rubyforge_project:
192
+ rubygems_version: 2.6.11
193
+ signing_key:
194
+ specification_version: 4
195
+ summary: This gem retrieves rss feeds and caches their contents
196
+ test_files: []