Skip to content

Commit

Permalink
Add support for extended entities
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed May 24, 2014
1 parent ecea9c5 commit ed7c708
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/twitter/entities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def hashtags?
# @note Must include entities in your request for this method to work
# @return [Array<Twitter::Media>]
def media
entities(MediaFactory, :media)
extended_entities = entities(MediaFactory, :media, :extended_entities)
extended_entities.empty? ? entities(MediaFactory, :media) : extended_entities
end
memoize :media

Expand Down Expand Up @@ -84,9 +85,10 @@ def user_mentions?
private

# @param klass [Class]
# @param key [Symbol]
def entities(klass, key)
@attrs.fetch(:entities, {}).fetch(key.to_sym, []).collect do |entity|
# @param key2 [Symbol]
# @param key1 [Symbol]
def entities(klass, key2, key1 = :entities)
@attrs.fetch(key1.to_sym, {}).fetch(key2.to_sym, []).collect do |entity|
klass.new(entity)
end
end
Expand Down

0 comments on commit ed7c708

Please sign in to comment.