To make the cookie object comply with the expected API, I need to workaround:
adapted_cookie = {}
some_cookie.instance_variable_get('@attributes').each do |key, value|
cookie[key.to_sym] = value
end
browser.cookies.set(**adapted_cookie)
Why would that be important? For my use case, I store cookies and then retrieve them at another moment in the future:
# Save:
File.write('cookies.bin', Marshal.dump(browser.cookies.all))
# Load:
Marshal.load(File.read('cookies.bin')).values.each do |raw_cookie|
adapted_cookie = {}
raw_cookie.instance_variable_get('@attributes').each do |key, value|
adapted_cookie[key.to_sym] = value
end
browser.cookies.set(**adapted_cookie)
end
Some ideas to improve this flow:
Expose the @attributes, so I don't need to instance_variable_get;
Create a to_h method to have access to a hash accepted in cookies.set;
Just allow cookies.set to accept instances of Ferrum::Cookies::Cookie.
Today, I have to set cookies through:
This is great, but if I want, for example, to use a retrieved cookie:
To make the cookie object comply with the expected API, I need to workaround:
Why would that be important? For my use case, I store cookies and then retrieve them at another moment in the future:
Some ideas to improve this flow:
@attributes
, so I don't need toinstance_variable_get
;to_h
method to have access to a hash accepted incookies.set
;cookies.set
to accept instances ofFerrum::Cookies::Cookie
.