nsrr 0.1.1 → 0.2.0.rc

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f8c53c2659b9c4675815c8da96ac1c40eeb03da
4
- data.tar.gz: 971bcc2bd566eaa7b1a7c9e55ac52630e3d69cc0
3
+ metadata.gz: b8c27aa5e00981e30edb2fd1e54be534f2080491
4
+ data.tar.gz: eedc928285c028bc7355ed1fa6a044978ce37fe7
5
5
  SHA512:
6
- metadata.gz: 8f09358a58b5a3d2581e20efff43ab614ae1934d5d331220566a0b1e4e3417ded013b8ec416a9da2b855b98d4256fe14e378f864ea4262a1d26fca82a6925294
7
- data.tar.gz: 1ca8bff8d3f083e9031354d55507d7e1424cc6758f0e9f9811d6dd9d2dcfafc521a89316b74a20370361cb54a65dbb613cf5d5ccbaf38d999abaf45876ff48cf
6
+ metadata.gz: b90b6320bedafd5eccf91672344ba0b5b5e27726abf0f3c3719bccdad996528af2a3ea66ca498aaa2b1818aa89068ff9c92d5301772f5b8ace20b7eaa32278f5
7
+ data.tar.gz: 72b6f6537adb848bc90e303562d7cc24bba363ca31d9b6818e3ba320af966cf7fa4abb96139c33a2a9f79990b3b40ad701047fecdd1e5fc16f38b3765c6c38bc
@@ -1,3 +1,13 @@
1
+ ## 0.2.0
2
+
3
+ ### Enhancements
4
+ - The `nsrr download` command now allows users to download files from private datasets
5
+ - The `nsrr download` command provides better feedback on the validity of the authorization token provided by the user
6
+ - Use of Ruby 2.2.1 is now recommended
7
+
8
+ ### Bug Fixes
9
+ - Fixed an issue preventing public files from being downloaded when an invalid token was entered
10
+
1
11
  ## 0.1.1 (October 23, 2014)
2
12
 
3
13
  ### Enhancements
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 NSRR
1
+ Copyright (c) 2015 NSRR
2
2
  https://github.com/nsrr
3
3
 
4
4
 
data/README.md CHANGED
@@ -80,18 +80,18 @@ $ nsrr console
80
80
  ```
81
81
  > d = Dataset.find 'shhs'
82
82
  > d.download
83
+ Get your token here: https://sleepdata.org/token
84
+ Enter your token: AUTHORIZED
85
+ File Check: md5
86
+ Depth: recursive
83
87
 
84
- File Integrity Check Method: md5
85
- Depth: recursive
86
- Get your token here: https://sleepdata.org/token
87
- Please enter your download token:
88
88
  create shhs/
89
89
  create shhs/datasets
90
- identical shhs-cvd-dataset-0.4.0.csv
91
- identical shhs-data-dictionary-0.4.0-domains.csv
92
- identical shhs-data-dictionary-0.4.0-forms.csv
93
- identical shhs-data-dictionary-0.4.0-variables.csv
94
- identical shhs1-dataset-0.4.0.csv
90
+ identical shhs-cvd-dataset-0.6.0.csv
91
+ identical shhs-data-dictionary-0.6.0-domains.csv
92
+ identical shhs-data-dictionary-0.6.0-forms.csv
93
+ identical shhs-data-dictionary-0.6.0-variables.csv
94
+ identical shhs1-dataset-0.6.0.csv
95
95
  ...
96
96
  ```
97
97
 
@@ -115,10 +115,10 @@ For example to download only the shhs1 edfs folder and skip MD5 file validation:
115
115
  > d = Dataset.find 'shhs'
116
116
  > d.download('edfs/shhs1', method: 'fast', depth: 'shallow')
117
117
 
118
- File Integrity Check Method: fast
119
- Depth: shallow
120
- Get your token here: https://sleepdata.org/token
121
- Please enter your download token:
118
+ Get your token here: https://sleepdata.org/token
119
+ Enter your token: AUTHORIZED
120
+ File Check: md5
121
+ Depth: recursive
122
122
 
123
123
  create shhs/edfs/shhs1
124
124
  download 100001.EDF
@@ -134,15 +134,15 @@ You can type `Ctrl-C` to pause the download, and retype the command to restart:
134
134
  > d = Dataset.find 'shhs'
135
135
  > d.download
136
136
 
137
- File Integrity Check Method: md5
138
- Depth: recursive
139
- Get your token here: https://sleepdata.org/token
140
- Please enter your download token:
137
+ Get your token here: https://sleepdata.org/token
138
+ Enter your token: AUTHORIZED
139
+ File Check: md5
140
+ Depth: recursive
141
141
 
142
142
  create shhs/
143
143
  create shhs/datasets
144
- download shhs-cvd-dataset-0.4.0.csv
145
- download shhs-data-dictionary-0.4.0-domains.csv
144
+ download shhs-cvd-dataset-0.6.0.csv
145
+ download shhs-data-dictionary-0.6.0-domains.csv
146
146
  ^C
147
147
  Interrupted
148
148
 
@@ -152,15 +152,15 @@ Finished in 4.384734 seconds.
152
152
 
153
153
  > d.download
154
154
 
155
- File Integrity Check Method: md5
156
- Depth: recursive
157
- Get your token here: https://sleepdata.org/token
158
- Please enter your download token:
155
+ Get your token here: https://sleepdata.org/token
156
+ Enter your token: AUTHORIZED
157
+ File Check: md5
158
+ Depth: recursive
159
159
 
160
160
  create shhs/
161
161
  create shhs/datasets
162
- identical shhs-cvd-dataset-0.4.0.csv
163
- identical shhs-data-dictionary-0.4.0-domains.csv
162
+ identical shhs-cvd-dataset-0.6.0.csv
163
+ identical shhs-data-dictionary-0.6.0-domains.csv
164
164
  ^C
165
165
  Interrupted
166
166
 
@@ -1,6 +1,7 @@
1
1
  require 'colorize'
2
2
 
3
3
  require 'nsrr/models/all'
4
+ require 'nsrr/helpers/authorization'
4
5
 
5
6
  module Nsrr
6
7
  module Commands
@@ -11,7 +12,7 @@ module Nsrr
11
12
  end
12
13
  end
13
14
 
14
- attr_reader :dataset_slug, :folder, :file_comparison, :depth
15
+ attr_reader :token, :dataset_slug, :folder, :file_comparison, :depth
15
16
 
16
17
  def initialize(argv)
17
18
  (@token, argv) = parse_parameter_with_value(argv, ['token'], '')
@@ -21,19 +22,27 @@ module Nsrr
21
22
  @folder = (argv[1].to_s.split('/')[1..-1] || []).join('/')
22
23
  end
23
24
 
25
+ # Run with Authorization
24
26
  def run
25
- @dataset = Dataset.find @dataset_slug
26
- if @dataset
27
- @dataset.download_token = @token
28
- @dataset.download(@folder, depth: @depth, method: @file_comparison)
29
- else
27
+ begin
30
28
  if @dataset_slug == nil
31
29
  puts "Please specify a dataset: " + "nsrr download DATASET".colorize(:white)
30
+ puts "Read more on the download command here:"
31
+ puts " " + "https://github.com/nsrr/nsrr-gem".colorize( :blue ).on_white.underline
32
32
  else
33
- puts "The dataset " + "#{@dataset_slug}".colorize(:white) + " was not found."
33
+ @token = Nsrr::Helpers::Authorization.get_token(@token) if @token.to_s == ''
34
+ @dataset = Dataset.find(@dataset_slug, @token)
35
+ if @dataset
36
+ @dataset.download(@folder, depth: @depth, method: @file_comparison)
37
+ else
38
+ puts "\nThe dataset " + "#{@dataset_slug}".colorize(:white) + " was not found."
39
+ auth_section = (@token.to_s == '' ? '' : "/a/#{@token}" )
40
+ datasets = Nsrr::Helpers::JsonRequest.get("#{Nsrr::WEBSITE}#{auth_section}/datasets.json")
41
+ puts "Did you mean one of: #{datasets.collect{|d| d['slug'].colorize(:white)}.sort.join(', ')}" if datasets and datasets.size > 0
42
+ end
34
43
  end
35
- puts "Read more on the download command here:"
36
- puts " " + "https://github.com/nsrr/nsrr-gem".colorize( :blue ).on_white.underline
44
+ rescue Interrupt
45
+ puts "\nINTERRUPTED".colorize(:red)
37
46
  end
38
47
  end
39
48
 
@@ -0,0 +1,22 @@
1
+ require 'nsrr/helpers/json_request'
2
+
3
+ module Nsrr
4
+ module Helpers
5
+ class Authorization
6
+ def self.get_token(token)
7
+ puts " Get your token here: " + "#{Nsrr::WEBSITE}/token".colorize( :blue ).on_white.underline
8
+ print " Enter your token: "
9
+ token = STDIN.noecho(&:gets).chomp if token.to_s.strip == ''
10
+
11
+ response = Nsrr::Helpers::JsonRequest.get("#{Nsrr::WEBSITE}/account/#{token}/profile.json")
12
+
13
+ if response.kind_of?(Hash) and response['authenticated']
14
+ puts "AUTHORIZED".colorize(:green) + " as " + "#{response['first_name']} #{response['last_name']}".colorize( :white )
15
+ else
16
+ puts "UNAUTHORIZED".colorize(:red) + " Public Access Only"
17
+ end
18
+ token
19
+ end
20
+ end
21
+ end
22
+ end
@@ -6,16 +6,18 @@ require 'io/console'
6
6
  require 'nsrr/helpers/constants'
7
7
  require 'nsrr/helpers/hash_helper'
8
8
  require 'nsrr/helpers/json_request'
9
+ require 'nsrr/helpers/authorization'
9
10
 
10
11
  require 'nsrr/models/file'
11
12
 
12
13
  module Nsrr
13
14
  module Models
14
15
  class Dataset
15
- def self.find(slug)
16
- json = Nsrr::Helpers::JsonRequest.get("#{Nsrr::WEBSITE}/datasets/#{slug}.json")
16
+ def self.find(slug, token = nil)
17
+ auth_section = (token.to_s == '' ? '' : "/a/#{token}")
18
+ json = Nsrr::Helpers::JsonRequest.get("#{Nsrr::WEBSITE}#{auth_section}/datasets/#{slug}.json")
17
19
  if json
18
- new(json)
20
+ new(json, token)
19
21
  else
20
22
  nil
21
23
  end
@@ -24,16 +26,17 @@ module Nsrr
24
26
  attr_accessor :download_token
25
27
  attr_reader :slug, :name
26
28
 
27
- def initialize(json = {})
29
+ def initialize(json = {}, token = nil)
28
30
  @slug = json['slug']
29
31
  @name = json['name']
30
32
  @files = {}
31
- @download_token = nil
33
+ @download_token = token
32
34
  end
33
35
 
34
36
  def files(path = nil)
35
37
  @files[path] ||= begin
36
- json = Nsrr::Helpers::JsonRequest.get("#{Nsrr::WEBSITE}/datasets/#{@slug}/json_manifest/#{path}")
38
+ auth_section = (@download_token.to_s == '' ? '' : "/a/#{@download_token}" )
39
+ json = Nsrr::Helpers::JsonRequest.get("#{Nsrr::WEBSITE}/datasets/#{@slug}#{auth_section}/json_manifest/#{path}")
37
40
  (json || []).collect{|file_json| Nsrr::Models::File.new(file_json)}
38
41
  end
39
42
  end
@@ -61,10 +64,11 @@ module Nsrr
61
64
  @files_failed = 0
62
65
 
63
66
  begin
64
- if @download_token.to_s == ''
65
- puts " File Integrity Check Method: " + options[:method].to_s.colorize(:white)
66
- puts " Depth: " + options[:depth].to_s.colorize(:white)
67
- set_download_token()
67
+ puts " File Check: " + options[:method].to_s.colorize(:white)
68
+ puts " Depth: " + options[:depth].to_s.colorize(:white)
69
+ puts ""
70
+ if @download_token == nil
71
+ @download_token = Nsrr::Helpers::Authorization.get_token(@download_token)
68
72
  end
69
73
 
70
74
  @start_time = Time.now
@@ -115,13 +119,6 @@ module Nsrr
115
119
  @folders_created += 1
116
120
  end
117
121
 
118
- def set_download_token
119
- puts " Get your token here: " + "#{Nsrr::WEBSITE}/token".colorize( :blue ).on_white.underline
120
- print "Please enter your download token: "
121
- @download_token = STDIN.noecho(&:gets).chomp
122
- puts ""
123
- end
124
-
125
122
  end
126
123
  end
127
124
  end
@@ -52,7 +52,8 @@ module Nsrr
52
52
  # If the second download and check fail, the file is marked as failed, and the downloader continues to the subsequent file.
53
53
  def force_download(path, token, method)
54
54
  download_folder = ::File.join(Dir.pwd, path.to_s, @name.to_s)
55
- download_url = "#{Nsrr::WEBSITE}/datasets/#{@dataset_slug}/files/a/#{token}/m/nsrr-gem-v#{Nsrr::VERSION::STRING.gsub('.', '-')}/#{@file_path.to_s}"
55
+ auth_section = (token.to_s == '' ? '' : "/a/#{token}")
56
+ download_url = "#{Nsrr::WEBSITE}/datasets/#{@dataset_slug}/files#{auth_section}/m/nsrr-gem-v#{Nsrr::VERSION::STRING.gsub('.', '-')}/#{@file_path.to_s}"
56
57
  download_request = Nsrr::Helpers::DownloadRequest.new(download_url, download_folder)
57
58
  download_request.get
58
59
 
@@ -1,9 +1,9 @@
1
1
  module Nsrr
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 1
6
- BUILD = nil # nil, "pre", "rc", "rc2"
4
+ MINOR = 2
5
+ TINY = 0
6
+ BUILD = "rc" # nil, "pre", "rc", "rc2"
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nsrr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0.rc
5
5
  platform: ruby
6
6
  authors:
7
7
  - Remo Mueller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-23 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -98,6 +98,7 @@ files:
98
98
  - lib/nsrr/commands/console.rb
99
99
  - lib/nsrr/commands/download.rb
100
100
  - lib/nsrr/commands/update.rb
101
+ - lib/nsrr/helpers/authorization.rb
101
102
  - lib/nsrr/helpers/constants.rb
102
103
  - lib/nsrr/helpers/download_request.rb
103
104
  - lib/nsrr/helpers/hash_helper.rb
@@ -122,12 +123,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
123
  version: '0'
123
124
  required_rubygems_version: !ruby/object:Gem::Requirement
124
125
  requirements:
125
- - - ">="
126
+ - - ">"
126
127
  - !ruby/object:Gem::Version
127
- version: '0'
128
+ version: 1.3.1
128
129
  requirements: []
129
130
  rubyforge_project:
130
- rubygems_version: 2.2.2
131
+ rubygems_version: 2.4.6
131
132
  signing_key:
132
133
  specification_version: 4
133
134
  summary: The official ruby gem to simplify file downloads and dataset integration