class Object
Public Instance Methods
build_data()
click to toggle source
# File lib/resty/commands/method_command.rb, line 74 def build_data return nil unless args[2] input = args[2..-1].join(" ") parse_json(input) || eval_ruby(input) || nil end
data()
click to toggle source
# File lib/resty/commands/method_command.rb, line 107 def data @data ||= build_data end
data_invalid?()
click to toggle source
# File lib/resty/commands/method_command.rb, line 64 def data_invalid? data.nil? && Resty::Request.data_required?(http_method) end
eval_response(response)
click to toggle source
# File lib/resty/commands/method_command.rb, line 68 def eval_response(response) target.eval("response = #{JSON.parse(response)}") rescue target.eval("response = %q(#{response})") end
eval_ruby(input)
click to toggle source
# File lib/resty/commands/method_command.rb, line 81 def eval_ruby(input) parsed_input = target.eval(input) if parsed_input.is_a?(String) JSON.parse(parsed_input) else parsed_input end rescue end
global_options()
click to toggle source
# File lib/resty/commands/method_command.rb, line 95 def global_options @global_options ||= eval "self", target end
http_method()
click to toggle source
# File lib/resty/commands/method_command.rb, line 99 def http_method args[0] end
options(opt)
click to toggle source
# File lib/resty/commands/method_command.rb, line 53 def options(opt) opt.on "H=", :headers, "Headers sent per-request. Ex: -H header:value -H header:value", as: Array end
parse_json(input)
click to toggle source
# File lib/resty/commands/method_command.rb, line 91 def parse_json(input) JSON.parse(input) rescue nil end
path()
click to toggle source
# File lib/resty/commands/method_command.rb, line 103 def path args[1] end
path_missing?()
click to toggle source
# File lib/resty/commands/method_command.rb, line 60 def path_missing? path.nil? end
process()
click to toggle source
# File lib/resty/commands/method_command.rb, line 38 def process if path_missing? "Missing path. Type '#{http_method} -h' for more info, or 'help'." elsif data_invalid? "Invalid data. Type '#{http_method} -h' for more info, or 'help'." else params = { method: http_method, path: path, data: data } request = Resty::Request.new(global_options, params) request.send_request({headers: request_headers}) do |response, request| eval_response(response) return Hashie::Mash.new(response: response, request: request) end end end
request_headers()
click to toggle source
# File lib/resty/commands/method_command.rb, line 111 def request_headers opts[:headers] ? Resty::Options.parse_headers(opts[:headers]) : {} end
setup()
click to toggle source
# File lib/resty/commands/method_command.rb, line 34 def setup @user_auth = nil end