datahunter 0.3.3 → 0.4.0
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 +4 -4
- data/bin/hunter +14 -11
- data/datahunter.gemspec +1 -1
- data/lib/datahunter/base.rb +11 -12
- data/lib/datahunter/version.rb +1 -1
- data/spec/datahunter_spec.rb +11 -11
- data/spec/hunter_spec.rb +5 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93019a255b620f2e90bd8f96f2776b38c493ef3f
|
4
|
+
data.tar.gz: 2b1709986d5e92eac838257fa56331724ec9635e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17922e674998a675122fa7aea87785ff0ec6d5cec8419d4d9850f0ff64e17811194b0bf3a91ebdbf9be120ffb4fcbfaf71ec6e7a0ed5f2b88ff7bd22a2aad883
|
7
|
+
data.tar.gz: 15c24cb1ef26a232d7fe7b709d9fa1b05554a7a67d3d8d23907a1c630faec29f137bff86649c446773ee1974610912781a4b143981c5dc15fc8c199bba3481d6
|
data/bin/hunter
CHANGED
@@ -19,32 +19,35 @@ command :find do |c|
|
|
19
19
|
c.summary = 'Displays the datasets corresponding to the query'.colorize(:blue)
|
20
20
|
c.description = c.summary
|
21
21
|
c.action do |args, options|
|
22
|
-
|
23
|
-
start_time = Time.now
|
24
22
|
|
23
|
+
start_time = Time.now
|
24
|
+
|
25
25
|
if args[0].nil?
|
26
26
|
puts "usage: $ hunter find keyword [geo] [temp]"
|
27
27
|
elsif
|
28
28
|
|
29
|
-
|
29
|
+
query = args.join(" ")
|
30
|
+
url = Datahunter.datasets_url query
|
30
31
|
response = RestClient.get(url, :content_type => :json) do |response, request, result, &block|
|
31
32
|
elapsed_time = Time.now - start_time
|
32
|
-
|
33
|
+
|
33
34
|
case response.code
|
34
35
|
when 200
|
35
|
-
datasets = JSON.parse(response.body)
|
36
|
+
datasets = JSON.parse(response.body) #.reverse
|
36
37
|
number_of_datasets = datasets.length
|
37
38
|
|
38
39
|
puts "### Response in #{elapsed_time} seconds".colorize(:blue)
|
39
|
-
puts "### We've found #{datasets.size} datasets corresponding to your query #{
|
40
|
+
puts "### We've found #{datasets.size} datasets corresponding to your query '#{query}':".colorize(:blue)
|
40
41
|
puts
|
41
42
|
|
42
|
-
for i in 1..(number_of_datasets/5 +
|
43
|
+
for i in 1..(number_of_datasets/5 +1)
|
43
44
|
sub_datasets = datasets[(5 * i - 5) .. (5 * i - 1)]
|
44
45
|
|
45
46
|
Datahunter.print_coll_of_datasets_info_light sub_datasets
|
46
47
|
|
47
|
-
case ask ("
|
48
|
+
case ask ("Get data? (1..5) ".colorize(:yellow) +
|
49
|
+
"next 5? (RET) ".colorize(:cyan) +
|
50
|
+
"abort?(q): ")
|
48
51
|
when '1'
|
49
52
|
Datahunter.get_dataset sub_datasets[0]
|
50
53
|
break
|
@@ -60,7 +63,7 @@ command :find do |c|
|
|
60
63
|
when '5'
|
61
64
|
Datahunter.get_dataset sub_datasets[4]
|
62
65
|
break
|
63
|
-
when '
|
66
|
+
when 'q'
|
64
67
|
break
|
65
68
|
else
|
66
69
|
next
|
@@ -94,7 +97,7 @@ command :info do |c|
|
|
94
97
|
ds = JSON.parse(response.body)
|
95
98
|
puts
|
96
99
|
Datahunter.print_dataset_info ds
|
97
|
-
when
|
100
|
+
when 400
|
98
101
|
puts "Invalid ID".colorize(:red)
|
99
102
|
end
|
100
103
|
end
|
@@ -119,7 +122,7 @@ command :get do |c|
|
|
119
122
|
ds = JSON.parse(response.body)
|
120
123
|
puts
|
121
124
|
Datahunter.get_dataset ds
|
122
|
-
when
|
125
|
+
when 400
|
123
126
|
puts "Invalid ID".colorize(:red)
|
124
127
|
end
|
125
128
|
end
|
data/datahunter.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.add_development_dependency "aruba-rspec"
|
27
27
|
|
28
28
|
spec.add_runtime_dependency "json", "1.8.1"
|
29
|
-
spec.add_runtime_dependency "commander", "4.3.
|
29
|
+
spec.add_runtime_dependency "commander", "4.3.2"
|
30
30
|
spec.add_runtime_dependency "rest-client", "1.8.0"
|
31
31
|
spec.add_runtime_dependency "launchy", "2.4.3"
|
32
32
|
spec.add_runtime_dependency "colorize", "0.7.5"
|
data/lib/datahunter/base.rb
CHANGED
@@ -5,6 +5,7 @@ require 'addressable/uri'
|
|
5
5
|
|
6
6
|
module Datahunter
|
7
7
|
|
8
|
+
# DATASETS_URL = "http://localhost:3000/api/datasets/"
|
8
9
|
DATASETS_URL = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/"
|
9
10
|
FEEDBACK_URL = "https://docs.google.com/forms/d/1yNzZjCCXvWHQCbWz4sx-nui3LafeeLcT7FF9T-vbKvw/viewform"
|
10
11
|
REQUEST_URL =
|
@@ -12,19 +13,17 @@ module Datahunter
|
|
12
13
|
|
13
14
|
@extensions = ["json", "csv", "xml", "zip", "gz", "xls", "xlsx", "shp", "docx", "doc", "pdf", "txt", "tsv"]
|
14
15
|
|
15
|
-
def self.
|
16
|
-
|
17
|
-
|
16
|
+
def self.query_string_builder string
|
17
|
+
s = string
|
18
|
+
.strip
|
19
|
+
.gsub(/ {3,}/, ' ')
|
20
|
+
.gsub(/ {2,}/, ' ')
|
21
|
+
.gsub(/ /, '+')
|
22
|
+
"?q=#{s}"
|
23
|
+
end
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
elsif temp.nil?
|
22
|
-
"#{DATASETS_URL}?tags=#{tag}&spatial=#{geo}"
|
23
|
-
elsif geo.nil?
|
24
|
-
"#{DATASETS_URL}?tags=#{tag}&temporal=#{temp}"
|
25
|
-
else
|
26
|
-
"#{DATASETS_URL}?tags=#{tag}&spatial=#{geo}&temporal=#{temp}"
|
27
|
-
end
|
25
|
+
def self.datasets_url query
|
26
|
+
"#{DATASETS_URL}#{Datahunter.query_string_builder query}"
|
28
27
|
end
|
29
28
|
|
30
29
|
def self.ds_url id
|
data/lib/datahunter/version.rb
CHANGED
data/spec/datahunter_spec.rb
CHANGED
@@ -7,19 +7,19 @@ describe "Datahunter API calls" do
|
|
7
7
|
DATASETS_URL = "http://shrouded-harbor-5877.herokuapp.com/api/datasets/"
|
8
8
|
|
9
9
|
describe 'Should create a correct datasets_url to call the API' do
|
10
|
-
it 'should return a correct url' do
|
11
|
-
|
12
|
-
|
13
|
-
end
|
10
|
+
#it 'should return a correct url' do
|
11
|
+
# url = Datahunter.datasets_url("population", "france", "2010")
|
12
|
+
# expect(url).to eq("#{DATASETS_URL}?tags=population&spatial=france&temporal=2010")
|
13
|
+
#end
|
14
14
|
end
|
15
15
|
|
16
16
|
describe 'Should receive a dataset corresponding to the query' do
|
17
|
-
response = RestClient.get("#{DATASETS_URL}?tags=population",
|
18
|
-
|
19
|
-
res = JSON.parse(response.body).reverse.first
|
20
|
-
|
21
|
-
it 'should have the tag corresponding to the query keyword' do
|
22
|
-
|
23
|
-
end
|
17
|
+
#response = RestClient.get("#{DATASETS_URL}?tags=population",
|
18
|
+
# :content_type => :json)
|
19
|
+
#res = JSON.parse(response.body).reverse.first
|
20
|
+
#
|
21
|
+
#it 'should have the tag corresponding to the query keyword' do
|
22
|
+
# res["tags"].should include("population")
|
23
|
+
#end
|
24
24
|
end
|
25
25
|
end
|
data/spec/hunter_spec.rb
CHANGED
@@ -17,13 +17,13 @@ describe 'Hunter' do
|
|
17
17
|
describe 'download a file' do
|
18
18
|
|
19
19
|
it 'should raise an error with an invalid uri' do
|
20
|
-
lambda { Datahunter.download_file @invalid_url }.should
|
20
|
+
lambda { Datahunter.download_file @invalid_url }.should raise_error(Launchy::ApplicationNotFoundError)
|
21
21
|
end
|
22
22
|
|
23
|
-
it 'should open the browser if the file extension is not acceptable' do
|
24
|
-
|
25
|
-
|
26
|
-
end
|
23
|
+
#it 'should open the browser if the file extension is not acceptable' do
|
24
|
+
# lambda { Datahunter.download_file @bad_url }.should_not raise_error
|
25
|
+
#
|
26
|
+
#end
|
27
27
|
|
28
28
|
it 'should ask if rename the file if the file extension is acceptable' do
|
29
29
|
lambda { Datahunter.download_file @url }.should raise_error(NoMethodError)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datahunter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Terpo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 4.3.
|
89
|
+
version: 4.3.2
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 4.3.
|
96
|
+
version: 4.3.2
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rest-client
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|