Class: Accessor

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

Instance Method Summary collapse

Constructor Details

#initialize(cookie_file_name, credentials_collector) ⇒ Accessor

Returns a new instance of Accessor.



7
8
9
10
11
12
13
# File 'lib/etvnet_seek/accessor.rb', line 7

def initialize cookie_file_name, credentials_collector
  @cookie_helper = CookieHelper.new cookie_file_name
  @credentials_collector = credentials_collector

  @access_page = AccessPage.new
  @login_page = LoginPage.new
end

Instance Method Details

#access(item, *params) ⇒ Object



15
16
17
18
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
47
48
49
50
# File 'lib/etvnet_seek/accessor.rb', line 15

def access item, *params
  @try_again = false

  cookie = @cookie_helper.load_cookie

  if cookie.nil?
    username, password = *@credentials_collector.call(*params)

    @try_again = (username, password)

    nil
    #access item
  else
    cookie.gsub!("\"", "\"\"")

    result1 = cookie.scan(/.*sessid=([\d|\w]*);.*/)      
    result2 = cookie.scan(/.*_lc=([\d|\w]*);.*/)

    short_cookie = "sessid=#{result1[0][0]};_lc=#{result2[0][0]}"
    media_info = @access_page.request_media_info(item.link.scan(/.*\/(\d*)\//)[0][0], short_cookie)

    if media_info.session_expired?
      @cookie_helper.delete_cookie

      username, password = *@credentials_collector.call(*params)

      @try_again = (username, password)

      nil

      #access item
    else
      LinkInfo.new(item, media_info)
    end
  end
end

#login(username, password) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/etvnet_seek/accessor.rb', line 56

def  username, password
  cookie = @login_page.(username, password)

  @cookie_helper.save_cookie cookie

  cookie.nil?
end

#try_again?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/etvnet_seek/accessor.rb', line 52

def try_again?
  @try_again
end