Class: Jets::CLI::Curl::Adapter::Cookies::Jar

Inherits:
Object
  • Object
show all
Includes:
Util::Logging
Defined in:
lib/jets/cli/curl/adapter/cookies/jar.rb

Instance Method Summary collapse

Methods included from Util::Logging

#log

Constructor Details

#initialize(result, filename) ⇒ Jar

Returns a new instance of Jar.



5
6
7
# File 'lib/jets/cli/curl/adapter/cookies/jar.rb', line 5

def initialize(result, filename)
  @result, @filename = result, filename
end

Instance Method Details

#write_to_fileObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jets/cli/curl/adapter/cookies/jar.rb', line 9

def write_to_file
  cookies = @result[:cookies]
  if cookies.nil? || cookies.empty?
    log.debug "No cookies found in the result."
    return
  end

  File.open(@filename, "w") do |file|
    cookies.each do |cookie|
      file.puts("# HTTP Cookie File")
      file.puts("# Created by jets curl #{Jets::VERSION}")
      file.puts("# Date: #{Time.now}\n\n")
      file.puts("#{cookie}\n")
    end
  end

  log.debug "Cookies written to #{@filename}."
end