Sha256: 41af23f00babe2a3b5715316805dc1888e0cc3647218e28a0404ca9d4409ff05

Contents?: true

Size: 953 Bytes

Versions: 2

Compression:

Stored size: 953 Bytes

Contents

module Imgurapi
  class Image < Base

    IMGUR_HOST = 'i.imgur.com'
    IMAGE_EXTENSION = 'jpg' # jpg is the default extension for every Imgur image

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

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

    # 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
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
imgurapi-3.2.2 lib/imgurapi/models/image.rb
imgurapi-3.2.1 lib/imgurapi/models/image.rb