ical_importer 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,5 @@
1
+ #### 2012-10-10 **Version 0.15**
2
+
3
+ * Adjustable request timeout on ical feed retrieval
4
+
5
+ > @NickLaMuro: https://github.com/tstmedia/ical_importer/pull/2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ical_importer (0.0.14)
4
+ ical_importer (0.0.15)
5
5
  activesupport (~> 3.0.15)
6
6
  i18n
7
7
  ri_cal
data/README.md CHANGED
@@ -21,6 +21,9 @@ Then you can do:
21
21
  ```ruby
22
22
  IcalImporter::Parser.new(a_url).parse # To get just an array of events
23
23
 
24
+ # To get just an array of events, with a longer timeout [default is 8 sec]
25
+ IcalImporter::Parser.new(a_url, :timeout => 40).parse
26
+
24
27
  IcalImporter::Parser.new(a_url).parse do |event|
25
28
  event.uid
26
29
  event.title
@@ -1,10 +1,19 @@
1
1
  module IcalImporter
2
2
  class Parser
3
3
  attr_reader :feed, :bare_feed, :url
4
+ attr_accessor :timeout
4
5
 
5
- def initialize(url)
6
+ DEFAULT_TIMEOUT = 8
7
+
8
+ # Get a new Parser object
9
+ #
10
+ # url - URL where we download the ical feed
11
+ # options - Options hash
12
+ # :timeout - Custom timeout for downloading ical feed [Default: 8]
13
+ def initialize(url, options={})
6
14
  @url = url
7
15
  @bare_feed = open_ical
16
+ @timeout = options[:timeout] || DEFAULT_TIMEOUT
8
17
  if should_parse?
9
18
  @bare_feed.pos = 0
10
19
  begin
@@ -57,7 +66,7 @@ module IcalImporter
57
66
  def open_ical(protocol = 'http')
58
67
  raise ArgumentError, "Must be http or https" unless %w[http https].include? protocol
59
68
  begin
60
- ::Timeout::timeout(8) do
69
+ ::Timeout::timeout(@timeout) do
61
70
  open prepped_uri(protocol)
62
71
  end
63
72
  rescue
@@ -1,3 +1,3 @@
1
1
  module IcalImporter
2
- VERSION = '0.0.14'
2
+ VERSION = '0.0.15'
3
3
  end
@@ -16,6 +16,23 @@ module IcalImporter
16
16
  RiCal.should_receive(:parse).with bare_stuff
17
17
  Parser.new(url)
18
18
  end
19
+
20
+ it "defaults a timeout to the DEFAULT_TIMEOUT" do
21
+ Parser.any_instance.stub(:open_ical).and_return bare_stuff
22
+ parser = Parser.new(url)
23
+ parser.timeout.should == Parser::DEFAULT_TIMEOUT
24
+ end
25
+
26
+ context "when a user defines a timeout" do
27
+ it "sets the timeout" do
28
+ Parser.any_instance.stub(:open_ical).and_return bare_stuff
29
+ parser = Parser.new(url, :timeout => 11)
30
+ parser.timeout.should == 11
31
+
32
+ parser.timeout = 10
33
+ parser.timeout.should == 10
34
+ end
35
+ end
19
36
  end
20
37
 
21
38
  describe "#should_parse?" do
@@ -90,6 +107,21 @@ module IcalImporter
90
107
  it "fails with an invalid protocol" do
91
108
  expect { subject.send(:open_ical, 'wrong_proto') }.to raise_error(ArgumentError, "Must be http or https")
92
109
  end
110
+
111
+ it "will wait up to #{Parser::DEFAULT_TIMEOUT} secs" do
112
+ Timeout.should_receive(:timeout).with(Parser::DEFAULT_TIMEOUT)
113
+ subject.send(:open_ical, 'http')
114
+ end
115
+
116
+ context "when timeout is defined" do
117
+
118
+ it "will wait up to the defined time" do
119
+ subject.timeout = 9
120
+ Timeout.should_receive(:timeout).with(9)
121
+ subject.send(:open_ical, 'http')
122
+ end
123
+
124
+ end
93
125
  end
94
126
 
95
127
  describe "#prepped_uri" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ical_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-29 00:00:00.000000000 Z
12
+ date: 2012-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -118,6 +118,7 @@ files:
118
118
  - .rspec
119
119
  - .rvmrc
120
120
  - .travis.yml
121
+ - CHANGELOG
121
122
  - Gemfile
122
123
  - Gemfile.lock
123
124
  - README.md
@@ -158,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
158
159
  version: '0'
159
160
  segments:
160
161
  - 0
161
- hash: -3814022261725594651
162
+ hash: 3561992931881412650
162
163
  required_rubygems_version: !ruby/object:Gem::Requirement
163
164
  none: false
164
165
  requirements:
@@ -167,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  version: '0'
168
169
  segments:
169
170
  - 0
170
- hash: -3814022261725594651
171
+ hash: 3561992931881412650
171
172
  requirements: []
172
173
  rubyforge_project:
173
174
  rubygems_version: 1.8.24