netflix_roulette 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +8 -8
  2. data/lib/netflix_roulette.rb +74 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZDZjMWY3NWY3MmNkZTg1YjI2NTNhNTVkOWUyOWRiYzljMjBmNzM0Zg==
4
+ YzU1ZjI0YTZlNDliMGNhNWEyNjk5MTM5OWRmNzZmYzdhMGM0MzljOA==
5
5
  data.tar.gz: !binary |-
6
- MWIzMmE3MDE1MjViM2JkNGI1NWQ5ZGM2NzAzODg0M2RlOWUwZTg0OA==
6
+ YzY2OTNiZmIyYjlmODJjNjBkMmM1Yjk2ZGMyMmZlZTgwZjA4OWEzNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzUyYjhjOGE4NzJhYWVlZDZkOWJlZjRhMDVjN2E2MmI3OTM2ZTI4OTE1Y2Q4
10
- NmI2ZTg2YTRlNGVmN2E2Y2RmYmZmZWZhYTdkMDA2NTg2Nzc4YTUyMTdmODVi
11
- NGJlYjMxZDA1ZmZiOTA2OGUwOGE3NjhkNmJkYzk2MzkwZmMyYzE=
9
+ ZDQyYjlkYTM3MWNhZmI0NTlmMWFlOThhMzY4OTM1NjdlZDE0MDUyZTc0YzE2
10
+ ZWVhYTIxY2E4MTMzZTYxZWI5OGIzYWVhOGVjMzk0Y2IyNzBiOTk0MTkzNjRi
11
+ MDllMmUwYTVjN2I1NWZkYWI3YWQzNjZkYWU5Yjk2MmZjNzYxMTk=
12
12
  data.tar.gz: !binary |-
13
- NGQ4M2JlMzk3NTUwMjU4NDU3Nzg5MDJhZDI4MGI5YzllOGJhZDlkZDBiYTk0
14
- NjVjYjY3NzNhMDE5MzliMzBlZDM4NjQwMjUwZmQ3NGY3NWZlNGRhZjYwMDQ5
15
- NDQxZTE1ZDgzMjViMDRmOTQ4OGY1MjI0MWM4NWE3MmViMzM3ZGM=
13
+ OGVjNGNlMmRmZGFmNGIxZWE2MTliMDVjOGZmM2FhMzMzMmI5NWZkYjllYzQ5
14
+ MjliODdhYjg2ZDRkNGVlYjIyZDFkMjVhZTE2OTg0ODJiYTE5NmEyNjRhZmFm
15
+ YzYzNzdlY2RjMzAyZjM5NDhlOTc4MTdmYjIzNmI4ODkwZTVjYWE=
@@ -0,0 +1,74 @@
1
+ require "net/http"
2
+ require "json"
3
+
4
+ class NetflixRoulette
5
+ class << self
6
+ {
7
+ get_media_rating: "rating",
8
+ get_media_poster: "poster",
9
+ get_media_type: "mediatype",
10
+ get_media_release_year: "release_year",
11
+ get_media_cast: "show_cast",
12
+ get_media_category: "category",
13
+ get_media_summary: "summary",
14
+ get_media_director: "director",
15
+ get_netflix_id: "show_id"
16
+ }.each_pair do |method_name, key|
17
+ define_method method_name do |title, year = 0|
18
+ client(title, year).fetch[key] || "Unable to locate data"
19
+ end
20
+ end
21
+
22
+ def get_all_data(title, year = 0)
23
+ client(title, year).fetch
24
+ end
25
+
26
+ def get_version
27
+ Client::API_VERSION
28
+ end
29
+
30
+ private
31
+
32
+ def client(title, year)
33
+ Client.new(title, year)
34
+ end
35
+ end
36
+
37
+ class Client
38
+ API_URL = URI("http://netflixroulette.net/api/api.php")
39
+ API_VERSION = "5.0"
40
+
41
+ attr_accessor :title, :year
42
+
43
+ def initialize(title, year = 0)
44
+ @title = title
45
+ @year = year
46
+ end
47
+
48
+ def version
49
+ API_VERSION
50
+ end
51
+
52
+ def fetch
53
+ uri = API_URL
54
+ uri.query = URI.encode_www_form({ title: title, year: year })
55
+ response = Net::HTTP.get_response uri
56
+
57
+ result = JSON.parse response.body
58
+ end
59
+ end
60
+ end
61
+
62
+ # nr = NetflixRoulette::Client.new "Breaking Bad"
63
+ # puts nr.fetch
64
+ #
65
+ # puts NetflixRoulette.get_media_rating("Breaking Bad")
66
+ # puts NetflixRoulette.get_media_poster("Breaking Bad")
67
+ # puts NetflixRoulette.get_media_type("Breaking Bad")
68
+ # puts NetflixRoulette.get_media_release_year("Breaking Bad")
69
+ # puts NetflixRoulette.get_media_cast("Breaking Bad")
70
+ # puts NetflixRoulette.get_media_category("Breaking Bad")
71
+ # puts NetflixRoulette.get_media_summary("Breaking Bad")
72
+ # puts NetflixRoulette.get_media_director("Breaking Bad")
73
+ # puts NetflixRoulette.get_netflix_id("Breaking Bad")
74
+ # puts NetflixRoulette.get_all_data("Breaking Bad")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netflix_roulette
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Österreicher