Rdownloader 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83cae612f6213d89fa2a7309f7abc6f755939ecc
4
+ data.tar.gz: 422356e2dcc86926b4deb42f7f559108b2b4a1ba
5
+ SHA512:
6
+ metadata.gz: 3dc2ac01d819ce2154b8c947e3bc9ad189e92415a567bb6e3fb18bc914c453c84bcb586075c96abe75977f7e8912e0a44fc3d1d426da448e735d1fcf46065331
7
+ data.tar.gz: 8aa2cd272d0cca3c3054b853de5210be1206606e90a95536b9a5b9f94d5c6ecd88e04f34e2141d7ed8f080011a64be6d5a7f3fc80241b2cfa5c0e5fbc93cfd1d
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in Rdownloader.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Rdownloader
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/Rdownloader`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'Rdownloader'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install Rdownloader
22
+
23
+ ## Usage
24
+
25
+ Rdownloader.download("*")
26
+
27
+ "*" == binary URL
28
+
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yukiraicom/Rdownloader.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "Rdownloader/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "Rdownloader"
8
+ spec.version = Rdownloader::VERSION
9
+ spec.authors = ["yukiraicom"]
10
+ spec.email = ["yuukiarai19970524@gmail.com"]
11
+ spec.summary = %q{Rdownloader is a download library for Ruby.}
12
+ spec.description = %q{Rdownloader...}
13
+ spec.homepage = "https://github.com/yukiraicom/Rdownloader"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ # if spec.respond_to?(:metadata)
18
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
19
+ # else
20
+ # raise "RubyGems 2.0 or newer is required to protect against " \
21
+ # "public gem pushes."
22
+ # end
23
+
24
+ # Specify which files should be added to the gem when it is released.
25
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
26
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+
36
+ # gem.add_runtime_dependency 'open-uri'
37
+ # gem.add_runtime_dependency "uri"
38
+ # gem.add_runtime_dependency 'pry'
39
+ # gem.add_runtime_dependency 'net/http'
40
+ spec.add_runtime_dependency 'ruby-progressbar', ["~> 1.9.0"]
41
+ # gem.add_runtime_dependency 'securerandom'
42
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "Rdownloader"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,58 @@
1
+ require "Rdownloader/version"
2
+ require 'open-uri'
3
+ require "uri"
4
+ require 'pry'
5
+ require 'net/http'
6
+ require 'ruby-progressbar'
7
+ require 'securerandom'
8
+
9
+ module Rdownloader
10
+ def self.download(path_origin)
11
+ a = URI.escape(path_origin)
12
+ uri = URI.parse(a)
13
+ path_parsed = uri
14
+ redirect_url = Net::HTTP.get_response(path_parsed)['location']
15
+ path = redirect_url #string
16
+ path = path_origin if path.nil?
17
+ filenamevar1 = "#{SecureRandom.hex(2)}" #適当なファイル名
18
+ filenamevar2 = ".pdf"
19
+ @@fileName = "#{filenamevar1}" + "#{filenamevar2}" #ここはスクレイピングする
20
+ new_url = URI.encode(path) #string
21
+ new_url_fileName = URI.decode(path).force_encoding('UTF-8')
22
+ content_length = nil
23
+ progress_bar = nil
24
+ open(@@fileName, 'wb') do |output|
25
+ p "ダウンロード中..."
26
+ open(new_url,
27
+ :content_length_proc => lambda{ |content_length|
28
+ if content_length
29
+ # プログレスバーの最大長にcontent-lengthを指定
30
+ progress_bar = ProgressBar.create(:total => content_length)
31
+ end
32
+ },
33
+ :progress_proc => lambda{ |transferred_bytes|
34
+ if progress_bar
35
+ # プログレスバーの進捗状況にこれまで転送されたバイト数を代入する
36
+ progress_bar.progress = transferred_bytes
37
+ else
38
+ puts "#{transferred_bytes} / Total size is unknown"
39
+ end
40
+ }
41
+ ) do |data|
42
+ output.write(data.read)
43
+ end
44
+ end
45
+ end
46
+
47
+ # class pdfDownload
48
+
49
+ # end
50
+ #Download.download('https://shugo.net/tmp/metaprogramming.pdf')
51
+
52
+ # system("gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -sOutputFile=output.pdf #{@fileName}")
53
+ # #上記入力ファイル名が取れないとsh: 1: Syntax error: "(" unexpected のエラーになる。
54
+ # #9/29...memo...outputは生成される
55
+ # abc = "9/29.pdf"
56
+ # system("mv output.pdf #{abc}")#ここがうまくいかない
57
+ # end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Rdownloader
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: Rdownloader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yukiraicom
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-08 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-progressbar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.9.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.9.0
55
+ description: Rdownloader...
56
+ email:
57
+ - yuukiarai19970524@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - Rdownloader.gemspec
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/Rdownloader.rb
70
+ - lib/Rdownloader/version.rb
71
+ homepage: https://github.com/yukiraicom/Rdownloader
72
+ licenses: []
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.5.1
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Rdownloader is a download library for Ruby.
94
+ test_files: []