cloudfactory 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. data/.gitignore +11 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +10 -0
  4. data/README.md +44 -0
  5. data/Rakefile +40 -0
  6. data/bin/cf +8 -0
  7. data/cf.gemspec +76 -0
  8. data/example/google_translate_app/Gemfile +12 -0
  9. data/example/google_translate_app/config.ru +7 -0
  10. data/example/google_translate_app/google_translate_input.csv +4 -0
  11. data/example/google_translate_app/google_translator_app.rb +53 -0
  12. data/example/google_translate_app/views/index.haml +2 -0
  13. data/example/google_translate_app/views/layout.haml +7 -0
  14. data/example/google_translate_app/views/run.haml +4 -0
  15. data/example/google_translate_app/views/style.sass +2 -0
  16. data/example/human_worker_app/Gemfile +12 -0
  17. data/example/human_worker_app/config.ru +7 -0
  18. data/example/human_worker_app/human_worker_app.rb +55 -0
  19. data/example/human_worker_app/human_worker_input.csv +5 -0
  20. data/example/human_worker_app/public/app.js +12 -0
  21. data/example/human_worker_app/temp.csv +3 -0
  22. data/example/human_worker_app/views/index.haml +15 -0
  23. data/example/human_worker_app/views/layout.haml +10 -0
  24. data/example/human_worker_app/views/result.haml +18 -0
  25. data/example/human_worker_app/views/run.haml +12 -0
  26. data/example/human_worker_app/views/style.sass +25 -0
  27. data/example/sample_yaml_files/concept_tagging_robot.yaml +18 -0
  28. data/example/sample_yaml_files/content_scraping_robot.yaml +19 -0
  29. data/example/sample_yaml_files/entity_extraction_robot.yaml +18 -0
  30. data/example/sample_yaml_files/google_translate_robot.yaml +20 -0
  31. data/example/sample_yaml_files/image_processing_robot.yaml +20 -0
  32. data/example/sample_yaml_files/keyword_matching_and_text_extraction_robot.yaml +26 -0
  33. data/example/sample_yaml_files/mailer_robot.yaml +21 -0
  34. data/example/sample_yaml_files/media_converter_robot.yaml +21 -0
  35. data/example/sample_yaml_files/media_splitting_robot.yaml +20 -0
  36. data/example/sample_yaml_files/multiple_skill_badge.yaml +75 -0
  37. data/example/sample_yaml_files/sentiment_robot.yaml +19 -0
  38. data/example/sample_yaml_files/skill_badge.yaml +56 -0
  39. data/example/sample_yaml_files/stat_badge.yaml +40 -0
  40. data/example/sample_yaml_files/term_extraction_robot.yaml +20 -0
  41. data/example/sample_yaml_files/tournament_station_and_form_fields.yaml +40 -0
  42. data/features/form_generation.feature +46 -0
  43. data/features/form_preview.feature +98 -0
  44. data/features/line_creation.feature +99 -0
  45. data/features/line_deletion.feature +50 -0
  46. data/features/line_generation.feature +57 -0
  47. data/features/run.feature +141 -0
  48. data/features/support/cli_steps.rb +16 -0
  49. data/features/support/env.rb +23 -0
  50. data/features/target_url.feature +82 -0
  51. data/fixtures/api_credentials_example.yml +4 -0
  52. data/fixtures/input_data/media_converter_robot.csv +2 -0
  53. data/fixtures/input_data/test.csv +2 -0
  54. data/lib/cf.rb +94 -0
  55. data/lib/cf/account.rb +32 -0
  56. data/lib/cf/cli.rb +52 -0
  57. data/lib/cf/cli/config.rb +87 -0
  58. data/lib/cf/cli/form.rb +82 -0
  59. data/lib/cf/cli/line.rb +237 -0
  60. data/lib/cf/cli/production.rb +62 -0
  61. data/lib/cf/cli/templates/css_file.css.erb +22 -0
  62. data/lib/cf/cli/templates/form_preview.html.erb +17 -0
  63. data/lib/cf/cli/templates/html_file.html.erb +21 -0
  64. data/lib/cf/cli/templates/js_file.js.erb +18 -0
  65. data/lib/cf/cli/templates/line.tt +55 -0
  66. data/lib/cf/cli/templates/sample-line/form.css +27 -0
  67. data/lib/cf/cli/templates/sample-line/form.html +26 -0
  68. data/lib/cf/cli/templates/sample-line/form.js +7 -0
  69. data/lib/cf/cli/templates/sample-line/line.yml.erb +67 -0
  70. data/lib/cf/cli/templates/sample-line/sample-line.csv +3 -0
  71. data/lib/cf/client.rb +56 -0
  72. data/lib/cf/custom_task_form.rb +136 -0
  73. data/lib/cf/department.rb +24 -0
  74. data/lib/cf/final_output.rb +20 -0
  75. data/lib/cf/form_field.rb +62 -0
  76. data/lib/cf/human_worker.rb +67 -0
  77. data/lib/cf/input_format.rb +134 -0
  78. data/lib/cf/line.rb +231 -0
  79. data/lib/cf/robot_worker.rb +31 -0
  80. data/lib/cf/run.rb +158 -0
  81. data/lib/cf/station.rb +340 -0
  82. data/lib/cf/task_form.rb +147 -0
  83. data/lib/cf/version.rb +3 -0
  84. data/lib/generators/cf/form/form_generator.rb +55 -0
  85. data/lib/generators/cf/form/templates/cf_form.html.erb +11 -0
  86. data/lib/generators/cf/install/install_generator.rb +22 -0
  87. data/lib/generators/cf/install/templates/README +13 -0
  88. data/lib/generators/cf/install/templates/cloud_factory.rb +7 -0
  89. data/spec/account_spec.rb +11 -0
  90. data/spec/badge_spec.rb +88 -0
  91. data/spec/concept_tagging_robot_spec.rb +54 -0
  92. data/spec/config_spec.rb +20 -0
  93. data/spec/content_scraping_robot_spec.rb +58 -0
  94. data/spec/custom_task_form_spec.rb +190 -0
  95. data/spec/department_spec.rb +14 -0
  96. data/spec/entity_extraction_robot_spec.rb +56 -0
  97. data/spec/form_field_spec.rb +126 -0
  98. data/spec/generators/form_generator_spec.rb +60 -0
  99. data/spec/generators/install_generator_spec.rb +35 -0
  100. data/spec/google_translate_robot_spec.rb +64 -0
  101. data/spec/human_worker_spec.rb +118 -0
  102. data/spec/image_processing_robot_spec.rb +56 -0
  103. data/spec/input_format_spec.rb +113 -0
  104. data/spec/keyword_matching_and_text_extraction_robot_spec.rb +73 -0
  105. data/spec/line_spec.rb +338 -0
  106. data/spec/mailer_robot_spec.rb +62 -0
  107. data/spec/media_converter_robot_spec.rb +72 -0
  108. data/spec/media_splitting_robot_spec.rb +62 -0
  109. data/spec/run_spec.rb +298 -0
  110. data/spec/sentiment_robot_spec.rb +56 -0
  111. data/spec/spec_helper.rb +39 -0
  112. data/spec/station_spec.rb +256 -0
  113. data/spec/task_form_spec.rb +96 -0
  114. data/spec/term_extraction_robot_spec.rb +58 -0
  115. data/spec/text_appending_robot_spec.rb +86 -0
  116. metadata +472 -0
@@ -0,0 +1,134 @@
1
+ module CF
2
+ class InputFormat
3
+ include Client
4
+
5
+ # name for the input_format, e.g. :name => "image_url"
6
+ attr_accessor :name
7
+
8
+ # required boolean either true or false , e.g. :required => "true" & if false then you don't need to mention
9
+ attr_accessor :required
10
+
11
+ # valid_type format of the source for the input_format, e.g. :valid_type => "url"
12
+ attr_accessor :valid_type
13
+
14
+ # ID of an input_format
15
+ attr_accessor :id
16
+
17
+ # ID of Line with which input_format is associated
18
+ attr_accessor :line_title, :errors
19
+
20
+ # ==Initializes a new input_format
21
+ # * Syntax for creating new input_format: <b>InputFormat.new(</b> Hash <b>)</b>
22
+ # ===Usage Example:
23
+ # line = CF::Line.create("Digitize", "Survey")
24
+ #
25
+ # attrs = {:line => line,
26
+ # :name => "image_url",
27
+ # :required => true,
28
+ # :valid_type => "url"}
29
+ #
30
+ # input_format = CF::InputFormat.new(attrs)
31
+ # line.input_formats input_format
32
+ def initialize(options={})
33
+ @station = options[:station]
34
+ @line = options[:line]
35
+ @name = options[:name]
36
+ @required = options[:required]
37
+ @valid_type = options[:valid_type]
38
+ if !@station.nil? or !@line.nil?
39
+ line_title = @station.nil? ? @line.title : @station.line_title
40
+ resp = self.class.post("/lines/#{CF.account_name}/#{@line.title.downcase}/input_formats.json", :input_format => {:name => @name, :required => @required, :valid_type => @valid_type})
41
+ if resp.code != 200
42
+ self.errors = resp.error.message
43
+ end
44
+ @line_title = line_title
45
+ if !@station.nil? && @station.except.nil? && @station.extra.nil?
46
+ @station.input_formats = self
47
+ else
48
+ @line.input_formats = self
49
+ end
50
+ end
51
+ end
52
+
53
+ # ==Returns all the input headers of a specific line
54
+ # line = CF::Line.new("Digitize Card","Survey")
55
+ #
56
+ # attrs_1 = {:line => line,
57
+ # :name => "image_url",
58
+ # :required => true,
59
+ # :valid_type => "url"
60
+ # }
61
+ # attrs_2 = {:line => line,
62
+ # :name => "text_url",
63
+ # :required => true,
64
+ # :valid_type => "url"
65
+ # }
66
+ #
67
+ # input_format_1 = CF::InputFormat.new(attrs_1)
68
+ # line.input_formats input_format_1
69
+ # input_format_2 = CF::InputFormat.new(attrs_2)
70
+ # line.input_formats input_format_2
71
+ #
72
+ # input_formats_of_line = CF::InputFormat.all(line)
73
+ # returns an array of input headers associated with line
74
+ def self.all(line)
75
+ get("/lines/#{CF.account_name}/#{line.title.downcase}/input_formats.json")
76
+ end
77
+
78
+ # ==Returns a particular input header of a specific line
79
+ # ===Usage example
80
+ # line = CF::Line.new("Digitize Card","Survey")
81
+ # attrs = {:line => line,
82
+ # :name => "image_url_type",
83
+ # :required => true,
84
+ # :valid_type => "url"
85
+ # }
86
+ #
87
+ # input_format = CF::InputFormat.new(attrs)
88
+ # line.input_formats input_format
89
+ # input_format = line.input_formats[0]
90
+ #
91
+ # got_input_format = input_format.get
92
+ def get
93
+ self.class.get("/lines/#{line_id}/input_formats/#{id}.json")
94
+ end
95
+
96
+ # ==Updates input header
97
+ # ===Usage example
98
+ # line = CF::Line.new("Digitize Card","Survey")
99
+ # attrs = {:line => line,
100
+ # :name => "image_url_type",
101
+ # :required => true,
102
+ # :valid_type => "url"
103
+ # }
104
+ #
105
+ # input_format = CF::InputFormat.new(attrs)
106
+ # line.input_formats input_format
107
+ # input_format = line.input_formats[0]
108
+ #
109
+ # updated_input_format = input_format.update({:name => "jackpot", :field_type => "lottery"})
110
+ def update(options={})
111
+ @name = options[:name]
112
+ @required = options[:required]
113
+ @valid_type = options[:valid_type]
114
+ self.class.put("/lines/#{line_id}/input_formats/#{id}.json", :input_format => {:name => @name, :required => @required, :valid_type => @valid_type})
115
+ end
116
+
117
+ # line = CF::Line.new("Digitize Card","Survey")
118
+ # attrs = {:line => line,
119
+ # :name => "image_url_type",
120
+ # :required => true,
121
+ # :valid_type => "url"
122
+ # }
123
+ #
124
+ # input_format = CF::InputFormat.new(attrs)
125
+ # line.input_formats input_format
126
+ #
127
+ # input_format = line.input_formats[0]
128
+ # input_format.delete
129
+ # deletes input header
130
+ def delete
131
+ self.class.delete("/lines/#{line_id}/input_formats/#{id}.json")
132
+ end
133
+ end
134
+ end
data/lib/cf/line.rb ADDED
@@ -0,0 +1,231 @@
1
+ module CF
2
+ class Line
3
+ require 'httparty'
4
+ include Client
5
+
6
+ # Title of the Line
7
+ attr_accessor :title
8
+
9
+ # Category Name is required for the category which is categorized according to ID, e.g. "4dc8ad6572f8be0600000001"
10
+ attr_accessor :department_name
11
+
12
+ # Public is a boolean attribute which when set to true becomes public & vice-versa
13
+ #
14
+ # Public attribute is optional
15
+ attr_accessor :public
16
+
17
+ # Description attribute describes about the line
18
+ #
19
+ # Description attribute is optional
20
+ attr_accessor :description
21
+
22
+ # id attribute is for the line_id & is required to be stored for making Api calls
23
+ attr_accessor :id
24
+
25
+ # stations contained within line object
26
+ attr_accessor :stations
27
+
28
+ # input_formats contained within line object
29
+ attr_accessor :input_formats
30
+ attr_accessor :errors
31
+ #attr_accessor :input_format_instance
32
+ #attr_accessor :station_instance
33
+
34
+ # ==Initializes a new line
35
+ # ==Usage of line.new("line_name")
36
+ #
37
+ # line = Line.new("Digit", "Survey")
38
+ def initialize(title, department_name, options={})
39
+ @input_formats =[]
40
+ @stations =[]
41
+ @title = title
42
+ @department_name = department_name
43
+ @public = options[:public]
44
+ @description = options[:description]
45
+ resp = self.class.post("/lines/#{CF.account_name}.json", {:line => {:title => title, :department_name => department_name, :public => @public, :description => @description}})
46
+ if resp.code != 200
47
+ self.errors = resp.error.message
48
+ end
49
+ end
50
+
51
+ # ==Usage of line.stations << station
52
+ # line = CF::Line.new("line name")
53
+ # station = CF::Station.new({:type => "Work"})
54
+ # line.stations station
55
+ #
56
+ # * returns
57
+ # line.stations as an array of stations
58
+ def stations stations = nil
59
+ if stations
60
+ type = stations.type
61
+ @station_input_formats = stations.station_input_formats
62
+ if type == "Improve" && self.stations.size < 1
63
+ raise ImproveStationNotAllowed.new("You cannot add Improve Station as a first station of a line")
64
+ else
65
+ request_general =
66
+ {
67
+ :body =>
68
+ {
69
+ :api_key => CF.api_key,
70
+ :station => {:type => type, :input_formats => @station_input_formats}
71
+ }
72
+ }
73
+ if type == "Tournament"
74
+ @jury_worker = stations.jury_worker
75
+ @auto_judge = stations.auto_judge
76
+ request_tournament =
77
+ {
78
+ :body =>
79
+ {
80
+ :api_key => CF.api_key,
81
+ :station => {:type => type, :jury_worker => @jury_worker, :auto_judge => @auto_judge, :input_formats => @station_input_formats}
82
+ }
83
+ }
84
+ resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{self.title.downcase}/stations.json",request_tournament)
85
+ else
86
+ resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{self.title.downcase}/stations.json",request_general)
87
+ end
88
+ station = CF::Station.new()
89
+ resp.to_hash.each_pair do |k,v|
90
+ station.send("#{k}=",v) if station.respond_to?(k)
91
+ end
92
+ station.line = self
93
+ station.line_title = self.title
94
+ if resp.response.code != "200"
95
+ station.errors = resp.parsed_response['error']['message']
96
+ end
97
+ @stations << station
98
+ end
99
+ else
100
+ @stations
101
+ end
102
+ end
103
+
104
+ def << stations #:nodoc:
105
+ type = stations.type
106
+ @stations << stations
107
+ resp = CF::Station.post("/lines/#{self.id}/stations.json", :station => {:type => type})
108
+ end
109
+
110
+
111
+ def stations=(stations) # :nodoc:
112
+ @stations << stations
113
+ #resp = CF::Station.post("/lines/#{id}/stations.json", :station => {:type => stations.type})
114
+ #@station_id = resp._id
115
+ end
116
+
117
+ # ==Initializes a new line
118
+ # ==Usage of line.create("line_name") do |block|
119
+ # ===creating Line within block using variable
120
+ # Line.create("line_name") do |line|
121
+ # CF::InputFormat.new({:line => line, :label => "image_url", :field_type => "text_data", :value => "http://s3.amazon.com/bizcardarmy/medium/1.jpg", :required => true, :validation_format => "url"})
122
+ # CF::Station.new({:line => line, :type => "Work"})
123
+ # end
124
+ #
125
+ # ===OR creating without variable
126
+ # CF::Line.create("line_name") do
127
+ # CF::InputFormat.new({:line => self, :label => "image_url", :field_type => "text_data", :value => "http://s3.amazon.com/bizcardarmy/medium/1.jpg", :required => true, :validation_format => "url"})
128
+ # CF::Station.new({:line => self, :type => "Work"})
129
+ # end
130
+ def self.create(title, department_name, options={}, &block)
131
+ line = Line.new(title,department_name,options={})
132
+ @public = options[:public]
133
+ @description = options[:description]
134
+ if block.arity >= 1
135
+ block.call(line)
136
+ else
137
+ line.instance_eval &block
138
+ end
139
+ line
140
+ end
141
+
142
+ # ==Usage of line.input_formats(input_format)
143
+ # line = Line.new("line name", "Survey")
144
+ #
145
+ # input_format = CF::InputFormat.new({:label => "image_url", :field_type => "text_data", :value => "http://s3.amazon.com/bizcardarmy/medium/1.jpg", :required => true, :validation_format => "url"})
146
+ # line.input_formats input_format
147
+ # * returns
148
+ # line.input_formats as an array of input_formats
149
+ def input_formats input_formats_value = nil
150
+ if input_formats_value
151
+ name = input_formats_value.name
152
+ required = input_formats_value.required
153
+ valid_type = input_formats_value.valid_type
154
+ resp = CF::InputFormat.post("/lines/#{CF.account_name}/#{self.title.downcase}/input_formats.json", :input_format => {:name => name, :required => required, :valid_type => valid_type})
155
+ input_format = CF::InputFormat.new()
156
+ resp.each_pair do |k,v|
157
+ input_format.send("#{k}=",v) if input_format.respond_to?(k)
158
+ end
159
+ if resp.code != 200
160
+ input_format.errors = resp.error.message
161
+ end
162
+ @input_formats << input_format
163
+ else
164
+ @input_formats
165
+ end
166
+ end
167
+ def input_formats=(input_formats_value) # :nodoc:
168
+ @input_formats << input_formats_value
169
+ end
170
+
171
+ # ==Returns the content of a line by making an Api call
172
+ # ===Syntax for get_line method is
173
+ # CF::Line.info(line)
174
+ def self.info(line)
175
+ if line.class == CF::Line
176
+ resp = get("/lines/#{CF.account_name}/#{line.title.downcase}.json")
177
+ else
178
+ resp = get("/lines/#{CF.account_name}/#{line.downcase}.json")
179
+ end
180
+ end
181
+
182
+ # ==Finds a line
183
+ # ===Syntax for find method is
184
+ # CF::Line.find(line.id)
185
+ def self.find(line_id)
186
+ get("/lines/#{line_id}.json")
187
+ end
188
+ # ==Returns all the lines of an account
189
+ # ===Syntax for all method is
190
+ # CF::Line.all
191
+ def self.all
192
+ get("/lines/#{CF.account_name}.json")
193
+ end
194
+
195
+ def get_stations
196
+ CF::Station.get("/lines/#{ACCOUNT_NAME}/#{self.title.downcase}/stations.json")
197
+ end
198
+ # ==Return all the lines whose public value is set true
199
+ # ===Syntax for public_lines method is
200
+ # CF::Line.public_lines
201
+ def self.public_lines
202
+ get("/public_lines.json")
203
+ end
204
+
205
+ # ==Updates a line
206
+ # ===Syntax for update method is
207
+ # line = CF::Line.new("Digitize Card", "Survey")
208
+ # line.update({:title => "New Title"})
209
+ # * This changes the title of the "line" object from "Digitize Card" to "New Title"
210
+ def update(options={})
211
+ old_title = self.title
212
+ @title = options[:title]
213
+ @department_name = options[:department_name]
214
+ @public = options[:public]
215
+ @description = options[:description]
216
+ self.class.put("/lines/#{CF.account_name}/#{old_title.downcase}.json", :line => {:title => @title, :department_name => @department_name, :public => @public, :description => @description})
217
+ end
218
+
219
+ # ==Deletes a line
220
+ # ===Syantax for delete method
221
+ # line = CF::Line.new("Digitize Card", "Survey")
222
+ # line.delete
223
+ def destroy
224
+ self.class.delete("/lines/#{CF.account_name}/#{self.title.downcase}.json")
225
+ end
226
+
227
+ def self.destroy(title)
228
+ delete("/lines/#{CF.account_name}/#{title.downcase}.json")
229
+ end
230
+ end
231
+ end
@@ -0,0 +1,31 @@
1
+ module CF
2
+ class RobotWorker
3
+ require 'httparty'
4
+ include Client
5
+
6
+ # type of the station, e.g. station = Station.new(line, {:type => "Work"})
7
+ attr_accessor :settings, :type, :errors, :station, :number, :reward
8
+
9
+ def initialize(options={})
10
+ @type = options[:type].nil? ? nil : options[:type].camelize
11
+ @settings = options[:settings]
12
+ station = options[:station]
13
+
14
+ if station
15
+ request = options[:settings].merge(:type => @type)
16
+ resp = self.class.post("/lines/#{CF.account_name}/#{station.line_title.downcase}/stations/#{station.index}/workers.json", :worker => request)
17
+ if resp.code != 200
18
+ self.errors = resp.error.message
19
+ end
20
+ self.number = resp.number
21
+ self.reward = resp.reward
22
+ self.station = station
23
+ station.worker = self
24
+ end
25
+ end
26
+
27
+ def self.create(options)
28
+ RobotWorker.new(options)
29
+ end
30
+ end
31
+ end
data/lib/cf/run.rb ADDED
@@ -0,0 +1,158 @@
1
+ module CF
2
+ class Run
3
+ require 'httparty'
4
+ include Client
5
+
6
+ # title of the "run" object
7
+ attr_accessor :title
8
+
9
+ # file attributes to upload
10
+ attr_accessor :file, :input
11
+
12
+ # line attribute with which run is associated
13
+ attr_accessor :line
14
+
15
+ attr_accessor :id, :errors
16
+
17
+ # ==Initializes a new Run
18
+ # ==Usage Example:
19
+ #
20
+ # line = CF::Line.create("Digitize Card","Digitization") do |l|
21
+ # CF::InputHeader.new({:label => "Company", :field_type => "text_data", :value => "Google", :required => true, :validation_format => "general"})
22
+ # CF::InputHeader.new({:label => "Website", :field_type => "text_data", :value => "www.google.com", :required => true, :validation_format => "url"})
23
+ # CF::Station.create({:line => l, :type => "work") do |s|
24
+ # CF::HumanWorker.new({:station => s, :number => 1, :reward => 20)
25
+ # CF::StandardInstruction.create(:station => s, :title => "Enter text from a business card image", :description => "Describe"}) do |i|
26
+ # CF::FormField.new({:instruction => i, :label => "First Name", :field_type => "SA", :required => "true"})
27
+ # CF::FormField.new({:instruction => i, :label => "Middle Name", :field_type => "SA"})
28
+ # CF::FormField.new({:instruction => i, :label => "Last Name", :field_type => "SA", :required => "true"})
29
+ # end
30
+ # end
31
+ # end
32
+ #
33
+ # run = CF::Run.new(line, "run name", File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
34
+ def initialize(line, title, input)
35
+ @line = line
36
+ @title = title
37
+ if File.exist?(input.to_s)
38
+ @file = input
39
+ @param_data = File.new(input, 'rb')
40
+ @param_for_input = :file
41
+ resp = self.class.post("/lines/#{CF.account_name}/#{@line.title.downcase}/runs.json", {:data => {:run => {:title => @title}}, @param_for_input => @param_data})
42
+ if resp.code != 200
43
+ self.errors = resp.error.message
44
+ end
45
+ else
46
+ @input = input
47
+ @param_data = input
48
+ @param_for_input = :inputs
49
+ options =
50
+ {
51
+ :body =>
52
+ {
53
+ :api_key => CF.api_key,
54
+ :data =>{:run => { :title => @title }, :inputs => @param_data}
55
+ }
56
+ }
57
+ run = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@line.title.downcase}/runs.json",options)
58
+ if run.code != 200
59
+ self.errors = run.parsed_response['error']['message']
60
+ end
61
+ end
62
+ end
63
+
64
+ # ==Creates a new Run
65
+ # ==Usage Example:
66
+ #
67
+ # line = CF::Line.create("Digitize Card","Digitization") do |l|
68
+ # CF::InputHeader.new({:line => l, :label => "Company", :field_type => "text_data", :value => "Google", :required => true, :validation_format => "general"})
69
+ # CF::InputHeader.new({:line => l, :label => "Website", :field_type => "text_data", :value => "www.google.com", :required => true, :validation_format => "url"})
70
+ # CF::Station.create({:line => l, :type => "work") do |s|
71
+ # CF::HumanWorker.new({:station => s, :number => 1, :reward => 20)
72
+ # CF::StandardInstruction.create(:station => s, :title => "Enter text from a business card image", :description => "Describe"}) do |i|
73
+ # CF::FormField.new({:instruction => i, :label => "First Name", :field_type => "SA", :required => "true"})
74
+ # CF::FormField.new({:instruction => i, :label => "Middle Name", :field_type => "SA"})
75
+ # CF::FormField.new({:instruction => i, :label => "Last Name", :field_type => "SA", :required => "true"})
76
+ # end
77
+ # end
78
+ # end
79
+ #
80
+ # run = CF::Run.create(line, "run name", File.expand_path("../../fixtures/input_data/test.csv", __FILE__))
81
+ def self.create(line, title, file)
82
+ Run.new(line, title, file)
83
+ end
84
+
85
+ def get # :nodoc:
86
+ self.class.get("/lines/#{@line.id}/runs/#{@id}.json")
87
+ end
88
+
89
+ def self.get_final_output(run_id)
90
+ resp = get("/runs/#{run_id}/final_outputs.json")
91
+
92
+ @final_output =[]
93
+ resp.each do |r|
94
+ result = FinalOutput.new()
95
+ r.to_hash.each_pair do |k,v|
96
+ result.send("#{k}=",v) if result.respond_to?(k)
97
+ end
98
+ @final_output << result
99
+ end
100
+ return @final_output
101
+ end
102
+
103
+ def final_output
104
+ resp = self.class.get("/runs/#{CF.account_name}/#{self.title.downcase}/output.json")
105
+ @final_output =[]
106
+ resp['output'].each do |r|
107
+ result = FinalOutput.new()
108
+ r.to_hash.each_pair do |k,v|
109
+ result.send("#{k}=",v) if result.respond_to?(k)
110
+ end
111
+ if result.final_output == nil
112
+ result.final_output = resp.output
113
+ end
114
+ @final_output << result
115
+ end
116
+ return @final_output
117
+ end
118
+
119
+ def self.final_output(title)
120
+ resp = get("/runs/#{CF.account_name}/#{title.downcase}/output.json")
121
+ @final_output =[]
122
+ resp['output'].each do |r|
123
+ result = FinalOutput.new()
124
+ r.to_hash.each_pair do |k,v|
125
+ result.send("#{k}=",v) if result.respond_to?(k)
126
+ end
127
+ if result.final_output == nil
128
+ result.final_output = resp.output
129
+ end
130
+ @final_output << result
131
+ end
132
+ return @final_output
133
+ end
134
+
135
+ def self.output(options={})
136
+ station_no = options[:station]
137
+ title = options[:title]
138
+ resp = get("/runs/#{CF.account_name}/#{title.downcase}/output/#{station_no}.json")
139
+ return resp['output'].first.to_hash
140
+ end
141
+
142
+ def output(options={})
143
+ station_no = options[:station]
144
+ resp = self.class.get("/runs/#{CF.account_name}/#{self.title.downcase}/output/#{station_no}.json")
145
+ return resp['output'].first.to_hash
146
+ end
147
+
148
+ def self.find(title)
149
+ resp = get("/runs/#{CF.account_name}/#{title.downcase}.json")
150
+ if resp.code != 200
151
+ resp.error = resp.error.message
152
+ resp.merge!(:errors => "#{resp.error}")
153
+ resp.delete(:error)
154
+ end
155
+ return resp
156
+ end
157
+ end
158
+ end