Class: CFAdmin::Curl
Instance Method Summary collapse
Methods inherited from CF::CLI
#add_exception_name_to_msg, #build_client, #check_logged_in, #check_target, client, #client, client=, #client_target, #color_enabled?, #debug?, #default_action, #ensure_config_dir, #err, #execute, #fail, #fail_unknown, #force?, #formatted_exception_output, #help, #help_header, #invalidate_client, #log_error, #log_error_and_dump_crashlog, #name_list, #normalize_targets_info, #one_of, #quiet?, #remove_target_info, #sane_target_url, #save_target_info, #save_targets, #save_token_if_it_changes, #set_target, #table, #target_info, #targets_info, #user_colors, #verbose?, #wrap_errors
Methods included from CF::Spacing
#indented, #justify, #line, #lines, #quiet?, #spaced, #start_line, #tabular, #text_width, #trim_escapes
Methods included from CF::Interactive
#ask, #handler, #input_state, #list_choices, #prompt, #show_default
Instance Method Details
permalink #curl ⇒ Object
[View source]
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/admin/curl.rb', line 17 def curl mode = input[:mode].upcase path = input[:path] body = input[:body] headers = {} input[:headers].each do |h| k, v = h.split(/\s*:\s*/, 2) headers[k.downcase] = v end content = headers["content-type"] accept = headers["accept"] content ||= :json if body accept ||= :json unless %w(DELETE HEAD).include?(mode) req, res = client.base.rest_client.request( mode, remove_leading_slash(path), :headers => headers, :accept => accept, :payload => body, :content => body && content) body = res[:body] type = res[:headers]["content-type"] if type && type.include?("application/json") json = MultiJson.load(body) puts MultiJson.dump(json, :pretty => true) else puts body end end |
permalink #precondition ⇒ Object
[View source]
7 8 9 |
# File 'lib/admin/curl.rb', line 7 def precondition check_target end |
permalink #remove_leading_slash(path) ⇒ Object
[View source]
55 56 57 |
# File 'lib/admin/curl.rb', line 55 def remove_leading_slash(path) path.sub(%r{^/}, '') end |