-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplexTv.rb
More file actions
48 lines (42 loc) · 1.12 KB
/
plexTv.rb
File metadata and controls
48 lines (42 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
#!/usr/bin/ruby
require 'rubygems'
require 'json'
require 'httparty'
class PlexTv
include HTTParty
base_uri 'http://plex.tv/'
format :xml
def initialize(config)
if !config.empty?
if !config['plex']['api_key'].empty?
$token = config['plex']['api_key']
else
if defined? $logger
$logger.error("Missing Plex token")
end
end
end
end
def get(query, auth=nil, token_check=false)
if !token_check
new_query = query + "?X-Plex-Token=#{$token}"
else
new_query = query
end
if auth.nil?
response = self.class.get(new_query)
else
response = self.class.get(new_query, :basic_auth => auth)
end
if response.code != 200
if response.code == 401
puts "Invalid plex.tv credentials"
abort
else
puts "Cannot connect to plex.tv! Change your connection."
abort
end
end
return response
end
end