Class: Imgur::Client::Images

Inherits:
Cistern::Collection
  • Object
show all
Includes:
Imgur::Collection, PagedCollection
Defined in:
lib/imgur/models/images.rb

Instance Method Summary collapse

Methods included from Imgur::Collection

#get, included, #model_request, #model_root

Methods included from PagedCollection

#==, #collection_request, #collection_root, included, #last_page, #next_page, #previous_page

Instance Method Details

#all(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/imgur/models/images.rb', line 13

def all(options={})
  path = ""
  path = path + "/#{options[:resource] || "gallery"}"
  if options[:section]
    path = path + "/#{options[:section]}"
  elsif options[:subreddit]
    path = path + "/r/#{options[:subreddit]}"
  end
  path = path + "/#{options[:sort]}" if options[:sort]
  path = path + "/#{options[:page] || 0}.json"

  data = connection.get_images(path: path).body["data"]
  connection.images.load(data)
end

#upload(options = {}) ⇒ Object

Raises:

  • (ArgumentError)


28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/imgur/models/images.rb', line 28

def upload(options={})
  raise ArgumentError, ":image is missing: File name or URL requrired" unless options[:image]
  options[:image] = case options[:image]
                    when /^(http|ftp)/
                      options[:image]
                    when /\.(jp(e)?g|gif|bmp|png|tif(f)?)$/i
                      File.open(options[:image], 'rb')
                    else
                      raise ArgumentError, "Invalid image value"
                    end
  data = connection.upload_image(options).body["data"]
  connection.images.new(data)
end