rubyctaculous 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rails", "3.0.17"
4
+ gem "capybara", ">= 0.4.0"
5
+ gem "sqlite3"
6
+
7
+ gem "httparty", "~> 0.9.0"
8
+
9
+ group :development do
10
+ gem "pry"
11
+ end
12
+
13
+ # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
14
+ # gem 'ruby-debug'
15
+ # gem 'ruby-debug19'
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,59 @@
1
+ Rubyctaculous
2
+ =============
3
+
4
+ Rubyctaculous is a client for Pictaculous.com.
5
+
6
+ Pictaculous is a service that returns a color palette for a given image.
7
+
8
+ Install
9
+ -------
10
+
11
+ ### Without bundler
12
+
13
+ ```shell
14
+ $ gem install rubyctaculous
15
+ ```
16
+
17
+ ### With bundler
18
+
19
+ Past this line to your Gemfile
20
+
21
+ ```ruby
22
+ gem 'rubyctaculous', '~> 0.0.1'
23
+ ```
24
+
25
+ Usage
26
+ -----
27
+
28
+ (PNG, GIF, JPG only. Files cannot be larger than 500k)
29
+
30
+ ```ruby
31
+ pictaculous = Pictaculous::Client.new
32
+
33
+ colors = pictaculous.color_palette_for_image('path/to/my/image.jpg')
34
+
35
+ puts colors.inspect
36
+ => ['FFFFD3', '372C78', '9D7891', '654A86'] # Hex format
37
+ ```
38
+
39
+ Errors
40
+ ------
41
+
42
+ If something goes wrong, a Pictaculous::Error will be raised.
43
+
44
+ Contribute
45
+ ----------
46
+
47
+ If you have ideas to improve this project, feel free to contribute. :)
48
+
49
+ Meta
50
+ ----
51
+
52
+ Pictaculous [Website](http://www.pictaculous.com/).
53
+
54
+ This project uses [Semantic Versioning](http://semver.org/).
55
+
56
+ Author
57
+ ------
58
+
59
+ Bastien Gysler :: [bastiengysler.com](http://www.bastiengysler.com/) :: @basgys
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rake'
10
+ require 'rake/rdoctask'
11
+
12
+ require 'rake/testtask'
13
+
14
+ Rake::TestTask.new(:test) do |t|
15
+ t.libs << 'lib'
16
+ t.libs << 'test'
17
+ t.pattern = 'test/**/*_test.rb'
18
+ t.verbose = false
19
+ end
20
+
21
+ task :default => :test
22
+
23
+ Rake::RDocTask.new(:rdoc) do |rdoc|
24
+ rdoc.rdoc_dir = 'rdoc'
25
+ rdoc.title = 'Rubyctaculous'
26
+ rdoc.options << '--line-numbers' << '--inline-source'
27
+ rdoc.rdoc_files.include('README.rdoc')
28
+ rdoc.rdoc_files.include('lib/**/*.rb')
29
+ end
@@ -0,0 +1,45 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Pictaculous
5
+ class Client
6
+ include HTTParty
7
+ base_uri 'http://pictaculous.com/api/1.0'
8
+
9
+ # Returns a color palette for a given image
10
+ #
11
+ # Parameters :
12
+ # * path (String)
13
+ #
14
+ # Returns :
15
+ # * colors (Array)
16
+ #
17
+ def color_palette_for_image(path)
18
+ body = {image: to_binary(path)}
19
+
20
+ response = JSON.parse(self.class.post("/", :body => body))
21
+
22
+ if response['info']
23
+ response['info']['colors']
24
+ elsif response['status'] == 'error'
25
+ raise Pictaculous::Error.new(response['error'])
26
+ end
27
+
28
+ rescue Errno::ENOENT => e
29
+ raise Pictaculous::Error.new "Image not found (path : #{path})"
30
+ rescue => e
31
+ raise Pictaculous::Error.new e.message
32
+ end
33
+
34
+ private
35
+
36
+ def to_binary(image)
37
+ if image.kind_of?(String)
38
+ File.open(image, "rb") { |f| f.read }
39
+ else
40
+ raise ArgumentError.new('Unsuported format type. Please use a string (path)')
41
+ end
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ module Pictaculous
2
+ class Error < ::Exception
3
+
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Pictaculous
2
+ Version = VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ module Pictaculous
2
+ autoload :Client, 'pictaculous/client'
3
+ autoload :Error, 'pictaculous/error'
4
+ autoload :Version, 'pictaculous/version'
5
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubyctaculous
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bastien Gysler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.0
30
+ description: A simplistic ruby client for Pictaculous.com. Send an image to Pictaculous
31
+ and it will return a color palette.
32
+ email: basgys@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/pictaculous/client.rb
38
+ - lib/pictaculous/error.rb
39
+ - lib/pictaculous/version.rb
40
+ - lib/rubyctaculous.rb
41
+ - MIT-LICENSE
42
+ - Rakefile
43
+ - Gemfile
44
+ - README.markdown
45
+ homepage: https://github.com/basgys/rubyctaculous
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.23
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Ruby client for Pictaculous.com
69
+ test_files: []