Module: Nasa
- Defined in:
- lib/nasa.rb,
lib/nasa/version.rb
Constant Summary collapse
- VERSION =
"1.1.1"
Class Method Summary collapse
- .build_the_url_and_fetch_data(element_looking_for, slug_or_id, user_slug_or_id, count = nil) ⇒ Object
-
.get_active_categories ⇒ Object
returns a list of active categories along with its slug, no of posts and title.
-
.get_active_tags ⇒ Object
returns a list of active tags along with its slug, no of posts and title.
-
.get_category_data_by_id(id, count = nil) ⇒ Object
if you know the id for a particular category, then awesome.
-
.get_category_data_by_slug(slug, count = nil) ⇒ Object
whereas if you dont know the id and you know the exact title then use this method.
-
.get_latest_data(count = 10) ⇒ Object
Get the latest feed published on ://data.nasa.gov you will get 10 feeds by default.
-
.get_tag_data_by_id(id, count = nil) ⇒ Object
if you know the id for a particular tag, then awesome.
-
.get_tag_data_by_slug(slug, count = nil) ⇒ Object
whereas if you dont know the id and you know the exact tag-name then use this method.
-
.search_by_id(id) ⇒ Object
if you know the id for a particular feed, then awesome.
-
.search_by_slug(slug) ⇒ Object
whereas if you dont know the id and you do know the exact title then use this method.
- .url ⇒ Object
Class Method Details
.build_the_url_and_fetch_data(element_looking_for, slug_or_id, user_slug_or_id, count = nil) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/nasa.rb', line 83 def self.build_the_url_and_fetch_data(element_looking_for, slug_or_id, user_slug_or_id , count=nil) nasa_api_url = self.url + "#{element_looking_for}/?#{slug_or_id}=#{user_slug_or_id}" if count nasa_api_url = nasa_api_url + "&count=#{count}" end return JSON.parse( Mechanize.new.get( nasa_api_url ).body ) end |
.get_active_categories ⇒ Object
returns a list of active categories along with its slug, no of posts and title
69 70 71 |
# File 'lib/nasa.rb', line 69 def self.get_active_categories JSON.parse( Mechanize.new.get( self.url + "get_category_index/").body ) end |
.get_active_tags ⇒ Object
returns a list of active tags along with its slug, no of posts and title
75 76 77 |
# File 'lib/nasa.rb', line 75 def self. JSON.parse( Mechanize.new.get( self.url + "get_tag_index/").body ) end |
.get_category_data_by_id(id, count = nil) ⇒ Object
if you know the id for a particular category, then awesome. get all the data under a category via its id. Pass in count too, default is 10
32 33 34 |
# File 'lib/nasa.rb', line 32 def self.get_category_data_by_id(id, count=nil) self.build_the_url_and_fetch_data("get_category_datasets", "id", id, count) end |
.get_category_data_by_slug(slug, count = nil) ⇒ Object
whereas if you dont know the id and you know the exact title then use this method. Search for category data via title. Pass in the slug What is slug ? slug = category title name in hyphen and downcase format.
Ex: category_title = “Earth Science”
slug = category_title.downcase.split.join('-') => "earth-science"
Pass in count too, default is 10
44 45 46 |
# File 'lib/nasa.rb', line 44 def self.get_category_data_by_slug(slug, count=nil) self.build_the_url_and_fetch_data("get_category_datasets", "slug", slug, count) end |
.get_latest_data(count = 10) ⇒ Object
Get the latest feed published on ://data.nasa.gov you will get 10 feeds by default.
9 10 11 |
# File 'lib/nasa.rb', line 9 def self.get_latest_data(count=10) JSON.parse( Mechanize.new.get( self.url + "get_recent_datasets?count=#{count}").body ) end |
.get_tag_data_by_id(id, count = nil) ⇒ Object
if you know the id for a particular tag, then awesome. get all the data under the tag via its id. Pass in count too, default is 10
51 52 53 |
# File 'lib/nasa.rb', line 51 def self.get_tag_data_by_id(id, count=nil) self.build_the_url_and_fetch_data("get_tag_datasets", "id", id, count) end |
.get_tag_data_by_slug(slug, count = nil) ⇒ Object
whereas if you dont know the id and you know the exact tag-name then use this method. Search for category data via title. Pass in the slug What is slug ? slug = tag-name in hyphen and downcase format.
Ex: category_title = “Earth Science”
slug = category_title.downcase.split.join('-') => "earth-science"
Pass in count too, default is 10
63 64 65 |
# File 'lib/nasa.rb', line 63 def self.get_tag_data_by_slug(slug, count=nil) self.build_the_url_and_fetch_data("get_tag_datasets", "slug", slug, count) end |
.search_by_id(id) ⇒ Object
if you know the id for a particular feed, then awesome. Get it via id.
14 15 16 |
# File 'lib/nasa.rb', line 14 def self.search_by_id(id) JSON.parse( Mechanize.new.get( self.url + "get_dataset?id=#{id}").body ) end |
.search_by_slug(slug) ⇒ Object
whereas if you dont know the id and you do know the exact title then use this method. Search for your data by title. Just pass in the slug. What is slug ? slug = title name in hyphen and downcase format.
Ex: if title = “Mars Map Catalog”
slug = title.downcase.split.join('-') => "mars-map-catalog"
25 26 27 |
# File 'lib/nasa.rb', line 25 def self.search_by_slug(slug) JSON.parse( Mechanize.new.get( self.url + "get_dataset?slug=#{slug}").body ) end |
.url ⇒ Object
79 80 81 |
# File 'lib/nasa.rb', line 79 def self.url "http://data.nasa.gov/api/" end |