blitline 2.1.0 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -0
- data/VERSION +1 -1
- data/blitline.gemspec +3 -3
- data/lib/blitline.rb +22 -1
- data/test/test_service.rb +22 -9
- metadata +4 -4
data/README.md
CHANGED
@@ -61,6 +61,22 @@ This result does not indicate that the job is done! The job has been put on a qu
|
|
61
61
|
way to identify when the job is completed is by adding a `postback_url` to the job hash and we will call back that url
|
62
62
|
when we have completed the image processing.
|
63
63
|
|
64
|
+
As an alternative to blitline_service.post_jobs, you can use blitline_service.post_job_and_wait
|
65
|
+
|
66
|
+
$ blitline_service.post_job_and_wait
|
67
|
+
|
68
|
+
Which will block, and using Blitline's [long polling](http://www.blitline.com/docs/polling) functionality, return when the job is completed. The returned result will look like
|
69
|
+
|
70
|
+
```js
|
71
|
+
{"original_meta"=>{"width"=>720, "height"=>540}, "images"=>[{"image_identifier"=>"MY_CLIENT_ID", "s3_url"=>"http://s3.amazonaws.com/blitline/2013082822/20/7J6Izja0hkG7rvNj-MUJDfQ.jpg", "meta"=>{"width"=>100, "height"=>75}}], "job_id"=>"9hgxoQ10WI7YN2QcioUarbA"}
|
72
|
+
```
|
73
|
+
|
74
|
+
This JSON contains:
|
75
|
+
- Any error information associated with the job
|
76
|
+
- Metadata associated with the original image
|
77
|
+
- A list of images processed.
|
78
|
+
|
79
|
+
In fact, this result will contain all the exact same information a Blitline postback would contain.
|
64
80
|
|
65
81
|
The example above is a trivial (and pretty uninteresting) demonstration of how to use the Blitline gem. You can find documentation about Blitline.com and it's services by following the links below
|
66
82
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.0
|
data/blitline.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "blitline"
|
8
|
-
s.version = "2.
|
8
|
+
s.version = "2.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Blitline LLC"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2013-08-28"
|
13
13
|
s.description = "The blitline gems provides a simple easy wrapper to the Blitline.com web api"
|
14
14
|
s.email = "support@blitline.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -39,7 +39,7 @@ Gem::Specification.new do |s|
|
|
39
39
|
s.homepage = "http://github.com/blitline-dev/blitline"
|
40
40
|
s.licenses = ["MIT"]
|
41
41
|
s.require_paths = ["lib"]
|
42
|
-
s.rubygems_version = "1.8.
|
42
|
+
s.rubygems_version = "1.8.25"
|
43
43
|
s.summary = "Blitline provides simple image processing in the cloud"
|
44
44
|
|
45
45
|
if s.respond_to? :specification_version then
|
data/lib/blitline.rb
CHANGED
@@ -6,7 +6,8 @@ class Blitline
|
|
6
6
|
require 'blitline/save'
|
7
7
|
require 'blitline/s3_destination'
|
8
8
|
require 'blitline/http_poster'
|
9
|
-
|
9
|
+
require 'net/http'
|
10
|
+
|
10
11
|
include AttributeJsonizer
|
11
12
|
attr_accessor :jobs
|
12
13
|
|
@@ -53,4 +54,24 @@ class Blitline
|
|
53
54
|
return MultiJson.load(result)
|
54
55
|
end
|
55
56
|
|
57
|
+
def post_job_and_wait_for_poll
|
58
|
+
validate
|
59
|
+
raise "'post_job_with_poll' requires that there is only 1 job to submit" unless @jobs.length==1
|
60
|
+
result = Blitline::HttpPoster.post("http://api.blitline.com/job", { :json => MultiJson.dump(@jobs)})
|
61
|
+
json_result = MultiJson.load(result)
|
62
|
+
raise "Error posting job: #{result.to_s}" if result["error"]
|
63
|
+
job_id = json_result["results"][0]["job_id"]
|
64
|
+
return poll_job(job_id)
|
65
|
+
end
|
66
|
+
|
67
|
+
def poll_job(job_id)
|
68
|
+
raise "Invalid 'job_id'" unless job_id && job_id.length > 0
|
69
|
+
url = "/listen/#{job_id}"
|
70
|
+
response = Net::HTTP.get('cache.blitline.com', url)
|
71
|
+
json_response = MultiJson.load(response)
|
72
|
+
return_results = MultiJson.load(json_response["results"])
|
73
|
+
|
74
|
+
return return_results
|
75
|
+
end
|
76
|
+
|
56
77
|
end
|
data/test/test_service.rb
CHANGED
@@ -16,19 +16,31 @@ class TestService < Test::Unit::TestCase
|
|
16
16
|
assert(returned_values['results'][0]['images'].length > 0, "No images returned")
|
17
17
|
end
|
18
18
|
|
19
|
-
should "be able to
|
19
|
+
should "be able to add job via hash" do
|
20
20
|
blitline = Blitline.new
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
blitline.add_job_via_hash({
|
22
|
+
"application_id"=>"#{ENV['BLITLINE_APPLICATION_ID']}",
|
23
|
+
"src"=>"http://cdn.blitline.com/filters/boys.jpeg",
|
24
|
+
"functions"=>[
|
25
|
+
{
|
26
|
+
"name"=>"resize_to_fit",
|
27
|
+
"params"=>{
|
28
|
+
"width"=>100
|
29
|
+
},
|
30
|
+
"save"=>{
|
31
|
+
"image_identifier"=>"MY_CLIENT_ID"
|
32
|
+
}
|
33
|
+
}
|
34
|
+
]
|
35
|
+
})
|
36
|
+
|
37
|
+
|
26
38
|
returned_values = blitline.post_jobs
|
27
39
|
assert(returned_values.length > 0, "No results returned")
|
28
40
|
assert(returned_values['results'][0]['images'].length > 0, "No images returned")
|
29
41
|
end
|
30
42
|
|
31
|
-
should "be able to add job via hash" do
|
43
|
+
should "be able to add job via hash and wait for polling" do
|
32
44
|
blitline = Blitline.new
|
33
45
|
blitline.add_job_via_hash({
|
34
46
|
"application_id"=>"#{ENV['BLITLINE_APPLICATION_ID']}",
|
@@ -47,9 +59,10 @@ class TestService < Test::Unit::TestCase
|
|
47
59
|
})
|
48
60
|
|
49
61
|
|
50
|
-
returned_values = blitline.
|
62
|
+
returned_values = blitline.post_job_and_wait_for_poll
|
63
|
+
puts returned_values.inspect
|
51
64
|
assert(returned_values.length > 0, "No results returned")
|
52
|
-
assert(returned_values['
|
65
|
+
assert(returned_values['images'].length > 0, "No images returned")
|
53
66
|
end
|
54
67
|
|
55
68
|
should "be able to commit a job with multiple embedded functions" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blitline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_json
|
@@ -117,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
117
|
version: '0'
|
118
118
|
segments:
|
119
119
|
- 0
|
120
|
-
hash:
|
120
|
+
hash: 2250966872445256256
|
121
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
122
|
none: false
|
123
123
|
requirements:
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
128
|
rubyforge_project:
|
129
|
-
rubygems_version: 1.8.
|
129
|
+
rubygems_version: 1.8.25
|
130
130
|
signing_key:
|
131
131
|
specification_version: 3
|
132
132
|
summary: Blitline provides simple image processing in the cloud
|