nasa_earth 0.0.1
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 +7 -0
- data/lib/nasa_earth.rb +63 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f84e271728659ff75bf55dc62854b894f8c2bfd0
|
4
|
+
data.tar.gz: 97d0d54c8d841a487dcdc4bb67f068e43c2f1606
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd47cfa15db51effd9ae9329fd8ff764e81439a682c738807765e1ec81d92625fed910122e6d4d42ed4fab42190155a159d011bc3bdb4f12aacabd2e52bd66eb
|
7
|
+
data.tar.gz: a9814916ec5affb47a421fb7fa327983270ef8e970e157dcd3819eceb25f2212d297b9b79422f457eb988866235c4dd075b31beadacb5e03d32c082b8b27b5b6
|
data/lib/nasa_earth.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'boolean'
|
4
|
+
|
5
|
+
class NasaEarth
|
6
|
+
attr_accessor :api_key
|
7
|
+
|
8
|
+
VALIDATORS = {
|
9
|
+
api_key: { mandatory: true, type: String },
|
10
|
+
lat: { mandatory: true, type: Float },
|
11
|
+
lon: { mandatory: true, type: Float },
|
12
|
+
dim: { mandatory: false, type: Float },
|
13
|
+
date: { mandatory: false, type: String },
|
14
|
+
begin: { mandatory: false, type: String },
|
15
|
+
end: { mandatory: false, type: String },
|
16
|
+
cloud: { mandatory: false, type: Boolean },
|
17
|
+
}
|
18
|
+
|
19
|
+
def initialize options = {}
|
20
|
+
@api_key = options[:api_key]
|
21
|
+
end
|
22
|
+
|
23
|
+
def imagery params
|
24
|
+
params[:api_key] = @api_key unless @api_key.nil?
|
25
|
+
_check_params params
|
26
|
+
uri = URI('https://api.nasa.gov/planetary/earth/imagery')
|
27
|
+
uri.query = URI.encode_www_form(params)
|
28
|
+
return _get_response uri
|
29
|
+
end
|
30
|
+
|
31
|
+
def assets params
|
32
|
+
params[:api_key] = @api_key unless @api_key.nil?
|
33
|
+
_check_params params
|
34
|
+
uri = URI('https://api.nasa.gov/planetary/earth/assets')
|
35
|
+
uri.query = URI.encode_www_form(params)
|
36
|
+
return _get_response uri
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def _get_response uri
|
41
|
+
res = Net::HTTP.get_response(uri)
|
42
|
+
response = {
|
43
|
+
'code' => res.code,
|
44
|
+
'message' => res.message
|
45
|
+
}
|
46
|
+
if res.is_a? Net::HTTPSuccess
|
47
|
+
response['content'] = JSON.load(res.body)
|
48
|
+
end
|
49
|
+
return response
|
50
|
+
end
|
51
|
+
|
52
|
+
def _check_params params
|
53
|
+
VALIDATORS.each do |name, conditions|
|
54
|
+
if params.has_key? name
|
55
|
+
unless params[name].is_a? conditions[:type]
|
56
|
+
raise ArgumentError, "'#{name}' should be a #{conditions[:type].to_s}"
|
57
|
+
end
|
58
|
+
elsif conditions[:mandatory]
|
59
|
+
raise ArgumentError, "Argument '#{name}' is mandatory"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nasa_earth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gabriel de Tassigny
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: boolean
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
description: An unofficial NASA Earth API wrapper. It can be used to display images
|
28
|
+
for a specific location at different period in time.
|
29
|
+
email: gabriel@multivac.cc
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/nasa_earth.rb
|
35
|
+
homepage: https://github.com/gabriel-detassigny/nasa_earth
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 2.2.2
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: NASA Earth API
|
59
|
+
test_files: []
|