nasa 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README.rdoc +28 -0
  2. data/lib/nasa.rb +15 -23
  3. data/lib/nasa/version.rb +1 -1
  4. metadata +4 -4
  5. data/README.md +0 -3
@@ -0,0 +1,28 @@
1
+ = Nasa
2
+
3
+ Nasa api for Ruby developers
4
+
5
+ == Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'nasa'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install nasa
18
+
19
+ == Contributing
20
+
21
+ 1. Fork it
22
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
23
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
24
+ 4. Push to the branch (`git push origin my-new-feature`)
25
+ 5. Create new Pull Request
26
+
27
+
28
+ BTW, this is not an offical project by Nasa.
@@ -7,12 +7,12 @@ module Nasa
7
7
  # Get the latest feed published on http:://data.nasa.gov
8
8
  # you will get 10 feeds by default.
9
9
  def self.get_latest_data(count=10)
10
- JSON.parse( Mechanize.new.get( self.url + "/get_recent_datasets?count=#{count}").body )
10
+ JSON.parse( Mechanize.new.get( self.url + "get_recent_datasets?count=#{count}").body )
11
11
  end
12
12
 
13
13
  # if you know the id for a particular feed, then awesome. Get it via id.
14
14
  def self.search_by_id(id)
15
- JSON.parse( Mechanize.new.get( self.url + "/get_dataset?id=#{id}").body )
15
+ JSON.parse( Mechanize.new.get( self.url + "get_dataset?id=#{id}").body )
16
16
  end
17
17
 
18
18
  # whereas if you dont know the id and you do know the exact title then use this method.
@@ -23,18 +23,14 @@ module Nasa
23
23
  # Ex: if title = "Mars Map Catalog"
24
24
  # slug = title.downcase.split.join('-') => "mars-map-catalog"
25
25
  def self.search_by_slug(slug)
26
- JSON.parse( Mechanize.new.get( self.url + "/get_dataset?slug=#{slug}").body )
26
+ JSON.parse( Mechanize.new.get( self.url + "get_dataset?slug=#{slug}").body )
27
27
  end
28
28
 
29
29
  # if you know the id for a particular category, then awesome.
30
30
  # get all the data under a category via its id.
31
31
  # Pass in count too, default is 10
32
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 )
33
+ self.build_the_url_and_fetch_data("get_category_datasets", "id", id, count)
38
34
  end
39
35
 
40
36
  # whereas if you dont know the id and you know the exact title then use this method.
@@ -46,22 +42,14 @@ module Nasa
46
42
  # slug = category_title.downcase.split.join('-') => "earth-science"
47
43
  # Pass in count too, default is 10
48
44
  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 )
45
+ self.build_the_url_and_fetch_data("get_category_datasets", "slug", slug, count)
54
46
  end
55
47
 
56
48
  # if you know the id for a particular tag, then awesome.
57
49
  # get all the data under the tag via its id.
58
50
  # Pass in count too, default is 10
59
51
  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 )
52
+ self.build_the_url_and_fetch_data("get_tag_datasets", "id", id, count)
65
53
  end
66
54
 
67
55
  # whereas if you dont know the id and you know the exact tag-name then use this method.
@@ -73,11 +61,7 @@ module Nasa
73
61
  # slug = category_title.downcase.split.join('-') => "earth-science"
74
62
  # Pass in count too, default is 10
75
63
  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 )
64
+ self.build_the_url_and_fetch_data("get_tag_datasets", "slug", slug, count)
81
65
  end
82
66
 
83
67
  # returns a list of active categories along with
@@ -95,4 +79,12 @@ module Nasa
95
79
  def self.url
96
80
  "http://data.nasa.gov/api/"
97
81
  end
82
+
83
+ def self.build_the_url_and_fetch_data(element_looking_for, slug_or_id, user_slug_or_id , count=nil)
84
+ nasa_api_url = self.url + "#{element_looking_for}/?#{slug_or_id}=#{user_slug_or_id}"
85
+ if count
86
+ nasa_api_url = nasa_api_url + "&count=#{count}"
87
+ end
88
+ return JSON.parse( Mechanize.new.get( nasa_api_url ).body )
89
+ end
98
90
  end
@@ -1,3 +1,3 @@
1
1
  module Nasa
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nasa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-09-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mechanize
16
- requirement: &2156548220 !ruby/object:Gem::Requirement
16
+ requirement: &2154174120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156548220
24
+ version_requirements: *2154174120
25
25
  description: Nasa api for ruby developers
26
26
  email:
27
27
  - thirthappa.kaushik@gmail.com
@@ -32,7 +32,7 @@ files:
32
32
  - .gitignore
33
33
  - Gemfile
34
34
  - LICENSE
35
- - README.md
35
+ - README.rdoc
36
36
  - Rakefile
37
37
  - lib/nasa.rb
38
38
  - lib/nasa/version.rb
data/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Nasa
2
-
3
- Soon to come Nasa api for ruby developers.