Class: MWS::Request

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

Constant Summary collapse

DEFAULT_METHOD =
:post

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Request

Returns a new instance of Request.



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

def initialize(args)
  @method   = args[:method] || DEFAULT_METHOD
  @path     = args[:path]
  @endpoint = args[:endpoint]
  @headers  = args[:headers] || {}
  @body     = args[:body] || ""
end

Instance Method Details

#executeObject



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

def execute
  client = Net::HTTP.new(@endpoint, 443)
  client.use_ssl = true

  client.start do |https|
    case @method
    when :post then return https.post(@path, @body, headers)
    else raise ArgumentError, "#{@method} is unknown HTTP method"
    end
  end
end