hktv 1.0.1 → 1.0.3

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: 480088f574c5b62191b13bf05b158af33316b6a0
4
- data.tar.gz: b8cde4170b9e46f412663028818720cea5a21c51
3
+ metadata.gz: a2c34f24b4c46d0c380d837409d3f7d27780a880
4
+ data.tar.gz: 000e23229b54648023fdf792cdd3c9563fde8b68
5
5
  SHA512:
6
- metadata.gz: db2ea07db61ffa58cdd23dd7043072bcf02d41f5c03c943c03a33c5cce3b34bfb6e8424118d893c48b881b290af38b16316fded9d69ecf0e3f065defba45f006
7
- data.tar.gz: ded7e980b52a9555b8320c573dd02c7231be9d0360e66fe462f967c0f401d25bd0eb9eaa087b48b534016ad2624310a832e5a16624f52f485b4859026b8edc06
6
+ metadata.gz: bd45546215d8d851721bd3f4f8892164981d212dd3833ee82c3e9072e566906c7598df4693be9b99c20d89626f4ecc27083022208ef0ef6b58dca0540e6165e3
7
+ data.tar.gz: d2d062538db56b4922a90ec2b0e6bb9c39c3f203f73b35daa22aa5b0831156aeb1f5650bcba0f7682c4d5ce11d0d13a7b1ba0d5cf46b554bc25c47845fcdffde
data/README.md CHANGED
@@ -7,7 +7,7 @@ Command line utilities to find and download HKTV videos.
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'hktv', github: "siuying/ruby-hktv"
10
+ gem 'hktv'
11
11
  ```
12
12
 
13
13
  And then execute:
data/lib/hktv.rb CHANGED
@@ -53,7 +53,7 @@ class HKTV
53
53
 
54
54
  # return true if client has authenticated, false otherwise
55
55
  def authenticated?
56
- if @expires_date && Time.now > @expires_date
56
+ if expired?
57
57
  @access_token = nil
58
58
  @expires_date = nil
59
59
  @refresh_token = nil
@@ -62,6 +62,10 @@ class HKTV
62
62
  !@access_token.nil?
63
63
  end
64
64
 
65
+ def expired?
66
+ !@expires_date || Time.now > @expires_date
67
+ end
68
+
65
69
  # return true if client needs ott token
66
70
  def needs_ott_token?
67
71
  return @ott_token.nil? || (@ott_expires_date && Time.now > @ott_expires_date)
@@ -76,7 +80,7 @@ class HKTV
76
80
  "password" => password
77
81
  }
78
82
 
79
- auth = post_json("https://www.hktvmall.com:443/hktvwebservices/oauth/token?rand=#{Time.now.to_i}", body: options, basic_auth: {username: API_USERNAME, password: API_PASSWORD})
83
+ auth = self.class.post("https://www.hktvmall.com:443/hktvwebservices/oauth/token?rand=#{Time.now.to_i}", body: options, basic_auth: {username: API_USERNAME, password: API_PASSWORD})
80
84
  @access_token = auth["access_token"]
81
85
  @expires_date = Time.now + auth["expires_in"]
82
86
  @refresh_token = auth["refresh_token"]
@@ -90,7 +94,7 @@ class HKTV
90
94
  # hktv api just fail for unknown reason, retry to workaround it
91
95
  Retriable.retriable(tries: 20, base_interval: 1.0) do
92
96
  if authenticated?
93
- result = get_json("https://www.hktvmall.com:443/hktvwebservices/v1/hktv/ott/token?rand=#{Time.now.to_i}", headers: headers)
97
+ result = self.class.get("https://www.hktvmall.com:443/hktvwebservices/v1/hktv/ott/token?rand=#{Time.now.to_i}", headers: headers)
94
98
  else
95
99
  ts = Time.now.to_i
96
100
  options = {
@@ -223,18 +227,6 @@ class HKTV
223
227
  end
224
228
  end
225
229
 
226
- def post_json(path, options={})
227
- response = self.class.post(path, options)
228
- data = response.body
229
- JSON.parse(data)
230
- end
231
-
232
- def get_json(path, options={})
233
- response = self.class.get(path, options)
234
- data = response.body
235
- JSON.parse(data)
236
- end
237
-
238
230
  def sign_request(path, timestamp, params=[])
239
231
  return Digest::MD5.hexdigest(path + params.join("") + API_SECRET + timestamp.to_s)
240
232
  end
data/lib/hktv/command.rb CHANGED
@@ -106,6 +106,11 @@ class HKTV
106
106
 
107
107
  c.action do |args, options|
108
108
  hktv = self.load
109
+
110
+ if hktv.expired?
111
+ puts "Login expired! Run \"hktv login\" first."
112
+ raise "Login Expired"
113
+ end
109
114
 
110
115
  unless hktv.authenticated?
111
116
  puts "You have not login! Try \"hktv login\""
@@ -118,7 +123,7 @@ class HKTV
118
123
 
119
124
  filename = filename_with_title(title, ".mp4") if filename.nil?
120
125
  programs = extract_root_videos(hktv.programs)
121
- programs = programs.select {|program| program["title"].include?(title) }
126
+ programs = programs.select {|program| program["title"].start_with?(title) } || programs.select {|program| program["title"].include?(title) }
122
127
 
123
128
  if programs.size == 0
124
129
  puts "No video matching \"#{title}\""
data/lib/hktv/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class HKTV
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.3"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -14,12 +14,15 @@ VCR.configure do |c|
14
14
  i.request.uri.sub!(/:\/\/.*#{Regexp.escape(u.host)}/, "://#{u.host}" )
15
15
  end
16
16
 
17
+ username = ENV["HKTV_USER_NAME"] ? ENV["HKTV_USER_NAME"] : "<username>"
18
+ password = ENV["HKTV_PASSWORD"] ? ENV["HKTV_PASSWORD"] : "<password>"
19
+
17
20
  c.filter_sensitive_data('<HKTV_PASSWORD>') do
18
- CGI.escape ENV['HKTV_PASSWORD']
21
+ CGI.escape password
19
22
  end
20
23
 
21
24
  c.filter_sensitive_data('<HKTV_USER_NAME>') do
22
- CGI.escape ENV['HKTV_USER_NAME']
25
+ CGI.escape username
23
26
  end
24
27
 
25
28
  # Matches authenticated requests regardless of their Basic auth string (https://user:pass@domain.tld)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hktv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis Chong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-03 00:00:00.000000000 Z
11
+ date: 2015-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler