Class: Lightpanda::Cookies
- Inherits:
-
Object
- Object
- Lightpanda::Cookies
- Defined in:
- lib/lightpanda/cookies.rb
Instance Attribute Summary collapse
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
Instance Method Summary collapse
- #all ⇒ Object
- #clear ⇒ Object
- #get(name) ⇒ Object
-
#initialize(browser) ⇒ Cookies
constructor
A new instance of Cookies.
- #remove(name:, domain: nil, path: "/") ⇒ Object
- #set(name:, value:, domain: nil, path: "/", secure: false, http_only: false, expires: nil) ⇒ Object
Constructor Details
#initialize(browser) ⇒ Cookies
Returns a new instance of Cookies.
7 8 9 |
# File 'lib/lightpanda/cookies.rb', line 7 def initialize(browser) @browser = browser end |
Instance Attribute Details
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
5 6 7 |
# File 'lib/lightpanda/cookies.rb', line 5 def browser @browser end |
Instance Method Details
#all ⇒ Object
11 12 13 14 15 |
# File 'lib/lightpanda/cookies.rb', line 11 def all result = browser.command("Network.getAllCookies") result["cookies"] || [] end |
#clear ⇒ Object
43 44 45 |
# File 'lib/lightpanda/cookies.rb', line 43 def clear browser.command("Network.clearBrowserCookies") end |
#get(name) ⇒ Object
17 18 19 |
# File 'lib/lightpanda/cookies.rb', line 17 def get(name) all.find { || ["name"] == name } end |
#remove(name:, domain: nil, path: "/") ⇒ Object
36 37 38 39 40 41 |
# File 'lib/lightpanda/cookies.rb', line 36 def remove(name:, domain: nil, path: "/") params = { name: name, path: path } params[:domain] = domain if domain browser.command("Network.deleteCookies", **params) end |
#set(name:, value:, domain: nil, path: "/", secure: false, http_only: false, expires: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/lightpanda/cookies.rb', line 21 def set(name:, value:, domain: nil, path: "/", secure: false, http_only: false, expires: nil) params = { name: name, value: value, path: path, secure: secure, httpOnly: http_only } params[:domain] = domain if domain params[:expires] = expires.to_i if expires browser.command("Network.setCookie", **params) end |