nasa 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nasa.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Kaushik Thirthappa
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,3 @@
1
+ # Nasa
2
+
3
+ Soon to come Nasa api for ruby developers.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/lib/nasa.rb ADDED
@@ -0,0 +1,98 @@
1
+ require "nasa/version"
2
+ require "mechanize"
3
+ require "json"
4
+
5
+ module Nasa
6
+
7
+ # Get the latest feed published on http:://data.nasa.gov
8
+ # you will get 10 feeds by default.
9
+ def self.get_latest_data(count=10)
10
+ JSON.parse( Mechanize.new.get( self.url + "/get_recent_datasets?count=#{count}").body )
11
+ end
12
+
13
+ # if you know the id for a particular feed, then awesome. Get it via id.
14
+ def self.search_by_id(id)
15
+ JSON.parse( Mechanize.new.get( self.url + "/get_dataset?id=#{id}").body )
16
+ end
17
+
18
+ # whereas if you dont know the id and you do know the exact title then use this method.
19
+ # Search for your data by title. Just pass in the slug.
20
+ # What is slug ?
21
+ # slug = title name in hyphen and downcase format.
22
+ #
23
+ # Ex: if title = "Mars Map Catalog"
24
+ # slug = title.downcase.split.join('-') => "mars-map-catalog"
25
+ def self.search_by_slug(slug)
26
+ JSON.parse( Mechanize.new.get( self.url + "/get_dataset?slug=#{slug}").body )
27
+ end
28
+
29
+ # if you know the id for a particular category, then awesome.
30
+ # get all the data under a category via its id.
31
+ # Pass in count too, default is 10
32
+ def self.get_category_data_by_id(id, count=nil)
33
+ nasa_api_url = self.url + "get_category_datasets/?id=#{id}"
34
+ if count
35
+ nasa_api_url = nasa_api_url + "&count=#{count}"
36
+ end
37
+ JSON.parse( Mechanize.new.get( nasa_api_url ).body )
38
+ end
39
+
40
+ # whereas if you dont know the id and you know the exact title then use this method.
41
+ # Search for category data via title. Pass in the slug
42
+ # What is slug ?
43
+ # slug = category title name in hyphen and downcase format.
44
+ #
45
+ # Ex: category_title = "Earth Science"
46
+ # slug = category_title.downcase.split.join('-') => "earth-science"
47
+ # Pass in count too, default is 10
48
+ def self.get_category_data_by_slug(slug, count=nil)
49
+ nasa_api_url = self.url + "get_category_datasets/?slug=#{slug}"
50
+ if count
51
+ nasa_api_url = nasa_api_url + "&count=#{count}"
52
+ end
53
+ JSON.parse( Mechanize.new.get( nasa_api_url ).body )
54
+ end
55
+
56
+ # if you know the id for a particular tag, then awesome.
57
+ # get all the data under the tag via its id.
58
+ # Pass in count too, default is 10
59
+ def self.get_tag_data_by_id(id, count=nil)
60
+ nasa_api_url = self.url + "get_tag_datasets/?id=#{id}"
61
+ if count
62
+ nasa_api_url = nasa_api_url + "&count=#{count}"
63
+ end
64
+ JSON.parse( Mechanize.new.get( nasa_api_url ).body )
65
+ end
66
+
67
+ # whereas if you dont know the id and you know the exact tag-name then use this method.
68
+ # Search for category data via title. Pass in the slug
69
+ # What is slug ?
70
+ # slug = tag-name in hyphen and downcase format.
71
+ #
72
+ # Ex: category_title = "Earth Science"
73
+ # slug = category_title.downcase.split.join('-') => "earth-science"
74
+ # Pass in count too, default is 10
75
+ def self.get_tag_data_by_slug(slug, count=nil)
76
+ nasa_api_url = self.url + "get_tag_datasets/?slug=#{slug}"
77
+ if count
78
+ nasa_api_url = nasa_api_url + "&count=#{count}"
79
+ end
80
+ JSON.parse( Mechanize.new.get( nasa_api_url ).body )
81
+ end
82
+
83
+ # returns a list of active categories along with
84
+ # its slug, no of posts and title
85
+ def self.get_active_categories
86
+ JSON.parse( Mechanize.new.get( self.url + "get_category_index/").body )
87
+ end
88
+
89
+ # returns a list of active tags along with
90
+ # its slug, no of posts and title
91
+ def self.get_active_tags
92
+ JSON.parse( Mechanize.new.get( self.url + "get_tag_index/").body )
93
+ end
94
+
95
+ def self.url
96
+ "http://data.nasa.gov/api/"
97
+ end
98
+ end
@@ -0,0 +1,3 @@
1
+ module Nasa
2
+ VERSION = "1.1.0"
3
+ end
data/nasa.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/nasa/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Kaushik Thirthappa"]
6
+ gem.email = ["thirthappa.kaushik@gmail.com"]
7
+ gem.description = %q{Nasa api for ruby developers}
8
+ gem.summary = %q{Nasa has an api and here is how you can access it via ruby}
9
+ gem.homepage = "https://github.com/ktkaushik/nasa"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "nasa"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Nasa::VERSION
17
+
18
+ gem.add_dependency "mechanize"
19
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nasa
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kaushik Thirthappa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-24 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: &2156548220 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2156548220
25
+ description: Nasa api for ruby developers
26
+ email:
27
+ - thirthappa.kaushik@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - LICENSE
35
+ - README.md
36
+ - Rakefile
37
+ - lib/nasa.rb
38
+ - lib/nasa/version.rb
39
+ - nasa.gemspec
40
+ homepage: https://github.com/ktkaushik/nasa
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.17
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Nasa has an api and here is how you can access it via ruby
64
+ test_files: []