Class: CookieHelper
- Inherits:
-
Object
- Object
- CookieHelper
- Defined in:
- lib/etvnet_seek/cookie_helper.rb
Class Method Summary collapse
Instance Method Summary collapse
- #delete_cookie ⇒ Object
-
#initialize(cookie_file_name) ⇒ CookieHelper
constructor
A new instance of CookieHelper.
- #load_cookie ⇒ Object
- #save_cookie(cookie) ⇒ Object
Constructor Details
#initialize(cookie_file_name) ⇒ CookieHelper
Returns a new instance of CookieHelper.
3 4 5 |
# File 'lib/etvnet_seek/cookie_helper.rb', line 3 def initialize @cookie_file_name = end |
Class Method Details
.get_auth_and_expires(cookie) ⇒ Object
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 |
# File 'lib/etvnet_seek/cookie_helper.rb', line 19 def self.get_auth_and_expires length = "auth=".length auth = "" expires = "" fragment = while true do position = fragment.index("auth=") break if position == -1 if fragment[position+length..position+length] != ";" right_position = fragment[position..-1].index(";") auth = fragment[position+length..position+right_position-1] pos1 = position+right_position+1+"expires=".length+1 pos2 = fragment[pos1..-1].index(";") expires = fragment[pos1..pos1+pos2-1] break else fragment = fragment[position+length+1..-1] end end [auth, expires] end |
.get_username(cookie) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/etvnet_seek/cookie_helper.rb', line 48 def self.get_username length = "username=".length username = "" fragment = while true do position = fragment.index("username=") break if position == -1 if fragment[position+length..position+length] != ";" right_position = fragment[position..-1].index(";") username = fragment[position+length..position+right_position-1] break else fragment = fragment[position+length+1..-1] end end username end |
Instance Method Details
#delete_cookie ⇒ Object
15 16 17 |
# File 'lib/etvnet_seek/cookie_helper.rb', line 15 def File.delete @cookie_file_name if File.exist? @cookie_file_name end |
#load_cookie ⇒ Object
7 8 9 |
# File 'lib/etvnet_seek/cookie_helper.rb', line 7 def File.exist?(@cookie_file_name) ? : nil end |
#save_cookie(cookie) ⇒ Object
11 12 13 |
# File 'lib/etvnet_seek/cookie_helper.rb', line 11 def File.open(@cookie_file_name, 'w') { |file| file.puts } end |