explore_mars 0.4.4

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4a796f889c91a18a40ee81414146362fdf7277a7
4
+ data.tar.gz: 9ace25496a95003b03db4aae4cd21aa2b01ae158
5
+ SHA512:
6
+ metadata.gz: eca76e01d4e0d0542fca11248840c6c364cc9e52179e08542b0ad38c7e08fad1437788c8ec3bf7bc4a2768632f2288a9e8adbf4a000f9df12a58698ed0415a7f
7
+ data.tar.gz: e1a067c1386529c6b7a1c9f0af56643528f95cb3380334b098b481e05fc9074699d1130d8ffe9b414b872f7d8882cd999d63004835892f32934b10f03cc0fc0c
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ rvm:
2
+ - 2.0.0
3
+ - 2.1.0
4
+ - 2.2.2
5
+ before_install:
6
+ - gem update --system
7
+ install: "bundle install"
8
+ script: "bundle exec rake"
9
+
10
+ branches:
11
+ only:
12
+ - master
13
+
14
+ sudo: false
15
+ cache: bundler
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in explore_mars.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Chris C Cerami
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,120 @@
1
+ [![Gem Version](https://badge.fury.io/rb/explore_mars.svg)](http://badge.fury.io/rb/explore_mars)[![Build Status](https://travis-ci.org/chrisccerami/explore_mars.svg)](https://travis-ci.org/chrisccerami/explore_mars)[![Code Climate](https://codeclimate.com/github/chrisccerami/explore_mars/badges/gpa.svg)](https://codeclimate.com/github/chrisccerami/explore_mars)
2
+
3
+ # ExploreMars
4
+
5
+ ## Description
6
+
7
+ While I was attending [Launch Academy](http://www.launchacademy.com/),
8
+ I decided to build a simple API in Rails that would allow myself, other
9
+ developers, researchers, students, or anyone else to more easily access
10
+ photo data from NASA's Mars rover Curiosity. The idea was that by
11
+ surfacing those photos through an API, building apps that took advantage
12
+ of this public resource would become easier.
13
+
14
+ Since then I decided that to make it even easier, I would build a gem
15
+ that provides a few easy to use methods that access that API for you.
16
+ I have also since added support for the Opportunity rover to the API and
17
+ the gem.
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'explore_mars'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install explore_mars
34
+
35
+ ## Usage
36
+
37
+ There are only a few parts to this gem so far, so it's relatively simple
38
+ to use. By calling:
39
+
40
+ ```ruby
41
+ ExploreMars.get_by_sol(rover, sol, camera)
42
+ ```
43
+
44
+ you can make a call to the API, which will return a set of ```Photos```.
45
+ The ```rover``` parameter is name of the rover from which you'd like to
46
+ query. The rovers currently available are Curiosity and Opportunity.
47
+ The ```sol``` parameter is the Martian date of the rover's expedition
48
+ during which the photo was taken. The ```camera``` parameter is the
49
+ particular camera on the rover that the photo was taken with. The camera
50
+ argument can be entered as either a string or a symbol and is not case
51
+ sensitive. The cameras are as follows:
52
+
53
+ ### Curiosity's Cameras
54
+
55
+ Abbreviation | Camera
56
+ ------------ | ------------------------------
57
+ FHAZ | Front Hazard Avoidance Camera
58
+ RHAZ | Rear Hazard Avoidance Camera
59
+ MAST | Mast Camera
60
+ CHEMCAM | Chemistry and Camera Complex
61
+ MAHLI | Mars Hand Lens Imager
62
+ MARDI | Mars Descent Imager
63
+ NAVCAM | Navigation Camera
64
+
65
+ ### Opportunity's Cameras
66
+
67
+ Abbreviation | Camera
68
+ ------------ | -----------------------------
69
+ FHAZ | Front Hazard Avoidance Camera
70
+ RHAZ | Rear Hazard Avoidance Camera
71
+ PANCAM | Panoramic Camera
72
+ NAVCAM | Navigation Camera
73
+ MINITES | Miniature Thermal Emission Spectrometer (Mini-TES)
74
+
75
+ You can also make the API call without providing the camera argument to receive all photos that were taken on a particular sol from all cameras:
76
+
77
+ ```ruby
78
+ ExploreMars.get(rover, sol)
79
+ ```
80
+
81
+ If you would prefer to query by a particular Earth date instead, you can use:
82
+
83
+ ```ruby
84
+ ExploreMars.get_by_date(rover, date, camera)
85
+ ```
86
+
87
+ or
88
+
89
+ ```ruby
90
+ ExploreMars.get_by_date(rover, date)
91
+ ```
92
+
93
+ The date param should be entered as a String, formatted as "yyyy-mm-dd".
94
+
95
+
96
+ The ```Photo``` objects that get returned have five main attributes:
97
+ ```rover```, ```sol```, ```camera```, ```earth_date```, and ```src```.
98
+ The ```src``` attribute contains the source url of the actual image.
99
+ In order to display an image in a Rails view for example, I could use:
100
+
101
+ ```ruby
102
+ photos = ExploreMars::Call.get("curiosity", 869, "FHAZ")
103
+
104
+ photos.each do |photo|
105
+ image_tag(photo.src)
106
+ end
107
+ ```
108
+
109
+ # Contributing
110
+
111
+ If you would like to contribute to ExploreMars, feel free to create a
112
+ pull request. If you'd like to contact me, you can reach me at
113
+ [chrisccerami@gmail.com](mailto:chrisccerami@gmail.com) or on
114
+ Twitter [@chrisccerami](https://twitter.com/chrisccerami).
115
+
116
+ 1. Fork it ( https://github.com/chrisccerami/explore_mars/fork )
117
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
118
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
119
+ 4. Push to the branch (`git push origin my-new-feature`)
120
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ task :console do
9
+ exec "irb -r explore_mars -I ./lib"
10
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'explore_mars/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "explore_mars"
8
+ spec.version = ExploreMars::VERSION
9
+ spec.authors = ["Chris C Cerami"]
10
+ spec.email = ["chrisccerami@gmail.com"]
11
+ spec.date = '2015-03-25'
12
+ spec.summary = "Browse photos from the Mars rover Curiosity"
13
+ spec.description = "A gem to find photos from the Curiosity rover. It serves as a Ruby wrapper for the Mars Curiosity API. My intention is to eventually build a similar API for the Opportunity rover, which will also be accessible through this gem."
14
+ spec.homepage = "http://rubygems.org/gems/explore_mars"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_path = "lib"
21
+
22
+ spec.required_ruby_version = '~> 2.0'
23
+
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "shoulda-matchers"
27
+ spec.add_development_dependency "valid_attribute"
28
+ end
@@ -0,0 +1,39 @@
1
+ # external dependencies
2
+ require "uri"
3
+ require "net/http"
4
+ require "json"
5
+ require 'active_support/time'
6
+
7
+ # internal dependencies
8
+ require "explore_mars/version"
9
+ require "explore_mars/call"
10
+ require "explore_mars/photo"
11
+ require "explore_mars/sol_query"
12
+ require "explore_mars/date_query"
13
+
14
+ module ExploreMars
15
+ def self.help
16
+ puts "- use ExploreMars#get_by_sol(rover, sol, camera) to receive a collection of photos by sol"
17
+ puts "- use ExploreMars#get_by_date(rover, date, camera) to receive a collection of photos by Earth date"
18
+ puts "-- rover argument should be the name of one of NASA's Mars rovers"
19
+ puts "-- sol argument should be a number representing the Martian day on which the photo was taken"
20
+ puts "-- date argument should be a string formmated as yyyy-mm-dd"
21
+ puts "-- camera represents the camera with which it was taken, options are:"
22
+ puts "--- 'FHAZ' (Front Hazard Avoidance Camera)"
23
+ puts "--- 'RHAZ' (Rear Hazard Avoidance Camera)"
24
+ puts "--- 'MAST' (Mast Camera)"
25
+ puts "--- 'CHEMCAM' (Chemistry and Camera Complex)"
26
+ puts "--- 'NAVCAM' (Navigation Camera)"
27
+ puts "--- 'MAHLI' (Mars Hand Lens Imager)"
28
+ puts "--- 'MARDI' (Mars Descent Imager)"
29
+ puts "- ExploreMars::Photo#src will return the source url for the photo"
30
+ end
31
+
32
+ def self.get_by_sol(rover, sol, camera=nil)
33
+ SolQuery.new(rover, sol, camera).get
34
+ end
35
+
36
+ def self.get_by_date(rover, date, camera=nil)
37
+ DateQuery.new(rover, date, camera).get
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ module ExploreMars
2
+ class Call
3
+ CAMERAS = ["FHAZ", "RHAZ", "MAST", "CHEMCAM", "NAVCAM", "MAHLI", "MARDI", "PANCAM", "MINITES"]
4
+ BASE_URI = "https://mars-photos.herokuapp.com/api/v1/rovers/"
5
+
6
+ def get
7
+ check_cameras(@camera)
8
+ uri = build_uri
9
+ response = Net::HTTP.get(uri)
10
+ photos = JSON.parse(response)["photos"]
11
+ photos.map { |photo|
12
+ ExploreMars::Photo.new(photo["img_src"], photo["sol"],
13
+ photo["camera"]["name"], photo["earth_date"],
14
+ @rover)
15
+ }
16
+ end
17
+
18
+ private
19
+
20
+ def check_cameras(camera)
21
+ if !camera.empty? && !CAMERAS.include?(camera.upcase)
22
+ raise "Camera argument must be one of #{CAMERAS.join(', ')}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,19 @@
1
+ module ExploreMars
2
+ class DateQuery < Call
3
+ attr_accessor :date, :camera, :rover
4
+
5
+ def initialize(rover, date, camera=nil)
6
+ @date = date
7
+ @camera = camera.to_s.upcase
8
+ @rover = rover
9
+ end
10
+
11
+ def build_uri
12
+ if !@camera.empty?
13
+ URI.parse(BASE_URI + "#{@rover}/" + "photos?earth_date=#{@date}&camera=#{@camera}")
14
+ else
15
+ URI.parse(BASE_URI + "#{@rover}/" + "photos?earth_date=#{@date}")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ module ExploreMars
2
+ class Photo
3
+ require "date"
4
+ attr_reader :src, :sol, :camera, :earth_date, :rover
5
+
6
+ def initialize(src, sol, camera, earth_date, rover)
7
+ @src = src
8
+ @sol = sol
9
+ @camera = camera
10
+ @earth_date = Date.strptime(earth_date)
11
+ @rover = rover
12
+ end
13
+
14
+ def to_s
15
+ @src
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module ExploreMars
2
+ class SolQuery < Call
3
+ attr_accessor :sol, :camera, :rover
4
+ def initialize(rover, sol, camera=nil)
5
+ @sol = sol
6
+ @camera = camera.to_s.upcase
7
+ @rover = rover
8
+ end
9
+
10
+ def build_uri
11
+ if !@camera.empty?
12
+ URI.parse(BASE_URI + "#{@rover}/" + "photos?sol=#{@sol}&camera=#{@camera}")
13
+ else
14
+ URI.parse(BASE_URI + "#{@rover}/" + "photos?sol=#{@sol}")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module ExploreMars
2
+ VERSION = "0.4.4"
3
+ end
data/spec/call_spec.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "spec_helper"
2
+
3
+ describe ExploreMars::Call do
4
+ it "should have proper constants" do
5
+ expect(ExploreMars::Call::BASE_URI).to eq "https://mars-curiosity-api.herokuapp.com/api/v1/rovers/"
6
+ expect(ExploreMars::Call::CAMERAS).to eq ["FHAZ", "RHAZ", "MAST", "CHEMCAM", "NAVCAM", "MAHLI", "MARDI", "PANCAM", "MINITES"]
7
+ end
8
+ end
File without changes
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe ExploreMars do
4
+ it 'has a version number' do
5
+ expect(ExploreMars::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ describe ExploreMars::Photo do
4
+ describe "attributes" do
5
+ let(:photo) { ExploreMars::Photo.new("http://www.image.com", 829, "FHAZ", "2015-6-3", "curiosity") }
6
+
7
+ it "should have a src" do
8
+ expect(photo.src).to eq("http://www.image.com")
9
+ end
10
+
11
+ it "should have a sol" do
12
+ expect(photo.sol).to eq 829
13
+ end
14
+
15
+ it "should have a camera" do
16
+ expect(photo.camera).to eq "FHAZ"
17
+ end
18
+
19
+ it "should have an earth_date" do
20
+ expect(photo.earth_date.class).to eq Date
21
+ expect(photo.earth_date).to eq Date.strptime("2015-6-3")
22
+ end
23
+
24
+ it "should have a rover" do
25
+ expect(photo.rover).to eq "curiosity"
26
+ end
27
+ end
28
+
29
+ describe "to_s" do
30
+ it "should return the source url" do
31
+ photo = ExploreMars::Photo.new("http://www.image.com", 829, "FHAZ", "2015-6-3", "curiosity")
32
+
33
+ expect(photo.to_s).to eq photo.src
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe ExploreMars::SolQuery do
4
+ describe "attributes" do
5
+ it "should have a sol and a camera" do
6
+ query = ExploreMars::SolQuery.new("curiosity", 940, "FHAZ")
7
+
8
+ expect(query.rover).to eq "curiosity"
9
+ expect(query.sol).to eq 940
10
+ expect(query.camera).to eq "FHAZ"
11
+ end
12
+ end
13
+
14
+ describe "cameras" do
15
+ it "should be valid" do
16
+ expect{
17
+ ExploreMars::SolQuery.new("curiosity", 940, "FHAZ").get
18
+ }.not_to raise_error
19
+
20
+ expect{
21
+ ExploreMars::SolQuery.new("curiosity", 940, "Not a camera").get
22
+ }.to raise_error
23
+ end
24
+ end
25
+
26
+ describe "sol"
27
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'explore_mars'
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: explore_mars
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.4
5
+ platform: ruby
6
+ authors:
7
+ - Chris C Cerami
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
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: shoulda-matchers
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: valid_attribute
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 gem to find photos from the Curiosity rover. It serves as a Ruby wrapper
70
+ for the Mars Curiosity API. My intention is to eventually build a similar API for
71
+ the Opportunity rover, which will also be accessible through this gem.
72
+ email:
73
+ - chrisccerami@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - explore_mars.gemspec
86
+ - lib/explore_mars.rb
87
+ - lib/explore_mars/call.rb
88
+ - lib/explore_mars/date_query.rb
89
+ - lib/explore_mars/photo.rb
90
+ - lib/explore_mars/sol_query.rb
91
+ - lib/explore_mars/version.rb
92
+ - spec/call_spec.rb
93
+ - spec/date_query_spec.rb
94
+ - spec/explore_mars_spec.rb
95
+ - spec/photo_spec.rb
96
+ - spec/sol_query_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: http://rubygems.org/gems/explore_mars
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.5
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Browse photos from the Mars rover Curiosity
122
+ test_files:
123
+ - spec/call_spec.rb
124
+ - spec/date_query_spec.rb
125
+ - spec/explore_mars_spec.rb
126
+ - spec/photo_spec.rb
127
+ - spec/sol_query_spec.rb
128
+ - spec/spec_helper.rb