Class: CookieHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/etvnet_seek/cookie_helper.rb

Class Method Summary collapse

Instance Method Summary collapse

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
  @cookie_file_name = 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 cookie
  p cookie
  length = "expires=".length

  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(";")
      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 cookie
  length = "username=".length

  username = ""

  fragment = cookie

  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



17
18
19
# File 'lib/etvnet_seek/cookie_helper.rb', line 17

def delete_cookie
  File.delete @cookie_file_name if File.exist? @cookie_file_name
end


7
8
9
# File 'lib/etvnet_seek/cookie_helper.rb', line 7

def load_cookie
  File.exist?(@cookie_file_name) ? read_cookie : nil
end


11
12
13
14
15
# File 'lib/etvnet_seek/cookie_helper.rb', line 11

def save_cookie cookie
  return if cookie.nil?
  
  File.open(@cookie_file_name, 'w') { |file| file.puts cookie }
end