mars_photos 0.1.1 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7aad43fc0e661685d7eef95f4094b935c449d4b3
4
- data.tar.gz: 5c9fd83e491da06eaa5035ebacbe78c5ad8c331c
3
+ metadata.gz: a533a53524d6ab2e3f35b6682c8a19cb53449761
4
+ data.tar.gz: 557be1d304bf8f0c2902f3fa541232a8036281ef
5
5
  SHA512:
6
- metadata.gz: afdbb5641ad0da567d20853d3e7b5359e31e22fb47e8a0c97c206c0dc0951c5fcb17d9e77215eb19692e712fa933ea5e63737fd0f3b72f9b9aebfcb0bf854f44
7
- data.tar.gz: 757f8102538f900ad90c7ce663316a83cab96f8fc759ee810d2a8e152b68f1475ad7fc0c54733c11a4e75ecbd1939acb9e49ec4a15fe935cf7a2660a258d680f
6
+ metadata.gz: 82d7669f924d2a853bda847c3a42fa4f5b846143e643c9fa3c96a23d46b210522721f9af073a2d422318401ccb99520c3312005493d81c9723a73591bd9f9929
7
+ data.tar.gz: a57f096949946d4c9eeace474a4c4d9e397b4cb75da76df60d7dd3412522cc6efefbed5805ac42f898d4c86dda820d36fef5b0b9332d8cc7a5f8d8244eafdf18
data/README.md CHANGED
@@ -16,22 +16,41 @@ And then execute:
16
16
 
17
17
  Or install it yourself as:
18
18
 
19
- $ gem install mars-photos
19
+ $ gem install mars_photos
20
20
 
21
21
  ## Usage
22
22
 
23
- To retrieve photos by providing the rover, sol and camera, you can use the `get` method on the MarsPhotos module:
23
+ For basic usage, instantiate an API object either with or without an API key (if you don't provide one it will be set to the demo key, which allows for 30 requests per IP address per hour, and a maximum of 50 requests per day). Get an API key from NASA [here](https://api.nasa.gov/index.html#apply-for-an-api-key).
24
24
 
25
25
  ```ruby
26
- MarsPhotos.get(rover: 'curiosity', sol: 1000, cam: 'fhaz')
26
+ @api = MarsPhotos::API.new # Sets API key to 'DEMO_KEY'
27
+ @api = MarsPhotos::API.new('YOUR_KEY_HERE')
28
+ ```
29
+
30
+ Retrieve photos by rover and sol like this:
31
+
32
+ ```ruby
33
+ @api.get(rover: 'curiosity', sol: 1000)
27
34
  ```
28
35
 
29
36
  This returns an array of the photos, each with an `img_src` attribute.
30
37
 
31
- You can also call this method with a block:
38
+ You can provide an earth date in the format YYYY-MM-DD instead of a sol:
32
39
 
33
40
  ```ruby
34
- MarsPhotos.get(rover: 'curiosity', sol: 1000, cam: 'fhaz') do |photo|
41
+ @api.get(rover: 'curiosity', earth_date: '2015-6-3')
42
+ ```
43
+
44
+ For photos from a specific camera, just specify a `cam` in the method's parameters:
45
+
46
+ ```ruby
47
+ @api.get(rover: 'curiosity', sol: 1000, cam: 'fhaz')
48
+ ```
49
+
50
+ You can call this method with a block:
51
+
52
+ ```ruby
53
+ @api.get(rover: 'curiosity', sol: 1000) do |photo|
35
54
  puts photo['img_src']
36
55
  end
37
56
  ```
@@ -39,11 +58,47 @@ end
39
58
  You can also instantiate the Rover class:
40
59
 
41
60
  ```ruby
42
- @curiosity = MarsPhotos::Rover.new
61
+ @curiosity = MarsPhotos::Rover.new('curiosity')
43
62
 
44
63
  @curiosity.get(1000) # retrieves photos taken by curiosity on sol 1000
45
64
  ```
46
65
 
66
+ ### Rovers
67
+
68
+ Images are available from three rovers:
69
+
70
+ Rover | Landing Date
71
+ ------------ | ------------------------------
72
+ Spirit | January 4, 2004
73
+ Opportunity | January 25, 2004
74
+ Curiosity | August 6, 2012
75
+
76
+ ### Sols
77
+
78
+ Sol is a time measurement representing the number of Martian solar days since the rover landed. It starts from 0.
79
+
80
+ ### Curiosity's Cameras
81
+
82
+ Abbreviation | Camera
83
+ ------------ | ------------------------------
84
+ FHAZ | Front Hazard Avoidance Camera
85
+ RHAZ | Rear Hazard Avoidance Camera
86
+ MAST | Mast Camera
87
+ CHEMCAM | Chemistry and Camera Complex
88
+ MAHLI | Mars Hand Lens Imager
89
+ MARDI | Mars Descent Imager
90
+ NAVCAM | Navigation Camera
91
+
92
+ ### Opportunity and Spirit's Cameras
93
+
94
+ Abbreviation | Camera
95
+ ------------ | -----------------------------
96
+ FHAZ | Front Hazard Avoidance Camera
97
+ RHAZ | Rear Hazard Avoidance Camera
98
+ PANCAM | Panoramic Camera
99
+ NAVCAM | Navigation Camera
100
+ MINITES | Miniature Thermal Emission Spectrometer (Mini-TES)
101
+
47
102
  ## Development
48
103
 
49
104
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -52,7 +107,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
52
107
 
53
108
  ## Contributing
54
109
 
55
- Bug reports and pull requests are welcome on GitHub at https://github.com/cltweedie/mars-photos.
110
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cltweedie/mars_photos.
56
111
 
57
112
  ## License
58
113
 
data/lib/mars_photos.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'httparty'
2
2
  require 'mars_photos/rover'
3
- require 'mars_photos/mars_photos'
3
+ require 'mars_photos/api'
4
+ require 'mars_photos/mars_photos_calculations'
@@ -0,0 +1,28 @@
1
+ module MarsPhotos
2
+ class API
3
+ attr_reader :key
4
+
5
+ def initialize(key='DEMO_KEY')
6
+ @key = key
7
+ end
8
+
9
+ def get(rover:, sol: nil, earth_date: nil, cam: nil)
10
+ if sol
11
+ date = "&sol=#{sol}"
12
+ elsif earth_date
13
+ date = "&earth_date=#{earth_date}"
14
+ else
15
+ raise "You must provide a sol or earth date"
16
+ end
17
+
18
+ camera = cam ? "&camera=#{cam}" : ""
19
+
20
+ response = HTTParty.get("https://api.nasa.gov/mars-photos/api/v1/rovers/#{rover}/photos?api_key=#{@key}#{date}#{camera}")
21
+
22
+ if block_given?
23
+ response['photos'].each { |photo| yield photo }
24
+ end
25
+ response['photos']
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ module MarsPhotos::Calculations
2
+ def self.build_url(rover_name, parameter)
3
+ url_rovers = "https://api.nasa.gov/mars-photos/api/v1/rovers/"
4
+ key = parameter.keys.first.to_s
5
+ value = parameter[parameter.keys.first]
6
+ "#{url_rovers}#{rover_name}/photos?#{key}=#{value}&api_key=DEMO_KEY"
7
+ end
8
+ end
@@ -1,14 +1,14 @@
1
1
  module MarsPhotos
2
- class Rover
3
- attr_accessor :name
2
+ class Rover
3
+ attr_accessor :name
4
+ def initialize(name)
5
+ @name = name
6
+ end
4
7
 
5
- def initialize(name)
6
- self.name = name
7
- end
8
-
9
- def get(sol)
10
- response = HTTParty.get("https://api.nasa.gov/mars-photos/api/v1/rovers/#{self.name}/photos?sol=#{sol}&api_key=DEMO_KEY")
8
+ def get(parameter = {})
9
+ url = MarsPhotos::Calculations.build_url(name, parameter)
10
+ response = HTTParty.get(url)
11
11
  response['photos']
12
- end
13
- end
12
+ end
13
+ end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module MarsPhotos
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
data/mars_photos.gemspec CHANGED
@@ -30,6 +30,9 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "bundler", "~> 1.10"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  spec.add_development_dependency "rspec"
33
+ spec.add_development_dependency "simplecov"
34
+ spec.add_development_dependency "webmock"
35
+ spec.add_development_dependency "vcr"
33
36
 
34
37
  spec.add_dependency "httparty"
35
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mars_photos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Tweedie
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-04-21 00:00:00.000000000 Z
12
+ date: 2016-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -53,6 +53,48 @@ dependencies:
53
53
  - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: simplecov
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: webmock
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: vcr
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
56
98
  - !ruby/object:Gem::Dependency
57
99
  name: httparty
58
100
  requirement: !ruby/object:Gem::Requirement
@@ -86,7 +128,8 @@ files:
86
128
  - bin/console
87
129
  - bin/setup
88
130
  - lib/mars_photos.rb
89
- - lib/mars_photos/mars_photos.rb
131
+ - lib/mars_photos/api.rb
132
+ - lib/mars_photos/mars_photos_calculations.rb
90
133
  - lib/mars_photos/rover.rb
91
134
  - lib/mars_photos/version.rb
92
135
  - mars_photos.gemspec
@@ -1,9 +0,0 @@
1
- module MarsPhotos
2
- def self.get(rover:, sol:, cam:)
3
- response = HTTParty.get("https://api.nasa.gov/mars-photos/api/v1/rovers/#{rover}/photos?sol=#{sol}&camera=#{cam}&api_key=DEMO_KEY")
4
- if block_given?
5
- response['photos'].each { |photo| yield photo }
6
- end
7
- response['photos']
8
- end
9
- end