Class: Shin::Play::Sbstv

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

Defined Under Namespace

Classes: HTTPError, MissingArgument, NotValid

Instance Method Summary collapse

Instance Method Details

#before(params = {}) ⇒ Object

Fix these before running

Raises:



13
14
15
16
17
# File 'lib/shin/play/sbstv.rb', line 13

def before(params={})
  raise MissingArgument, "You are missing the argument 'sbstv_domain' which is required to use this source." unless Shin.get[:sbstv_domain] != nil
  
  "http://www." + Shin.get[:sbstv_domain]
end

#newObject



8
9
10
# File 'lib/shin/play/sbstv.rb', line 8

def new
  self
end

#programsObject

Programs

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/shin/play/sbstv.rb', line 20

def programs
  domain = before()
  
  # Response
  response = Base.get(domain + '/api/listPrograms?format=FLASH')
  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
  
  # Multiple
  if data != nil
    data.to_hashugar
  else
    raise NotValid, "Couldn't parse the JSON"
  end
end

#video(params = {}) ⇒ Object

Video

Raises:



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/shin/play/sbstv.rb', line 59

def video(params={})
  domain = before(params)
  raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
  
  # Response
  response = Base.get(domain + '/api/getVideo?format=FLASH&videoId=' + 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:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/shin/play/sbstv.rb', line 39

def videos(params={})
  domain = before(params)
  raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != ""
  
  # Response
  response = Base.get(domain + '/api/listVideos?format=FLASH&programId=' + 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
  
  # Multiple
  if data != nil
    data.to_hashugar
  else
    raise NotValid, "Couldn't parse the JSON"
  end
end