[{"data":1,"prerenderedAt":78},["Reactive",2],{"/samples/ruby/restclient":3,"related:MA06HUJgrL":60},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"link":12,"body":13,"_type":55,"_id":56,"_source":57,"_file":58,"_extension":59},"/samples/ruby/restclient","ruby",false,"","Restclient","RestClient is a simple and lightweight HTTP client library for Ruby. It provides a user-friendly API for making HTTP requests and handling responses. RestClient abstracts away the complexities of HTTP communication and provides features like automatic URL encoding, response handling, and exception handling.","Ruby","RestClient","https://github.com/rest-client/rest-client",{"type":14,"children":15,"toc":52},"root",[16,31,43],{"type":17,"tag":18,"props":19,"children":20},"element","p",{},[21,29],{"type":17,"tag":22,"props":23,"children":26},"a",{"href":12,"rel":24},[25],"nofollow",[27],{"type":28,"value":11},"text",{"type":28,"value":30}," is a simple and lightweight HTTP client library for Ruby. It provides a user-friendly API for making HTTP requests and handling responses. RestClient abstracts away the complexities of HTTP communication and provides features like automatic URL encoding, response handling, and exception handling.",{"type":17,"tag":32,"props":33,"children":37},"pre",{"className":34,"code":36,"language":5,"meta":7},[35],"language-ruby","require 'rest-client'\nrequire 'json'\n\ndef convert(api_key, params, endpoint = 'pdf')\n  # Ensure the endpoint is valid\n  unless %w[pdf png jpg webp].include?(endpoint)\n    raise ArgumentError, 'Invalid endpoint specified'\n  end\n\n  # Set the API URL\n  url = \"https://api.pdfshift.io/v3/convert/#{endpoint}\"\n\n  # Make the POST request\n  response = RestClient.post(url, params.to_json, {\n    'Content-Type' => 'application/json',\n    'X-API-Key' => api_key\n  })\n\n  # Check for successful response\n  unless response.code == 200\n    raise \"Request failed with status code #{response.code}: #{response.body}\"\n  end\n\n  # Return the response based on the presence of filename or webhook\n  response_body.key?('filename') || response_body.key?('webhook') ? JSON.parse(response.body) : response.body\nend\n",[38],{"type":17,"tag":39,"props":40,"children":41},"code",{"__ignoreMap":7},[42],{"type":28,"value":36},{"type":17,"tag":32,"props":44,"children":47},{"className":45,"code":46,"language":5,"meta":7},[35],"begin\n  result = convert('sk_XXXXXXXXXXXXXX', {'source' => 'https://en.wikipedia.org/wiki/REST'})\n  puts result\nrescue StandardError => e\n  puts \"Error: #{e.message}\"\nend\n",[48],{"type":17,"tag":39,"props":49,"children":50},{"__ignoreMap":7},[51],{"type":28,"value":46},{"title":7,"searchDepth":53,"depth":53,"links":54},2,[],"markdown","content:samples:ruby:restclient.md","content","samples/ruby/restclient.md","md",[61,65,69,73,74],{"_path":62,"language":10,"library":63,"_id":64},"/samples/ruby/faraday","Faraday","content:samples:ruby:faraday.md",{"_path":66,"language":10,"library":67,"_id":68},"/samples/ruby/httpparty","HttpParty","content:samples:ruby:httpparty.md",{"_path":70,"language":10,"library":71,"_id":72},"/samples/ruby/nethttp","Net::HTTP","content:samples:ruby:nethttp.md",{"_path":4,"language":10,"library":11,"_id":56},{"_path":75,"language":10,"library":76,"_id":77},"/samples/ruby/typhoeus","Typhoeus","content:samples:ruby:typhoeus.md",1785426823515]