class Bixby::HttpChannel
Public Class Methods
new(uri)
click to toggle source
# File lib/bixby-common/api/http_channel.rb, line 6 def initialize(uri) @uri = uri end
Public Instance Methods
execute(json_request)
click to toggle source
Execute the given request
@param [JsonRequest] json_request
@return [JsonResponse] response
# File lib/bixby-common/api/http_channel.rb, line 15 def execute(json_request) execute_internal(json_request) end
execute_download(json_request, &block)
click to toggle source
Execute a download request NOTE: This method is only available on the HTTP Channel.
@param [JsonRequest] json_request @param [Block] block
@return [JsonResponse] response
# File lib/bixby-common/api/http_channel.rb, line 27 def execute_download(json_request, &block) execute_internal(json_request, &block) end
Private Instance Methods
execute_internal(json_request, &block)
click to toggle source
Execute the request, optionally passing a block to handle the response
@param [JsonRequest] json_request @param [Block] block
@return [JsonResponse] response
# File lib/bixby-common/api/http_channel.rb, line 40 def execute_internal(json_request, &block) if json_request.respond_to?(:headers) then # always required for posting to API json_request.headers["Content-Type"] = "application/json" end req = HTTPI::Request.new(:url => @uri, :body => json_request.to_wire) # add in extra headers if we have a SignedJsonRequest (or anything which has additional headers) if json_request.respond_to? :headers then req.headers.merge!(json_request.headers) end if block then # execute request with block req.on_body(&block) HTTPI.post(req) return JsonResponse.new("success") else # execute normal req, and return parsed response res = HTTPI.post(req).body return JsonResponse.from_json(res) end end