class Plz::Commands::Request
Public Class Methods
new(headers: nil, params: nil, method: nil, base_url: nil, path: nil, options: nil)
click to toggle source
@param headers [Hash] @param params [Hash] @param method [String] @param base_url [String] @param path [String] @param options [Hash]
# File lib/plz/commands/request.rb, line 10 def initialize(headers: nil, params: nil, method: nil, base_url: nil, path: nil, options: nil) @headers = headers @params = params @method = method @base_url = base_url @path = path @options = options end
Public Instance Methods
call()
click to toggle source
Sends an HTTP request and logs out the response
# File lib/plz/commands/request.rb, line 20 def call response = client.send(@method.downcase, @path, @params, @headers) print ResponseRenderer.call( status: response.status, headers: response.headers, body: response.body, response_header: flag_to_show_response_header, response_body: flag_to_show_response_body, color: flag_to_color_response, ) rescue Faraday::ConnectionFailed => exception puts exception end
Private Instance Methods
client()
click to toggle source
@return [Faraday::Connection]
# File lib/plz/commands/request.rb, line 37 def client Faraday.new(url: @base_url) do |connection| connection.request :json connection.response :json connection.adapter :net_http end end
flag_to_color_response()
click to toggle source
@return [true, false]
# File lib/plz/commands/request.rb, line 56 def flag_to_color_response !@options[:"no-color"] end
flag_to_show_response_body()
click to toggle source
@return [true, false]
# File lib/plz/commands/request.rb, line 51 def flag_to_show_response_body !@options[:"no-response-body"] end
flag_to_show_response_header()
click to toggle source
@return [true, false]
# File lib/plz/commands/request.rb, line 46 def flag_to_show_response_header !@options[:"no-response-header"] end