nasa_apod 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +0 -7
- data/lib/nasa_apod/client.rb +28 -36
- data/lib/nasa_apod/search_results.rb +1 -2
- data/lib/nasa_apod/version.rb +1 -1
- data/spec/nasa_apod_spec.rb +0 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: accbff5d6943a6ea3766fa8bab9fb0d962009748
|
4
|
+
data.tar.gz: a282c0cfd0fa47d784d19fc1c6ae39d2eb463415
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcd7cef972eda3045c1beb7c42f02ec75dc381d546f0a9a75cdb80ce84d8009e305afb43557635664a80064453e92b79757dfb68ce37fec77cf8377f2e4aff87
|
7
|
+
data.tar.gz: e094aba6a476ac7b077c9856d25a19aeb44ab64d7cc50cc874af29e6b5f3fd3d5cd1a54b5d05a1c36bf88e34fef417f9c049391ace9a675bbf90d9508b9b4afa
|
data/README.md
CHANGED
@@ -39,13 +39,6 @@ result = client.search
|
|
39
39
|
result.explanation #=> "This big, bright, beautiful spiral galaxy is Messier 64..."
|
40
40
|
```
|
41
41
|
|
42
|
-
Get concept tags with result
|
43
|
-
```
|
44
|
-
result = client.search(concept_tags: true)
|
45
|
-
result.concepts #=> ["Sun","Sunspot","Light",...],
|
46
|
-
```
|
47
|
-
Note: Not all posts have concept tags.
|
48
|
-
|
49
42
|
Get image URL:
|
50
43
|
|
51
44
|
```
|
data/lib/nasa_apod/client.rb
CHANGED
@@ -1,34 +1,25 @@
|
|
1
1
|
module NasaApod
|
2
|
-
|
2
|
+
|
3
3
|
DEFAULT_URL = 'https://api.nasa.gov/planetary/apod'
|
4
|
-
|
4
|
+
|
5
5
|
class Client
|
6
|
-
attr_reader :api_key, :date, :
|
6
|
+
attr_reader :api_key, :date, :hd
|
7
7
|
|
8
8
|
def date=(date)
|
9
9
|
@date = parse_date(date)
|
10
10
|
end
|
11
11
|
|
12
|
-
def concept_tags=(concept_tags)
|
13
|
-
if concept_tags.nil? || concept_tags.blank?
|
14
|
-
@concept_tags = false
|
15
|
-
else
|
16
|
-
@concept_tags = concept_tags
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
12
|
def hd=(hd)
|
21
|
-
if hd.nil? || hd.blank?
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
@hd = if hd.nil? || hd.blank?
|
14
|
+
false
|
15
|
+
else
|
16
|
+
hd
|
17
|
+
end
|
26
18
|
end
|
27
|
-
|
28
|
-
def initialize(options={})
|
29
|
-
@api_key = options[:api_key] ||
|
19
|
+
|
20
|
+
def initialize(options = {})
|
21
|
+
@api_key = options[:api_key] || 'DEMO_KEY'
|
30
22
|
self.date = options[:date]
|
31
|
-
self.concept_tags = options[:concept_tags]
|
32
23
|
self.hd = options[:hd]
|
33
24
|
end
|
34
25
|
|
@@ -39,34 +30,34 @@ module NasaApod
|
|
39
30
|
# @image_permissions http://apod.nasa.gov/apod/lib/about_apod.html#srapply
|
40
31
|
# @authentication optional NASA api key https://api.nasa.gov/index.html#apply-for-an-api-key
|
41
32
|
# @option options [String] :api_key Optional. Uses DEMO_KEY as default.
|
42
|
-
# @option options [String] :date Optional. Returns the APOD results for
|
43
|
-
#
|
33
|
+
# @option options [String] :date Optional. Returns the APOD results for
|
34
|
+
# the given date. Date should be formatted as YYYY-MM-DD. Defaults as today.
|
44
35
|
# @return [NasaApod::SearchResults] Return APOD post for a specified date.
|
45
|
-
def search(options={})
|
36
|
+
def search(options = {})
|
46
37
|
self.date = options[:date] || date
|
47
|
-
@concept_tags = options[:concept_tags] || concept_tags
|
48
38
|
@hd = options[:hd] || hd
|
49
|
-
response = HTTParty.get(DEFAULT_URL,
|
39
|
+
response = HTTParty.get(DEFAULT_URL, query: attributes)
|
50
40
|
handle_response(response)
|
51
41
|
end
|
52
42
|
|
53
|
-
def random_post(options={})
|
54
|
-
date = rand(Date.parse(
|
55
|
-
|
43
|
+
def random_post(options = {})
|
44
|
+
date = rand(Date.parse('1995-06-16')..Date.today)
|
45
|
+
options[:date] = date
|
46
|
+
search(options)
|
56
47
|
end
|
57
48
|
|
58
|
-
|
49
|
+
alias wormhole random_post
|
59
50
|
|
60
51
|
def attributes
|
61
|
-
instance_variables.each_with_object(
|
62
|
-
hash[var.to_s.delete(
|
52
|
+
instance_variables.each_with_object({}) do |var, hash|
|
53
|
+
hash[var.to_s.delete('@')] = instance_variable_get(var)
|
63
54
|
end
|
64
55
|
end
|
65
56
|
|
66
57
|
private
|
67
58
|
|
68
59
|
def handle_response(response)
|
69
|
-
if response[
|
60
|
+
if response['error'].nil?
|
70
61
|
NasaApod::SearchResults.new(response)
|
71
62
|
else
|
72
63
|
NasaApod::Error.new(response)
|
@@ -74,11 +65,12 @@ module NasaApod
|
|
74
65
|
end
|
75
66
|
|
76
67
|
def parse_date(date)
|
77
|
-
|
78
|
-
|
79
|
-
|
68
|
+
case date
|
69
|
+
when Time
|
70
|
+
date.strftime('%Y-%m-%d')
|
71
|
+
when Date
|
80
72
|
date.to_s
|
81
|
-
|
73
|
+
when String
|
82
74
|
date
|
83
75
|
else
|
84
76
|
Date.today.to_s
|
@@ -1,10 +1,9 @@
|
|
1
1
|
module NasaApod
|
2
2
|
|
3
3
|
class SearchResults
|
4
|
-
attr_accessor :
|
4
|
+
attr_accessor :url, :media_type, :title, :explanation, :hd_url, :date, :copyright
|
5
5
|
|
6
6
|
def initialize(attributes={})
|
7
|
-
@concepts = attributes["concepts"]
|
8
7
|
@url = attributes["url"]
|
9
8
|
@media_type = attributes["media_type"]
|
10
9
|
@explanation = attributes["explanation"]
|
data/lib/nasa_apod/version.rb
CHANGED
data/spec/nasa_apod_spec.rb
CHANGED
@@ -10,10 +10,6 @@ module NasaApod
|
|
10
10
|
expect(client.api_key).to eq("DEMO_KEY")
|
11
11
|
end
|
12
12
|
|
13
|
-
it 'concept_tags defaults to false' do
|
14
|
-
expect(client.concept_tags).to eq(false)
|
15
|
-
end
|
16
|
-
|
17
13
|
it 'date defaults to a string of today' do
|
18
14
|
expect(client.date).to eq(Date.today.to_s)
|
19
15
|
end
|
@@ -76,7 +72,6 @@ module NasaApod
|
|
76
72
|
describe '#initialize' do
|
77
73
|
let(:result) { SearchResults.new(attributes) }
|
78
74
|
let(:attributes) {{"url" => "test_url",
|
79
|
-
"concepts" => ["test_concept1","test_concept2"],
|
80
75
|
"media_type" => "JPG",
|
81
76
|
"title" => "Test title",
|
82
77
|
"explanation" => "Test explanation",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nasa_apod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabe Dominguez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.8
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Ruby wrapper for NASA's Astronomy Picture of the Day API
|