Class: Request
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Request
constructor
A new instance of Request.
- #perform(request, options) ⇒ Object
Constructor Details
#initialize ⇒ Request
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, = {}) request = Net::HTTP::Get.new(URI(url)) Request.instance.perform( request, block_given? ? .merge(proc: proc { |res| yield(res) }) : ) 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, = {}) request = Net::HTTP::Post.new(URI(url)) request.set_form_data(form_data) Request.instance.perform( request, block_given? ? .merge(proc: proc { |res| yield(res) }) : ) 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, ) request["Cookie"] = response = @http.request(request) (response) (, response) response end |