dougsko-apod 0.0.3 → 0.1.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.
- data/VERSION +1 -1
- data/apod.gemspec +1 -1
- data/bin/apod-download +1 -1
- data/lib/apod.rb +15 -9
- data/lib/pic.rb +12 -0
- data/spec/apod_spec.rb +8 -2
- metadata +3 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/apod.gemspec
CHANGED
data/bin/apod-download
CHANGED
data/lib/apod.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
require 'rubygems'
|
7
7
|
require 'open-uri'
|
8
|
+
require 'httpclient'
|
8
9
|
require 'hpricot'
|
9
10
|
require 'lib/pic'
|
10
11
|
|
@@ -23,16 +24,21 @@ class Apod
|
|
23
24
|
@pictures.collect{ |pic| pic.title }
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
def search(query)
|
28
|
+
if query.size > 60
|
29
|
+
return "ERROR: Query must be less than 60 characters"
|
30
|
+
end
|
31
|
+
@pictures = []
|
32
|
+
clnt = HTTPClient.new("http://antwrp.gsfc.nasa.gov/cgi-bin/apod/apod_search")
|
33
|
+
results = clnt.post('http://antwrp.gsfc.nasa.gov/cgi-bin/apod/apod_search', {'tquery' => query}).content
|
34
|
+
doc = Hpricot(results)
|
35
|
+
doc.search("//p").each do |para|
|
36
|
+
title = para.at("a[2]")
|
37
|
+
link = para.at("a")
|
38
|
+
if title != nil and link != nil
|
39
|
+
@pictures << Pic.new(title.innerHTML, link["href"])
|
35
40
|
end
|
36
41
|
end
|
42
|
+
@pictures.pop
|
37
43
|
end
|
38
44
|
end
|
data/lib/pic.rb
CHANGED
@@ -10,4 +10,16 @@ class Pic
|
|
10
10
|
@title = title
|
11
11
|
@website = website
|
12
12
|
end
|
13
|
+
|
14
|
+
def download(save_path)
|
15
|
+
doc = Hpricot(open(self.website))
|
16
|
+
link = "http://apod.nasa.gov/" + doc.at("//center/p[2]/a")["href"]
|
17
|
+
url = URI.parse(link)
|
18
|
+
|
19
|
+
url.open do |pic|
|
20
|
+
File.open(save_path, "w") do |file|
|
21
|
+
file << pic.read
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
13
25
|
end
|
data/spec/apod_spec.rb
CHANGED
@@ -13,10 +13,16 @@ describe "Apod" do
|
|
13
13
|
@apod.titles.class.to_s.should == "Array"
|
14
14
|
end
|
15
15
|
|
16
|
-
it "
|
17
|
-
@apod.
|
16
|
+
it "search and download the first picture" do
|
17
|
+
@apod.search("earth")
|
18
|
+
@apod.pictures.first.download("/tmp/apod.jpg")
|
18
19
|
`file /tmp/apod.jpg`.should match(/image data/)
|
19
20
|
`rm /tmp/apod.jpg`
|
20
21
|
end
|
21
22
|
|
23
|
+
it "tries to search with a query that is too big" do
|
24
|
+
@apod.search("A"*61).should match(/ERROR/)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
22
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dougsko-apod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dougsko
|
@@ -57,6 +57,7 @@ files:
|
|
57
57
|
- spec/spec_helper.rb
|
58
58
|
has_rdoc: false
|
59
59
|
homepage: http://github.com/dougsko/apod
|
60
|
+
licenses:
|
60
61
|
post_install_message:
|
61
62
|
rdoc_options:
|
62
63
|
- --charset=UTF-8
|
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
78
|
requirements: []
|
78
79
|
|
79
80
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.
|
81
|
+
rubygems_version: 1.3.5
|
81
82
|
signing_key:
|
82
83
|
specification_version: 3
|
83
84
|
summary: A library to work with NASA's astronomy pictures of the day.
|