Permalink
Browse files

using bundler instead of jeweler. updated dependencies

  • Loading branch information...
1 parent bd624b9 commit f3a4cfe44c20a5b589b22fcc05557eccce2c10f2 @jwoertink committed Aug 28, 2012
Showing with 62 additions and 47 deletions.
  1. +3 −0 Gemfile
  2. +28 −0 Gemfile.lock
  3. +13 −32 Rakefile
  4. +13 −15 lib/imgur.rb
  5. +5 −0 lib/imgur/version.rb
View
@@ -0,0 +1,3 @@
+source :rubygems
+
+gemspec
View
@@ -0,0 +1,28 @@
+PATH
+ remote: .
+ specs:
+ imgur (0.3.1)
+ crack
+ curb
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ bacon (1.1.0)
+ crack (0.3.1)
+ curb (0.8.1)
+ multi_json (1.3.6)
+ simplecov (0.6.4)
+ multi_json (~> 1.0)
+ simplecov-html (~> 0.5.3)
+ simplecov-html (0.5.3)
+ yard (0.8.2.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bacon
+ imgur!
+ simplecov
+ yard
View
@@ -1,45 +1,26 @@
require 'rubygems'
require 'rake'
-begin
- require 'jeweler'
- Jeweler::Tasks.new do |gem|
- gem.name = "vanntastic-imgur"
- gem.summary = %Q{Imgur API interface}
- gem.description = %Q{An interface to the Imgur API}
- gem.email = "jdp34@njit.edu"
- gem.homepage = "http://github.com/jdp/imgur"
- gem.authors = ["Justin Poliey","Vann Ek"]
- gem.add_development_dependency "bacon", ">= 1.1.0"
- gem.add_development_dependency "yard", ">= 0.2.3.5"
- gem.add_development_dependency "curb", ">= 0.5.4.0"
- gem.add_development_dependency "crack", ">= 0.1.4"
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
- end
- Jeweler::GemcutterTasks.new
-rescue LoadError
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
-end
-
require 'rake/testtask'
Rake::TestTask.new(:spec) do |spec|
spec.libs << 'lib' << 'spec'
spec.pattern = 'spec/**/*_spec.rb'
spec.verbose = true
end
-begin
- require 'rcov/rcovtask'
- Rcov::RcovTask.new do |spec|
- spec.libs << 'spec'
- spec.pattern = 'spec/**/*_spec.rb'
- spec.verbose = true
- end
-rescue LoadError
- task :rcov do
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
- end
-end
+# Need to use simplecov for ruby 1.9
+# begin
+# require 'rcov/rcovtask'
+# Rcov::RcovTask.new do |spec|
+# spec.libs << 'spec'
+# spec.pattern = 'spec/**/*_spec.rb'
+# spec.verbose = true
+# end
+# rescue LoadError
+# task :rcov do
+# abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
+# end
+# end
task :spec => :check_dependencies
View
@@ -2,14 +2,11 @@
require 'crack/json'
require 'cgi'
-# @author Justin Poliey
-# Imgur module
module Imgur
- # General Imgur error container
class ImgurError < RuntimeError
- def initialize message
+ def initialize(message)
@message = message
super
end
@@ -18,12 +15,13 @@ def initialize message
# Imgur API interface
class API
+ BASE_URL = "http://imgur.com/api"
# Creates a new Imgur API instance
#
# @param [String] api_key Your API key from http://imgur.com/register/api/
# @return [API] An Imgur API instance
- def initialize api_key
+ def initialize(api_key)
@api_key = api_key
end
@@ -32,8 +30,8 @@ def initialize api_key
# @param [String] image_filename The filename of the image on disk to upload
# @raise [ImgurError]
# @return [Hash] Image data
- def upload_file image_filename
- c = Curl::Easy.new("http://imgur.com/api/upload.json")
+ def upload_file(image_filename)
+ c = Curl::Easy.new("#{BASE_URL}/upload.json")
c.multipart_form_post = true
c.http_post(Curl::PostField.content('key', @api_key), Curl::PostField.file('image', image_filename))
response = Crack::JSON.parse c.body_str
@@ -46,8 +44,8 @@ def upload_file image_filename
# @param [String] image_url The URL of the image to upload
# @raise [ImgurError]
# @return [Hash] Image data
- def upload_from_url image_url
- c = Curl::Easy.new("http://imgur.com/api/upload.json")
+ def upload_from_url(image_url)
+ c = Curl::Easy.new("#{BASE_URL}/upload.json")
c.http_post(Curl::PostField.content('key', @api_key), Curl::PostField.content('image', image_url))
response = Crack::JSON.parse c.body_str
raise ImgurError, response["rsp"]["error_msg"] if response["rsp"]["stat"] == "fail"
@@ -63,9 +61,9 @@ def upload_from_url image_url
# @option params [Integer] :page (1) Which page of images to display
# @raise [ImgurError]
# @return [Array<Hash>] Array of image data hashes
- def gallery params = {}
+ def gallery(params = {})
post_fields = params.collect { |k, v| CGI::escape(k.to_s) + '=' + CGI::escape(v.to_s) }.join('&')
- c = Curl::Easy.new("http://imgur.com/api/gallery.json?#{post_fields}")
+ c = Curl::Easy.new("#{BASE_URL}/gallery.json?#{post_fields}")
c.http_get
response = Crack::JSON.parse c.body_str
raise ImgurError, response["error"]["error_msg"] if response.key?("error")
@@ -77,8 +75,8 @@ def gallery params = {}
# @param [String] image_hash Imgur's hash of the image
# @raise [ImgurError]
# @return [Hash] Image statistics
- def image_stats image_hash
- c = Curl::Easy.new("http://imgur.com/api/stats/#{image_hash}.json")
+ def image_stats(image_hash)
+ c = Curl::Easy.new("#{BASE_URL}/stats/#{image_hash}.json")
c.http_get
response = Crack::JSON.parse c.body_str
raise ImgurError, response["error"]["error_msg"] if response.key?("error")
@@ -90,8 +88,8 @@ def image_stats image_hash
#
# @param [String] delete_hash Imgur's delete hash of the image
# @return [Boolean] Whether or not the image was deleted
- def delete image_hash
- c = Curl::Easy.new("http://imgur.com/api/delete/#{image_hash}.json?key=#{@api_key}")
+ def delete(image_hash)
+ c = Curl::Easy.new("#{BASE_URL}/delete/#{image_hash}.json?key=#{@api_key}")
c.http_get
response = Crack::JSON.parse c.body_str
response["rsp"]["stat"] == "ok"
@@ -0,0 +1,5 @@
+module Imgur
+
+ VERSION = "0.3.1"
+
+end

0 comments on commit f3a4cfe

Please sign in to comment.