Class: Shin::Play::Dplay

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

Defined Under Namespace

Classes: HTTPError, MissingArgument, NotValid

Instance Method Summary collapse

Instance Method Details

#before(params = {}) ⇒ Object

Fix these before running

Raises:



12
13
14
15
16
# File 'lib/shin/play/dplay.rb', line 12

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

  "http://www.dplay." + Shin.get[:dplay_code]
end

#module(params = {}) ⇒ Object

Module (added recently)

Raises:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/shin/play/dplay.rb', line 77

def module(params={})
  domain = before()

  # Response
  response = Base.get(domain + '/api/v2/ajax/modules?' + URI.encode_www_form(params))
  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

#newObject



7
8
9
# File 'lib/shin/play/dplay.rb', line 7

def new
  self
end

#program(params = {}) ⇒ Object

Program

Raises:



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

def program(params={})
  raise MissingArgument, "You are missing the argument 'show_id' which is required to use this source." unless params[:show_id] != ""
  domain = before()

  # Response
  response = Base.get(domain + '/api/v2/ajax/shows/' + params[:show_id].to_s + '?show_id=' + params[:show_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

#programs(params = {}) ⇒ Object

Programs

Raises:



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

def programs(params={})
  domain = before()

  # Response
  response = Base.get(domain + '/api/v2/ajax/shows?' + URI.encode_www_form(params))
  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

#videos(params = {}) ⇒ Object

Videos

Raises:



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

def videos(params={})
  domain = before()

  # Response
  response = Base.get(domain + '/api/v2/ajax/shows/' + params[:show_id] + '/seasons?' + URI.encode_www_form(params))
  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