tvzavr_client 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6978f85e59d078f0b90d1932a03ccc1fdcaf0072
4
- data.tar.gz: 432bb0b33c925839d2fab7786bed9d2f9fb6a361
3
+ metadata.gz: 1e500140c0b0e2a3d7b3947ade1fb66742d78588
4
+ data.tar.gz: 4cb1ef966dfc326cd6c73b61ac50cdd908c1d56b
5
5
  SHA512:
6
- metadata.gz: 0d178c6d6c383cbd1645e2d53f52395c350ac825dcd2bb7eeabd7c8de4d5e7ef7efe536758b556ee1f919296a3566b06b3c927d5666da22f9ef527a848c275a9
7
- data.tar.gz: ca4a41936ac42a8d6c330e5b0834145b6d022ee133cc019219240917ab79b54ce33e3a85f6b3d581b6ace0a51d4b7cf3eabe720cc816058f0d03230fa940fac5
6
+ metadata.gz: 093225bb3faeae5e4de9a9e19db8813e42f8d87a67fc171f5e8ccdf805b82179c800c4ad8f9394eba54ae64ecb359aa0aefe85f29c397e1d4e03c8d240901bcf
7
+ data.tar.gz: 6a310c2cceca90fa960e62b0e18cd8355ce786572c190121d0ee3e8f9c04563fdcd6af5fad1cd191e3bfe1b52dd21894d71fc4409007d3307c6075f20d0de234
@@ -1,3 +1,3 @@
1
1
  module TvzavrClient
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
data/lib/tvzavr_client.rb CHANGED
@@ -1,86 +1,88 @@
1
1
  require "tvzavr_client/version"
2
2
 
3
- class TvzavrClient
4
- attr_accessor :page, :per_page, :total_count
5
- attr_accessor :obj_data, :clip_id
6
- attr_reader :public_key, :private_key
3
+ module TvzavrClient
4
+ class Client
5
+ attr_accessor :page, :per_page, :total_count
6
+ attr_accessor :obj_data, :clip_id
7
+ attr_reader :public_key, :private_key
7
8
 
8
- def initialize(arg={})
9
- @page = arg[:page] || 1
10
- @per_page = arg[:per_page] || 30
11
- @public_key = arg[:public_key]
12
- @private_key = arg[:private_key]
13
- @defatul_tariff_id = 4 # Определено на строне tvzavr
14
- end
9
+ def initialize(arg={})
10
+ @page = arg[:page] || 1
11
+ @per_page = arg[:per_page] || 30
12
+ @public_key = arg[:public_key]
13
+ @private_key = arg[:private_key]
14
+ @defatul_tariff_id = 4 # Определено на строне tvzavr
15
+ end
15
16
 
16
- def get_catalog category_id = nil
17
- url="http://api.tvzavr.ru/api/3.0/catalog/get?limit=#{per_page}&offset=#{(page-1)*per_page}&plf=elx"
18
- url = url + "&cats=#{category_id}" unless category_id.blank?
19
- puts url
20
- body = RestClient.get(url).body
21
- @obj_data = JSON.parse(body)
22
- @total_count = @obj_data['result']['total_count']
23
- end
17
+ def get_catalog category_id = nil
18
+ url="http://api.tvzavr.ru/api/3.0/catalog/get?limit=#{per_page}&offset=#{(page-1)*per_page}&plf=elx"
19
+ url = url + "&cats=#{category_id}" unless category_id.blank?
20
+ puts url
21
+ body = RestClient.get(url).body
22
+ @obj_data = JSON.parse(body)
23
+ @total_count = @obj_data['result']['total_count']
24
+ end
24
25
 
25
- def get_series clip_id
26
- url = "http://www.tvzavr.ru/api/3.0/video/get_series?cid=#{clip_id}&plf=elx&apn=tvzavr&apv=3.9.1&ctt=json"
27
- puts url
28
- body = RestClient.get(url).body
29
- @obj_data = JSON.parse(body)
30
- @total_count = @obj_data['result']['total_count']
31
- end
26
+ def get_series clip_id
27
+ url = "http://www.tvzavr.ru/api/3.0/video/get_series?cid=#{clip_id}&plf=elx&apn=tvzavr&apv=3.9.1&ctt=json"
28
+ puts url
29
+ body = RestClient.get(url).body
30
+ @obj_data = JSON.parse(body)
31
+ @total_count = @obj_data['result']['total_count']
32
+ end
32
33
 
33
- def info
34
- url = "http://api.tvzavr.ru/api/3.0/video/get_info?cid=#{clip_id}"
35
- body = RestClient.get(url).body
36
- JSON.parse(body)
37
- end
34
+ def info
35
+ url = "http://api.tvzavr.ru/api/3.0/video/get_info?cid=#{clip_id}"
36
+ body = RestClient.get(url).body
37
+ JSON.parse(body)
38
+ end
38
39
 
39
- def thumb(clip_id)
40
- url="http://www.tvzavr.ru/cache/644x363/#{clip_id}.jpg"
41
- end
40
+ def thumb(clip_id)
41
+ url="http://www.tvzavr.ru/cache/644x363/#{clip_id}.jpg"
42
+ end
42
43
 
43
- def video_list
44
- @obj_data['result']['video_list']
45
- end
44
+ def video_list
45
+ @obj_data['result']['video_list']
46
+ end
46
47
 
47
- def series_list
48
- @obj_data['result']['series']
49
- end
48
+ def series_list
49
+ @obj_data['result']['series']
50
+ end
50
51
 
51
- def sign_pay(params)
52
- query_str = params.to_a.sort_by{|i| i[0]}.map{|i| i.join("=") }.join('&')
53
- for_sign = query_str + "&#{private_key}"
54
- sig = Digest::MD5.hexdigest(for_sign)#.upcase
55
- "#{query_str}&sign=#{sig}&public_key=#{public_key}"
56
- end
52
+ def sign_pay(params)
53
+ query_str = params.to_a.sort_by{|i| i[0]}.map{|i| i.join("=") }.join('&')
54
+ for_sign = query_str + "&#{private_key}"
55
+ sig = Digest::MD5.hexdigest(for_sign)#.upcase
56
+ "#{query_str}&sign=#{sig}&public_key=#{public_key}"
57
+ end
57
58
 
58
- def build_pay_url params
59
- res = "http://www.tvzavr.ru/api/pay/attach?#{sign_pay(params)}"
60
- puts res
61
- res
62
- end
59
+ def build_pay_url params
60
+ res = "http://www.tvzavr.ru/api/pay/attach?#{sign_pay(params)}"
61
+ puts res
62
+ res
63
+ end
63
64
 
64
- def sign_video_url params
65
- #md5("cid=19525&uid=123&589aceea-e1ee-11e5-a987-0025909102f8")
66
- for_sign = "cid=#{params[:video_id]}&uid=#{params[:user_id]}&#{private_key}"
67
- sig = Digest::MD5.hexdigest(for_sign)
68
- end
65
+ def sign_video_url params
66
+ #md5("cid=19525&uid=123&589aceea-e1ee-11e5-a987-0025909102f8")
67
+ for_sign = "cid=#{params[:video_id]}&uid=#{params[:user_id]}&#{private_key}"
68
+ sig = Digest::MD5.hexdigest(for_sign)
69
+ end
69
70
 
70
- def build_video_url params
71
- params[:quality] ||= 'nr'
72
- url = "http://api.tvzavr.ru/api/3.1/video/partner_url?cid=#{params[:video_id]}&quality=#{params[:quality]}&media=http&uid=#{params[:user_id]}&sign=#{sign_video_url(params)}&plf=#{public_key}"
73
- res = JSON.parse(RestClient.get(url).body)
74
- puts params
75
- puts res
76
- {status: res['status'], url: (res['status'].to_i == 0 ? res['result']['url'] : '')}
77
- end
71
+ def build_video_url params
72
+ params[:quality] ||= 'nr'
73
+ url = "http://api.tvzavr.ru/api/3.1/video/partner_url?cid=#{params[:video_id]}&quality=#{params[:quality]}&media=http&uid=#{params[:user_id]}&sign=#{sign_video_url(params)}&plf=#{public_key}"
74
+ res = JSON.parse(RestClient.get(url).body)
75
+ puts params
76
+ puts res
77
+ {status: res['status'], url: (res['status'].to_i == 0 ? res['result']['url'] : '')}
78
+ end
78
79
 
79
- def pay(user_id, tariff_id)
80
- url = build_pay_url({user_id: user_id, product_id: tariff_id})
81
- body = RestClient.get(url).body
82
- return :dublicate if body == 'duplicate_operation'
83
- return :ok if body == 'ok'
84
- return :error
80
+ def pay(user_id, tariff_id)
81
+ url = build_pay_url({user_id: user_id, product_id: tariff_id})
82
+ body = RestClient.get(url).body
83
+ return :dublicate if body == 'duplicate_operation'
84
+ return :ok if body == 'ok'
85
+ return :error
86
+ end
85
87
  end
86
88
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tvzavr_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - V. Glyantsev