nsrr 0.4.0.beta1 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'digest/md5'
4
- require 'nsrr/helpers/constants'
5
- require 'nsrr/helpers/download_request'
3
+ require "digest/md5"
4
+ require "nsrr/helpers/color"
5
+ require "nsrr/helpers/constants"
6
+ require "nsrr/helpers/download_request"
6
7
 
7
8
  module Nsrr
8
9
  module Models
@@ -11,25 +12,25 @@ module Nsrr
11
12
  attr_reader :dataset_slug, :full_path, :folder, :file_name, :is_file, :file_size, :file_checksum_md5, :archived
12
13
 
13
14
  def initialize(json = {})
14
- @dataset_slug = json['dataset']
15
- @full_path = json['full_path']
16
- @folder = json['folder']
17
- @file_name = json['file_name']
18
- @is_file = json['is_file']
19
- @file_size = json['file_size']
20
- @file_checksum_md5 = json['file_checksum_md5']
21
- @archived = json['archived']
22
- @latest_checksum = ''
15
+ @dataset_slug = json["dataset"]
16
+ @full_path = json["full_path"]
17
+ @folder = json["folder"]
18
+ @file_name = json["file_name"]
19
+ @is_file = json["is_file"]
20
+ @file_size = json["file_size"]
21
+ @file_checksum_md5 = json["file_checksum_md5"]
22
+ @archived = json["archived"]
23
+ @latest_checksum = ""
23
24
  @latest_file_size = -1
24
25
  end
25
26
 
26
27
  # method:
27
- # 'md5' => [default] Checks if a downloaded file exists with the exact md5 as the online version, if so, skips that file
28
- # 'fresh' => Downloads every file without checking if it was already downloaded
29
- # 'fast' => Only checks if a download file exists with the same file size as the online version, if so, skips that file
28
+ # "md5" => [default] Checks if a downloaded file exists with the exact md5 as the online version, if so, skips that file
29
+ # "fresh" => Downloads every file without checking if it was already downloaded
30
+ # "fast" => Only checks if a download file exists with the same file size as the online version, if so, skips that file
30
31
  def download(method, path, token)
31
- do_md5_check = (method == 'md5')
32
- redownload_all = (method == 'fresh')
32
+ do_md5_check = (method == "md5")
33
+ redownload_all = (method == "fresh")
33
34
 
34
35
  if do_md5_check
35
36
  if md5_matches?(path)
@@ -55,14 +56,14 @@ module Nsrr
55
56
  # If the second download and check fail, the file is marked as failed, and the downloader continues to the subsequent file.
56
57
  def force_download(path, token, method)
57
58
  download_folder = ::File.join(Dir.pwd, path.to_s, @file_name.to_s)
58
- auth_section = (token.to_s == '' ? '' : "/a/#{token}")
59
- download_url = "#{Nsrr::WEBSITE}/datasets/#{@dataset_slug}/files#{auth_section}/m/nsrr-gem-v#{Nsrr::VERSION::STRING.gsub('.', '-')}/#{@full_path.to_s}"
59
+ auth_section = (token.to_s == "" ? "" : "/a/#{token}")
60
+ download_url = "#{Nsrr::WEBSITE}/datasets/#{@dataset_slug}/files#{auth_section}/m/nsrr-gem-v#{Nsrr::VERSION::STRING.gsub(".", "-")}/#{@full_path.to_s}"
60
61
  download_request = Nsrr::Helpers::DownloadRequest.new(download_url, download_folder)
61
62
  download_request.get
62
63
  download_success = false
63
- if download_request.error.to_s == ''
64
+ if download_request.error.to_s == ""
64
65
  # Check to see if the file downloaded correctly
65
- # If the file size doesn't match, attempt one additional download
66
+ # If the file size does not match, attempt one additional download
66
67
  download_success = did_download_succeed?(method, path)
67
68
  unless download_success
68
69
  download_request = Nsrr::Helpers::DownloadRequest.new(download_url, download_folder)
@@ -70,12 +71,12 @@ module Nsrr
70
71
  download_success = did_download_succeed?(method, path)
71
72
  end
72
73
  end
73
- if download_request.error.to_s == '' and download_success
74
- puts " downloaded".colorize(:green) + " #{@file_name}"
74
+ if download_request.error.to_s == "" and download_success
75
+ puts " downloaded".green + " #{@file_name}"
75
76
  download_request.file_size
76
- elsif download_request.error.to_s == ''
77
- puts " failed".colorize(:red) + " #{@file_name}"
78
- if method == 'fast'
77
+ elsif download_request.error.to_s == ""
78
+ puts " failed".red + " #{@file_name}"
79
+ if method == "fast"
79
80
  puts " File size mismatch, expected: #{@file_size}"
80
81
  puts " actual: #{@latest_file_size}"
81
82
  else
@@ -83,17 +84,17 @@ module Nsrr
83
84
  puts " actual: #{@latest_checksum}"
84
85
  end
85
86
  ::File.delete(download_folder) if ::File.exist?(download_folder)
86
- 'fail'
87
+ "fail"
87
88
  else
88
- puts ' failed'.colorize(:red) + " #{@file_name}"
89
+ puts " failed".red + " #{@file_name}"
89
90
  puts " #{download_request.error}"
90
- 'fail'
91
+ "fail"
91
92
  end
92
93
  end
93
94
 
94
95
  def skip
95
- puts ' identical'.colorize(:light_blue) + " #{file_name}"
96
- 'skip'
96
+ puts " identical".blue + " #{file_name}"
97
+ "skip"
97
98
  end
98
99
 
99
100
  def md5_matches?(path)
@@ -105,7 +106,7 @@ module Nsrr
105
106
  @latest_checksum = if ::File.exist?(download_folder)
106
107
  Digest::MD5.file(download_folder).hexdigest
107
108
  else
108
- ''
109
+ ""
109
110
  end
110
111
  @latest_checksum
111
112
  end
@@ -125,7 +126,7 @@ module Nsrr
125
126
  end
126
127
 
127
128
  def did_download_succeed?(method, path)
128
- if method == 'fast'
129
+ if method == "fast"
129
130
  file_size_matches?(path)
130
131
  else
131
132
  md5_matches?(path)
@@ -2,11 +2,11 @@
2
2
 
3
3
  module Nsrr
4
4
  module VERSION #:nodoc:
5
- MAJOR = 0
6
- MINOR = 4
5
+ MAJOR = 6
6
+ MINOR = 0
7
7
  TINY = 0
8
- BUILD = 'beta1' # 'pre', 'beta1', 'beta2', 'rc', 'rc2', nil
8
+ BUILD = nil # "pre", "beta1", "beta2", "rc", "rc2", nil
9
9
 
10
- STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
10
+ STRING = [MAJOR, MINOR, TINY, BUILD].compact.join(".")
11
11
  end
12
12
  end
@@ -8,27 +8,30 @@
8
8
  # gem list -r nsrr
9
9
  # gem install nsrr
10
10
 
11
- lib = File.expand_path('../lib', __FILE__)
11
+ lib = File.expand_path("lib", __dir__)
12
12
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
13
- require 'nsrr/version'
13
+ require "nsrr/version"
14
14
 
15
15
  Gem::Specification.new do |spec|
16
- spec.name = 'nsrr'
16
+ spec.name = "nsrr"
17
17
  spec.version = Nsrr::VERSION::STRING
18
- spec.authors = ['Remo Mueller']
19
- spec.email = ['remosm@gmail.com']
20
- spec.summary = 'Download files easily from the NSRR website, https://sleepdata.org'
21
- spec.description = 'The official ruby gem to download files and datasets from the [NSRR](https://sleepdata.org)'
22
- spec.homepage = 'https://github.com/nsrr/nsrr-gem'
23
- spec.license = 'CC-BY-NC-SA-3.0'
18
+ spec.authors = ["Remo Mueller"]
19
+ spec.email = ["remosm@gmail.com"]
20
+ spec.summary = "Download files easily from the NSRR website, https://sleepdata.org"
21
+ spec.description = "The official ruby gem to download files and datasets from the [NSRR](https://sleepdata.org)"
22
+ spec.homepage = "https://github.com/nsrr/nsrr-gem"
24
23
 
25
- spec.files = Dir['{bin,lib}/**/*'] + ['CHANGELOG.md', 'LICENSE', 'Rakefile', 'README.md', 'nsrr.gemspec']
24
+ spec.required_ruby_version = ">= 2.7.2"
25
+ spec.required_rubygems_version = ">= 2.6.3"
26
+
27
+ spec.license = "MIT"
28
+
29
+ spec.files = Dir["{bin,lib}/**/*"] + ["CHANGELOG.md", "LICENSE", "Rakefile", "README.md", "nsrr.gemspec"]
26
30
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
27
31
  spec.test_files = spec.files.grep(%r{^(test)/})
28
- spec.require_paths = ['lib']
32
+ spec.require_paths = ["lib"]
29
33
 
30
- spec.add_dependency 'bundler', '~> 1.13'
31
- spec.add_dependency 'colorize', '~> 0.8.1'
32
- spec.add_dependency 'minitest'
33
- spec.add_dependency 'rake'
34
+ spec.add_dependency "bundler", ">= 1.3.0"
35
+ spec.add_dependency "minitest"
36
+ spec.add_dependency "rake"
34
37
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsrr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0.beta1
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Remo Mueller
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-12 00:00:00.000000000 Z
11
+ date: 2021-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.13'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.13'
27
- - !ruby/object:Gem::Dependency
28
- name: colorize
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: 0.8.1
19
+ version: 1.3.0
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - "~>"
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: 0.8.1
26
+ version: 1.3.0
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: minitest
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -84,6 +70,7 @@ files:
84
70
  - lib/nsrr/commands/download.rb
85
71
  - lib/nsrr/commands/update.rb
86
72
  - lib/nsrr/helpers/authorization.rb
73
+ - lib/nsrr/helpers/color.rb
87
74
  - lib/nsrr/helpers/constants.rb
88
75
  - lib/nsrr/helpers/download_request.rb
89
76
  - lib/nsrr/helpers/hash_helper.rb
@@ -95,9 +82,9 @@ files:
95
82
  - nsrr.gemspec
96
83
  homepage: https://github.com/nsrr/nsrr-gem
97
84
  licenses:
98
- - CC-BY-NC-SA-3.0
85
+ - MIT
99
86
  metadata: {}
100
- post_install_message:
87
+ post_install_message:
101
88
  rdoc_options: []
102
89
  require_paths:
103
90
  - lib
@@ -105,16 +92,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
92
  requirements:
106
93
  - - ">="
107
94
  - !ruby/object:Gem::Version
108
- version: '0'
95
+ version: 2.7.2
109
96
  required_rubygems_version: !ruby/object:Gem::Requirement
110
97
  requirements:
111
- - - ">"
98
+ - - ">="
112
99
  - !ruby/object:Gem::Version
113
- version: 1.3.1
100
+ version: 2.6.3
114
101
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.6.8
117
- signing_key:
102
+ rubygems_version: 3.2.5
103
+ signing_key:
118
104
  specification_version: 4
119
105
  summary: Download files easily from the NSRR website, https://sleepdata.org
120
106
  test_files: []