pulse-downloader 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +114 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +114 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/pulse/downloader.rb +13 -0
- data/lib/pulse/downloader/client.rb +57 -0
- data/lib/pulse/downloader/file_downloader.rb +76 -0
- data/lib/pulse/downloader/version.rb +5 -0
- data/lib/pulse/downloader/web_page_parser.rb +36 -0
- data/pulse-downloader.gemspec +37 -0
- metadata +227 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f1d8d3d5f2814c1744f58c8a09b118a478b2d1d3f1e92a66df86fd4352284fe4
|
4
|
+
data.tar.gz: 3384a0e37e73e237edf8cd9a2fbdac640473408b7c8e523b8a43ea80529a0680
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ee7a13ba93ca48c4306d6cede31c17753610c3496277830a8a5e4bb37b17e141ac231c37ce0bb5166d66db6f7fe6c969e20d8c85d758c3225b5d2b021035ce30
|
7
|
+
data.tar.gz: 6e2999c3df8cbbe876743c10396d59cd8d6c0b1f9723090b910f6594fdd11d0290e30a903b6238e49c36b51fd6f40f04542748c85fcfb34835cdb5f42fb7ab5f
|
data/.gitignore
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
57
|
+
|
58
|
+
.DS_Store
|
59
|
+
*.gem
|
60
|
+
*.rbc
|
61
|
+
/.config
|
62
|
+
/coverage/
|
63
|
+
/InstalledFiles
|
64
|
+
/pkg/
|
65
|
+
/spec/reports/
|
66
|
+
/spec/examples.txt
|
67
|
+
/test/tmp/
|
68
|
+
/test/version_tmp/
|
69
|
+
/tmp/
|
70
|
+
|
71
|
+
# Used by dotenv library to load environment variables.
|
72
|
+
# .env
|
73
|
+
|
74
|
+
# Ignore Byebug command history file.
|
75
|
+
.byebug_history
|
76
|
+
|
77
|
+
## Specific to RubyMotion:
|
78
|
+
.dat*
|
79
|
+
.repl_history
|
80
|
+
build/
|
81
|
+
*.bridgesupport
|
82
|
+
build-iPhoneOS/
|
83
|
+
build-iPhoneSimulator/
|
84
|
+
|
85
|
+
## Specific to RubyMotion (use of CocoaPods):
|
86
|
+
#
|
87
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
88
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
89
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
90
|
+
#
|
91
|
+
# vendor/Pods/
|
92
|
+
|
93
|
+
## Documentation cache and generated files:
|
94
|
+
/.yardoc/
|
95
|
+
/_yardoc/
|
96
|
+
/doc/
|
97
|
+
/rdoc/
|
98
|
+
|
99
|
+
## Environment normalization:
|
100
|
+
/.bundle/
|
101
|
+
/vendor/bundle
|
102
|
+
/lib/bundler/man/
|
103
|
+
|
104
|
+
# for a library or gem, you might want to ignore these files since the code is
|
105
|
+
# intended to run in multiple environments; otherwise, check them in:
|
106
|
+
# Gemfile.lock
|
107
|
+
# .ruby-version
|
108
|
+
# .ruby-gemset
|
109
|
+
|
110
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
111
|
+
.rvmrc
|
112
|
+
|
113
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
114
|
+
# .rubocop-https?--*
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at contact@jasonchalom.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pulse-downloader (0.1.2)
|
5
|
+
active_attr (~> 0.15)
|
6
|
+
httparty (~> 0.18)
|
7
|
+
nokogiri (~> 1.10.9)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actionpack (6.0.3.2)
|
13
|
+
actionview (= 6.0.3.2)
|
14
|
+
activesupport (= 6.0.3.2)
|
15
|
+
rack (~> 2.0, >= 2.0.8)
|
16
|
+
rack-test (>= 0.6.3)
|
17
|
+
rails-dom-testing (~> 2.0)
|
18
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
19
|
+
actionview (6.0.3.2)
|
20
|
+
activesupport (= 6.0.3.2)
|
21
|
+
builder (~> 3.1)
|
22
|
+
erubi (~> 1.4)
|
23
|
+
rails-dom-testing (~> 2.0)
|
24
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
25
|
+
active_attr (0.15.0)
|
26
|
+
actionpack (>= 3.0.2, < 6.1)
|
27
|
+
activemodel (>= 3.0.2, < 6.1)
|
28
|
+
activesupport (>= 3.0.2, < 6.1)
|
29
|
+
activemodel (6.0.3.2)
|
30
|
+
activesupport (= 6.0.3.2)
|
31
|
+
activesupport (6.0.3.2)
|
32
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
33
|
+
i18n (>= 0.7, < 2)
|
34
|
+
minitest (~> 5.1)
|
35
|
+
tzinfo (~> 1.1)
|
36
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
37
|
+
addressable (2.7.0)
|
38
|
+
public_suffix (>= 2.0.2, < 5.0)
|
39
|
+
ansi (1.5.0)
|
40
|
+
builder (3.2.4)
|
41
|
+
coderay (1.1.3)
|
42
|
+
concurrent-ruby (1.1.6)
|
43
|
+
crack (0.4.3)
|
44
|
+
safe_yaml (~> 1.0.0)
|
45
|
+
crass (1.0.6)
|
46
|
+
erubi (1.9.0)
|
47
|
+
hashdiff (1.0.1)
|
48
|
+
httparty (0.18.1)
|
49
|
+
mime-types (~> 3.0)
|
50
|
+
multi_xml (>= 0.5.2)
|
51
|
+
i18n (1.8.3)
|
52
|
+
concurrent-ruby (~> 1.0)
|
53
|
+
loofah (2.6.0)
|
54
|
+
crass (~> 1.0.2)
|
55
|
+
nokogiri (>= 1.5.9)
|
56
|
+
method_source (1.0.0)
|
57
|
+
mime-types (3.3.1)
|
58
|
+
mime-types-data (~> 3.2015)
|
59
|
+
mime-types-data (3.2020.0512)
|
60
|
+
mini_portile2 (2.4.0)
|
61
|
+
minitest (5.14.1)
|
62
|
+
minitest-focus (1.1.2)
|
63
|
+
minitest (>= 4, < 6)
|
64
|
+
minitest-reporters (1.4.2)
|
65
|
+
ansi
|
66
|
+
builder
|
67
|
+
minitest (>= 5.0)
|
68
|
+
ruby-progressbar
|
69
|
+
mocha (1.11.2)
|
70
|
+
multi_xml (0.6.0)
|
71
|
+
nokogiri (1.10.10)
|
72
|
+
mini_portile2 (~> 2.4.0)
|
73
|
+
pry (0.13.1)
|
74
|
+
coderay (~> 1.1)
|
75
|
+
method_source (~> 1.0)
|
76
|
+
public_suffix (4.0.5)
|
77
|
+
rack (2.2.3)
|
78
|
+
rack-test (1.1.0)
|
79
|
+
rack (>= 1.0, < 3)
|
80
|
+
rails-dom-testing (2.0.3)
|
81
|
+
activesupport (>= 4.2.0)
|
82
|
+
nokogiri (>= 1.6)
|
83
|
+
rails-html-sanitizer (1.3.0)
|
84
|
+
loofah (~> 2.3)
|
85
|
+
rake (12.3.3)
|
86
|
+
ruby-progressbar (1.10.1)
|
87
|
+
safe_yaml (1.0.5)
|
88
|
+
thread_safe (0.3.6)
|
89
|
+
timecop (0.9.1)
|
90
|
+
tzinfo (1.2.7)
|
91
|
+
thread_safe (~> 0.1)
|
92
|
+
webmock (3.8.3)
|
93
|
+
addressable (>= 2.3.6)
|
94
|
+
crack (>= 0.3.2)
|
95
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
96
|
+
zeitwerk (2.4.0)
|
97
|
+
|
98
|
+
PLATFORMS
|
99
|
+
ruby
|
100
|
+
|
101
|
+
DEPENDENCIES
|
102
|
+
bundler (~> 2.1.4)
|
103
|
+
minitest (~> 5.0)
|
104
|
+
minitest-focus (~> 1.1.2)
|
105
|
+
minitest-reporters (~> 1.4.2)
|
106
|
+
mocha (~> 1.11.2)
|
107
|
+
pry (~> 0.13)
|
108
|
+
pulse-downloader!
|
109
|
+
rake (~> 12.0)
|
110
|
+
timecop (~> 0.9.1)
|
111
|
+
webmock (~> 3.8.3)
|
112
|
+
|
113
|
+
BUNDLED WITH
|
114
|
+
2.1.4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Jason Chalom
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Jason Chalom
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Pulse::Downloader
|
2
|
+
|
3
|
+
This is a library to download a specific group of files linked to on an html page.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pulse-downloader'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pulse-downloader
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'pulse/downloader'
|
25
|
+
|
26
|
+
client = Pulse::Downloader::Client.new(
|
27
|
+
url: '',
|
28
|
+
file_type: 'zip',
|
29
|
+
save_data: true,
|
30
|
+
save_path: '',
|
31
|
+
read_from_save_path: false,
|
32
|
+
verify_ssl: true,
|
33
|
+
report_time: false
|
34
|
+
)
|
35
|
+
```
|
36
|
+
|
37
|
+
## Development
|
38
|
+
|
39
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
40
|
+
|
41
|
+
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).
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pulse-downloader. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/pulse-downloader/blob/master/CODE_OF_CONDUCT.md).
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
50
|
+
|
51
|
+
## Code of Conduct
|
52
|
+
|
53
|
+
Everyone interacting in the Pulse::Downloader project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pulse-downloader/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pulse/downloader"
|
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,13 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
require "pulse/downloader/version"
|
5
|
+
require 'pulse/downloader/web_page_parser'
|
6
|
+
require 'pulse/downloader/file_downloader'
|
7
|
+
require 'pulse/downloader/client'
|
8
|
+
|
9
|
+
module Pulse
|
10
|
+
module Downloader
|
11
|
+
class Error < StandardError; end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Pulse
|
2
|
+
module Downloader
|
3
|
+
class Client
|
4
|
+
include ::Pulse::Downloader::WebPageParser
|
5
|
+
include ::Pulse::Downloader::FileDownloader
|
6
|
+
|
7
|
+
attr_reader :url,
|
8
|
+
:file_type,
|
9
|
+
:save_data,
|
10
|
+
:save_path,
|
11
|
+
:read_from_save_path,
|
12
|
+
:verify_ssl,
|
13
|
+
:report_time,
|
14
|
+
:start_time,
|
15
|
+
:end_time
|
16
|
+
|
17
|
+
# TODO: Validation
|
18
|
+
# TODO: Retry
|
19
|
+
# TODO: DNS
|
20
|
+
def initialize(url:, file_type:, save_data: false, save_path: '', read_from_save_path: false, verify_ssl: true, report_time: false)
|
21
|
+
@url = url
|
22
|
+
@file_type = file_type
|
23
|
+
@save_data = save_data
|
24
|
+
@save_path = save_path
|
25
|
+
@read_from_save_path = read_from_save_path
|
26
|
+
@verify_ssl = verify_ssl
|
27
|
+
@report_time = report_time
|
28
|
+
end
|
29
|
+
|
30
|
+
def call!
|
31
|
+
call
|
32
|
+
end
|
33
|
+
|
34
|
+
def call
|
35
|
+
return false unless valid?
|
36
|
+
|
37
|
+
fetch_file_paths.map do |file_path|
|
38
|
+
download(file_path)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def valid?
|
43
|
+
true # TODO
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def get_micro_second_time
|
49
|
+
(Time.now.to_f * 1000).to_i
|
50
|
+
end
|
51
|
+
|
52
|
+
def print_time
|
53
|
+
puts "Request time: #{end_time - start_time} ms."
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Pulse
|
2
|
+
module Downloader
|
3
|
+
module FileDownloader
|
4
|
+
# save_path and verify_ssl are defined in client.rb
|
5
|
+
def download(file_path)
|
6
|
+
raise "save_path is undefined" if save_data && save_path == ''
|
7
|
+
|
8
|
+
@start_time = get_micro_second_time
|
9
|
+
|
10
|
+
file_data = HTTParty.get(compute_file_link(file_path), verify: verify_ssl)
|
11
|
+
|
12
|
+
@end_time = get_micro_second_time
|
13
|
+
|
14
|
+
if report_time
|
15
|
+
print_time
|
16
|
+
end
|
17
|
+
|
18
|
+
if save_data
|
19
|
+
File.open(compute_save_path(file_path), 'wb') do |file|
|
20
|
+
file.write(file_data.body)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
file_data
|
25
|
+
end
|
26
|
+
|
27
|
+
def fetch_save_paths
|
28
|
+
fetch_file_paths.map do |file_path|
|
29
|
+
"#{save_path}/#{compute_filename(file_path)}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def compute_hash_of(data)
|
34
|
+
{ data: data }.hash
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def compute_save_path(url)
|
40
|
+
"#{save_path}/#{compute_filename(url)}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def compute_filename(file_path)
|
44
|
+
file_path.scan(/[\/]\S+/).last
|
45
|
+
end
|
46
|
+
|
47
|
+
def compute_file_link(file_path)
|
48
|
+
if section?(file_path)
|
49
|
+
raise 'invalid download path'
|
50
|
+
elsif absolute?(file_path)
|
51
|
+
file_path
|
52
|
+
elsif relative?(file_path)
|
53
|
+
"#{url}/#{file_path}"
|
54
|
+
else
|
55
|
+
"#{url}/#{file_path}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def absolute?(file_path)
|
60
|
+
file_path.include?('http://') ||
|
61
|
+
file_path.include?('https://') ||
|
62
|
+
file_path.include?('ftp://') ||
|
63
|
+
file_path.include?('sftp://')||
|
64
|
+
file_path.include?('file://')
|
65
|
+
end
|
66
|
+
|
67
|
+
def relative?(file_path)
|
68
|
+
file_path[0] == '/'
|
69
|
+
end
|
70
|
+
|
71
|
+
def section?(file_path)
|
72
|
+
file_path[0] == '#'
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Pulse
|
2
|
+
module Downloader
|
3
|
+
module WebPageParser
|
4
|
+
def fetch_file_paths
|
5
|
+
@start_time = get_micro_second_time
|
6
|
+
|
7
|
+
response = HTTParty.get(url, verify: verify_ssl)
|
8
|
+
|
9
|
+
@end_time = get_micro_second_time
|
10
|
+
|
11
|
+
if report_time
|
12
|
+
print_time
|
13
|
+
end
|
14
|
+
|
15
|
+
extract_file_urls(response)
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def extract_file_urls(response)
|
21
|
+
return [] if response.body.nil? || response.body.empty?
|
22
|
+
|
23
|
+
parse_html(response.body)
|
24
|
+
.css('a')
|
25
|
+
.to_a
|
26
|
+
.map { |link| link['href'] }
|
27
|
+
.compact
|
28
|
+
.select { |link| link.include? file_type }
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_html(raw_html)
|
32
|
+
Nokogiri::HTML(raw_html)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative 'lib/pulse/downloader/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "pulse-downloader"
|
5
|
+
spec.version = Pulse::Downloader::VERSION
|
6
|
+
spec.authors = ["trex22"]
|
7
|
+
spec.email = ["contact@jasonchalom.com"]
|
8
|
+
|
9
|
+
spec.summary = "Client to download datasets from webpages."
|
10
|
+
spec.description = "Client to download datasets from webpages."
|
11
|
+
spec.homepage = "https://github.com/TRex22/pulse-downloader"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
# Specify which files should be added to the gem when it is released.
|
15
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
|
23
|
+
spec.add_dependency "httparty", "~> 0.18"
|
24
|
+
spec.add_dependency "active_attr", "~> 0.15"
|
25
|
+
spec.add_dependency "nokogiri", "~> 1.10.9"
|
26
|
+
|
27
|
+
# Development dependancies
|
28
|
+
spec.add_development_dependency "bundler", "~> 2.1.4"
|
29
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
30
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
31
|
+
spec.add_development_dependency "minitest-focus", "~> 1.1.2"
|
32
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.4.2"
|
33
|
+
spec.add_development_dependency "timecop", "~> 0.9.1"
|
34
|
+
spec.add_development_dependency "mocha", "~> 1.11.2"
|
35
|
+
spec.add_development_dependency "pry", "~> 0.13"
|
36
|
+
spec.add_development_dependency "webmock", "~> 3.8.3"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pulse-downloader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- trex22
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.18'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.18'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: active_attr
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.15'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.10.9
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.10.9
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.4
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.1.4
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '13.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '13.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-focus
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.1.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.1.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest-reporters
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.4.2
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.4.2
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: timecop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.9.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.9.1
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: mocha
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 1.11.2
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.11.2
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: pry
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0.13'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0.13'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webmock
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 3.8.3
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 3.8.3
|
181
|
+
description: Client to download datasets from webpages.
|
182
|
+
email:
|
183
|
+
- contact@jasonchalom.com
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- CODE_OF_CONDUCT.md
|
190
|
+
- Gemfile
|
191
|
+
- Gemfile.lock
|
192
|
+
- LICENSE
|
193
|
+
- LICENSE.txt
|
194
|
+
- README.md
|
195
|
+
- Rakefile
|
196
|
+
- bin/console
|
197
|
+
- bin/setup
|
198
|
+
- lib/pulse/downloader.rb
|
199
|
+
- lib/pulse/downloader/client.rb
|
200
|
+
- lib/pulse/downloader/file_downloader.rb
|
201
|
+
- lib/pulse/downloader/version.rb
|
202
|
+
- lib/pulse/downloader/web_page_parser.rb
|
203
|
+
- pulse-downloader.gemspec
|
204
|
+
homepage: https://github.com/TRex22/pulse-downloader
|
205
|
+
licenses:
|
206
|
+
- MIT
|
207
|
+
metadata: {}
|
208
|
+
post_install_message:
|
209
|
+
rdoc_options: []
|
210
|
+
require_paths:
|
211
|
+
- lib
|
212
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - ">="
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
217
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
requirements: []
|
223
|
+
rubygems_version: 3.1.4
|
224
|
+
signing_key:
|
225
|
+
specification_version: 4
|
226
|
+
summary: Client to download datasets from webpages.
|
227
|
+
test_files: []
|