downloadr 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fb4c356466b4e4e41b1db9a02b10a55c29eab05f
4
+ data.tar.gz: e0b65f85469cb03b40fea1ecb9e6ed17b24be785
5
+ SHA512:
6
+ metadata.gz: 115d4f880f88188aa63a5c796fd53d3c01d1fc7eb1aea07c76231ec3de15f3129eb2792c96a2aef052a6e24eb6015543b2c95de13d98d5dd53d0f09b4e81f047
7
+ data.tar.gz: ade2a68e5afafe4feae374c38690a2bd60c96c5e329413e13ed1584a1c675dcdc55e5d2655d156fc39f66575dd575dbeb6aa32d8dee9302824249f94da806ae0
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/.rvmrc ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 2.1.0@downloadr" > .rvmrc
9
+ environment_id="ruby-2.1.0@downloadr"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.25.25 (stable)" # 1.10.1 seems like a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | __rvm_awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ for __hook in "${rvm_path:-$HOME/.rvm}/hooks/after_use"*
27
+ do
28
+ if [[ -f "${__hook}" && -x "${__hook}" && -s "${__hook}" ]]
29
+ then \. "${__hook}" || true
30
+ fi
31
+ done
32
+ unset __hook
33
+ if (( ${rvm_use_flag:=1} >= 1 )) # display automatically
34
+ then
35
+ if [[ $- == *i* ]] # check for interactive shells
36
+ then printf "%b" "Using: $(tput setaf 2 2>/dev/null)$GEM_HOME$(tput sgr0 2>/dev/null)
37
+ " # show the user the ruby and gemset they are using in green
38
+ else printf "%b" "Using: $GEM_HOME
39
+ " # don't use colors in non-interactive shells
40
+ fi
41
+ fi
42
+ else
43
+ # If the environment file has not yet been created, use the RVM CLI to select.
44
+ rvm --create use "$environment_id" || {
45
+ echo "Failed to create RVM environment '${environment_id}'."
46
+ return 1
47
+ }
48
+ fi
49
+
50
+ # If you use bundler, this might be useful to you:
51
+ # if [[ -s Gemfile ]] && {
52
+ # ! builtin command -v bundle >/dev/null ||
53
+ # builtin command -v bundle | GREP_OPTIONS="" \grep $rvm_path/bin/bundle >/dev/null
54
+ # }
55
+ # then
56
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
57
+ # gem install bundler
58
+ # fi
59
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
60
+ # then
61
+ # bundle install | GREP_OPTIONS="" \grep -vE '^Using|Your bundle is complete'
62
+ # fi
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in downloadr.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jonathan Claudius
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Downloadr
2
+ [![Build Status](https://secure.travis-ci.org/claudijd/downloadr.png)](http://travis-ci.org/claudijd/downloadr)
3
+
4
+ A simple gem to make downloading files in a Ruby application simple without needing to roll your own downloader implementation.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'downloadr'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install downloadr
19
+
20
+ ## Usage
21
+
22
+ require 'downloadr'
23
+ Downloadr::HTTP.download("http://www.google.com/index.html", "index.html")
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/claudijd/downloadr/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,12 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'rubygems/package_task'
5
+ require 'rspec'
6
+ require 'rspec/core'
7
+ require 'rspec/core/rake_task'
8
+
9
+ task :default => :spec
10
+
11
+ desc "Run all specs in spec directory"
12
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'downloadr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "downloadr"
8
+ spec.version = Downloadr::VERSION
9
+ spec.authors = ["Jonathan Claudius"]
10
+ spec.email = ["claudijd@yahoo.com"]
11
+ spec.summary = %q{A simple gem to make downloading files in a Ruby application simple.}
12
+ spec.description = %q{A simple gem to make downloading files in a Ruby application simple without needing to roll your own downloader implementation.}
13
+ spec.homepage = "https://github.com/claudijd/downloadr"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', "~> 1.6"
22
+ spec.add_development_dependency 'rake', '~> 0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ end
@@ -0,0 +1,2 @@
1
+ require "downloadr/version"
2
+ require "downloadr/http"
@@ -0,0 +1,25 @@
1
+ require "net/http"
2
+ require "uri"
3
+
4
+ module Downloadr
5
+ # HTTP/HTTPS Transport handler for downloading a file
6
+ class HTTP
7
+ attr_reader :uri, :path
8
+
9
+ # @param [String] uri
10
+ # @param [String] path
11
+ def initialize(uri, path)
12
+ @uri = uri
13
+ @path = path
14
+ end
15
+
16
+ def download
17
+ File.write(@path, Net::HTTP.get(URI.parse(@uri)))
18
+ end
19
+
20
+ def self.download(uri, path)
21
+ downloader = Downloadr::HTTP.new(uri, path)
22
+ downloader.download
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Downloadr
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,79 @@
1
+ require 'downloadr'
2
+ require 'tempfile'
3
+
4
+ module Downloader
5
+ describe "HTTP" do
6
+ context "when initializing Downloadr::HTTP" do
7
+ before :each do
8
+ @file_path = Tempfile.new('downloadr')
9
+ @uri = "http://www.google.com/index.html"
10
+ @http_downloadr = Downloadr::HTTP.new(@uri, @file_path)
11
+ end
12
+
13
+ subject{@http_downloadr}
14
+
15
+ it { should be_kind_of Downloadr::HTTP}
16
+
17
+ it "should have the right uri" do
18
+ expect(subject.uri).to be(@uri)
19
+ end
20
+
21
+ it "should have the right file path" do
22
+ expect(subject.path).to be(@file_path)
23
+ end
24
+ end
25
+
26
+ context "when downloading a file via HTTP" do
27
+ before :each do
28
+ @file_path = Tempfile.new('downloadr')
29
+ @uri = "http://www.google.com/index.html"
30
+ @http_downloadr = Downloadr::HTTP.new(@uri, @file_path)
31
+ end
32
+
33
+ subject{@http_downloadr}
34
+
35
+ it "should start with an empty file" do
36
+ expect(subject.path.size).to be(0)
37
+ end
38
+
39
+ it "should return a Fixnum when being downloaded" do
40
+ expect(subject.download).to be_kind_of ::Fixnum
41
+ end
42
+
43
+ it "should have created a file on disk" do
44
+ subject.download
45
+ expect(subject.path.size).to be > 0
46
+ end
47
+
48
+ it "should have content that looks like google" do
49
+ subject.download
50
+ expect(File.read(subject.path)).to include("google")
51
+ end
52
+ end
53
+
54
+ context "when downloading via self.download" do
55
+ before :each do
56
+ @file_path = Tempfile.new('downloadr')
57
+ @uri = "http://www.google.com/index.html"
58
+ end
59
+
60
+ it "should start with an empty file" do
61
+ expect(@file_path.size).to be(0)
62
+ end
63
+
64
+ it "should return a Fixnum when being downloaded" do
65
+ expect(Downloadr::HTTP.download(@uri, @file_path)).to be_kind_of ::Fixnum
66
+ end
67
+
68
+ it "should have created a file on disk" do
69
+ Downloadr::HTTP.download(@uri, @file_path)
70
+ expect(@file_path.size).to be > 0
71
+ end
72
+
73
+ it "should have content that looks like google" do
74
+ Downloadr::HTTP.download(@uri, @file_path)
75
+ expect(File.read(@file_path)).to include("google")
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,76 @@
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
+ # These two settings work together to allow you to limit a spec run
21
+ # to individual examples or groups you care about by tagging them with
22
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
23
+ # get run.
24
+ config.filter_run :focus
25
+ config.run_all_when_everything_filtered = true
26
+
27
+ # Many RSpec users commonly either run the entire suite or an individual
28
+ # file, and it's useful to allow more verbose output when running an
29
+ # individual spec file.
30
+ if config.files_to_run.one?
31
+ # Use the documentation formatter for detailed output,
32
+ # unless a formatter has already been configured
33
+ # (e.g. via a command-line flag).
34
+ config.default_formatter = 'doc'
35
+ end
36
+
37
+ # Print the 10 slowest examples and example groups at the
38
+ # end of the spec run, to help surface which specs are running
39
+ # particularly slow.
40
+ config.profile_examples = 3
41
+
42
+ # Run specs in random order to surface order dependencies. If you find an
43
+ # order dependency and want to debug it, you can fix the order by providing
44
+ # the seed, which is printed after each run.
45
+ # --seed 1234
46
+ config.order = :random
47
+
48
+ # Seed global randomization in this process using the `--seed` CLI option.
49
+ # Setting this allows you to use `--seed` to deterministically reproduce
50
+ # test failures related to randomization by passing the same `--seed` value
51
+ # as the one that triggered the failure.
52
+ Kernel.srand config.seed
53
+
54
+ # rspec-expectations config goes here. You can use an alternate
55
+ # assertion/expectation library such as wrong or the stdlib/minitest
56
+ # assertions if you prefer.
57
+ config.expect_with :rspec do |expectations|
58
+ # Enable only the newer, non-monkey-patching expect syntax.
59
+ # For more details, see:
60
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ expectations.syntax = :expect
62
+ end
63
+
64
+ # rspec-mocks config goes here. You can use an alternate test double
65
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
66
+ config.mock_with :rspec do |mocks|
67
+ # Enable only the newer, non-monkey-patching expect syntax.
68
+ # For more details, see:
69
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
70
+ mocks.syntax = :expect
71
+
72
+ # Prevents you from mocking or stubbing a method that does not exist on
73
+ # a real object. This is generally recommended.
74
+ mocks.verify_partial_doubles = true
75
+ end
76
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: downloadr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Claudius
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: A simple gem to make downloading files in a Ruby application simple without
56
+ needing to roll your own downloader implementation.
57
+ email:
58
+ - claudijd@yahoo.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".rvmrc"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - downloadr.gemspec
72
+ - lib/downloadr.rb
73
+ - lib/downloadr/http.rb
74
+ - lib/downloadr/version.rb
75
+ - spec/downloadr/http_spec.rb
76
+ - spec/spec_helper.rb
77
+ homepage: https://github.com/claudijd/downloadr
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.2.2
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: A simple gem to make downloading files in a Ruby application simple.
101
+ test_files:
102
+ - spec/downloadr/http_spec.rb
103
+ - spec/spec_helper.rb