Module: Itest5ch::HttpMethods

Included in:
Board, BoardListPage, Thread
Defined in:
lib/itest5ch/http_methods.rb

Instance Method Summary collapse

Instance Method Details

#get_html(url, referer: nil) ⇒ String

Parameters:

  • url (String)
  • referer (String) (defaults to: nil)

Returns:

  • (String)


10
11
12
13
14
15
16
# File 'lib/itest5ch/http_methods.rb', line 10

def get_html(url, referer: nil)
  options = {}
  options["User-Agent"] = Itest5ch.config.user_agent if Itest5ch.config.user_agent
  options["Referer"] = referer if referer

  URI.parse(url).open(options).read
end

#get_json(url, referer: nil) ⇒ Hash

Parameters:

  • url (String)
  • referer (String) (defaults to: nil)

Returns:

  • (Hash)


22
23
24
# File 'lib/itest5ch/http_methods.rb', line 22

def get_json(url, referer: nil)
  JSON.parse(get_html(url, referer: referer))
end