nasa_apod 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +2 -0
- data/lib/nasa_apod/client.rb +74 -0
- data/lib/nasa_apod/error.rb +13 -0
- data/lib/nasa_apod/search_results.rb +15 -0
- data/lib/nasa_apod/version.rb +3 -0
- data/lib/nasa_apod.rb +6 -0
- data/nasa_apod.gemspec +26 -0
- data/spec/nasa_apod_spec.rb +71 -0
- data/spec/spec_helper.rb +1 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d0c937cbaee254da9ab931d3407389e407672c5
|
4
|
+
data.tar.gz: 2d8d580e9f7839c5b83c42744613b8e9748ade03
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d152a093d41f7cf36c420716510e6182af8d67d396cd810b43522f70ce0fd5eee3d581968c8a15ebd4e90e9e3d6c82557471eecb26486967c4bf5eb0ec1690b2
|
7
|
+
data.tar.gz: 1385b33f8b926117768dd927561296785d3bbd4154a292d5b70a6e454f0c35145072cf57c34d8a90a715f702c69d0d44d713798952c5d632688725f127123150
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Gabe D
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# NasaApod
|
2
|
+
|
3
|
+
A Ruby gem for consuming the NASA Astronomy Picture of the Day API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'nasa_apod'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install nasa_apod
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```
|
22
|
+
client = NasaApod::Client.new(api_key: "DEMO_KEY") #DEMO_KEY usage is limited.
|
23
|
+
result = client.search(date: "2015-06-18") #You can also pass in a Ruby Date object.
|
24
|
+
result
|
25
|
+
```
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it ( https://github.com/[my-github-username]/nasa_apod/fork )
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
module NasaApod
|
2
|
+
|
3
|
+
DEFAULT_URL = 'https://api.nasa.gov/planetary/apod'
|
4
|
+
|
5
|
+
class Client
|
6
|
+
attr_reader :api_key, :date, :list_concepts
|
7
|
+
|
8
|
+
def date=(date)
|
9
|
+
@date = parse_date(date)
|
10
|
+
end
|
11
|
+
|
12
|
+
def list_concepts=(list_concepts)
|
13
|
+
if list_concepts.nil? || list_concepts.blank?
|
14
|
+
@list_concepts = false
|
15
|
+
else
|
16
|
+
@list_concepts = list_concepts
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(options={})
|
21
|
+
@api_key = options[:api_key] || "DEMO_KEY"
|
22
|
+
self.date = options[:date]
|
23
|
+
self.list_concepts = options[:list_concepts]
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns APOD info for specified day.
|
27
|
+
#
|
28
|
+
# @see https://api.nasa.gov/api.html#apod
|
29
|
+
# @rate_limited Yes https://api.nasa.gov/api.html#authentication
|
30
|
+
# @image_permissions http://apod.nasa.gov/apod/lib/about_apod.html#srapply
|
31
|
+
# @authentication optional NASA api key https://api.nasa.gov/index.html#apply-for-an-api-key
|
32
|
+
# @option options [String] :api_key Optional. Uses DEMO_KEY as default.
|
33
|
+
# @option options [String] :date Optional. Returns the APOD results for the given date. Date should be formatted as YYYY-MM-DD. Defaults as today.
|
34
|
+
# @option options [Boolean] :concept_tags Optional. Returns an array of concept tags if available. Defaults to False.
|
35
|
+
# @return [NasaApod::SearchResults] Return APOD post for a specified date.
|
36
|
+
def search(options={})
|
37
|
+
self.date = options[:date] || date
|
38
|
+
@list_concepts = options[:list_concepts] || list_concepts
|
39
|
+
response = HTTParty.get("https://api.nasa.gov/planetary/apod?api_key=#{api_key}&date=#{date}&concept_tags=#{list_concepts}")
|
40
|
+
handle_response(response)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def handle_response(response)
|
46
|
+
if response["error"].nil?
|
47
|
+
NasaApod::SearchResults.new(response)
|
48
|
+
else
|
49
|
+
NasaApod::Error.new(response)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def write_attrs(attributes)
|
54
|
+
@concepts = attributes["concepts"]
|
55
|
+
@url = attributes["url"]
|
56
|
+
@media_type = attributes["media_type"]
|
57
|
+
@explanation = attributes["explanation"]
|
58
|
+
@title = attributes["title"]
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse_date(date)
|
62
|
+
if date.is_a?(Time)
|
63
|
+
date.strftime("%Y-%m-%d")
|
64
|
+
elsif date.is_a?(Date)
|
65
|
+
date.to_s
|
66
|
+
elsif date.is_a?(String)
|
67
|
+
date
|
68
|
+
else
|
69
|
+
Date.today.to_s
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module NasaApod
|
2
|
+
|
3
|
+
class Error
|
4
|
+
attr_reader :code, :code_definition, :message
|
5
|
+
|
6
|
+
def initialize(response)
|
7
|
+
@code = response.code
|
8
|
+
@code_definition = response.message
|
9
|
+
@message = response["error"]["message"] if response["error"]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module NasaApod
|
2
|
+
|
3
|
+
class SearchResults
|
4
|
+
attr_accessor :concepts, :url, :media_type, :title, :explanation
|
5
|
+
|
6
|
+
def initialize(attributes={})
|
7
|
+
@concepts = attributes["concepts"]
|
8
|
+
@url = attributes["url"]
|
9
|
+
@media_type = attributes["media_type"]
|
10
|
+
@explanation = attributes["explanation"]
|
11
|
+
@title = attributes["title"]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
data/lib/nasa_apod.rb
ADDED
data/nasa_apod.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nasa_apod/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nasa_apod"
|
8
|
+
spec.version = NasaApod::VERSION
|
9
|
+
spec.authors = ["Gabe Dominguez"]
|
10
|
+
spec.email = ["gabe.p.dominguez@gmail.com"]
|
11
|
+
spec.summary = %q{Ruby wrapper for NASA's Astronomy Picture of the Day API}
|
12
|
+
spec.description = %q{A Ruby gem for consuming the NASA Astronomy Picture of the Day API. }
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
spec.add_development_dependency 'httparty'
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module NasaApod
|
4
|
+
|
5
|
+
describe Client do
|
6
|
+
describe '#initialize' do
|
7
|
+
let(:client) { Client.new }
|
8
|
+
|
9
|
+
it 'api key defaults to DEMO_KEY' do
|
10
|
+
expect(client.api_key).to eq("DEMO_KEY")
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'list_concepts defaults to false' do
|
14
|
+
expect(client.list_concepts).to eq(false)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'date defaults to a string of today' do
|
18
|
+
expect(client.date).to eq(Date.today.to_s)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#search' do
|
23
|
+
let(:client) { Client.new }
|
24
|
+
|
25
|
+
it 'returns results' do
|
26
|
+
results = client.search(:date => Date.today.prev_day)
|
27
|
+
expect(results.class).to eq(NasaApod::SearchResults)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'changes picture when date changes' do
|
31
|
+
results = client.search(:date => Date.today.prev_day)
|
32
|
+
yesterdays_title = results.title
|
33
|
+
results = client.search(:date => Date.today)
|
34
|
+
todays_title = results.title
|
35
|
+
expect(yesterdays_title).to_not eq(todays_title)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe SearchResults do
|
42
|
+
describe '#initialize' do
|
43
|
+
let(:result) { SearchResults.new(attributes) }
|
44
|
+
let(:attributes) {{"url" => "test_url",
|
45
|
+
"concepts" => ["test_concept1","test_concept2"],
|
46
|
+
"media_type" => "JPG",
|
47
|
+
"title" => "Test title",
|
48
|
+
"explanation" => "Test explanation"}}
|
49
|
+
|
50
|
+
it 'assigns all attributes properly' do
|
51
|
+
attributes.keys.each do |attr|
|
52
|
+
expect(result.send(attr)).to eq(attributes[attr])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe Error do
|
59
|
+
describe '#initialize' do
|
60
|
+
let(:result) { Error.new(error_reponse) }
|
61
|
+
let(:error_reponse) {HTTParty.get("https://api.nasa.gov/planetary/apod")}
|
62
|
+
|
63
|
+
it 'knows what went wrong' do
|
64
|
+
expect(error_reponse.code).to eq(403)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'nasa_apod'
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nasa_apod
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabe Dominguez
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: 'A Ruby gem for consuming the NASA Astronomy Picture of the Day API. '
|
70
|
+
email:
|
71
|
+
- gabe.p.dominguez@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/nasa_apod.rb
|
82
|
+
- lib/nasa_apod/client.rb
|
83
|
+
- lib/nasa_apod/error.rb
|
84
|
+
- lib/nasa_apod/search_results.rb
|
85
|
+
- lib/nasa_apod/version.rb
|
86
|
+
- nasa_apod.gemspec
|
87
|
+
- spec/nasa_apod_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: ''
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.2.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Ruby wrapper for NASA's Astronomy Picture of the Day API
|
113
|
+
test_files:
|
114
|
+
- spec/nasa_apod_spec.rb
|
115
|
+
- spec/spec_helper.rb
|
116
|
+
has_rdoc:
|