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
|
# File 'lib/shin/data/viasat.rb', line 12
def images(params={})
raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
response = Base.get('http://se.press.viasat.tv/export?id=' + params[:id].to_s + '&enhancedinfo=true')
raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
data = response.body.split( /\r?\n/ ) rescue nil
if data != nil and data != "" and data.kind_of?(Array)
array = {portrait: nil, landscape: nil, all: []}
data.each do |d|
url, width, height, image_type, removed = d.split(",")
if image_type == 'portrait' and array[:portrait] == nil
array[:portrait] = url
elsif image_type == 'landscape' and array[:landscape] == nil
array[:landscape] = url
else
array[:all] << {url: url, width: width, height: height, type: image_type}
end
end
array.to_hashugar
else
raise NotValid, "We failed to parse the document."
end
end
|