Class: Imgur::Api::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/imgur/api/image.rb

Instance Attribute Summary

Attributes inherited from Base

#session

Instance Method Summary collapse

Methods inherited from Base

#communication

Instance Method Details

#image(id) ⇒ Object



6
7
8
9
10
# File 'lib/imgur/api/image.rb', line 6

def image(id)
  raise 'Please provide a valid image identificator' if id.nil? or !id.kind_of? String or id == '' or !!(id =~ /[^\w]/)

  Imgur::Image.new communication.call(:get, "image/#{id}")
end

#image_delete(id) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/imgur/api/image.rb', line 26

def image_delete(id)
  if id.kind_of? Imgur::Image
    id = id.id
  end

  raise 'Please provide a valid image identificator' if id.nil? or !id.kind_of? String or id == '' or !!(id =~ /[^\w]/)

  communication.call(:delete, "image/#{id}")
end

#image_upload(local_file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/imgur/api/image.rb', line 13

def image_upload(local_file)
  if local_file.kind_of? String
    file = File.open(local_file, 'rb')
  elsif local_file.respond_to? :read
    file = local_file
  else
    raise 'Must provide a File or file path'
  end

  Imgur::Image.new communication.call(:post, 'image', image: Base64.encode64(file.read))
end