lib/trubl/client.rb
# ToDo: model response handling off of oauth2.client.request
# in fact, perhaps we swap this out for the oauth2 request method...
model response handling off of oauth2.client.request
in fact, perhaps we swap this out for the oauth2 request method
model response handling off of oauth2 . client . request in fact perhaps we swap this out for the oauth2 request method
def request(method, path, params = {})
      params = {} if params.nil?
      uri = full_uri(path)
      h = options(params.delete(:headers) || {})
      body = params.delete(:body) || {}
      params = params[:query] if params.has_key?(:query)
      Trubl.logger.info { "Trubl::Client   #{method}-ing #{uri} with params #{params}" }
      conn = Faraday.new(url: api_uri_root) do |faraday|
        faraday.adapter :net_http do |http|
          http.use_ssl = (@uri_port == 443 || @uri_scheme == 'https')
        end
      end
      response = conn.send(method, path, params) do |request|
        h.each { |k, v| request.headers[k] = v }
        request.body = HTTParty::HashConversions.to_params(body)
      end
      response.define_singleton_method :code, -> { self.status } if response.respond_to?(:status)
      Trubl.logger.debug { "Trubl::Client response: #{response.inspect}" }
      if !response.code =~ /20[0-9]/
        Trubl.logger.fatal { "Trubl::Client   #{response.code} #{method}-ing #{uri.to_s} #{response.parsed_response}" }
      else
        Trubl.logger.debug { "Trubl::Client   #{uri} response: #{response.body}" }
      end
      response.body.force_encoding("utf-8") if response.body and response.body.respond_to?(:force_encoding)
      response
    end
def request ( method , path , params = { } ) params = { } if params . nil? uri = full_uri ( path ) h = options ( params . delete ( :headers ) || { } ) body = params . delete ( :body ) || { } params = params [ :query ] if params . has_key? ( :query ) Trubl . logger . info { "Trubl::Client   #{method}-ing #{uri} with params #{params}" } conn = Faraday . new ( url : api_uri_root ) do | faraday | faraday . adapter :net_http do | http | http . use_ssl = ( @uri_port == 443 || @uri_scheme == 'https' ) end end response = conn . send ( method , path , params ) do | request | h . each { | k , v | request . headers [ k ] = v } request . body = HTTParty :: HashConversions . to_params ( body ) end response . define_singleton_method :code , -> { self . status } if response . respond_to? ( :status ) Trubl . logger . debug { "Trubl::Client response: #{response.inspect}" } if ! response . code =~ / 20[0-9] / Trubl . logger . fatal { "Trubl::Client   #{response.code} #{method}-ing #{uri.to_s} #{response.parsed_response}" } else Trubl . logger . debug { "Trubl::Client   #{uri} response: #{response.body}" } end response . body . force_encoding ( "utf-8" ) if response . body and response . body . respond_to? ( :force_encoding ) response end
ToDo: model response handling off of oauth2.client.request
in fact, perhaps we swap this out for the oauth2 request method...
ToDo : model response handling off of oauth2 . client . request in fact perhaps we swap this out for the oauth2 request method ...
# For backwards compatibility
method
path
params