12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/lh2gh.rb', line 12
def submit(path, params = {}, klass=nil, format = :yaml, &block)
cache = params.delete(:cache)
cache = true if cache.nil?
cache = false
params.each_pair do |k,v|
if path =~ /:#{k.to_s}/
params.delete(k)
path = path.gsub(":#{k.to_s}", v)
end
end
begin
key = "#{Api.api.class.to_s}:#{path}"
resp = if cache
APICache.get(key, :cache => 61) do
yield(path, params, format, auth_parameters)
end
else
yield(path, params, format, auth_parameters)
end
rescue Net::HTTPBadResponse
raise RetryableAPIError
end
raise RetryableAPIError, resp.code.to_i if RETRYABLE_STATUS.include? resp.code.to_i
raise NotFound, klass || self.class if resp.code.to_i == 404
raise APIError,
"GitHub returned status #{resp.code}" unless ((resp.code.to_i == 200) || (resp.code.to_i == 201))
return resp if resp..empty?
content_type = Array === resp.['content-type'] ? resp.['content-type'] : [resp.['content-type']]
ctype = content_type.first.split(";").first
raise FormatError, [ctype, format] unless CONTENT_TYPE[format.to_s].include?(ctype)
if format == 'yaml' && resp['error']
raise APIError, resp['error']
end
resp
end
|