tvteka 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tvteka/api.rb +78 -0
- data/lib/tvteka/client.rb +4 -8
- metadata +3 -4
- data/lib/tvteka/request.rb +0 -68
- data/lib/tvteka/response.rb +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a59fcaa24b02b6422aab41f7aa6c14e1722dd603
|
4
|
+
data.tar.gz: 1d72a076f585b9fd03f56c0505e9149ad907892e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8933db3a7a16462e1ecb6bbde65e7e7a34c8a4cac92cf64a87a219a8c9dd5861064d7397503397b3b85cb697959a2e90e7da0b0961964173f6ed38154775e0ee
|
7
|
+
data.tar.gz: 4938b59afb053b4552c1a373d9f73e3fca0a36fc0f6ea3d6dbdba8778e2f6977d7d5fa57d553714f4820d5fe87d9dc6187b849291090366458f7910bc2732919
|
data/lib/tvteka/api.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
module Tvteka
|
2
|
+
class API
|
3
|
+
|
4
|
+
def get(request_type, url, params, &block)
|
5
|
+
cookies = params.delete(:cookies)
|
6
|
+
params = params.to_a.map {|p| "#{p[0]}=#{p[1]}" }.join("&")
|
7
|
+
request = create_request(url + "?" + params, :get)
|
8
|
+
add_cookies(request, cookies) if cookies
|
9
|
+
create_task(request_type, request, &block).resume
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def config
|
15
|
+
NSURLSessionConfiguration.defaultSessionConfiguration
|
16
|
+
end
|
17
|
+
|
18
|
+
def session
|
19
|
+
NSURLSession.sessionWithConfiguration(config)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_request(url, method)
|
23
|
+
url = NSURL.URLWithString(url)
|
24
|
+
request = NSMutableURLRequest.requestWithURL(url)
|
25
|
+
request.addValue("application/vnd.tvp.xbmc+json", forHTTPHeaderField: "Content-Type")
|
26
|
+
request.addValue("application/vnd.tvp.xbmc+json", forHTTPHeaderField: "Accept")
|
27
|
+
request.setHTTPMethod(method.to_s.upcase)
|
28
|
+
request
|
29
|
+
end
|
30
|
+
|
31
|
+
def add_cookies(request, cookies)
|
32
|
+
cookies.each do |k, v|
|
33
|
+
request.setValue("#{k}=#{v}", forHTTPHeaderField: "Cookie")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def create_task(request_type, request, &block)
|
38
|
+
if block_given?
|
39
|
+
session.dataTaskWithRequest(request, completionHandler: -> (data, response, error) {
|
40
|
+
block.call(APIResponse.new(request_type, data, response, error))
|
41
|
+
})
|
42
|
+
else
|
43
|
+
session.dataTaskWithRequest(request)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class APIResponse
|
48
|
+
attr_reader :success, :data, :error
|
49
|
+
|
50
|
+
def initialize(request_type, data, response, error)
|
51
|
+
@success = (200...300).include?(response.statusCode)
|
52
|
+
|
53
|
+
if request_type == :session
|
54
|
+
parsed_data = NSJSONSerialization.JSONObjectWithData(data, options:0, error: nil)
|
55
|
+
@data = Tvteka::Session.new(parsed_data)
|
56
|
+
elsif request_type == :session
|
57
|
+
parsed_data = NSJSONSerialization.JSONObjectWithData(data, options:0, error: nil)
|
58
|
+
@data = Tvteka::Session.new(parsed_data)
|
59
|
+
elsif request_type == :live
|
60
|
+
puts data
|
61
|
+
parsed_data = NSJSONSerialization.JSONObjectWithData(data, options:0, error: nil)
|
62
|
+
@data = Tvteka::Channel.init_from_array(parsed_data)
|
63
|
+
elsif request_type == :live_channel
|
64
|
+
parsed_data = NSJSONSerialization.JSONObjectWithData(data, options:0, error: nil)
|
65
|
+
@data = Tvteka::Show.init_from_array(parsed_data)
|
66
|
+
else
|
67
|
+
@data = NSJSONSerialization.JSONObjectWithData(data, options: 0, error: nil)
|
68
|
+
end
|
69
|
+
|
70
|
+
@error = error
|
71
|
+
end
|
72
|
+
|
73
|
+
def successful?
|
74
|
+
@success
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/lib/tvteka/client.rb
CHANGED
@@ -3,29 +3,25 @@ module Tvteka
|
|
3
3
|
def self.session(username, password, options = {}, &block)
|
4
4
|
options = { "session[login]" => username, "session[password]" => password, "device[type]" => "xmbc", "device[id]" => "c0:3d:45:28:fc:ad" }.merge(options)
|
5
5
|
|
6
|
-
|
7
|
-
response.process_data(:session) if response.success?
|
6
|
+
Tvteka::API.new.get(:session, "http://tvteka.com/session/register", options) do |response|
|
8
7
|
block.call response
|
9
8
|
end
|
10
9
|
end
|
11
10
|
|
12
11
|
def self.verify(token, &block)
|
13
|
-
|
14
|
-
response.process_data(:verify) if response.success?
|
12
|
+
Tvteka::API.new.get(:verify, "http://tvteka.com/session/verify", {cookies: {"deviceToken" => token}}) do |response|
|
15
13
|
block.call response
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
19
17
|
def self.live(token, &block)
|
20
|
-
|
21
|
-
response.process_data(:live) if response.success?
|
18
|
+
Tvteka::API.new.get(:live, "http://tvteka.com/live", {cookies: {"deviceToken" => token}}) do |response|
|
22
19
|
block.call response
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
23
|
def self.live_channel(token, channel, &block)
|
27
|
-
|
28
|
-
response.process_data(:live_channel) if response.success?
|
24
|
+
Tvteka::API.new.get(:live_channel, "http://tvteka.com/live/#{channel}", {cookies: {"deviceToken" => token}}) do |response|
|
29
25
|
block.call response
|
30
26
|
end
|
31
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tvteka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksandr Lossenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: motion-cocoapods
|
@@ -47,11 +47,10 @@ extra_rdoc_files: []
|
|
47
47
|
files:
|
48
48
|
- README.md
|
49
49
|
- lib/tvteka.rb
|
50
|
+
- lib/tvteka/api.rb
|
50
51
|
- lib/tvteka/channel.rb
|
51
52
|
- lib/tvteka/client.rb
|
52
53
|
- lib/tvteka/error.rb
|
53
|
-
- lib/tvteka/request.rb
|
54
|
-
- lib/tvteka/response.rb
|
55
54
|
- lib/tvteka/session.rb
|
56
55
|
- lib/tvteka/show.rb
|
57
56
|
homepage: https://bitbucket.org/egze/tvteka/
|
data/lib/tvteka/request.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
module Tvteka
|
2
|
-
class Request
|
3
|
-
|
4
|
-
BASE_URL = ""
|
5
|
-
|
6
|
-
def get(url, params = {}, cookies = {}, &block)
|
7
|
-
r = STHTTPRequest.requestWithURLString(url)
|
8
|
-
|
9
|
-
r.setHeaderWithName("Accept", value: "application/vnd.tvp.xbmc+json")
|
10
|
-
|
11
|
-
r.completionBlock = Proc.new do |header, body|
|
12
|
-
block.call response.build_with_result(body)
|
13
|
-
end
|
14
|
-
|
15
|
-
r.errorBlock = Proc.new do |error|
|
16
|
-
puts error.inspect
|
17
|
-
block.call response.build_with_error(error)
|
18
|
-
end
|
19
|
-
|
20
|
-
cookies.each do |k, v|
|
21
|
-
r.addCookieWithName(k, value: v)
|
22
|
-
end
|
23
|
-
|
24
|
-
r.startAsynchronous
|
25
|
-
end
|
26
|
-
|
27
|
-
def post(url, params = {}, cookies = {}, &block)
|
28
|
-
r = STHTTPRequest.requestWithURLString(url)
|
29
|
-
|
30
|
-
r.setHeaderWithName("Accept", value: "application/vnd.tvp.xbmc+json")
|
31
|
-
|
32
|
-
r.POSTDictionary = params
|
33
|
-
|
34
|
-
r.completionBlock = Proc.new do |header, body|
|
35
|
-
block.call response.build_with_result(body)
|
36
|
-
end
|
37
|
-
|
38
|
-
r.errorBlock = Proc.new do |error|
|
39
|
-
puts error.inspect
|
40
|
-
block.call response.build_with_error(error)
|
41
|
-
end
|
42
|
-
|
43
|
-
cookies.each do |k, v|
|
44
|
-
r.addCookieWithName(k, value: v)
|
45
|
-
end
|
46
|
-
|
47
|
-
r.startAsynchronous
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
def http_client
|
53
|
-
AFMotion::SessionClient.build_shared("http://tvteka.com") do
|
54
|
-
session_configuration :default
|
55
|
-
header "Accept", "application/json"
|
56
|
-
response_serializer :json
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def response
|
61
|
-
Tvteka::Response
|
62
|
-
end
|
63
|
-
|
64
|
-
def create_options(options)
|
65
|
-
{}.merge(options)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
data/lib/tvteka/response.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
module Tvteka
|
2
|
-
class Response
|
3
|
-
def self.build_with_result(result)
|
4
|
-
response = self.new
|
5
|
-
|
6
|
-
response.success = true
|
7
|
-
response.json = result
|
8
|
-
|
9
|
-
response
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.build_with_error(error)
|
13
|
-
response = self.new
|
14
|
-
|
15
|
-
response.success = false
|
16
|
-
response.error = Tvteka::Error.new(error)
|
17
|
-
|
18
|
-
response
|
19
|
-
end
|
20
|
-
|
21
|
-
attr_accessor :data, :json, :success, :error
|
22
|
-
|
23
|
-
def process_data(type = :default)
|
24
|
-
if type == :session
|
25
|
-
parsed_data = NSJSONSerialization.JSONObjectWithData(String(self.json).dataUsingEncoding(NSUnicodeStringEncoding), options:0, error: Pointer.new(:object))
|
26
|
-
self.data = Tvteka::Session.new(parsed_data)
|
27
|
-
elsif type == :verify
|
28
|
-
parsed_data = NSJSONSerialization.JSONObjectWithData(String(self.json).dataUsingEncoding(NSUnicodeStringEncoding), options:0, error: Pointer.new(:object))
|
29
|
-
self.data = Tvteka::Session.new(parsed_data)
|
30
|
-
elsif type == :live
|
31
|
-
parsed_data = NSJSONSerialization.JSONObjectWithData(String(self.json).dataUsingEncoding(NSUnicodeStringEncoding), options:0, error: Pointer.new(:object))
|
32
|
-
self.data = Tvteka::Channel.init_from_array(parsed_data)
|
33
|
-
elsif type == :live_channel
|
34
|
-
parsed_data = NSJSONSerialization.JSONObjectWithData(String(self.json).dataUsingEncoding(NSUnicodeStringEncoding), options:0, error: Pointer.new(:object))
|
35
|
-
self.data = Tvteka::Show.init_from_array(parsed_data)
|
36
|
-
else
|
37
|
-
self.data = self.json
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def success?
|
42
|
-
@success
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|