Skip to content

Commit

Permalink
Create apparition.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
espen committed Nov 18, 2020
1 parent f9ec1e2 commit 6d331e2
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions lib/show_me_the_cookies/adapters/apparition.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module ShowMeTheCookies
class Apparition
def initialize(driver)
@browser = driver.browser
@driver = driver
end

def get_me_the_cookie(name)
cookie = cookies_hash[name.to_s]
translate(cookie) unless cookie.nil?
end

def get_me_the_cookies
cookies_hash.values.map(&method(:translate))
end

def expire_cookies
cookies_hash.each do |name, cookie|
delete_cookie(name) if (cookie.expires rescue nil).nil?
end
end

def delete_cookie(name)
@browser.remove_cookie(name.to_s)
end

def create_cookie(name, value, options)
# see: https://github.com/jonleighton/poltergeist#manipulating-cookies
@driver.set_cookie(name, value, options)
end

private

def cookies_hash
@driver.cookies
end

def translate(cookie)
{
:name => cookie.name,
:domain => cookie.domain,
:value => cookie.value,
:expires => (cookie.expires rescue nil),
:path => cookie.path,
:secure => cookie.secure?,
:httponly => cookie.httponly?
}
end
end
end

0 comments on commit 6d331e2

Please sign in to comment.