tvteka 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 045958c47238b641a9b5f35ab5a508351ff62a6b
4
+ data.tar.gz: 644205a7d28abd12ddab261c2effcac5cd7e72e2
5
+ SHA512:
6
+ metadata.gz: 57558d7324e4fa2ceee91d4cf48043960e15d9600226f7c8c37c4abb81de575be2f198383aa01c0aeffd26f4717fe2288ce76b53e010fb1114702581ad7d6d5d
7
+ data.tar.gz: 1caf168ecc5cdeab7ddb8d81859e0714d25fff900f1220195e91b271d2bc162024afc84376cb513758ae16862375f80213ebc0d896d78953ae2643fe3c7dd740
@@ -0,0 +1,78 @@
1
+ # tvteka
2
+
3
+ A native [RubyMotion](http://www.rubymotion.com/) wrapper around the [Tvteka](http://tvteka.com/site/api) API.
4
+
5
+ ##Installation
6
+
7
+ Gemfile
8
+ ```ruby
9
+ gem 'tvteka'
10
+ ```
11
+
12
+ Rakefile
13
+ ``` ruby
14
+ require 'tvteka'
15
+ ```
16
+
17
+ then run bundle install and you should be good to go.
18
+
19
+ Tvteka relies on [STHTTPRequest](https://github.com/nst/STHTTPRequest) to run so you'll need to install the neccessary pods.
20
+
21
+ ```
22
+ ### First get Cocoapods up and running.
23
+ $ pod setup
24
+
25
+ ### Now install the needed pods.
26
+ $ rake pod:install
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### Obtain device token
32
+
33
+ ```ruby
34
+ Tvteka::Client.register(your_username, your_password) do |response|
35
+ if response.success?
36
+ response.data # returns instance of Tvteka::Session with token
37
+ else
38
+ response.error
39
+ end
40
+ end
41
+ ```
42
+
43
+ ### Verify that device token is still valid
44
+
45
+ ```ruby
46
+ Tvteka::Client.verify(token) do |response|
47
+ if response.success?
48
+ response.data # returns instance of Tvteka::Session with authorized attribute
49
+ else
50
+ response.error
51
+ end
52
+ end
53
+ ```
54
+
55
+ ### Get list of live channels
56
+
57
+ ```ruby
58
+ Tvteka::Client.live(token) do |response|
59
+ if response.success?
60
+ response.data # returns array of Tvteka::Channel
61
+ else
62
+ response.error
63
+ end
64
+ end
65
+ ```
66
+
67
+ ### Get list of shows for single channel
68
+
69
+ ```ruby
70
+ Tvteka::Client.live_channel(token) do |response|
71
+ if response.success?
72
+ response.data # returns array of Tvteka::Show
73
+ else
74
+ response.error
75
+ end
76
+ end
77
+ ```
78
+
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ unless defined?(Motion::Project::Config)
4
+ raise "This file must be required within a RubyMotion project Rakefile."
5
+ end
6
+
7
+ require 'motion-cocoapods'
8
+
9
+ lib_dir_path = File.dirname(File.expand_path(__FILE__))
10
+ Motion::Project::App.setup do |app|
11
+ app.files.unshift(Dir.glob(File.join(lib_dir_path, "tvteka/**/*.rb")))
12
+ end
@@ -0,0 +1,17 @@
1
+ module Tvteka
2
+ class Channel
3
+
4
+ attr_accessor :id, :thumb_url, :videostatus, :favourited, :link, :telecast, :width, :button, :logo, :tz_offset, :schedule_date, :streaming_urls, :timezone, :height, :name, :schedule_link
5
+
6
+ def initialize(params = {})
7
+ params.each do |k, v|
8
+ self.send("#{k}=", v)
9
+ end
10
+ end
11
+
12
+ def self.init_from_array(params_array = [])
13
+ params_array.map {|params| Tvteka::Channel.new(params)}
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,37 @@
1
+ module Tvteka
2
+ class Client
3
+ def self.session(username, password, options = {}, &block)
4
+ options = { "session[login]" => username, "session[password]" => password, "device[type]" => "xmbc", "device[id]" => "c0:3d:45:28:fc:ad" }.merge(options)
5
+
6
+ request.post("http://tvteka.com/session/register", options) do |response|
7
+ response.process_data(:session) if response.success?
8
+ block.call response
9
+ end
10
+ end
11
+
12
+ def self.verify(token, &block)
13
+ request.post("http://tvteka.com/session/verify", {}, {"deviceToken" => token}) do |response|
14
+ response.process_data(:verify) if response.success?
15
+ block.call response
16
+ end
17
+ end
18
+
19
+ def self.live(token, &block)
20
+ request.get("http://tvteka.tv/live", {}, {"deviceToken" => token}) do |response|
21
+ response.process_data(:live) if response.success?
22
+ block.call response
23
+ end
24
+ end
25
+
26
+ def self.live_channel(token, channel, &block)
27
+ request.get("http://tvteka.tv/live/#{channel}", {}, {"deviceToken" => token}) do |response|
28
+ response.process_data(:live_channel) if response.success?
29
+ block.call response
30
+ end
31
+ end
32
+
33
+ def self.request
34
+ Tvteka::Request.new
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,9 @@
1
+ module Tvteka
2
+ class Error
3
+ attr_reader :error
4
+
5
+ def initialize(error)
6
+ @error = error
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,68 @@
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
@@ -0,0 +1,46 @@
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
@@ -0,0 +1,19 @@
1
+ module Tvteka
2
+
3
+ class Session
4
+
5
+ attr_accessor :device_type_id, :device_id, :token, :created_at, :authorized, :subscription_active, :stb_active, :user_id, :user_timezone, :user_tz_offset, :display_name
6
+
7
+ def initialize(params = {})
8
+ params.each do |k, v|
9
+ self.send("#{k}=", v)
10
+ end
11
+ end
12
+
13
+ def authorized?
14
+ authorized
15
+ end
16
+
17
+ end
18
+
19
+ end
@@ -0,0 +1,17 @@
1
+ module Tvteka
2
+ class Show
3
+
4
+ attr_accessor :id, :description, :beginning, :beginning_str, :avail, :ending_str, :ended, :link, :beginning_real, :videostatus, :ending, :title, :ending_real, :width, :height, :streaming_urls, :thumb_url
5
+
6
+ def initialize(params = {})
7
+ params.each do |k, v|
8
+ self.send("#{k}=", v)
9
+ end
10
+ end
11
+
12
+ def self.init_from_array(params_array = [])
13
+ params_array.map {|params| Tvteka::Show.new(params)}
14
+ end
15
+
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tvteka
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Aleksandr Lossenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: motion-cocoapods
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Rubymotion API wrapper for tvteka.com
42
+ email:
43
+ - aleksandr@byteflip.de
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - lib/tvteka.rb
50
+ - lib/tvteka/channel.rb
51
+ - lib/tvteka/client.rb
52
+ - lib/tvteka/error.rb
53
+ - lib/tvteka/request.rb
54
+ - lib/tvteka/response.rb
55
+ - lib/tvteka/session.rb
56
+ - lib/tvteka/show.rb
57
+ homepage: https://bitbucket.org/egze/tvteka/
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.5.1
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Rubymotion API wrapper for tvteka.com
81
+ test_files: []