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_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 cookie
  length = "auth=".length

  auth = ""
  expires = ""

  fragment = cookie

  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 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



15
16
17
# File 'lib/etvnet_seek/cookie_helper.rb', line 15

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
# File 'lib/etvnet_seek/cookie_helper.rb', line 11

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