Class: Imgur::Client::Images
- Inherits:
-
Cistern::Collection
- Object
- Cistern::Collection
- Imgur::Client::Images
- 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(={}) path = "" path = path + "/#{[:resource] || "gallery"}" if [:section] path = path + "/#{[:section]}" elsif [:subreddit] path = path + "/r/#{[:subreddit]}" end path = path + "/#{[:sort]}" if [:sort] path = path + "/#{[:page] || 0}.json" data = connection.get_images(path: path).body["data"] connection.images.load(data) end |
#upload(options = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/imgur/models/images.rb', line 28 def upload(={}) raise ArgumentError, ":image is missing: File name or URL requrired" unless [:image] [:image] = case [:image] when /^(http|ftp)/ [:image] when /\.(jp(e)?g|gif|bmp|png|tif(f)?)$/i File.open([:image], 'rb') else raise ArgumentError, "Invalid image value" end data = connection.upload_image().body["data"] connection.images.new(data) end |