Class: Shin::Play::Viaplay
- Inherits:
-
Object
- Object
- Shin::Play::Viaplay
- Defined in:
- lib/shin/play/viaplay.rb
Defined Under Namespace
Classes: HTTPError, MissingArgument, NotValid
Instance Method Summary collapse
-
#before(params = {}) ⇒ Object
Fix these before running.
-
#movies(params = {}) ⇒ Object
Movies.
- #new ⇒ Object
-
#rental_movies(params = {}) ⇒ Object
Rental movies.
-
#series(params = {}) ⇒ Object
Series.
Instance Method Details
#before(params = {}) ⇒ Object
Fix these before running
11 12 13 14 15 |
# File 'lib/shin/play/viaplay.rb', line 11 def before(params={}) raise MissingArgument, "You are missing the argument 'viaplay_country' which is required to use this source." unless Shin.get[:viaplay_country] != nil "https://content.viaplay." + Shin.get[:viaplay_country] + "/pcdash-" + Shin.get[:viaplay_country] + "/" end |
#movies(params = {}) ⇒ Object
Movies
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/shin/play/viaplay.rb', line 67 def movies(params={}) # domain domain = before() country = Shin.get[:viaplay_country] # Translated shit type = "kaikki" if country == "fi" type = "alle" if country == "dk" or country == "no" type = "samtliga" if country == "se" if params[:page] != nil id = type + "?pageNumber=" + params[:page].to_s + "&sort=recently_added" elsif params[:id] != nil id = params[:id].to_s else id = type + "?sort=recently_added" end # Response if country == "fi" response = Base.get(domain + 'leffat/' + id) elsif country == "no" response = Base.get(domain + 'filmer/' + id) else response = Base.get(domain + 'film/' + id) end 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['_embedded']['viaplay:blocks'].to_hashugar else raise NotValid, "Couldn't parse the JSON" end end |
#new ⇒ Object
6 7 8 |
# File 'lib/shin/play/viaplay.rb', line 6 def new self end |
#rental_movies(params = {}) ⇒ Object
Rental movies
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/shin/play/viaplay.rb', line 111 def rental_movies(params={}) # domain domain = before() country = Shin.get[:viaplay_country] # Translated shit type = "kaikki" if country == "fi" type = "alle" if country == "dk" or country == "no" type = "samtliga" if country == "se" if params[:page] != nil id = type + "?pageNumber=" + params[:page].to_s + "&sort=recently_added" elsif params[:id] != nil id = params[:id].to_s else id = type + "?sort=recently_added" end # Response if country == "fi" response = Base.get(domain + 'vuokraamo/' + id) elsif country == "dk" response = Base.get(domain + 'lejebutik/' + id) elsif country == "no" response = Base.get(domain + 'leiebutikk/' + id) else response = Base.get(domain + 'hyrbutik/' + id) end 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['_embedded']['viaplay:blocks'].to_hashugar else raise NotValid, "Couldn't parse the JSON" end end |
#series(params = {}) ⇒ Object
Series
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/shin/play/viaplay.rb', line 18 def series(params={}) # domain domain = before() country = Shin.get[:viaplay_country] # Translated shit type = "kaikki" if country == "fi" type = "alle" if country == "dk" or country == "no" type = "samtliga" if country == "se" # URLs if params[:page] != nil id = type + "?pageNumber=" + params[:page].to_s + "&sort=recently_added" elsif params[:season] != nil id = params[:id] + "?seasonNumber=" + params[:season].to_s + "&partial=1&block=2" elsif params[:id] != nil id = params[:id].to_s else id = type + "?sort=recently_added" end # Response if country == "fi" response = Base.get(domain + 'sarjat/' + id) else response = Base.get(domain + 'serier/' + id) end 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 # Episodes for a seaosn is in products, not blocks. if params[:season] != nil data['_embedded']['viaplay:products'].to_hashugar else data['_embedded']['viaplay:blocks'].to_hashugar end else raise NotValid, "Couldn't parse the JSON" end end |