41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/cf/station.rb', line 41
def initialize(options={})
@input_formats =[]
@badges = []
@line_title = options[:line].nil? ? nil : options[:line].title
@type = options[:type].nil? ? nil : options[:type].camelize
@jury_worker = options[:jury_worker]
@auto_judge = options[:auto_judge]
@station_input_formats = options[:input_formats]
@line_instance = options[:line]
@batch_size = options[:batch_size]
@gold_standards = []
@gold_fields = options[:gold_fields]
@acceptance_ratio = options[:acceptance_ratio]
if @batch_size.nil?
request_general =
{
:body =>
{
:api_key => CF.api_key,
:station => {:type => @type, :input_formats => @station_input_formats, :gold_fields => @gold_fields}
}
}
if @acceptance_ratio.nil?
request_tournament =
{
:body =>
{
:api_key => CF.api_key,
:station => {:type => @type, :jury_worker => @jury_worker, :auto_judge => @auto_judge, :input_formats => @station_input_formats, :gold_fields => @gold_fields}
}
}
else
request_tournament =
{
:body =>
{
:api_key => CF.api_key,
:station => {:type => @type, :jury_worker => @jury_worker, :auto_judge => @auto_judge, :input_formats => @station_input_formats, :acceptance_ratio => @acceptance_ratio, :gold_fields => @gold_fields}
}
}
end
else
request_general =
{
:body =>
{
:api_key => CF.api_key,
:station => {:type => @type, :input_formats => @station_input_formats, :batch_size => @batch_size, :gold_fields => @gold_fields}
}
}
if @acceptance_ratio.nil?
request_tournament =
{
:body =>
{
:api_key => CF.api_key,
:station => {:type => @type, :jury_worker => @jury_worker, :auto_judge => @auto_judge, :input_formats => @station_input_formats, :batch_size => @batch_size, :gold_fields => @gold_fields}
}
}
else
request_tournament =
{
:body =>
{
:api_key => CF.api_key,
:station => {:type => @type, :jury_worker => @jury_worker, :auto_judge => @auto_judge, :input_formats => @station_input_formats, :batch_size => @batch_size, :acceptance_ratio => @acceptance_ratio, :gold_fields => @gold_fields}
}
}
end
end
if @line_title
if @type == "Improve"
line = options[:line]
if line.stations.size < 1
raise ImproveStationNotAllowed.new("You cannot add Improve Station as a first station of a line")
else
resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@line_instance.title.downcase}/stations.json",request_general)
end
elsif @type == "Tournament"
resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@line_instance.title.downcase}/stations.json",request_tournament)
else
resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@line_instance.title.downcase}/stations.json",request_general)
end
resp.to_hash.each_pair do |k,v|
self.send("#{k}=",v) if self.respond_to?(k)
end
@line_instance.stations = self
if resp.response.code != "200"
self.errors = resp.parsed_response['error']['message']
end
end
end
|