Class: Imgurapi::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/imgurapi/models/image.rb

Constant Summary collapse

IMGUR_HOST =
'i.imgur.com'
IMAGE_EXTENSION =

jpg is the default extension for every Imgur image

'jpg'

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Imgurapi::Base

Instance Method Details



7
8
9
10
11
12
13
14
15
# File 'lib/imgurapi/models/image.rb', line 7

def link(use_ssl = false)
  protocol = if use_ssl
               'https://'
             else
               'http://'
             end

  "#{protocol}#{IMGUR_HOST}/#{id}.#{IMAGE_EXTENSION}"
end

#url(size: nil, use_ssl: false) ⇒ Object

Provides the download URL in case you know a valid imgur hash and don’t want to make a network trip with .find Just in case you don’t need the full Imgurapi::Image object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/imgurapi/models/image.rb', line 19

def url(size: nil, use_ssl: false)
  size = case size
         when :small_square, :small, :s
           's'
         when :large_thumbnail, :large, :l
           'l'
         else
           ''
         end

  splitted_link = link(use_ssl).split('.')
  splitted_link[splitted_link.size - 2] << size
  splitted_link.join '.'
end