hci 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,13 @@
1
- Hci::Client.load_path = Rails.root + Hci::Client.load_path
2
- Rails.configuration.after_initialize do
3
- Hci::Client.load!
1
+ if defined?(ActionController::Metal)
2
+ class Railtie < Rails::Railtie
3
+ initializer :load_hci do |app|
4
+ Hci::Client.load_path = Rails.root + Hci::Client.load_path
5
+ Hci::Client.load!
6
+ end
7
+ end
8
+ else
9
+ Rails.configuration.after_initialize do
10
+ Hci::Client.load_path = Rails.root + Hci::Client.load_path
11
+ Hci::Client.load!
12
+ end
4
13
  end
data/lib/hci/hit.rb CHANGED
@@ -19,8 +19,12 @@ module Hci
19
19
  self.hits[name] = hit
20
20
  end
21
21
 
22
- def request(name, resource_id)
23
- @hits[name].request(resource_id)
22
+ def request(name, options)
23
+ @hits[name].request(options)
24
+ end
25
+
26
+ def cancel(name, options)
27
+ @hits[name].cancel(options)
24
28
  end
25
29
 
26
30
  def find(name)
@@ -47,7 +51,12 @@ module Hci
47
51
 
48
52
  def request(options)
49
53
  hit_request = HitRequest.new(self, options)
50
- hit_request.invoke
54
+ hit_request.create
55
+ end
56
+
57
+ def cancel(options)
58
+ hit_request = HitRequest.new(self, options)
59
+ hit_request.cancel
51
60
  end
52
61
 
53
62
  def to_hash
@@ -9,9 +9,19 @@ module Hci
9
9
  @http_end_point = Client.http_end_point
10
10
  end
11
11
 
12
- def invoke
13
- RestClient.post("#{@http_end_point}/hits", {:hit=>@hit.to_hash.merge(@params).merge(:callback_url=>Client.callback_url), :api_key=>Client.api_key}.to_json, :content_type => :json, :accept => :json)
12
+ def create
13
+ RestClient.post("#{@http_end_point}/hits", *request_params)
14
14
  end
15
-
15
+
16
+ def cancel
17
+ RestClient.post("#{@http_end_point}/hits/cancel", *request_params)
18
+ end
19
+
20
+ private
21
+
22
+ def request_params
23
+ [{:hit=>@hit.to_hash.merge(@params).merge(:callback_url=>Client.callback_url), :api_key=>Client.api_key}.to_json, {:content_type => :json, :accept => :json}]
24
+ end
25
+
16
26
  end
17
27
  end
data/lib/hci/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Hci
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
 
4
4
  end
@@ -26,7 +26,7 @@ describe "HitRequest" do
26
26
  hit_request = Hci::HitRequest.new(hit, :callback_params=>{:resource_id=>'1234'})
27
27
 
28
28
  stub_request(:post, "hci.heroku.com/hits")
29
- hit_request.invoke
29
+ hit_request.create
30
30
  a_request(:post, "http://hci.heroku.com/hits").with(:body=>{'hit'=>
31
31
  {
32
32
  'name'=>"Approve photo",
@@ -42,6 +42,47 @@ describe "HitRequest" do
42
42
 
43
43
  end
44
44
 
45
+
46
+ it "should invoke a hit cancellation" do
47
+
48
+ hit = Hci::Hit.define "Approve photo" do |h|
49
+
50
+ h.directions = "Please classify this photo by choosing the appropriate tickboxes."
51
+ h.image_url = "http://www.google.com/logo.png"
52
+ h.answer_type = "tags"
53
+ h.answer_options = ['Obscenity', 'Nudity', 'Blurry', 'Upside down or sideways', 'Contains more than one person in the foreground', 'Has people in the background', 'Contains children']
54
+ h.responses_required = 3
55
+ h.replace = false
56
+
57
+ h.on_completion do |result|
58
+ puts "Complete"
59
+ end
60
+
61
+ h.on_failure do |result|
62
+ puts "Failed"
63
+ end
64
+
65
+ end
66
+
67
+ hit_request = Hci::HitRequest.new(hit, :callback_params=>{:resource_id=>'1234'})
68
+
69
+ stub_request(:post, "hci.heroku.com/hits/cancel")
70
+ hit_request.cancel
71
+ a_request(:post, "http://hci.heroku.com/hits/cancel").with(:body=>{'hit'=>
72
+ {
73
+ 'name'=>"Approve photo",
74
+ 'directions'=>"Please classify this photo by choosing the appropriate tickboxes.",
75
+ 'image_url'=>"http://www.google.com/logo.png",
76
+ 'answer_options'=> ['Obscenity', 'Nudity', 'Blurry', 'Upside down or sideways', 'Contains more than one person in the foreground', 'Has people in the background', 'Contains children'],
77
+ 'responses_required'=>3,
78
+ 'answer_type'=>'tags',
79
+ 'callback_url'=>"#{Hci::Client.callback_host}/hci_hit_result",
80
+ 'callback_params'=>{'resource_id'=>'1234'},
81
+ 'replace'=>false
82
+ }, :api_key=>'test-api-key'}).should have_been_made.once
83
+
84
+ end
85
+
45
86
  it "should allow options to be overridden when making the request" do
46
87
 
47
88
  hit = Hci::Hit.define "Approve photo" do |h|
@@ -65,7 +106,7 @@ describe "HitRequest" do
65
106
  hit_request = Hci::HitRequest.new(hit, {:callback_params=>{:resource_id=>'1234'}, :image_url=>"http://www.example.com/image.jpg"})
66
107
 
67
108
  stub_request(:post, "hci.heroku.com/hits")
68
- hit_request.invoke
109
+ hit_request.create
69
110
  a_request(:post, "http://hci.heroku.com/hits").with(:body=>{'hit'=>
70
111
  {
71
112
  'name'=>"Approve photo",
data/spec/hci_hit_spec.rb CHANGED
@@ -66,11 +66,18 @@ describe "Hit" do
66
66
  end
67
67
 
68
68
  it "should request a hit" do
69
-
69
+ hit = Hci::Hit.define("Approve photo") { }
70
+ hit.should_receive(:request).with(:request_id=>'123')
71
+ Hci::Hit.request("Approve photo", :request_id=>'123')
72
+ end
73
+
74
+ it "should cancel a hit" do
70
75
  hit = Hci::Hit.define("Approve photo") { }
71
76
  hit.should_receive(:request).with(:request_id=>'123')
72
77
  Hci::Hit.request("Approve photo", :request_id=>'123')
73
78
 
79
+ hit.should_receive(:cancel).with(:request_id=>'123')
80
+ Hci::Hit.cancel("Approve photo", :request_id=>'123')
74
81
  end
75
82
 
76
83
  it "should find a hit" do
metadata CHANGED
@@ -1,8 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hci
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
6
10
  platform: ruby
7
11
  authors:
8
12
  - Sam Oliver
@@ -10,7 +14,7 @@ autorequire:
10
14
  bindir: bin
11
15
  cert_chain: []
12
16
 
13
- date: 2011-02-28 00:00:00 +00:00
17
+ date: 2011-03-20 00:00:00 +00:00
14
18
  default_executable:
15
19
  dependencies:
16
20
  - !ruby/object:Gem::Dependency
@@ -21,6 +25,8 @@ dependencies:
21
25
  requirements:
22
26
  - - ">="
23
27
  - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
24
30
  version: "0"
25
31
  type: :runtime
26
32
  version_requirements: *id001
@@ -32,6 +38,8 @@ dependencies:
32
38
  requirements:
33
39
  - - ">="
34
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
35
43
  version: "0"
36
44
  type: :runtime
37
45
  version_requirements: *id002
@@ -43,6 +51,10 @@ dependencies:
43
51
  requirements:
44
52
  - - ">="
45
53
  - !ruby/object:Gem::Version
54
+ segments:
55
+ - 1
56
+ - 2
57
+ - 9
46
58
  version: 1.2.9
47
59
  type: :development
48
60
  version_requirements: *id003
@@ -54,6 +66,8 @@ dependencies:
54
66
  requirements:
55
67
  - - ">="
56
68
  - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
57
71
  version: "0"
58
72
  type: :development
59
73
  version_requirements: *id004
@@ -104,17 +118,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
104
118
  requirements:
105
119
  - - ">="
106
120
  - !ruby/object:Gem::Version
121
+ segments:
122
+ - 0
107
123
  version: "0"
108
124
  required_rubygems_version: !ruby/object:Gem::Requirement
109
125
  none: false
110
126
  requirements:
111
127
  - - ">="
112
128
  - !ruby/object:Gem::Version
129
+ segments:
130
+ - 0
113
131
  version: "0"
114
132
  requirements: []
115
133
 
116
134
  rubyforge_project: hci
117
- rubygems_version: 1.5.3
135
+ rubygems_version: 1.3.7
118
136
  signing_key:
119
137
  specification_version: 3
120
138
  summary: HCI client