-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
301 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'twitter/identity' | ||
require 'twitter/media/video_info' | ||
|
||
module Twitter | ||
module Media | ||
class Video < Twitter::Identity | ||
# @return [Array<Integer>] | ||
attr_reader :indices | ||
display_uri_attr_reader | ||
uri_attr_reader :expanded_uri, :media_uri, :media_uri_https, :uri | ||
|
||
# Returns an array of photo sizes | ||
# | ||
# @return [Array<Twitter::Size>] | ||
def sizes | ||
@attrs.fetch(:sizes, []).each_with_object({}) do |(key, value), object| | ||
object[key] = Size.new(value) | ||
end | ||
end | ||
memoize :sizes | ||
|
||
# Returns video info | ||
# | ||
# @return [Twitter::Media::VideoInfo] | ||
def video_info | ||
VideoInfo.new(@attrs[:video_info]) unless @attrs[:video_info].nil? | ||
end | ||
memoize :video_info | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'twitter/variant' | ||
|
||
module Twitter | ||
module Media | ||
class VideoInfo < Twitter::Base | ||
# @return [Array<Integer] | ||
attr_reader :aspect_ratio | ||
|
||
# @return [Integer] | ||
attr_reader :duration_millis | ||
|
||
# Returns an array of video variants | ||
# | ||
# @return [Array<Twitter::Variant>] | ||
def variants | ||
@attrs.fetch(:variants, []).map do |variant| | ||
Variant.new(variant) | ||
end | ||
end | ||
memoize :variants | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'twitter/base' | ||
|
||
module Twitter | ||
class Variant < Twitter::Base | ||
# @return [Integer] | ||
attr_reader :bitrate | ||
|
||
# @return [String] | ||
attr_reader :content_type | ||
uri_attr_reader :uri | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
shared_examples_for 'a Twitter::Media object' do | ||
describe '#==' do | ||
it 'returns true when objects IDs are the same' do | ||
media = described_class.new(id: 1) | ||
other = described_class.new(id: 1) | ||
expect(media == other).to be true | ||
end | ||
it 'returns false when objects IDs are different' do | ||
media = described_class.new(id: 1) | ||
other = described_class.new(id: 2) | ||
expect(media == other).to be false | ||
end | ||
it 'returns false when classes are different' do | ||
media = described_class.new(id: 1) | ||
other = Twitter::Identity.new(id: 1) | ||
expect(media == other).to be false | ||
end | ||
end | ||
|
||
describe '#sizes' do | ||
it 'returns a hash of Sizes when sizes is set' do | ||
sizes = described_class.new(id: 110_102_452_988_157_952, sizes: {small: {h: 226, w: 340, resize: 'fit'}, large: {h: 466, w: 700, resize: 'fit'}, medium: {h: 399, w: 600, resize: 'fit'}, thumb: {h: 150, w: 150, resize: 'crop'}}).sizes | ||
expect(sizes).to be_a Hash | ||
expect(sizes[:small]).to be_a Twitter::Size | ||
end | ||
it 'is empty when sizes is not set' do | ||
sizes = described_class.new(id: 110_102_452_988_157_952).sizes | ||
expect(sizes).to be_empty | ||
end | ||
end | ||
|
||
describe '#display_uri' do | ||
it 'returns a String when the display_url is set' do | ||
photo = Twitter::Media::Photo.new(id: 1, display_url: 'example.com/expanded...') | ||
expect(photo.display_uri).to be_a String | ||
expect(photo.display_uri).to eq('example.com/expanded...') | ||
end | ||
it 'returns nil when the display_url is not set' do | ||
photo = Twitter::Media::Photo.new(id: 1) | ||
expect(photo.display_uri).to be_nil | ||
end | ||
end | ||
|
||
describe '#display_uri?' do | ||
it 'returns true when the display_url is set' do | ||
photo = Twitter::Media::Photo.new(id: 1, display_url: 'example.com/expanded...') | ||
expect(photo.display_uri?).to be true | ||
end | ||
it 'returns false when the display_url is not set' do | ||
photo = Twitter::Media::Photo.new(id: 1) | ||
expect(photo.display_uri?).to be false | ||
end | ||
end | ||
|
||
describe '#expanded_uri' do | ||
it 'returns a URI when the expanded_url is set' do | ||
media = described_class.new(id: 1, expanded_url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
expect(media.expanded_uri).to be_an Addressable::URI | ||
expect(media.expanded_uri.to_s).to eq('http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
end | ||
it 'returns nil when the expanded_url is not set' do | ||
media = described_class.new(id: 1) | ||
expect(media.expanded_uri).to be_nil | ||
end | ||
end | ||
|
||
describe '#expanded_uri?' do | ||
it 'returns true when the expanded_url is set' do | ||
media = described_class.new(id: 1, expanded_url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
expect(media.expanded_uri?).to be true | ||
end | ||
it 'returns false when the expanded_url is not set' do | ||
media = described_class.new(id: 1) | ||
expect(media.expanded_uri?).to be false | ||
end | ||
end | ||
|
||
describe '#media_uri' do | ||
it 'returns a URI when the media_url is set' do | ||
media = described_class.new(id: 1, media_url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
expect(media.media_uri).to be_an Addressable::URI | ||
expect(media.media_uri.to_s).to eq('http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
end | ||
it 'returns nil when the media_url is not set' do | ||
media = described_class.new(id: 1) | ||
expect(media.media_uri).to be_nil | ||
end | ||
end | ||
|
||
describe '#media_uri?' do | ||
it 'returns true when the media_url is set' do | ||
media = described_class.new(id: 1, media_url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
expect(media.media_uri?).to be true | ||
end | ||
it 'returns false when the media_url is not set' do | ||
media = described_class.new(id: 1) | ||
expect(media.media_uri?).to be false | ||
end | ||
end | ||
|
||
describe '#media_uri_https' do | ||
it 'returns a URI when the media_url_https is set' do | ||
media = described_class.new(id: 1, media_url_https: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
expect(media.media_uri_https).to be_an Addressable::URI | ||
expect(media.media_uri_https.to_s).to eq('http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
end | ||
it 'returns nil when the media_url_https is not set' do | ||
media = described_class.new(id: 1) | ||
expect(media.media_uri_https).to be_nil | ||
end | ||
end | ||
|
||
describe '#media_uri_https?' do | ||
it 'returns true when the media_url_https is set' do | ||
media = described_class.new(id: 1, media_url_https: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
expect(media.media_uri_https?).to be true | ||
end | ||
it 'returns false when the media_url_https is not set' do | ||
media = described_class.new(id: 1) | ||
expect(media.media_uri_https?).to be false | ||
end | ||
end | ||
|
||
describe '#uri' do | ||
it 'returns a URI when the url is set' do | ||
media = described_class.new(id: 1, url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
expect(media.uri).to be_an Addressable::URI | ||
expect(media.uri.to_s).to eq('http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
end | ||
it 'returns nil when the url is not set' do | ||
media = described_class.new(id: 1) | ||
expect(media.uri).to be_nil | ||
end | ||
end | ||
|
||
describe '#uri?' do | ||
it 'returns true when the url is set' do | ||
media = described_class.new(id: 1, url: 'http://pbs.twimg.com/media/BQD6MPOCEAAbCH0.png') | ||
expect(media.uri?).to be true | ||
end | ||
it 'returns false when the url is not set' do | ||
media = described_class.new(id: 1) | ||
expect(media.uri?).to be false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.