$: << File.dirname(__FILE__) + "/../lib" require 'rubygems' require 'crowdflower' require 'json' API_KEY = ENV["API_KEY"] DOMAIN_BASE = ENV["DOMAIN_BASE"] || "https://api.localdev.crowdflower.com:8443" CrowdFlower::Job.connect! API_KEY, DOMAIN_BASE unless API_KEY && API_KEY.size > 3 puts < 'testtt', :instructions => 'testttt fdsf sfds fsdfs fesfsdf', :cml => ''}) say "Registering a webhook." job.update :webhook_uri => "http://localhost:8080/crowdflower" say "Tags" assert job.tags.empty? job.update_tags ["testing_123", "testing_456"] assert job.tags.map{|t| t["name"]}.sort == ["testing_123", "testing_456"] job.remove_tags ["testing_123"] assert job.tags.map{|t| t["name"]} == ["testing_456"] job.add_tags ["testing_789"] assert job.tags.map{|t| t["name"]} == ["testing_456", "testing_789"] say "Copying the existing job to a new one." job2 = job.copy :all_units => true say "-- Waiting for CrowdFlower to finish copying the job." # You could also register a webhook to have CrowdFlower notify your # server. wait_until { job2.get["units_count"] == 8 } say "Ordering the job." order = CrowdFlower::Order.new(job) unit_count = 8 order.debit(8) wait_until { job.get["state"].casecmp('running') == 0} say "Checking enabled_channels." assert !job.channels["enabled_channels"].empty? # To see exact list of enabled jobs: # p job.channels["enabled_channels"] say "Order job2 to check channels when specifying channel parameter." order = CrowdFlower::Order.new(job2) order.debit(8, "channel"=>"cf_internal") assert job2.channels["enabled_channels"] == ["cf_internal"] say "Canceling the unit." unit_id = job.units.all.to_a[0][0] unit = CrowdFlower::Unit.new(job) wait_until { unit.get(unit_id)['state'] == 'judgable' } puts unit.cancel(unit_id).inspect assert unit.get(unit_id)['state'] == 'canceled' say "Webhook test needs to be written." #job.test_webhook say ">-< Tests complete. >-<"