Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ pkg

# For rubinius:
#*.rbc

# Ignoring built gem
*.gem
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ source "http://rubygems.org"
group :development do
gem "shoulda", ">= 0"
gem "jeweler"
gem "pry"
end

gem 'multi_json'
gem "multi_json"
gem "terminator"
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ GEM
specs:
addressable (2.3.5)
builder (3.2.2)
coderay (1.1.0)
faraday (0.7.6)
addressable (~> 2.2)
multipart-post (~> 1.1)
rack (~> 1.1)
fattr (2.2.2)
git (1.2.6)
github_api (0.4.10)
faraday (~> 0.7.6)
Expand All @@ -25,6 +27,7 @@ GEM
rake
rdoc
json (1.8.1)
method_source (0.8.2)
mini_portile (0.5.2)
multi_json (1.3.6)
multipart-post (1.2.0)
Expand All @@ -33,16 +36,25 @@ GEM
oauth2 (0.5.2)
faraday (~> 0.7)
multi_json (~> 1.0)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.5.2)
rake (10.1.1)
rdoc (4.1.1)
json (~> 1.4)
shoulda (2.11.3)
slop (3.6.0)
terminator (1.0.0)
fattr (>= 2.2)

PLATFORMS
ruby

DEPENDENCIES
jeweler
multi_json
pry
shoulda
terminator
35 changes: 22 additions & 13 deletions lib/blitline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Blitline
require 'blitline/s3_destination'
require 'blitline/http_poster'
require 'net/http'
require 'terminator'

include AttributeJsonizer
attr_accessor :jobs
Expand Down Expand Up @@ -56,23 +57,31 @@ def post_jobs
end

def post_job_and_wait_for_poll
validate
raise "'post_job_with_poll' requires that there is only 1 job to submit" unless @jobs.length==1
result = Blitline::HttpPoster.post("http://#{@domain}.blitline.com/job", { :json => MultiJson.dump(@jobs)})
json_result = MultiJson.load(result)
raise "Error posting job: #{result.to_s}" if result["error"]
job_id = json_result["results"][0]["job_id"]
return poll_job(job_id)
validate
raise "'post_job_with_poll' requires that there is only 1 job to submit" unless @jobs.length==1
result = Blitline::HttpPoster.post("http://#{@domain}.blitline.com/job", { :json => MultiJson.dump(@jobs)})
json_result = MultiJson.load(result)
raise "Error posting job: #{result.to_s}" if result["error"]
job_id = json_result["results"][0]["job_id"]
return poll_job(job_id)
end

def poll_job(job_id)
raise "Invalid 'job_id'" unless job_id && job_id.length > 0
url = "/listen/#{job_id}"
response = Net::HTTP.get('cache.blitline.com', url)
json_response = MultiJson.load(response)
return_results = MultiJson.load(json_response["results"])
raise "Invalid 'job_id'" unless job_id && job_id.length > 0
url = "/listen/#{job_id}"

response = "{}"

begin
Terminator.terminate 2 do
response = Net::HTTP.get('cache.blitline.com', url)
end
rescue Terminator.error
end

json_response = MultiJson.load(response)

return return_results
return json_response
end

end
2 changes: 2 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rubygems'
require 'bundler'

begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
Expand All @@ -9,6 +10,7 @@
end
require 'test/unit'
require 'shoulda'
require 'pry'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
Expand Down
4 changes: 2 additions & 2 deletions test/test_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TestService < Test::Unit::TestCase

returned_values = blitline.post_job_and_wait_for_poll
assert(returned_values.length > 0, "No results returned")
assert(returned_values['images'].length > 0, "No images returned")
assert(returned_values['results']['images'].length > 0, "No images returned")
end

should "be able to handle incorrect JSON" do
Expand All @@ -85,7 +85,7 @@ class TestService < Test::Unit::TestCase

returned_values = blitline.post_job_and_wait_for_poll
assert(returned_values.length > 0, "No results returned")
assert(returned_values['images'].length > 0, "No images returned")
assert(returned_values['results']['images'].length > 0, "No images returned")
end

should "be able to commit a job with multiple embedded functions" do
Expand Down