Class: Request

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/request.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRequest

Returns a new instance of Request.



28
29
30
31
32
# File 'lib/request.rb', line 28

def initialize
  @base_uri = URI("https://order.dominos.jp/eng/")
  @http = Net::HTTP.start(@base_uri.host, @base_uri.port, use_ssl: true)
  @jar = HTTP::CookieJar.new
end

Class Method Details

.get(url, options = {}) ⇒ Object



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

def self.get(url, options = {})
  request = Net::HTTP::Get.new(URI(url))

  Request.instance.perform(
    request,
    block_given? ? options.merge(proc: proc { |res| yield(res) }) : options
  )
end

.post(url, form_data, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/request.rb', line 18

def self.post(url, form_data, options = {})
  request = Net::HTTP::Post.new(URI(url))
  request.set_form_data(form_data)

  Request.instance.perform(
    request,
    block_given? ? options.merge(proc: proc { |res| yield(res) }) : options
  )
end

Instance Method Details

#perform(request, options) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/request.rb', line 34

def perform(request, options)
  request["Cookie"] = cookies_value
  response = @http.request(request)

  save_cookies(response)
  parse_options(options, response)

  response
end