rssendy 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4279fe8795a2b0eed13011b09f0db4a4fc8ef2b2
4
- data.tar.gz: 8d6635ebb524ea491eff6ef6826ddc2c928e2dd0
3
+ metadata.gz: 2feac2b5ec0601ea52e8481f00f3355594018bc5
4
+ data.tar.gz: 1d3f5022dc0b41ba46754288d329ab97b6009745
5
5
  SHA512:
6
- metadata.gz: 9cb39eef61139aecf4d70e0b60facdb3a62e9289429b46103ea3f27c30590b3eadf20357a40266ef02951d1043626d89b736aeab725c4776a1b6ab06233cff33
7
- data.tar.gz: f44bac0b1d320bb2a4d1ced454658f7d473b8275afd6aee00d77789791ba8388172146a0f7872039d685ca4ced542565a7d24c3aab70f1d5f878438d6f4de022
6
+ metadata.gz: 35be4485db70650686dba33e206937a08e8b9ae36041a43f07d374f9f65fb33da3f5a29b34fd4402418b8c60a92de5e0ff2992c676ba52fba21f81abc517391c
7
+ data.tar.gz: 71f368a5dd5a3cf467c8c0a953bb2fc30f644968e81280f8a874fce9b361482b356e5bcd6e7d144fe9fde82823a2af635f59327ee4573c582134042eaf11db09
@@ -1,3 +1,3 @@
1
1
  module RSSendy
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/rssendy.rb CHANGED
@@ -29,7 +29,7 @@ module RSSendy
29
29
  class Feed
30
30
  PROPERTIES = %i{
31
31
  api_key url template host from_name from_email reply_to
32
- subject plain_text html_text list_ids brand_id send_campaign
32
+ plain_text html_text list_ids brand_id send_campaign rss_subject
33
33
  }
34
34
  REQUIREMENTS = %i(api_key content url template host from_name from_email reply_to subject)
35
35
 
@@ -49,17 +49,25 @@ module RSSendy
49
49
  return @__cont_blk__ unless cont
50
50
  @__cont_blk__ = ->(doc) {doc.instance_eval(cont.sub(/^doc\./, ''))}
51
51
  end
52
+
53
+ def subject(subj=nil)
54
+ return @__subject__ unless subj
55
+ @__subject__ = subj
56
+ end
52
57
  end
53
58
 
54
59
  def initialize(opts={})
55
60
  PROPERTIES.each do |property|
56
61
  send("#{property}=", opts[property] || self.class.send(property))
57
62
  end
63
+ @subject = opts.fetch(:subject, self.class.subject)
58
64
  @content = opts.fetch(:content, self.class.content)
65
+ @rss_subject = !!rss_subject
59
66
  end
60
67
 
61
68
  attr_accessor(*PROPERTIES)
62
69
  attr_reader :response, :doc, :items, :html_template
70
+ attr_writer :subject
63
71
 
64
72
  def content
65
73
  return @content if Proc === @content || @content.nil?
@@ -67,6 +75,14 @@ module RSSendy
67
75
  @content = ->(doc) { doc.instance_eval(_cont.sub(/^doc\./, '')) }
68
76
  end
69
77
 
78
+ def subject
79
+ return @subject unless rss_subject? && !(Proc === @subject)
80
+ return unless @subject
81
+
82
+ _subj = @subject.dup
83
+ @subject = ->(doc) { doc.instance_eval(_subj.sub(/^doc\./, '')) }
84
+ end
85
+
70
86
  def pull!
71
87
  raise InvalidFeedError, "Feed invalid. Missing keys: #{missing_keys.inspect}" unless valid?
72
88
 
@@ -99,12 +115,16 @@ module RSSendy
99
115
 
100
116
  private
101
117
 
118
+ def rss_subject?
119
+ rss_subject
120
+ end
121
+
102
122
  def build_opts
103
123
  {
104
124
  from_name: from_name,
105
125
  from_email: from_email,
106
126
  reply_to: reply_to,
107
- subject: subject,
127
+ subject: rss_subject? ? parse_subject : subject,
108
128
  html_text: build_template
109
129
  }.tap {|opts|
110
130
  %i(plain_text list_ids brand_id send_campaign).each do |property|
@@ -113,6 +133,10 @@ module RSSendy
113
133
  end
114
134
  }
115
135
  end
136
+
137
+ def parse_subject
138
+ doc.instance_eval(subject)
139
+ end
116
140
  end
117
141
  end
118
142
 
data/spec/rssendy_spec.rb CHANGED
@@ -19,6 +19,9 @@ RSpec.describe RSSendy::Feed do
19
19
  <<-RSS
20
20
  <rss xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0">
21
21
  <channel>
22
+ <title>
23
+ why, hello thar
24
+ </title>
22
25
  <item>
23
26
  <content:encoded>
24
27
  <![CDATA[
@@ -72,6 +75,24 @@ RSpec.describe RSSendy::Feed do
72
75
  describe 'instance' do
73
76
  let(:feed) { subject.new }
74
77
 
78
+ describe "setting subject" do
79
+ context "when rss_subject false" do
80
+ it "has subject set manually" do
81
+ expect(feed.subject).to eql("latest news")
82
+ end
83
+ end
84
+
85
+ context "when rss_subject true" do
86
+ before do
87
+ feed.subject = 'doc.at_xpath("//title").text.strip'
88
+ feed.rss_subject = true
89
+ end
90
+
91
+ it "pulls subject from feed" do
92
+ expect(feed.subject[doc]).to eql("why, hello thar")
93
+ end
94
+ end
95
+ end
75
96
  describe '#build_template' do
76
97
  context "when valid" do
77
98
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rssendy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - jonah honeyman