[{"data":1,"prerenderedAt":79},["Reactive",2],{"/samples/ruby/httpparty":3,"related:veuPAiWPKd":61},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"language":10,"library":11,"link":12,"body":13,"_type":56,"_id":57,"_source":58,"_file":59,"_extension":60},"/samples/ruby/httpparty","ruby",false,"","Httpparty","HTTParty is a Ruby HTTP client library that provides a simple and intuitive API for making HTTP requests and handling responses. It abstracts away the complexities of HTTP communication and provides features like automatic parsing of JSON and XML responses, request timeouts, and response caching.","Ruby","HttpParty","https://lostisland.github.io/faraday/",{"type":14,"children":15,"toc":53},"root",[16,32,44],{"type":17,"tag":18,"props":19,"children":20},"element","p",{},[21,30],{"type":17,"tag":22,"props":23,"children":26},"a",{"href":12,"rel":24},[25],"nofollow",[27],{"type":28,"value":29},"text","HTTParty",{"type":28,"value":31}," is a Ruby HTTP client library that provides a simple and intuitive API for making HTTP requests and handling responses. It abstracts away the complexities of HTTP communication and provides features like automatic parsing of JSON and XML responses, request timeouts, and response caching.",{"type":17,"tag":33,"props":34,"children":38},"pre",{"className":35,"code":37,"language":5,"meta":7},[36],"language-ruby","require 'httparty'\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  # Set headers\n  headers = {\n    'Content-Type' => 'application/json',\n    'X-API-Key' => api_key\n  }\n\n  # Make the POST request\n  response = HTTParty.post(url, body: params.to_json, headers: headers)\n\n  # Check for successful response\n  unless response.success?\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",[39],{"type":17,"tag":40,"props":41,"children":42},"code",{"__ignoreMap":7},[43],{"type":28,"value":37},{"type":17,"tag":33,"props":45,"children":48},{"className":46,"code":47,"language":5,"meta":7},[36],"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",[49],{"type":17,"tag":40,"props":50,"children":51},{"__ignoreMap":7},[52],{"type":28,"value":47},{"title":7,"searchDepth":54,"depth":54,"links":55},2,[],"markdown","content:samples:ruby:httpparty.md","content","samples/ruby/httpparty.md","md",[62,66,67,71,75],{"_path":63,"language":10,"library":64,"_id":65},"/samples/ruby/faraday","Faraday","content:samples:ruby:faraday.md",{"_path":4,"language":10,"library":11,"_id":57},{"_path":68,"language":10,"library":69,"_id":70},"/samples/ruby/nethttp","Net::HTTP","content:samples:ruby:nethttp.md",{"_path":72,"language":10,"library":73,"_id":74},"/samples/ruby/restclient","RestClient","content:samples:ruby:restclient.md",{"_path":76,"language":10,"library":77,"_id":78},"/samples/ruby/typhoeus","Typhoeus","content:samples:ruby:typhoeus.md",1785426823484]