nasa_apod 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 86d31a43152985d59e34975a663fcb651a2bd777
4
- data.tar.gz: 658ec7835c0844b0cad89a118e744f1d03a497a9
3
+ metadata.gz: 61d6d9f7704b23273d740a7209453dd814a39fb1
4
+ data.tar.gz: 5ec5a5f6460072032eb478590625e3cc07ac1741
5
5
  SHA512:
6
- metadata.gz: 9906f36774613d527a27684ac1f4998253701c3eebb4e4d0a0c6640288737e8373dadc91093a0a0a9cecf387acb0e066bd9ab2c1d71091c42908e20c06b43b87
7
- data.tar.gz: c76b3f7243c91b3bdd3260c15ee02c98ff0ad2430289c7fab7dcdd51084a275e9dbc24bfc0c5a75c0df1a6028ff1396bfd5a6b8ddef404476b6af06e1d418bc1
6
+ metadata.gz: d7316997ecbc3a6f01ea70a0189de1983c19cae7155a484788d7c9357a96e57080b4b85016a595078df363364dc130e835a9efe135354c25e5630d345f30ba75
7
+ data.tar.gz: b6d01c6d16305eeb275b5241fde5a0a8f1b2b39c40732b2635f74f7fa228227345c03278e09cc5125d004963649e78f3aa8b521ae9da9c5853db9585c2d04bdc
data/README.md CHANGED
@@ -46,6 +46,15 @@ result = client.search
46
46
  result.url #=> "http://apod.nasa.gov/apod/image/1506/CeresMountain_Dawn_1041.jpg"
47
47
  ```
48
48
 
49
+ Note: Sometimes result.url will return a video url. You should build logic to handle both media_type: 'image' and media_type: 'video'.
50
+
51
+ If the media_type: 'video', you can use video_thumbnail_url to get a jpg thumbnail of the video.
52
+
53
+ ```
54
+ result = client.search
55
+ result.video_thumbnail_url #=> 'http://img.youtube.com/vi/3LdZ_NftIh8/sddefault.jpg'
56
+ ```
57
+
49
58
  Get HD image URL:
50
59
 
51
60
  ```
@@ -40,14 +40,14 @@ module NasaApod
40
40
 
41
41
  alias wormhole random_post
42
42
 
43
+ private
44
+
43
45
  def attributes
44
46
  instance_variables.each_with_object({}) do |var, hash|
45
47
  hash[var.to_s.delete('@')] = instance_variable_get(var)
46
48
  end
47
49
  end
48
50
 
49
- private
50
-
51
51
  def handle_response(response)
52
52
  if response['error'].nil?
53
53
  NasaApod::SearchResults.new(response)
@@ -2,6 +2,7 @@ module NasaApod
2
2
 
3
3
  class SearchResults
4
4
  attr_accessor :url, :media_type, :title, :explanation, :hd_url, :date, :copyright
5
+ attr_reader :video_thumbnail_url
5
6
 
6
7
  def initialize(attributes={})
7
8
  @url = attributes["url"]
@@ -12,6 +13,18 @@ module NasaApod
12
13
  @date = attributes["date"]
13
14
  @copyright = attributes["copyright"]
14
15
  end
16
+
17
+ def video_thumbnail_url
18
+ if @media_type == 'video'
19
+ "http://img.youtube.com/vi/#{youtube_id}/sddefault.jpg"
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def youtube_id
26
+ @url.match(/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/ ]{11})/)[1]
27
+ end
15
28
  end
16
29
 
17
30
  end
@@ -1,3 +1,3 @@
1
1
  module NasaApod
2
- VERSION = "1.1.1"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -42,7 +42,7 @@ module NasaApod
42
42
  end
43
43
 
44
44
  it 'returns a HD image with params' do
45
- results = client.search(:hd => true)
45
+ results = client.search(:date => Date.parse("2016-05-08"), :hd => true)
46
46
  expect(results.hd_url).to_not be(nil)
47
47
  end
48
48
  end
@@ -57,15 +57,6 @@ module NasaApod
57
57
  end
58
58
  end
59
59
 
60
- describe '#attributes' do
61
- let(:client) { Client.new }
62
-
63
- it 'returns a hash of attributes' do
64
- attributes = client.attributes
65
- expect(attributes.class).to eq(Hash)
66
- expect(attributes['api_key']).to eq('DEMO_KEY')
67
- end
68
- end
69
60
  end
70
61
 
71
62
  describe SearchResults do
@@ -84,6 +75,22 @@ module NasaApod
84
75
  end
85
76
  end
86
77
  end
78
+
79
+ context 'when media_type is video' do
80
+ describe "#video_thumbnail_url" do
81
+ let(:result) { SearchResults.new(attributes) }
82
+ let(:attributes) {{"url" => "https://www.youtube.com/embed/3LdZ_NftIh8?rel=0",
83
+ "media_type" => "video",
84
+ "title" => "Test title",
85
+ "explanation" => "Test explanation",
86
+ "date" => "1995-06-16"
87
+ }}
88
+
89
+ it 'returns a image url' do
90
+ expect(result.video_thumbnail_url).to eq('http://img.youtube.com/vi/3LdZ_NftIh8/sddefault.jpg')
91
+ end
92
+ end
93
+ end
87
94
  end
88
95
 
89
96
  describe Error do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nasa_apod
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabe Dominguez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-20 00:00:00.000000000 Z
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler