shared_workforce 0.2.13 → 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,7 +10,7 @@ module SharedWorkforce
10
10
  attr_accessor :request_class
11
11
 
12
12
  def initialize
13
- @http_end_point = "http://api.sharedworkforce.com"
13
+ @http_end_point = "https://api.sharedworkforce.com"
14
14
  @request_class = default_request_class
15
15
  end
16
16
 
@@ -35,7 +35,7 @@ module SharedWorkforce
35
35
  end
36
36
 
37
37
  def valid?
38
- @api_key.present?
38
+ api_key.present?
39
39
  end
40
40
 
41
41
  private
@@ -14,6 +14,7 @@ module SharedWorkforce
14
14
  :image_url,
15
15
  :image_crop_ratio,
16
16
  :text,
17
+ :html,
17
18
  :on_success,
18
19
  :on_failure,
19
20
  :on_complete
@@ -133,6 +134,7 @@ module SharedWorkforce
133
134
  :callback_url => callback_url,
134
135
  :replace => replace,
135
136
  :text => text,
137
+ :html => html,
136
138
  :callback_params => attributes
137
139
  }.reject {|k,v| v.nil? }
138
140
  end
@@ -1,4 +1,4 @@
1
1
  module SharedWorkforce
2
- VERSION = "0.2.13"
2
+ VERSION = "0.2.14"
3
3
 
4
4
  end
@@ -6,35 +6,31 @@ describe "Configuration" do
6
6
 
7
7
  describe "#api_key" do
8
8
  it "should use the API key set in ENV['SHAREDWORKFORCE_API_KEY']" do
9
- old_env = ENV['SHAREDWORKFORCE_API_KEY']
10
- ENV['SHAREDWORKFORCE_API_KEY'] = "API_KEY_FROM_ENV"
11
- configuration.api_key.should == "API_KEY_FROM_ENV"
12
- ENV['SHAREDWORKFORCE_API_KEY'] = old_env
9
+ with_env 'SHAREDWORKFORCE_API_KEY', 'API_KEY_FROM_ENV' do
10
+ configuration.api_key.should == "API_KEY_FROM_ENV"
11
+ end
13
12
  end
14
13
 
15
14
  it "should be overridable with a custom value" do
16
- old_env = ENV['SHAREDWORKFORCE_API_KEY']
17
- ENV['SHAREDWORKFORCE_API_KEY'] = "API_KEY_FROM_ENV"
18
- configuration.api_key = "CUSTOM_API_KEY"
19
- configuration.api_key.should == "CUSTOM_API_KEY"
20
- ENV['SHAREDWORKFORCE_API_KEY'] = old_env
15
+ with_env 'SHAREDWORKFORCE_API_KEY', 'API_KEY_FROM_ENV' do
16
+ configuration.api_key = "CUSTOM_API_KEY"
17
+ configuration.api_key.should == "CUSTOM_API_KEY"
18
+ end
21
19
  end
22
20
  end
23
21
 
24
22
  describe "#callback_host" do
25
23
  it "should use the callback host set in ENV['SHAREDWORKFORCE_CALLBACK_HOST']" do
26
- old_env = ENV['SHAREDWORKFORCE_CALLBACK_HOST']
27
- ENV['SHAREDWORKFORCE_CALLBACK_HOST'] = "http://env.example.com"
28
- configuration.callback_host.should == "http://env.example.com"
29
- ENV['SHAREDWORKFORCE_CALLBACK_HOST'] = old_env
24
+ with_env 'SHAREDWORKFORCE_CALLBACK_HOST', "http://env.example.com" do
25
+ configuration.callback_host.should == "http://env.example.com"
26
+ end
30
27
  end
31
28
 
32
29
  it "should be overridable with a custom value" do
33
- old_env = ENV['SHAREDWORKFORCE_CALLBACK_HOST']
34
- ENV['SHAREDWORKFORCE_CALLBACK_HOST'] = "env.example.com"
35
- configuration.callback_host = "custom.example.com"
36
- configuration.callback_host.should == "custom.example.com"
37
- ENV['SHAREDWORKFORCE_CALLBACK_HOST'] = old_env
30
+ with_env 'SHAREDWORKFORCE_CALLBACK_HOST', "env.example.com" do
31
+ configuration.callback_host = "custom.example.com"
32
+ configuration.callback_host.should == "custom.example.com"
33
+ end
38
34
  end
39
35
  end
40
36
 
@@ -72,9 +68,23 @@ describe "Configuration" do
72
68
 
73
69
  describe "#valid" do
74
70
  it "should be false if no api key is set" do
75
- configuration.api_key = nil
76
- configuration.should_not be_valid
71
+ with_env 'SHAREDWORKFORCE_API_KEY', nil do
72
+ configuration.should_not be_valid
73
+ end
77
74
  end
75
+
76
+ it "should be true if the api key is set in ENV" do
77
+ with_env 'SHAREDWORKFORCE_API_KEY', 'SOMETHING' do
78
+ configuration.should be_valid
79
+ end
80
+ end
78
81
  end
82
+
83
+ def with_env(key, value, &block)
84
+ old_value = ENV[key]
85
+ ENV[key] = value
86
+ yield
87
+ ENV[key] = old_value
88
+ end
79
89
 
80
90
  end
@@ -7,9 +7,9 @@ describe "TaskRequest::Http" do
7
7
  task = ApprovePhotoTask.new
8
8
  task_request = SharedWorkforce::TaskRequest::Http.new(task, :image_url=>"http://www.google.com/logo.png", :image_crop_ratio=>1.7, :callback_params=>{:resource_id=>'1234'})
9
9
 
10
- stub_request(:post, "api.sharedworkforce.com/tasks")
10
+ stub_request(:post, "https://api.sharedworkforce.com/tasks")
11
11
  task_request.create
12
- a_request(:post, "http://api.sharedworkforce.com/tasks").with(:body=>{'task'=>
12
+ a_request(:post, "https://api.sharedworkforce.com/tasks").with(:body=>{'task'=>
13
13
  {
14
14
  'title'=>"Approve Photo",
15
15
  'instruction'=>"Please classify this photo by choosing the appropriate tickboxes.",
@@ -20,7 +20,8 @@ describe "TaskRequest::Http" do
20
20
  'answer_type'=>'tags',
21
21
  'callback_url'=>"#{SharedWorkforce.configuration.callback_host}/shared_workforce/task_response",
22
22
  'callback_params'=>{'resource_id'=>'1234'},
23
- 'replace'=>true
23
+ 'replace'=>true,
24
+ 'html'=>'<strong>Custom html</strong>'
24
25
  }, :api_key=>'test-api-key'}).should have_been_made.once
25
26
 
26
27
  end
@@ -41,9 +42,9 @@ describe "TaskRequest::Http" do
41
42
 
42
43
  task_request = SharedWorkforce::TaskRequest::Http.new(task.new, {:callback_params=>{:resource_id=>'1234'}, :image_url=>"http://www.example.com/image.jpg"})
43
44
 
44
- stub_request(:post, "api.sharedworkforce.com/tasks")
45
+ stub_request(:post, "https://api.sharedworkforce.com/tasks")
45
46
  task_request.create
46
- a_request(:post, "http://api.sharedworkforce.com/tasks").with(:body=>{'task'=>
47
+ a_request(:post, "https://api.sharedworkforce.com/tasks").with(:body=>{'task'=>
47
48
  {
48
49
  'title'=>"Approve Photo",
49
50
  'instruction'=>"Please classify this photo by choosing the appropriate tickboxes.",
@@ -53,7 +54,7 @@ describe "TaskRequest::Http" do
53
54
  'answer_type'=>'tags',
54
55
  'callback_url'=>"#{SharedWorkforce.configuration.callback_host}/shared_workforce/task_response",
55
56
  'callback_params'=>{'resource_id'=>'1234'},
56
- 'replace'=>false,
57
+ 'replace'=>false
57
58
  }, :api_key=>'test-api-key'}).should have_been_made.once
58
59
  end
59
60
  end
@@ -63,9 +64,9 @@ describe "TaskRequest::Http" do
63
64
 
64
65
  task_request = SharedWorkforce::TaskRequest::Http.new(ApprovePhotoTask.new, :callback_params=>{:resource_id=>'1234'})
65
66
 
66
- stub_request(:post, "api.sharedworkforce.com/tasks/cancel")
67
+ stub_request(:post, "https://api.sharedworkforce.com/tasks/cancel")
67
68
  task_request.cancel
68
- a_request(:post, "http://api.sharedworkforce.com/tasks/cancel").with(:body=>{'task'=>
69
+ a_request(:post, "https://api.sharedworkforce.com/tasks/cancel").with(:body=>{'task'=>
69
70
  {
70
71
  'title'=>"Approve Photo",
71
72
  'instruction'=>"Please classify this photo by choosing the appropriate tickboxes.",
@@ -75,7 +76,8 @@ describe "TaskRequest::Http" do
75
76
  'answer_type'=>'tags',
76
77
  'callback_url'=>"#{SharedWorkforce.configuration.callback_host}/shared_workforce/task_response",
77
78
  'callback_params'=>{'resource_id'=>'1234'},
78
- 'replace'=>true
79
+ 'replace'=>true,
80
+ 'html'=>'<strong>Custom html</strong>'
79
81
  }, :api_key=>'test-api-key'}).should have_been_made.once
80
82
 
81
83
  end
@@ -10,11 +10,11 @@ describe "TaskRequest::HttpWithPoller" do
10
10
  :callback_params=>{:resource_id=>'1234'}
11
11
  )
12
12
 
13
- stub_request(:post, "api.sharedworkforce.com/tasks").to_return(:body=>{:id=>123}.to_json)
13
+ stub_request(:post, "https://api.sharedworkforce.com/tasks").to_return(:body=>{:id=>123}.to_json)
14
14
 
15
15
  task_request.create
16
16
 
17
- a_request(:post, "http://api.sharedworkforce.com/tasks").with(:body=>{'task'=>
17
+ a_request(:post, "https://api.sharedworkforce.com/tasks").with(:body=>{'task'=>
18
18
  {
19
19
  'title'=>"Approve Photo",
20
20
  'instruction'=>"Please classify this photo by choosing the appropriate tickboxes.",
@@ -27,6 +27,7 @@ describe "TaskRequest::HttpWithPoller" do
27
27
  'callback_params'=>{'resource_id'=>'1234'},
28
28
  'replace'=>true,
29
29
  'callback_enabled'=>false,
30
+ 'html'=>'<strong>Custom html</strong>'
30
31
  }, :api_key=>'test-api-key'}).should have_been_made.once
31
32
  end
32
33
  end
data/spec/task_spec.rb CHANGED
@@ -18,6 +18,7 @@ describe "Task" do
18
18
  answer_type :crop
19
19
  image_crop_ratio 1.7
20
20
  guidelines "* be careful"
21
+ html "<strong>Custom html</strong>"
21
22
 
22
23
  answer_options ['Obscenity', 'Nudity', 'Blurry', 'Upside down or sideways']
23
24
 
@@ -41,6 +42,7 @@ describe "Task" do
41
42
  task.image_crop_ratio.should == 1.7
42
43
  task.answer_options.should == ['Obscenity', 'Nudity', 'Blurry', 'Upside down or sideways']
43
44
  task.guidelines.should == "* be careful"
45
+ task.html.should == "<strong>Custom html</strong>"
44
46
  end
45
47
 
46
48
  it "should allow certain default attributes to be overwritten" do
@@ -240,9 +242,9 @@ describe "Task" do
240
242
  it "should make a new task http request" do
241
243
  task = Class.new { include SharedWorkforce::Task }
242
244
 
243
- stub_request(:post, "http://api.sharedworkforce.com/tasks")
245
+ stub_request(:post, "https://api.sharedworkforce.com/tasks")
244
246
  task.new.request(:request_id=>'123')
245
- a_request(:post, "http://api.sharedworkforce.com/tasks").should have_been_made.once
247
+ a_request(:post, "https://api.sharedworkforce.com/tasks").should have_been_made.once
246
248
  end
247
249
  end
248
250
 
@@ -250,9 +252,9 @@ describe "Task" do
250
252
  it "should send a cancel task http request" do
251
253
  task_class = Class.new { include SharedWorkforce::Task }
252
254
 
253
- stub_request(:post, "http://api.sharedworkforce.com/tasks/cancel")
255
+ stub_request(:post, "https://api.sharedworkforce.com/tasks/cancel")
254
256
  task_class.cancel(@resource_class.new)
255
- a_request(:post, "http://api.sharedworkforce.com/tasks/cancel").should have_been_made.once
257
+ a_request(:post, "https://api.sharedworkforce.com/tasks/cancel").should have_been_made.once
256
258
  end
257
259
 
258
260
  it "should not raise a ConfigurationError if a callback host is not set" do
@@ -9,6 +9,7 @@ class ApprovePhotoTask
9
9
  answer_options ['Obscenity', 'Nudity', 'Blurry', 'Upside down or sideways', 'Contains more than one person in the foreground', 'Has people in the background', 'Contains children']
10
10
  answer_type :tags
11
11
  image_url "http://www.google.com/logo.png"
12
+ html '<strong>Custom html</strong>'
12
13
 
13
14
  replace true
14
15
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shared_workforce
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.13
4
+ version: 0.2.14
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-02 00:00:00.000000000 Z
12
+ date: 2012-09-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &70323744943380 !ruby/object:Gem::Requirement
16
+ requirement: &70318914187300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70323744943380
24
+ version_requirements: *70318914187300
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70323744942960 !ruby/object:Gem::Requirement
27
+ requirement: &70318914186880 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70323744942960
35
+ version_requirements: *70318914186880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: activesupport
38
- requirement: &70323744942540 !ruby/object:Gem::Requirement
38
+ requirement: &70318914186460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70323744942540
46
+ version_requirements: *70318914186460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70323744942040 !ruby/object:Gem::Requirement
49
+ requirement: &70318914185960 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.2.9
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70323744942040
57
+ version_requirements: *70318914185960
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: webmock
60
- requirement: &70323744941620 !ruby/object:Gem::Requirement
60
+ requirement: &70318914185540 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70323744941620
68
+ version_requirements: *70318914185540
69
69
  description: Shared Workforce is a service and simple API for human intelligence tasks
70
70
  email:
71
71
  - sam@samoliver.com