Class: Shin::Play::Tv4play
- Inherits:
-
Object
- Object
- Shin::Play::Tv4play
- Defined in:
- lib/shin/play/tv4play.rb
Defined Under Namespace
Classes: HTTPError, MissingArgument, NotValid
Instance Method Summary collapse
-
#movies ⇒ Object
Movies.
- #new ⇒ Object
-
#programs ⇒ Object
Programs.
-
#video(params = {}) ⇒ Object
Video.
-
#videos(params = {}) ⇒ Object
Videos.
Instance Method Details
#movies ⇒ Object
Movies
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/shin/play/tv4play.rb', line 73 def movies # Response response = Base.get('http://webapi.tv4play.se/play/movie_assets?platform=web&start=0&rows=9999') 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['results'].to_hashugar else raise NotValid, "Couldn't parse the JSON" end end |
#new ⇒ Object
6 7 8 |
# File 'lib/shin/play/tv4play.rb', line 6 def new self end |
#programs ⇒ Object
Programs
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/shin/play/tv4play.rb', line 11 def programs # Response response = Base.get('http://webapi.tv4play.se/play/programs?per_page=900&page=1') 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['results'].to_hashugar else raise NotValid, "Couldn't parse the JSON" end end |
#video(params = {}) ⇒ Object
Video
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/shin/play/tv4play.rb', line 49 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://webapi.tv4play.se/play/video_assets?id=' + 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 if data['total_hits'] == 0 raise NotValid, "No results" else data['results'].first.to_hashugar end else raise NotValid, "Couldn't parse the JSON" end end |
#videos(params = {}) ⇒ Object
Videos
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/shin/play/tv4play.rb', line 29 def videos(params={}) raise MissingArgument, "You are missing the argument 'id' which is required to use this source." unless params[:id] != "" # Response response = Base.get('http://webapi.tv4play.se/play/video_assets?type=episode&is_live=false&platform=web&per_page=99999&node_nids=' + 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['results'].to_hashugar else raise NotValid, "Couldn't parse the JSON" end end |