weneedfeed 0.8.0 → 0.9.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
  SHA256:
3
- metadata.gz: a2634d6a72650518bf2845381116e208a65fbb9f067b6e19f58352bb46ecb5ba
4
- data.tar.gz: 1ccc6647e1a02d34af10460b34d5cd594eb5a184cbe18e2244d45637a38d9d96
3
+ metadata.gz: 3b2041bae9e09565e1b72a4799f8a57034ad73c139de460dc0d187a5b94dbbe2
4
+ data.tar.gz: 292b45f698fb86f8cd5632687210ab6c09cd74a6d6ad340bb6eb7b989ffc4e3a
5
5
  SHA512:
6
- metadata.gz: 18d069fc8460e37e79b67869bd91f64d28f865d052c4464d6f169f811ad32c27698ccad3235f4b7f047160cd68341f56a576701758bb367d9766e9f8d46dc9c3
7
- data.tar.gz: b4f5e74955365a5184b90ea2ce877b0f548e55da5a9eb55e1f92ad64e66f0426397fb441ccda7d4a678ec5c9acb2b4f782c0185fdbe511139b53087b0e6e0a05
6
+ metadata.gz: 8dc45d743eb961d6a18983b8c20340b1e4c2085c7ed1c348332bddb51c211aa2c5067211e789f9cdd192eb3b161602d63f304adc8421ade49210ce11396a0031
7
+ data.tar.gz: 60f284ba462f92130a3de4702e33ae3d73418a3057459b40656e75f0a27e8ad9bc8b67946b1137b590f38250d5dec695cdfe41cad58f96947cf0dc0885c2839b
@@ -7,14 +7,24 @@ on:
7
7
  - master
8
8
 
9
9
  jobs:
10
- build:
11
- runs-on: ubuntu-18.04
10
+ rspec:
11
+ runs-on: ubuntu-20.04
12
12
  steps:
13
13
  - uses: actions/checkout@v2
14
+ - uses: ruby/setup-ruby@v1
15
+ with:
16
+ bundler-cache: true
17
+ ruby-version: 2.7.2
18
+ - run: bundle exec rspec --force-color
19
+ rubocop:
20
+ runs-on: ubuntu-20.04
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ with:
24
+ ref: ${{ github.event.pull_request.head.sha }}
14
25
  - uses: ruby/setup-ruby@v1
15
26
  with:
16
27
  bundler-cache: true
17
28
  ruby-version: 2.7.2
18
29
  - uses: r7kamura/rubocop-problem-matchers-action@v1
19
30
  - run: bundle exec rubocop --parallel
20
- - run: bundle exec rspec --force-color
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## Unreleased
9
9
 
10
+ ## 0.9.0 - 2020-12-03
11
+
12
+ ### Added
13
+
14
+ - Add item_image_selector.
15
+
10
16
  ## 0.8.0 - 2020-11-25
11
17
 
12
18
  ### Added
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weneedfeed (0.8.0)
4
+ weneedfeed (0.9.0)
5
5
  activesupport
6
6
  builder
7
7
  faraday
8
8
  faraday_middleware
9
9
  hibana (>= 0.2)
10
+ mimemagic
10
11
  nokogiri
11
12
  rack-capture (>= 0.4.0)
12
13
  thor
@@ -44,6 +45,7 @@ GEM
44
45
  tilt
45
46
  i18n (1.8.5)
46
47
  concurrent-ruby (~> 1.0)
48
+ mimemagic (0.3.5)
47
49
  mini_portile2 (2.4.0)
48
50
  minitest (5.14.2)
49
51
  multipart-post (2.1.1)
@@ -106,7 +108,7 @@ GEM
106
108
  addressable (>= 2.3.6)
107
109
  crack (>= 0.3.2)
108
110
  hashdiff (>= 0.4.0, < 2.0.0)
109
- zeitwerk (2.4.1)
111
+ zeitwerk (2.4.2)
110
112
 
111
113
  PLATFORMS
112
114
  ruby
data/README.md CHANGED
@@ -27,7 +27,7 @@ gem install weneedfeed
27
27
 
28
28
  ## Schema
29
29
 
30
- You need to write a schema file named with `weneedfeed.yml` to use this gem.
30
+ Weneedfeed requires `weneedfeed.yml` that describes URLs and selectors.
31
31
 
32
32
  ### Example
33
33
 
@@ -39,6 +39,7 @@ pages:
39
39
  url: http://example.com/1
40
40
  item_selector: li
41
41
  item_description_selector: p:nth-child(3)
42
+ item_image_selector: img
42
43
  item_link_selector: a
43
44
  item_time_selector: time
44
45
  item_title_selector: p:nth-child(2)
@@ -47,6 +48,7 @@ pages:
47
48
  description: Example feed with XPath
48
49
  url: http://example.com/2
49
50
  item_selector: //li
51
+ item_image_selector: .//img
50
52
  item_description_selector: .//p[3]
51
53
  item_link_selector: .//a
52
54
  item_time_selector: .//time
@@ -109,6 +111,13 @@ CSS or XPath selector to find element with description information in each item.
109
111
  - optional
110
112
  - Used for `<description>` in `<item>`.
111
113
 
114
+ ### `item_image_selector`
115
+
116
+ CSS or XPath selector to find `<img>`element in each item.
117
+
118
+ - optional
119
+ - Used for `<enclosure>` in `<item>`.
120
+
112
121
  ### `item_time_selector`
113
122
 
114
123
  CSS or XPath selector to find element with datetime information in each item.
@@ -13,6 +13,7 @@ module Weneedfeed
13
13
  scraping = ::Weneedfeed::Scraping.new(
14
14
  description: page_schema.description,
15
15
  item_description_selector: page_schema.item_description_selector,
16
+ item_image_selector: page_schema.item_image_selector,
16
17
  item_link_selector: page_schema.item_link_selector,
17
18
  item_time_selector: page_schema.item_time_selector,
18
19
  item_title_selector: page_schema.item_title_selector,
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'mimemagic'
4
+
3
5
  module Weneedfeed
4
6
  class Item
5
7
  class << self
@@ -16,6 +18,7 @@ module Weneedfeed
16
18
  end
17
19
 
18
20
  # @param [String, nil] description_selector
21
+ # @param [String, nil] image_selector
19
22
  # @param [String, nil] link_selector
20
23
  # @param [Nokogiri::Node] node
21
24
  # @param [String] time_selector
@@ -23,6 +26,7 @@ module Weneedfeed
23
26
  # @param [String] url
24
27
  def initialize(
25
28
  description_selector:,
29
+ image_selector:,
26
30
  link_selector:,
27
31
  node:,
28
32
  time_selector:,
@@ -30,6 +34,7 @@ module Weneedfeed
30
34
  url:
31
35
  )
32
36
  @description_selector = description_selector
37
+ @image_selector = image_selector
33
38
  @link_selector = link_selector
34
39
  @node = node
35
40
  @time_selector = time_selector
@@ -44,6 +49,29 @@ module Weneedfeed
44
49
  @node.at(@description_selector)&.inner_html
45
50
  end
46
51
 
52
+ # @return [String, nil]
53
+ def image_mime_type
54
+ return unless image_url
55
+
56
+ ::MimeMagic.by_path(image_url)&.type
57
+ end
58
+
59
+ # @return [String, nil]
60
+ def image_path_or_url
61
+ return unless @image_selector
62
+
63
+ @node.at(@image_selector)&.[]('src')
64
+ end
65
+
66
+ def image_url
67
+ return unless image_path_or_url
68
+
69
+ ::URI.join(
70
+ @url,
71
+ image_path_or_url
72
+ ).to_s
73
+ end
74
+
47
75
  # @return [String]
48
76
  def link
49
77
  ::URI.join(
@@ -13,6 +13,7 @@ module Weneedfeed
13
13
 
14
14
  # @param [String, nil] description
15
15
  # @param [String, nil] item_description_selector
16
+ # @param [String, nil] item_image_selector
16
17
  # @param [String] item_link_selector
17
18
  # @param [String, nil] item_time_selector
18
19
  # @param [String] item_title_selector
@@ -23,6 +24,7 @@ module Weneedfeed
23
24
  def initialize(
24
25
  description:,
25
26
  item_description_selector:,
27
+ item_image_selector:,
26
28
  item_link_selector:,
27
29
  item_time_selector:,
28
30
  item_title_selector:,
@@ -33,6 +35,7 @@ module Weneedfeed
33
35
  )
34
36
  @description = description
35
37
  @item_description_selector = item_description_selector
38
+ @item_image_selector = item_image_selector
36
39
  @item_link_selector = item_link_selector
37
40
  @item_time_selector = item_time_selector
38
41
  @item_title_selector = item_title_selector
@@ -47,6 +50,7 @@ module Weneedfeed
47
50
  @node.search(@item_selector).map do |node|
48
51
  ::Weneedfeed::Item.new(
49
52
  description_selector: @item_description_selector,
53
+ image_selector: @item_image_selector,
50
54
  link_selector: @item_link_selector,
51
55
  node: node,
52
56
  time_selector: @item_time_selector,
@@ -5,6 +5,7 @@ module Weneedfeed
5
5
  :description,
6
6
  :id,
7
7
  :item_description_selector,
8
+ :item_image_selector,
8
9
  :item_link_selector,
9
10
  :item_time_selector,
10
11
  :item_title_selector,
@@ -27,6 +27,7 @@ module Weneedfeed
27
27
  description: hash['description'],
28
28
  id: hash['id'],
29
29
  item_description_selector: hash['item_description_selector'],
30
+ item_image_selector: hash['item_image_selector'],
30
31
  item_link_selector: hash['item_link_selector'],
31
32
  item_time_selector: hash['item_time_selector'],
32
33
  item_title_selector: hash['item_title_selector'],
@@ -16,6 +16,7 @@ module Weneedfeed
16
16
 
17
17
  # @param [String, nil] description
18
18
  # @param [String, nil] item_description_selector
19
+ # @param [String, nil] item_image_selector
19
20
  # @param [String] item_link_selector
20
21
  # @param [String, nil] item_time_selector
21
22
  # @param [String] item_title_selector
@@ -25,6 +26,7 @@ module Weneedfeed
25
26
  def initialize(
26
27
  description:,
27
28
  item_description_selector:,
29
+ item_image_selector:,
28
30
  item_link_selector:,
29
31
  item_time_selector:,
30
32
  item_title_selector:,
@@ -34,6 +36,7 @@ module Weneedfeed
34
36
  )
35
37
  @description = description
36
38
  @item_description_selector = item_description_selector
39
+ @item_image_selector = item_image_selector
37
40
  @item_link_selector = item_link_selector
38
41
  @item_time_selector = item_time_selector
39
42
  @item_title_selector = item_title_selector
@@ -48,6 +51,7 @@ module Weneedfeed
48
51
  description: @description,
49
52
  node: parsed_body,
50
53
  item_description_selector: @item_description_selector,
54
+ item_image_selector: @item_image_selector,
51
55
  item_selector: @item_selector,
52
56
  item_link_selector: @item_link_selector,
53
57
  item_time_selector: @item_time_selector,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Weneedfeed
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.0'
5
5
  end
@@ -18,6 +18,9 @@
18
18
  <description><![CDATA[<%= item.description %>]]></description>
19
19
  <content:encoded><![CDATA[<%= item.description %>]]></content:encoded>
20
20
  <guid isPermaLink="true"><%= item.link %></guid>
21
+ <% if item.image_url %>
22
+ <enclosure url="<%= item.image_url %>" length="0" type="<%= item.image_mime_type %>"/>
23
+ <% end %>
21
24
  </item>
22
25
  <% end %>
23
26
  </channel>
@@ -30,6 +30,7 @@ Gem::Specification.new do |spec|
30
30
  spec.add_runtime_dependency 'faraday'
31
31
  spec.add_runtime_dependency 'faraday_middleware'
32
32
  spec.add_runtime_dependency 'hibana', '>= 0.2'
33
+ spec.add_runtime_dependency 'mimemagic'
33
34
  spec.add_runtime_dependency 'nokogiri'
34
35
  spec.add_runtime_dependency 'rack-capture', '>= 0.4.0'
35
36
  spec.add_runtime_dependency 'thor'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weneedfeed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-24 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mimemagic
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: nokogiri
85
99
  requirement: !ruby/object:Gem::Requirement