Sha256: a8635136bdd6ae50405e00effe3728d5a14b5191f948c2ba9081fca474c9988d
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
## # # Request class # # Methods acepted: # GET # POST # PATCH # # (basically it uses Net::HTTP, but other methods are not supported by API anyway...) # # Endpoint is based on you yaml setting # You can find a template in templates directory here in repository # # Body gets assembled in (put name of class here) class :) (not here yet) TODO # # return value is Net::HTTPResponse which has to be parsed TODO (put name of class here) # module Tessera class Request def initialize(method, endpoint, body) @method = method @endpoint = endpoint @body = body end def send net_http_send # Response.new(net_http_send) end protected def net_http_send uri = URI("#{Tessera.configuration.base_url}#{@endpoint}") request = net_http_class.new(uri) headers.each { |k, v| request[k] = v } request.body = @body.to_json Net::HTTP.start(uri.hostname, uri.port, use_ssl: (uri.scheme == 'https')) do |http| http.request(request) end end def net_http_class Kernel.const_get("Net::HTTP::#{@method.capitalize}") end def headers { 'Accept-Encoding' => 'application/json', 'Content-Type' => 'application/json' } end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tessera-1.0.1 | lib/tessera/request.rb |
tessera-1.0.0 | lib/tessera/request.rb |