Class: Shin::Data::Viasat

Inherits:
Object
  • Object
show all
Defined in:
lib/shin/data/viasat.rb

Defined Under Namespace

Classes: HTTPError, NotValid

Instance Method Summary collapse

Instance Method Details

#images(params = {}) ⇒ Object

Raises:

  • (MissingArgument)


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
  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
  
  # Its splitted by newlines
  data = response.body.split( /\r?\n/ ) rescue nil
  
  # Just check to be sure
  if data != nil and data != "" and data.kind_of?(Array)
    # For each do this
    array = {portrait: nil, landscape: nil, all: []}
    
    data.each do |d|
      url, width, height, image_type, removed = d.split(",")
      # Just return one
      if image_type == 'portrait' and array[:portrait] == nil
        array[:portrait] = url
      elsif image_type == 'landscape' and array[:landscape] == nil
        array[:landscape] = url
      else
        # We don't add the ones already specified above.
        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

#newObject



7
8
9
# File 'lib/shin/data/viasat.rb', line 7

def new
  self
end