Class: Shin::Play::Viasat

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

Defined Under Namespace

Classes: HTTPError, MissingArgument, NotValid

Instance Method Summary collapse

Instance Method Details

#channels(params = {}) ⇒ Object

Channels

Raises:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/shin/play/viasat.rb', line 36

def channels(params={})
  params[:page] ||= 1
  
  # Response
  response = Base.get('http://playapi.mtgx.tv/v3/channels?' + URI.encode_www_form(params))
  raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
  
  # Return this
  ret = {page: nil, total_pages: nil, results: []}

  # Data
  data = Oj.load(response.body) rescue nil
  
  # Can't be nil
  if data != nil
    ret[:page] = data['count']['page'].to_i
    ret[:total_pages] = data['count']['total_pages'].to_i
    ret[:results] = data["_embedded"]['channels']
    
    ret.to_hashugar
  else
    raise NotValid, "Couldn't parse the JSON"
  end

end

#newObject



6
7
8
# File 'lib/shin/play/viasat.rb', line 6

def new
  self
end

#video(params = {}) ⇒ Object

Video

Raises:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/shin/play/viasat.rb', line 63

def video(params={})
  raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
  
  # Response
  response = Base.get('http://playapi.mtgx.tv/v3/videos/' + params[:id].to_s)
  raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
  
  # Data
  data = Oj.load(response.body) rescue nil
  
  # Can't be nil
  if data != nil
    data.to_hashugar
  else
    raise NotValid, "Couldn't parse the JSON"
  end
end

#videos(params = {}) ⇒ Object

Videos

Raises:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/shin/play/viasat.rb', line 11

def videos(params={})
  # Response
  response = Base.get('http://playapi.mtgx.tv/v3/videos?' + URI.encode_www_form(params))
  raise HTTPError, "The response didn't have a 200 HTTP Code. It had #{response.code}." unless response.code == 200
  
  # Return this
  ret = {page: nil, total_pages: nil, results: []}

  # Data
  data = Oj.load(response.body) rescue nil
  
  # Can't be nil
  if data != nil
    ret[:page] = data['count']['page'].to_i
    ret[:total_pages] = data['count']['total_pages'].to_i
    ret[:results] = data["_embedded"]['videos']
    
    ret.to_hashugar
  else
    raise NotValid, "Couldn't parse the JSON"
  end
  
end