blitline 2.5.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7bfcc452de6885cad8b160ad5e54dbd16da71e2
4
- data.tar.gz: 6d97c5a427fb194b611d6d3de8790d151d94babc
3
+ metadata.gz: 7cc50d6d9f1eedd7d3d10fadc87a7c047d5238f9
4
+ data.tar.gz: 8b48a1f1406ce0935d6a3b68ff383058dcb41468
5
5
  SHA512:
6
- metadata.gz: e0ad45e759a6daa7fdc635d798204ae0ddf50d9ea137affbbd811f25d2280619b1f92c8023638e478b03a571a23beeff38e9f77ad20df9685259deb866d18c54
7
- data.tar.gz: 6c30a4e39a28cc1f81d43f983f09c7f0a1bbc0153ca8fbab707b556e23501cbc810f40c45a733482676c0eb10b8aa6d7cd3fa136a9b895c3202716de86df3c45
6
+ metadata.gz: 841f7c1b23f7cd95d4620302b5798fc471bfc50941755abfbf4f7789c7ddc577f539f556afbf4848785c410b6ee34e06bde6ec86f3017b463049a87017f1eccf
7
+ data.tar.gz: 6cd70d1d7654108ac3eaa12d40b92842e7c7caf7136f233dd229198badb65ec704ed6acab66cc1085cc8982a8030878ce604582a6e753182d4a3ba06a66fca24
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.5.0
1
+ 2.5.1
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: blitline 2.5.0 ruby lib
5
+ # stub: blitline 2.5.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "blitline"
9
- s.version = "2.5.0"
9
+ s.version = "2.5.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Blitline LLC"]
14
- s.date = "2015-03-12"
14
+ s.date = "2015-06-17"
15
15
  s.description = "The blitline gems provides a simple easy wrapper to the Blitline.com web api"
16
16
  s.email = "support@blitline.com"
17
17
  s.extra_rdoc_files = [
@@ -7,7 +7,7 @@ class Blitline
7
7
  require 'blitline/s3_destination'
8
8
  require 'blitline/http_poster'
9
9
  require 'net/http'
10
-
10
+
11
11
  include AttributeJsonizer
12
12
  attr_accessor :jobs
13
13
 
@@ -55,12 +55,12 @@ class Blitline
55
55
  json_result = result
56
56
  else
57
57
  json_result = MultiJson.load(result)
58
- end
58
+ end
59
59
  @jobs = [] # clear jobs
60
60
  return json_result
61
61
  end
62
62
 
63
- def post_job_and_wait_for_poll
63
+ def post_job_and_wait_for_poll(timeout_secs = 60)
64
64
  validate
65
65
  raise "'post_job_with_poll' requires that there is only 1 job to submit" unless @jobs.length==1
66
66
  result = Blitline::HttpPoster.post("http://#{@domain}.blitline.com/job", { :json => MultiJson.dump(@jobs)})
@@ -72,21 +72,37 @@ class Blitline
72
72
 
73
73
  raise "Error posting job: #{result.to_s}" if result["error"]
74
74
  job_id = json_result["results"][0]["job_id"]
75
- return poll_job(job_id)
75
+ return poll_job(job_id, timeout_secs)
76
76
  end
77
77
 
78
- def poll_job(job_id)
78
+ def poll_job(job_id, timeout_secs = 60)
79
79
  raise "Invalid 'job_id'" unless job_id && job_id.length > 0
80
80
  url = "/listen/#{job_id}"
81
- response = Net::HTTP.get('cache.blitline.com', url)
81
+ response = fetch(url, timeout_secs)
82
+
82
83
  if response.is_a?(Hash)
83
84
  json_result = response
84
85
  else
85
86
  json_result = MultiJson.load(response)
86
87
  end
87
- return_results = json_result["results"]
88
+
89
+ # Change 2.5.0 -> 2.5.1 (Return JSON instead of string)
90
+ if json_result["results"].is_a?(Hash)
91
+ return_results = json_result["results"]
92
+ else
93
+ return_results = MultiJson.load(json_result["results"])
94
+ end
88
95
 
89
96
  return return_results
90
97
  end
91
98
 
99
+ def fetch(uri_str, timeout_secs, limit = 10)
100
+ raise "Too Many Redirects" if limit == 0
101
+
102
+ http = Net::HTTP.new("cache.blitline.com")
103
+ http.read_timeout = timeout_secs
104
+ request = Net::HTTP::Get.new(uri_str)
105
+ response = http.request(request, uri_str)
106
+ MultiJson.load(response.body)
107
+ end
92
108
  end
@@ -21,4 +21,4 @@ class Blitline
21
21
  end
22
22
  end
23
23
  end
24
- end
24
+ end
@@ -36,29 +36,16 @@ class TestBlitline < Test::Unit::TestCase
36
36
  job.application_id = "foo"
37
37
  job.add_function("blur", nil, "my_image")
38
38
  blitline.jobs << job
39
- blitline.post_jobs
39
+ results = blitline.post_jobs
40
40
  end
41
41
  end
42
42
 
43
- should "raise exception if job missing image identifier" do
44
- blitline = Blitline.new
45
- job = Blitline::Job.new("http://ww.foo.com")
46
- job.add_function("blue", nil, "my_image")
47
- job.application_id = "foo"
48
- blitline.jobs << job
49
-
50
- results = blitline.post_jobs
51
- assert_not_nil results['results']
52
- assert_not_nil results['results'][0]
53
- assert_not_nil results['results'][0]['error']
54
- end
55
-
56
43
  should "properly jsonize the jsonizable_attributes" do
57
44
  job = Blitline::Job.new("http://ww.foo.com")
58
45
  job.add_function("blue", nil, "my_image")
59
46
  job.application_id = "foo"
60
47
  job.add_jsonizable_attribute("pre_process", { "move_original" => { "s3_destination" => Blitline::S3Destination.new("my_key","my_bucket")}})
61
-
48
+
62
49
  results = MultiJson.dump(job)
63
50
  assert_not_nil results["pre_process"]
64
51
  assert results == '{"src":"http://ww.foo.com","functions":[{"name":"blue","save":{"image_identifier":"my_image"}}],"application_id":"foo","pre_process":{"move_original":{"s3_destination":{"key":"my_key","bucket":"my_bucket","headers":{}}}}}'
@@ -75,6 +75,37 @@ class TestService < Test::Unit::TestCase
75
75
  assert(returned_values['images'].length > 0, "No images returned")
76
76
  end
77
77
 
78
+ should "be able to set timoeut for polling" do
79
+ assert_raises Net::ReadTimeout do
80
+ blitline = Blitline.new
81
+ blitline.add_job_via_hash({
82
+ "application_id"=> "#{ENV['BLITLINE_APPLICATION_ID']}",
83
+ "src"=> SAMPLE_IMAGE_SRC,
84
+ "src_data" => { "colorspace" => "srgb"},
85
+ "get_exif" => true,
86
+ "v" => 1.20,
87
+ "functions"=> [
88
+ {
89
+ "name"=> "resize_to_fit",
90
+ "params"=> {
91
+ "width"=> 100,
92
+ "autosharpen"=> true
93
+ },
94
+ "save"=> {
95
+ "image_identifier"=> "MY_CLIENT_ID"
96
+ }
97
+ }
98
+ ]
99
+ })
100
+
101
+
102
+ returned_values = blitline.post_job_and_wait_for_poll(0)
103
+ assert(returned_values.length > 0, "No results returned")
104
+ assert(returned_values['images'].length > 0, "No images returned")
105
+ end
106
+ end
107
+
108
+
78
109
  should "be able to handle incorrect JSON" do
79
110
  blitline = Blitline.new
80
111
  blitline.add_job_via_hash({
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blitline
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Blitline LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json