blitline 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.4"
12
+ gem "rcov", ">= 0"
13
+ end
14
+
15
+ gem 'yajl-ruby', :require => 'yajl'
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.9.2.2)
10
+ rcov (0.9.11)
11
+ shoulda (2.11.3)
12
+ yajl-ruby (1.1.0)
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ bundler (~> 1.0.0)
19
+ jeweler (~> 1.6.4)
20
+ rcov
21
+ shoulda
22
+ yajl-ruby
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Blitline LLC
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.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = blitline
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to blitline
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 developer blitline. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "blitline"
18
+ gem.homepage = "http://github.com/blitline_dev/blitline"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Blitline provides simple image processing in the cloud}
21
+ gem.description = %Q{The blitline gems provides a simple easy wrapper to the Blitline.com web api}
22
+ gem.email = "support@blitline.com"
23
+ gem.authors = ["Blitline LLC"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ test.rcov_opts << '--exclude "gems/*"'
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "blitline #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.1
data/blitline.gemspec ADDED
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "blitline"
8
+ s.version = "1.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Blitline LLC"]
12
+ s.date = "2011-12-09"
13
+ s.description = "The blitline gems provides a simple easy wrapper to the Blitline.com web api"
14
+ s.email = "support@blitline.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "blitline.gemspec",
28
+ "lib/blitline.rb",
29
+ "lib/blitline/attribute_jsonizer.rb",
30
+ "lib/blitline/function.rb",
31
+ "lib/blitline/http_poster.rb",
32
+ "lib/blitline/job.rb",
33
+ "lib/blitline/s3_destination.rb",
34
+ "lib/blitline/save.rb",
35
+ "test/helper.rb",
36
+ "test/test_blitline.rb"
37
+ ]
38
+ s.homepage = "http://github.com/blitline_dev/blitline"
39
+ s.licenses = ["MIT"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = "1.8.12"
42
+ s.summary = "Blitline provides simple image processing in the cloud"
43
+
44
+ if s.respond_to? :specification_version then
45
+ s.specification_version = 3
46
+
47
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
48
+ s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
49
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
52
+ s.add_development_dependency(%q<rcov>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
55
+ s.add_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
58
+ s.add_dependency(%q<rcov>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ end
67
+ end
68
+
@@ -0,0 +1,13 @@
1
+ module AttributeJsonizer
2
+ require 'yajl'
3
+
4
+ def to_json
5
+ json_hash = {}
6
+ self.instance_variables.each do |iv|
7
+ key = iv
8
+ value = self.instance_variable_get(iv)
9
+ json_hash[key.to_s.gsub("@","")] = value
10
+ end
11
+ Yajl::Encoder.encode(json_hash)
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ class Blitline
2
+ class Function
3
+ include AttributeJsonizer
4
+ attr_accessor :name, :params, :save, :functions
5
+
6
+ def initialize(name, params = nil)
7
+ @name = name
8
+ @params = params unless params.nil?
9
+ end
10
+
11
+ def add_save(image_identifier, s3_key = nil, s3_bucket = nil)
12
+ save = Blitline::Save.new(image_identifier)
13
+ if s3_key && s3_bucket
14
+ save.add_s3_destination(s3_key, s3_bucket)
15
+ end
16
+ @save = save
17
+ end
18
+
19
+ def add_function(function_name, function_params, image_identifier = nil)
20
+ function = Blitline::Function.new(function_name, function_params)
21
+ @functions << function
22
+ function.add_save(image_identifier) if image_identifier
23
+ end
24
+
25
+ def validate
26
+ raise "Function must have a name" if @name.nil?
27
+ raise "Params must be a hash" if @params && !@params.is_a(Hash)
28
+ @save.validate if @save
29
+ @functions.each { |f| f.validate } if @functions
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,24 @@
1
+ class Blitline
2
+ require 'net/http'
3
+ require 'uri'
4
+
5
+ class HttpPoster
6
+ # Perform a POST request.
7
+ # Optionally takes a form_data hash.
8
+ # Optionally takes a block to receive chunks of the response.
9
+ def self.post(path, form_data=nil, &block)
10
+ uri = URI.parse(path) unless path.is_a?(URI)
11
+ @http = Net::HTTP.new(uri.host, uri.port)
12
+ request = Net::HTTP::Post.new(path)
13
+ request.set_form_data(form_data) if form_data
14
+ @http.request(request) do |response|
15
+ if response.is_a? Net::HTTPSuccess
16
+ return response.read_body(&block)
17
+ else
18
+ response.read_body
19
+ response.error!
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ class Blitline
2
+ class Job
3
+ include AttributeJsonizer
4
+ attr_accessor :application_id, :src, :postback_url, :functions
5
+
6
+ def initialize(image_src)
7
+ @src = image_src
8
+ @functions = []
9
+ end
10
+
11
+ def add_function(function_name, function_params, image_identifier = nil)
12
+ function = Blitline::Function.new(function_name, function_params)
13
+ function.add_save(image_identifier) if image_identifier
14
+ @functions << function
15
+ end
16
+
17
+ def validate
18
+ raise "Job must have an application_id" if @application_id.nil?
19
+ raise "Job must have an image_src to work on" if @src.nil?
20
+ @functions.each { |f| f.validate }
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ class Blitline
2
+ class S3Destination
3
+ include AttributeJsonizer
4
+ attr_accessor :key, :bucket
5
+
6
+ def initialize(key, bucket)
7
+ @key = key
8
+ @bucket = bucket
9
+ end
10
+
11
+ def validate
12
+ raise "S3Destination must have a key" if @key.nil?
13
+ raise "S3Destination must have a bucket" if @bucket.nil?
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ class Blitline
2
+ class Save
3
+ include AttributeJsonizer
4
+ attr_accessor :image_identifier, :s3_destination
5
+
6
+ def initialize(image_identifier)
7
+ @image_identifier = image_identifier
8
+ end
9
+
10
+ def add_s3_destination(key, bucket)
11
+ @s3_destination = Blitline::S3Destination.new(key, bucket)
12
+ end
13
+
14
+ def validate
15
+ raise "Save must have an image_identifier. This value is returned with results and let's you, the client, identify what image this is" if @image_identifier.nil?
16
+ @s3_destination.validate unless @s3_destination.nil?
17
+ end
18
+ end
19
+ end
data/lib/blitline.rb ADDED
@@ -0,0 +1,47 @@
1
+ class Blitline
2
+ require 'yajl'
3
+ require 'blitline/attribute_jsonizer'
4
+ require 'blitline/function'
5
+ require 'blitline/job'
6
+ require 'blitline/save'
7
+ require 'blitline/s3_destination'
8
+ require 'blitline/http_poster'
9
+
10
+ include AttributeJsonizer
11
+ attr_accessor :jobs
12
+
13
+ def initialize
14
+ @jobs = []
15
+ end
16
+
17
+ # Heroku users don't need to specify application_id if they have ENV['BLITLINE_URL'] defined
18
+ def add_job(image_source, function_name, function_params, image_identifier, application_id = nil)
19
+ job = Blitline::Job.new(image_source)
20
+ environment_app_id = ENV['BLITLINE_URL'] && ENV['BLITLINE_URL'].split("/").last
21
+ job.application_id = environment_app_id || application_id
22
+ job.add_function(function_name, function_params, image_identifier)
23
+ @jobs << job
24
+ end
25
+
26
+ # Heroku users don't need to specify application_id if they have ENV['BLITLINE_URL'] defined
27
+ def add_job_with_callback(image_source, function_name, function_params, image_identifier, postback_url, application_id = nil)
28
+ job = Blitline::Job.new(image_source)
29
+ environment_app_id = ENV['BLITLINE_URL'] && ENV['BLITLINE_URL'].split("/").last
30
+ job.application_id = environment_app_id || application_id
31
+ job.add_function(function_name, function_params, image_identifier)
32
+ job.postback_url = postback_url
33
+ @jobs << job
34
+ end
35
+
36
+ def validate
37
+ raise "At least 1 job must be present to run" if @jobs.length < 1
38
+ @jobs.each { |j| j.validate }
39
+ end
40
+
41
+ def post_jobs
42
+ validate
43
+ result = Blitline::HttpPoster.post("http://www.blitline.com/api/job", { :json => Yajl::Encoder.encode(@jobs)})
44
+ return Yajl::Parser.parse(result)
45
+ end
46
+
47
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'blitline'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,54 @@
1
+ require 'helper'
2
+
3
+ class TestBlitline < Test::Unit::TestCase
4
+
5
+ should "raise exception if missing jobs" do
6
+ assert_raises RuntimeError do
7
+ blitline = Blitline.new
8
+ blitline.post_jobs
9
+ end
10
+ end
11
+
12
+ should "raise exception if job missing application id" do
13
+ assert_raises RuntimeError do
14
+ blitline = Blitline.new
15
+ blitline.jobs << Blitline::Job.new("http://ww.foo.com")
16
+ blitline.post_jobs
17
+ end
18
+ end
19
+
20
+ should "raise exception if job missing image identifier" do
21
+ assert_raises RuntimeError do
22
+ blitline = Blitline.new
23
+ job = Blitline::Job.new("http://ww.foo.com")
24
+ job.application_id = "foo"
25
+ job.add_function("blue", nil)
26
+ blitline.jobs << job
27
+ blitline.post_jobs
28
+ end
29
+ end
30
+
31
+ should "raise exception if job missing image identifier" do
32
+ assert_raises RuntimeError do
33
+ blitline = Blitline.new
34
+ job = Blitline::Job.new("http://ww.foo.com")
35
+ job.application_id = "foo"
36
+ job.add_function("blur", nil, "my_image")
37
+ blitline.jobs << job
38
+ blitline.post_jobs
39
+ end
40
+ end
41
+
42
+ should "raise exception if job missing image identifier" do
43
+ blitline = Blitline.new
44
+ job = Blitline::Job.new("http://ww.foo.com")
45
+ job.add_function("blue", nil, "my_image")
46
+ job.application_id = "foo"
47
+ blitline.jobs << job
48
+ results = blitline.post_jobs
49
+ assert_not_nil results['results']
50
+ assert_not_nil results['results'][0]
51
+ assert_not_nil results['results'][0]['error']
52
+ end
53
+
54
+ end
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blitline
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Blitline LLC
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yajl-ruby
16
+ requirement: &20770920 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *20770920
25
+ - !ruby/object:Gem::Dependency
26
+ name: shoulda
27
+ requirement: &20770140 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *20770140
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &20769540 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *20769540
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &20768780 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *20768780
58
+ - !ruby/object:Gem::Dependency
59
+ name: rcov
60
+ requirement: &20768240 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *20768240
69
+ description: The blitline gems provides a simple easy wrapper to the Blitline.com
70
+ web api
71
+ email: support@blitline.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files:
75
+ - LICENSE.txt
76
+ - README.rdoc
77
+ files:
78
+ - .document
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - LICENSE.txt
82
+ - README.rdoc
83
+ - Rakefile
84
+ - VERSION
85
+ - blitline.gemspec
86
+ - lib/blitline.rb
87
+ - lib/blitline/attribute_jsonizer.rb
88
+ - lib/blitline/function.rb
89
+ - lib/blitline/http_poster.rb
90
+ - lib/blitline/job.rb
91
+ - lib/blitline/s3_destination.rb
92
+ - lib/blitline/save.rb
93
+ - test/helper.rb
94
+ - test/test_blitline.rb
95
+ homepage: http://github.com/blitline_dev/blitline
96
+ licenses:
97
+ - MIT
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ segments:
109
+ - 0
110
+ hash: 144569250605677256
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubyforge_project:
119
+ rubygems_version: 1.8.12
120
+ signing_key:
121
+ specification_version: 3
122
+ summary: Blitline provides simple image processing in the cloud
123
+ test_files: []