giphy 1.0.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/giphy/client.rb +3 -2
- data/lib/giphy/random_gif.rb +59 -0
- data/lib/giphy/search.rb +5 -1
- data/lib/giphy/version.rb +1 -1
- data/spec/giphy/client_spec.rb +13 -3
- data/spec/giphy/random_gif_spec.rb +61 -0
- data/spec/giphy/search_spec.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37034eeefabd1bbeb9bc706ed7d6ddf33b647ed3
|
4
|
+
data.tar.gz: 99a9d9fe92d92c545b1d584e6fd2c06c22e0782d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53f9d90a4f775e8d8e9e846a11f179d86e94a8230206939f74daba6b3e7794c42031b6f1562bb6de767a39185c517b0fa9237f943dd21f034487a496ced9e5f2
|
7
|
+
data.tar.gz: 8cb649fad8848b1deccb9cc4d984f6581e8950c8271da61a2ced99341aadf428ce62ae8af4019cfa7810880a44f7d3fd6b07440b6913b74756502750b61c9113
|
data/README.md
CHANGED
data/lib/giphy/client.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Giphy
|
2
|
+
class RandomGif
|
3
|
+
def initialize(hash)
|
4
|
+
@hash = hash
|
5
|
+
end
|
6
|
+
|
7
|
+
def id
|
8
|
+
hash.fetch('id')
|
9
|
+
end
|
10
|
+
|
11
|
+
def url
|
12
|
+
URI(hash.fetch('url'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def image_original_url
|
16
|
+
URI(hash.fetch('image_original_url'))
|
17
|
+
end
|
18
|
+
|
19
|
+
def image_url
|
20
|
+
URI(hash.fetch('image_url'))
|
21
|
+
end
|
22
|
+
|
23
|
+
def image_mp4_url
|
24
|
+
URI(hash.fetch('image_mp4_url'))
|
25
|
+
end
|
26
|
+
|
27
|
+
def image_frames
|
28
|
+
hash.fetch('image_frames')
|
29
|
+
end
|
30
|
+
|
31
|
+
def image_width
|
32
|
+
hash.fetch('image_width')
|
33
|
+
end
|
34
|
+
|
35
|
+
def image_height
|
36
|
+
hash.fetch('image_height')
|
37
|
+
end
|
38
|
+
|
39
|
+
def rating
|
40
|
+
hash.fetch('rating')
|
41
|
+
end
|
42
|
+
|
43
|
+
def username
|
44
|
+
hash.fetch('username')
|
45
|
+
end
|
46
|
+
|
47
|
+
def caption
|
48
|
+
hash.fetch('caption')
|
49
|
+
end
|
50
|
+
|
51
|
+
def tags
|
52
|
+
hash.fetch('tags')
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
attr_reader :hash
|
58
|
+
end
|
59
|
+
end
|
data/lib/giphy/search.rb
CHANGED
@@ -42,7 +42,7 @@ module Giphy
|
|
42
42
|
|
43
43
|
def random
|
44
44
|
result = client.random
|
45
|
-
|
45
|
+
random_gif.new(result)
|
46
46
|
end
|
47
47
|
|
48
48
|
def artists
|
@@ -78,6 +78,10 @@ module Giphy
|
|
78
78
|
Giphy::FavoriteGif
|
79
79
|
end
|
80
80
|
|
81
|
+
def random_gif
|
82
|
+
Giphy::RandomGif
|
83
|
+
end
|
84
|
+
|
81
85
|
def artist
|
82
86
|
Giphy::Artist
|
83
87
|
end
|
data/lib/giphy/version.rb
CHANGED
data/spec/giphy/client_spec.rb
CHANGED
@@ -51,9 +51,19 @@ describe Giphy::Client do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
describe "#favorites" do
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
context "when no username is passed to it" do
|
55
|
+
it "does a GET on the 'favorites' endpoint with no username" do
|
56
|
+
Giphy::Request.stub(:get).with('/favorites', {username: ''}).and_return(api_response)
|
57
|
+
expect(subject.favorites).to eq response
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when a username is passed as an argument" do
|
62
|
+
it "does a GET on the 'favorites' endpoint with the username" do
|
63
|
+
username = 'absurdnoise'
|
64
|
+
Giphy::Request.stub(:get).with('/favorites', {username: username}).and_return(api_response)
|
65
|
+
expect(subject.favorites(username)).to eq response
|
66
|
+
end
|
57
67
|
end
|
58
68
|
end
|
59
69
|
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Giphy::RandomGif do
|
4
|
+
subject { Giphy::RandomGif.new(hash) }
|
5
|
+
|
6
|
+
context "when iniatialized with a valid hash" do
|
7
|
+
let(:hash) do
|
8
|
+
{
|
9
|
+
"type" => "gif",
|
10
|
+
"id" => "SWx6sXuaPhUA0",
|
11
|
+
"url" => "http://giphy.com/gifs/SWx6sXuaPhUA0",
|
12
|
+
"image_original_url" => "http://s3.amazonaws.com/giphymedia/media/SWx6sXuaPhUA0/giphy.gif",
|
13
|
+
"image_url" => "http://s3.amazonaws.com/giphymedia/media/SWx6sXuaPhUA0/giphy.gif",
|
14
|
+
"image_mp4_url" => "http://s3.amazonaws.com/giphymedia/media/SWx6sXuaPhUA0/giphy.mp4",
|
15
|
+
"image_frames" => "32",
|
16
|
+
"image_width" => "480",
|
17
|
+
"image_height" => "200",
|
18
|
+
"rating" => "g",
|
19
|
+
"username" => "cheezburger",
|
20
|
+
"caption" => "hello",
|
21
|
+
"tags" => [
|
22
|
+
"cat",
|
23
|
+
"fall",
|
24
|
+
"puns",
|
25
|
+
"box",
|
26
|
+
"caturday"
|
27
|
+
]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
its(:id) { should eq 'SWx6sXuaPhUA0' }
|
32
|
+
its(:url) { should eq URI('http://giphy.com/gifs/SWx6sXuaPhUA0') }
|
33
|
+
its(:image_original_url) { should eq URI('http://s3.amazonaws.com/giphymedia/media/SWx6sXuaPhUA0/giphy.gif') }
|
34
|
+
its(:image_url) { should eq URI('http://s3.amazonaws.com/giphymedia/media/SWx6sXuaPhUA0/giphy.gif') }
|
35
|
+
its(:image_mp4_url) { should eq URI('http://s3.amazonaws.com/giphymedia/media/SWx6sXuaPhUA0/giphy.mp4') }
|
36
|
+
its(:image_frames) { should eq '32' }
|
37
|
+
its(:image_width) { should eq '480' }
|
38
|
+
its(:image_height) { should eq '200' }
|
39
|
+
its(:rating) { should eq 'g' }
|
40
|
+
its(:username) { should eq 'cheezburger' }
|
41
|
+
its(:caption) { should eq 'hello' }
|
42
|
+
its(:tags) { should eq ['cat', 'fall', 'puns', 'box', 'caturday'] }
|
43
|
+
end
|
44
|
+
|
45
|
+
context "when initialized with an empty/invalid hash" do
|
46
|
+
let(:hash) { {} }
|
47
|
+
|
48
|
+
it { expect{ subject.id }.to raise_error KeyError }
|
49
|
+
it { expect{ subject.url }.to raise_error KeyError }
|
50
|
+
it { expect{ subject.image_original_url }.to raise_error KeyError }
|
51
|
+
it { expect{ subject.image_url }.to raise_error KeyError }
|
52
|
+
it { expect{ subject.image_mp4_url }.to raise_error KeyError }
|
53
|
+
it { expect{ subject.image_frames }.to raise_error KeyError }
|
54
|
+
it { expect{ subject.image_width }.to raise_error KeyError }
|
55
|
+
it { expect{ subject.image_height }.to raise_error KeyError }
|
56
|
+
it { expect{ subject.rating }.to raise_error KeyError }
|
57
|
+
it { expect{ subject.username }.to raise_error KeyError }
|
58
|
+
it { expect{ subject.caption }.to raise_error KeyError }
|
59
|
+
it { expect{ subject.tags }.to raise_error KeyError }
|
60
|
+
end
|
61
|
+
end
|
data/spec/giphy/search_spec.rb
CHANGED
@@ -79,7 +79,7 @@ describe Giphy::Search do
|
|
79
79
|
describe "#random" do
|
80
80
|
it "returns a new Gif from the client result" do
|
81
81
|
client.stub(random: client_result)
|
82
|
-
Giphy::
|
82
|
+
Giphy::RandomGif.stub(:new).with(client_result).and_return(response)
|
83
83
|
expect(subject.random).to eq response
|
84
84
|
end
|
85
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: giphy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Sogamoso
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/giphy/gif_by_id.rb
|
125
125
|
- lib/giphy/image.rb
|
126
126
|
- lib/giphy/null_image.rb
|
127
|
+
- lib/giphy/random_gif.rb
|
127
128
|
- lib/giphy/request.rb
|
128
129
|
- lib/giphy/response.rb
|
129
130
|
- lib/giphy/search.rb
|
@@ -140,6 +141,7 @@ files:
|
|
140
141
|
- spec/giphy/gif_spec.rb
|
141
142
|
- spec/giphy/image_spec.rb
|
142
143
|
- spec/giphy/null_image_spec.rb
|
144
|
+
- spec/giphy/random_gif_spec.rb
|
143
145
|
- spec/giphy/request_spec.rb
|
144
146
|
- spec/giphy/response_spec.rb
|
145
147
|
- spec/giphy/search_spec.rb
|
@@ -182,9 +184,11 @@ test_files:
|
|
182
184
|
- spec/giphy/gif_spec.rb
|
183
185
|
- spec/giphy/image_spec.rb
|
184
186
|
- spec/giphy/null_image_spec.rb
|
187
|
+
- spec/giphy/random_gif_spec.rb
|
185
188
|
- spec/giphy/request_spec.rb
|
186
189
|
- spec/giphy/response_spec.rb
|
187
190
|
- spec/giphy/search_spec.rb
|
188
191
|
- spec/giphy/special_gif_spec.rb
|
189
192
|
- spec/shared_examples/special_gif_contract_spec.rb
|
190
193
|
- spec/spec_helper.rb
|
194
|
+
has_rdoc:
|