Class: Imagebin

Inherits:
Object
  • Object
show all
Includes:
REXML
Defined in:
lib/imagebin.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Imagebin

Returns a new instance of Imagebin.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/imagebin.rb', line 11

def initialize(options)
    @options = { "image" => "file",
                 "key" => "api_key",
    }
    @options.merge!(options)
    res = HTTPClient.post('http://imgur.com/api/upload.xml',
                          {:image => File.open(@options['image']),
                           :key => @options['key']}).content
    begin
        @doc = Document.new(res)
    rescue
        res[/<h1>(.*)<\/h1>/]
        puts $1
        exit
    end
    raise @doc.elements.to_a("//error_msg")[0].text if @doc.elements.to_a("//error_msg").length > 0
end

Instance Method Details

#delete_hashObject



33
34
35
# File 'lib/imagebin.rb', line 33

def delete_hash
    @doc.elements.to_a("//delete_hash")[0].text
end

#delete_pageObject



53
54
55
# File 'lib/imagebin.rb', line 53

def delete_page
    @doc.elements.to_a("//delete_page")[0].text
end

#image_hashObject



29
30
31
# File 'lib/imagebin.rb', line 29

def image_hash
    @doc.elements.to_a("//image_hash")[0].text
end

#imgur_pageObject



49
50
51
# File 'lib/imagebin.rb', line 49

def imgur_page
    @doc.elements.to_a("//imgur_page")[0].text
end

#large_thumbnailObject



41
42
43
# File 'lib/imagebin.rb', line 41

def large_thumbnail
    @doc.elements.to_a("//large_thumbnail")[0].text
end

#original_imageObject



37
38
39
# File 'lib/imagebin.rb', line 37

def original_image
    @doc.elements.to_a("//original_image")[0].text
end

#small_thumbnailObject



45
46
47
# File 'lib/imagebin.rb', line 45

def small_thumbnail
    @doc.elements.to_a("//small_thumbnail")[0].text
end