prss 0.0.4 → 0.1.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: d1176b8f43cdd7c519ad79d292b850861d06b6ff
4
- data.tar.gz: 7c374a5ac3c2517461430c3fe097ae4c371abcfa
3
+ metadata.gz: ee79ca4d201ebbb863d737edfffd73710aa4b20b
4
+ data.tar.gz: 9af8aec01e87a5a30fab518a44b270489bfd9b63
5
5
  SHA512:
6
- metadata.gz: f7eb59102064673804a8ede8afd50008ce8b0493b49a426bb48dc148a6b3bc05e0a2bff0adc5f453e534a15ecfb65da82d75ec6f4e67b9346044d05eac0cbf55
7
- data.tar.gz: 73b69e973a54eade35212d51f957b8bd83f6f4aac58ad0b9b1b3141732b4b772ff4c9c26926fbabe06a627b2454387200af86c5e534da4f55395dd44821ac106
6
+ metadata.gz: 074b08ebb7ab6b160fe677bc3ce123aa9e3a41b20022dab036ddba830d2293aa761bedb9e48093976bf4e7384a93a13694c0b701f0321a364b63781d3346051f
7
+ data.tar.gz: fb15dfb41b540497e6076198245629375f709908eff3452c465142804e569ce2e748eb6296c2acc35fce7aee163e94ea3afc4eadc6f99c618a33a0f78a8e09d6
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/bin/prss CHANGED
@@ -1,11 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'prss'
4
- case ARGV.size
5
- when 2
6
- PRSS::CLI.new(*ARGV).run!
7
- else
8
- puts %{
9
- USAGE: prss passkey output_dir
10
- }
11
- end
4
+
5
+ PRSS::CLI.start
@@ -1,7 +1,8 @@
1
1
  module PRSS
2
2
  autoload :CLI, 'prss/cli'
3
3
  autoload :Downloader, 'prss/downloader'
4
- autoload :Fetcher, 'prss/fetcher'
5
- autoload :Parser, 'prss/parser'
4
+ autoload :Feed, 'prss/feed'
5
+ autoload :Links, 'prss/links'
6
6
  autoload :VERSION, 'prss/version'
7
+ autoload :Watcher, 'prss/watcher'
7
8
  end
@@ -1,20 +1,26 @@
1
- require 'pathname'
1
+ require 'thor'
2
2
 
3
3
  module PRSS
4
- class CLI
5
- def initialize passkey, output_dir
6
- @passkey = passkey
7
- @output_dir = Pathname.new(output_dir)
8
- raise 'no passkey' unless passkey
9
- raise 'no output dir' unless output_dir
4
+ class CLI < Thor
5
+
6
+
7
+ desc 'watch PASSKEY OUTPUT', 'run in loop in given interval'
8
+ method_option :interval, type: :numeric, default: 30, aliases: %w[-i]
9
+ def watch(passkey, output)
10
+ Downloader.verify!(output)
11
+ feed = Feed.new(passkey)
12
+ watcher = Watcher.new(feed)
13
+ watcher.start(options[:interval], output)
10
14
  end
11
15
 
12
- def run!
13
- output = Fetcher.new(@passkey).output
14
- links = Parser.new(output)
15
- downloaded = Downloader.new(links).download_to(@output_dir)
16
+ desc 'download PASSKEY OUTPUT', 'fetch feed once and quit'
17
+ def download(passkey, output)
18
+ Downloader.verify!(output)
19
+
20
+ feed = Feed.new(passkey)
21
+ downloaded = feed.download_to(output_dir)
16
22
 
17
- puts "Downloaded #{downloaded.count} files to #{@output_dir}."
23
+ puts "Downloaded #{downloaded.count} files to #{output_dir}."
18
24
  puts "Files:", *downloaded unless downloaded.empty?
19
25
  end
20
26
  end
@@ -10,13 +10,18 @@ module PRSS
10
10
  @hydra = Typhoeus::Hydra.new
11
11
  end
12
12
 
13
- def download_to(output_path)
13
+ def self.verify!(output_path)
14
14
  output = Pathname.new(output_path).expand_path
15
15
  raise 'output path is not directory' unless output.directory?
16
+ output
17
+ end
18
+
19
+ def download_to(output_path)
20
+ output = self.class.verify!(output_path)
16
21
 
17
22
  @files = []
18
23
  @links.each do |link|
19
- request = Typhoeus::Request.new(link, :follow_location => true)
24
+ request = Typhoeus::Request.new(link, followlocation: true)
20
25
 
21
26
  request.on_complete do |response|
22
27
  @files << save_file(response, output)
@@ -30,10 +35,12 @@ module PRSS
30
35
  @files
31
36
  end
32
37
 
33
- def save_file response, output
38
+ def save_file(response, output)
34
39
  filename = response.headers_hash['Content-Disposition'][/filename="(.+)"$/ ,1]
35
40
  file = output.join(filename)
36
41
 
42
+ return if file.exist?
43
+
37
44
  open(file, 'wb') do |file|
38
45
  file.write(response.body)
39
46
  end
@@ -2,7 +2,7 @@ require 'typhoeus'
2
2
  require 'uri'
3
3
 
4
4
  module PRSS
5
- class Fetcher
5
+ class Feed
6
6
  PERSONAL_FEED_URL = "https://hdbits.org/rss/my"
7
7
 
8
8
  attr_reader :uri
@@ -14,12 +14,25 @@ module PRSS
14
14
  end
15
15
 
16
16
  def response
17
- @response ||= Typhoeus::Request.get(@uri.to_s)
17
+ Typhoeus::Request.get(@uri.to_s).tap do |response|
18
+ puts "Fetched #{@uri} in #{response.total_time}s"
19
+ end
18
20
  end
19
21
 
20
22
  def output
21
23
  response.body
22
24
  end
23
25
 
26
+ def links
27
+ Links.new(output)
28
+ end
29
+
30
+ def download_to(output)
31
+ downloader.download_to(output)
32
+ end
33
+
34
+ def downloader
35
+ Downloader.new(links)
36
+ end
24
37
  end
25
38
  end
@@ -1,7 +1,7 @@
1
1
  require 'nokogiri'
2
2
 
3
3
  module PRSS
4
- class Parser
4
+ class Links
5
5
  def initialize(xml)
6
6
  @xml = xml
7
7
  end
@@ -11,7 +11,9 @@ module PRSS
11
11
  end
12
12
 
13
13
  def links
14
- channel.xpath('//item/link')
14
+ channel.xpath('//item/link').tap do |links|
15
+ puts "Found #{links.size} links"
16
+ end
15
17
  end
16
18
 
17
19
  def each(&block)
@@ -1,3 +1,3 @@
1
1
  module PRSS
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,20 @@
1
+ module PRSS
2
+ class Watcher
3
+ def initialize(feed)
4
+ @feed = feed
5
+ end
6
+
7
+ def start(interval, output)
8
+ loop = Thread.new do
9
+ loop do
10
+ @feed.download_to(output)
11
+ sleep(interval)
12
+ end
13
+ end
14
+
15
+ Kernel.trap( "INT" ) { loop.exit }
16
+
17
+ loop.join
18
+ end
19
+ end
20
+ end
@@ -15,6 +15,9 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = PRSS::VERSION
17
17
 
18
- gem.add_dependency 'nokogiri', '>= 1.5.0'
19
- gem.add_dependency 'typhoeus', '>= 0.3.2'
18
+ gem.add_dependency 'nokogiri', '~> 1.6.2'
19
+ gem.add_dependency 'typhoeus', '~> 0.6.9'
20
+ gem.add_dependency 'thor', '~> 0.19.1'
21
+
22
+ gem.add_development_dependency 'rspec', '~> 3.0'
20
23
  end
@@ -0,0 +1,78 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, make a
10
+ # separate helper file that requires this one and then use it only in the specs
11
+ # that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # The settings below are suggested to provide a good initial experience
19
+ # with RSpec, but feel free to customize to your heart's content.
20
+ =begin
21
+ # These two settings work together to allow you to limit a spec run
22
+ # to individual examples or groups you care about by tagging them with
23
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
24
+ # get run.
25
+ config.filter_run :focus
26
+ config.run_all_when_everything_filtered = true
27
+
28
+ # Many RSpec users commonly either run the entire suite or an individual
29
+ # file, and it's useful to allow more verbose output when running an
30
+ # individual spec file.
31
+ if config.files_to_run.one?
32
+ # Use the documentation formatter for detailed output,
33
+ # unless a formatter has already been configured
34
+ # (e.g. via a command-line flag).
35
+ config.default_formatter = 'doc'
36
+ end
37
+
38
+ # Print the 10 slowest examples and example groups at the
39
+ # end of the spec run, to help surface which specs are running
40
+ # particularly slow.
41
+ config.profile_examples = 10
42
+
43
+ # Run specs in random order to surface order dependencies. If you find an
44
+ # order dependency and want to debug it, you can fix the order by providing
45
+ # the seed, which is printed after each run.
46
+ # --seed 1234
47
+ config.order = :random
48
+
49
+ # Seed global randomization in this process using the `--seed` CLI option.
50
+ # Setting this allows you to use `--seed` to deterministically reproduce
51
+ # test failures related to randomization by passing the same `--seed` value
52
+ # as the one that triggered the failure.
53
+ Kernel.srand config.seed
54
+
55
+ # rspec-expectations config goes here. You can use an alternate
56
+ # assertion/expectation library such as wrong or the stdlib/minitest
57
+ # assertions if you prefer.
58
+ config.expect_with :rspec do |expectations|
59
+ # Enable only the newer, non-monkey-patching expect syntax.
60
+ # For more details, see:
61
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
62
+ expectations.syntax = :expect
63
+ end
64
+
65
+ # rspec-mocks config goes here. You can use an alternate test double
66
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
67
+ config.mock_with :rspec do |mocks|
68
+ # Enable only the newer, non-monkey-patching expect syntax.
69
+ # For more details, see:
70
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ mocks.syntax = :expect
72
+
73
+ # Prevents you from mocking or stubbing a method that does not exist on
74
+ # a real object. This is generally recommended.
75
+ mocks.verify_partial_doubles = true
76
+ end
77
+ =end
78
+ end
metadata CHANGED
@@ -1,43 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Cichra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-18 00:00:00.000000000 Z
11
+ date: 2014-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.0
19
+ version: 1.6.2
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: 1.5.0
26
+ version: 1.6.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: typhoeus
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.2
33
+ version: 0.6.9
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: 0.3.2
40
+ version: 0.6.9
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.19.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.19.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
41
69
  description: Simple fetcher of HDbits private RSS stream
42
70
  email:
43
71
  - michal@o2h.cz
@@ -46,7 +74,8 @@ executables:
46
74
  extensions: []
47
75
  extra_rdoc_files: []
48
76
  files:
49
- - .gitignore
77
+ - ".gitignore"
78
+ - ".rspec"
50
79
  - Gemfile
51
80
  - README.md
52
81
  - Rakefile
@@ -54,10 +83,12 @@ files:
54
83
  - lib/prss.rb
55
84
  - lib/prss/cli.rb
56
85
  - lib/prss/downloader.rb
57
- - lib/prss/fetcher.rb
58
- - lib/prss/parser.rb
86
+ - lib/prss/feed.rb
87
+ - lib/prss/links.rb
59
88
  - lib/prss/version.rb
89
+ - lib/prss/watcher.rb
60
90
  - prss.gemspec
91
+ - spec/spec_helper.rb
61
92
  homepage: ''
62
93
  licenses: []
63
94
  metadata: {}
@@ -67,19 +98,21 @@ require_paths:
67
98
  - lib
68
99
  required_ruby_version: !ruby/object:Gem::Requirement
69
100
  requirements:
70
- - - '>='
101
+ - - ">="
71
102
  - !ruby/object:Gem::Version
72
103
  version: '0'
73
104
  required_rubygems_version: !ruby/object:Gem::Requirement
74
105
  requirements:
75
- - - '>='
106
+ - - ">="
76
107
  - !ruby/object:Gem::Version
77
108
  version: '0'
78
109
  requirements: []
79
110
  rubyforge_project:
80
- rubygems_version: 2.1.11
111
+ rubygems_version: 2.2.2
81
112
  signing_key:
82
113
  specification_version: 4
83
114
  summary: Parses HDbits private RSS stream, downloads and saves all files to specified
84
115
  directory
85
- test_files: []
116
+ test_files:
117
+ - spec/spec_helper.rb
118
+ has_rdoc: