Class: GiphyAPI::Gif

Inherits:
Base
  • Object
show all
Defined in:
lib/giphy_api/resources/gif.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

find_with_scope

Methods included from RawDataAttributes

#assign_raw_data, included

Constructor Details

#initialize(attributes = {}) ⇒ Gif

Returns a new instance of Gif.



33
34
35
36
37
38
39
# File 'lib/giphy_api/resources/gif.rb', line 33

def initialize attributes = {}
  super(attributes)
  self.user = User.new raw_data['user'] if raw_data['user']
  self.images = (raw_data['images'] || Image.extract_images(raw_data)).collect do |type, image|
    [type, Image.new(image)]
  end.to_h
end

Instance Attribute Details

#imagesObject

Returns the value of attribute images.



5
6
7
# File 'lib/giphy_api/resources/gif.rb', line 5

def images
  @images
end

#userObject

Returns the value of attribute user.



5
6
7
# File 'lib/giphy_api/resources/gif.rb', line 5

def user
  @user
end

Class Method Details

.find(id, **options) ⇒ Object



24
25
26
# File 'lib/giphy_api/resources/gif.rb', line 24

def find id, **options
  find_with_scope("/#{id}", :one, options)
end

.find_by_ids(*ids, **options) ⇒ Object



28
29
30
# File 'lib/giphy_api/resources/gif.rb', line 28

def find_by_ids *ids, **options
  find_with_scope('', :all, options.merge(ids: ids.join(',')))
end

.random(**options) ⇒ Object



20
21
22
# File 'lib/giphy_api/resources/gif.rb', line 20

def random **options
  find_with_scope('/random', :one, options)
end

.search(keyword, **options) ⇒ Object



8
9
10
# File 'lib/giphy_api/resources/gif.rb', line 8

def search keyword, **options
  find_with_scope('/search', :all, options.merge(q: keyword))
end

.translate(term, **options) ⇒ Object



16
17
18
# File 'lib/giphy_api/resources/gif.rb', line 16

def translate term, **options
  find_with_scope('/translate', :one, options.merge(s: term))
end


12
13
14
# File 'lib/giphy_api/resources/gif.rb', line 12

def trending **options
  find_with_scope('/trending', :all, options)
end