Class: CookieHelper
- Inherits:
-
Object
- Object
- CookieHelper
- Defined in:
- lib/etvnet_seek/cookie_helper.rb
Class Method Summary collapse
-
.get_expires(cookie) ⇒ Object
def self.get_expires cookie length = “expires=”.length.
- .get_username(cookie) ⇒ Object
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_expires(cookie) ⇒ Object
def self.get_expires cookie
length = "expires=".length
#auth = ""
expires = ""
fragment = cookie
while true do
position = fragment.index("expires=")
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
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/etvnet_seek/cookie_helper.rb', line 50 def self.get_expires p length = "expires=".length expires = "" fragment = while true do position = fragment.index("expires=") break if position == -1 if fragment[position+length..position+length] != ";" right_position = fragment[position..-1].index(";") expires = fragment[position+length..position+right_position-1] break else fragment = fragment[position+length+1..-1] end end expires end |
.get_username(cookie) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/etvnet_seek/cookie_helper.rb', line 76 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
17 18 19 |
# File 'lib/etvnet_seek/cookie_helper.rb', line 17 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 14 15 |
# File 'lib/etvnet_seek/cookie_helper.rb', line 11 def return if .nil? File.open(@cookie_file_name, 'w') { |file| file.puts } end |