{"id":16945177,"url":"https://github.com/rafbm/micky","last_synced_at":"2025-04-11T15:31:53.552Z","repository":{"id":10341852,"uuid":"12476119","full_name":"rafbm/micky","owner":"rafbm","description":"Lightweight and worry-free HTTP client for Ruby","archived":false,"fork":false,"pushed_at":"2022-12-22T14:13:39.000Z","size":48,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-09T04:09:35.441Z","etag":null,"topics":["errors","exceptions","http","redirects","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rafbm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-08-30T02:18:23.000Z","updated_at":"2025-02-25T08:50:09.000Z","dependencies_parsed_at":"2023-01-13T15:53:07.921Z","dependency_job_id":null,"html_url":"https://github.com/rafbm/micky","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafbm%2Fmicky","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafbm%2Fmicky/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafbm%2Fmicky/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafbm%2Fmicky/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafbm","download_url":"https://codeload.github.com/rafbm/micky/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247974731,"owners_count":21026742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["errors","exceptions","http","redirects","ruby"],"created_at":"2024-10-13T21:21:25.118Z","updated_at":"2025-04-11T15:31:53.184Z","avatar_url":"https://github.com/rafbm.png","language":"Ruby","readme":"# Micky\n\nMicky makes simple HTTP requests (`GET`/`HEAD`), follows redirects, handles\nexceptions (invalid hosts/URIs, server errors, timeouts, redirect loops),\nautomatically parses responses (JSON, etc.), is very lightweight, and has no\ndependency.\n\nMicky is for those times you would have used\n[`Net::HTTP`](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/Net/HTTP.html‎)\nor [`OpenURI`](http://ruby-doc.org/stdlib/libdoc/open-uri/rdoc/OpenURI.html),\nbut don’t want to bother handling all the sneaky things mentionned above, and\ndon’t want to add heavy dependencies to your app.\n\n## Installation\n\nAdd this line to your application’s Gemfile:\n\n```ruby\ngem 'micky'\n```\n\nAnd then execute:\n\n```sh\n$ bundle\n```\n\nOr install it yourself as:\n\n```sh\n$ gem install micky\n```\n\n## Usage\n\nMicky provides two methods: `get` and `head`.\n\nOn successful requests, it will return a subclass of\n[`Net::HTTPReponse`](http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/Net/HTTPResponse.html).\nFor any error it might encounter during the request (invalid hosts/URIs,\nserver errors, timeouts, redirect loops), it will return `nil`.\n\n```ruby\nresponse = Micky.get('http://google.com')\nresponse.content_type # \"text/html\"\nresponse.body         # \"\u003c!doctype html\u003e\u003chtml ...\"\n\nresponse = Micky.get('http://invalidhost.foo')\nresponse # nil\n```\n\n### Classic example\n\n```ruby\nif Micky.head(params[:website_url])\n  # User provided a valid URL\n  url = URI(params[:website_url])\n  url.path = '/favicon.ico'\n\n  if favicon = Micky.get(url)\n    # Do whatever with the raw `favicon.body`, for whatever reason\n  else\n    # This site has no favicon, or a broken one, too bad\n  end\nelse\n  # Some error happened, display error message to user\nend\n```\n\n### Headers and query strings\n\nRequest headers and query string params can be passed as `:headers` and `:query`.\n\n```ruby\nMicky.get('http://drpm.me/unwz.jpg', headers: { 'Accept' =\u003e 'text/html' })\nMicky.get('http://urls.api.twitter.com/1/urls/count.json', query: { url: 'dropmeme.com' })\n```\n\n### OAuth `Authorization` header\n\nMicky supports creating a OAuth `Authorization` header with the help of the\n[SimpleOAuth](https://github.com/laserlemon/simple_oauth) gem.\n\n```ruby\nMicky.get(\n  'https://api.twitter.com/1.1/statuses/user_timeline.json',\n  oauth: {\n    consumer_key: 'l0tSAl3tT3RsAnD1G1tS',\n    consumer_secret: 'l0tSAl3tT3RsAnD1G1tS',\n    token: 'l0tSAl3tT3RsAnD1G1tS',\n    token_secret: 'l0tSAl3tT3RsAnD1G1tS',\n  },\n)\n```\n\nTo use the `:oauth` argument, just ensure [`simple_oauth`](http://rubygems.org/gems/simple_oauth) is available:\n\n```ruby\ngem 'simple_oauth'\n```\n\n### Automatically parse responses into Ruby objects\n\n`Micky::Response#body` always returns the response as a string. To parse this\nstring into a Ruby object, use `Micky::Response#data`.\n\nResponses with `Content-Type: application/json` are automatically parsed by\nRuby’s [`JSON`](http://ruby-doc.org/stdlib/libdoc/json/rdoc/JSON.html) library.\n\n```ruby\nresponse = Micky.get('http://urls.api.twitter.com/1/urls/count.json?url=dropmeme.com')\nresponse.content_type # 'application/json'\n\n# plain string\nresponse.body # '{\"count\":33,\"url\":\"http://dropmeme.com/\"}'\n\n# proper hash\nresponse.data # {\"count\"=\u003e33, \"url\"=\u003e\"http://dropmeme.com/\"}\n```\n\n#### Add custom parsers\n\nTo add custom response parsers for specific content-types, insert lambdas in\nthe `Micky.parsers` hash.\n\nFor instance, to parse HTML documents with [Nokogiri](http://nokogiri.org):\n\n```ruby\nMicky.parsers['text/html'] = -\u003e (body) {\n  Nokogiri::HTML(body)\n}\n```\n\nOverwrite the default `application/json` parser to use\n[Oj](http://github.com/ohler55/oj):\n\n```ruby\nMicky.parsers['application/json'] = -\u003e (body) {\n  begin\n    Oj.load(body)\n  rescue Oj::ParseError\n  end\n}\n```\n\nParse images into [MiniMagick](https://github.com/minimagick/minimagick)\ninstances:\n\n```ruby\nimage_parser = -\u003e (body) {\n  begin\n    MiniMagick::Image.read(body)\n  rescue MiniMagick::Invalid\n  end\n}\n\n%w[image/png image/jpeg image/jpg image/gif].each do |type|\n  Micky.parsers[type] = image_parser\nend\n```\n\n## TODO\n\n- Support :basic_auth and :digest_auth through [HTTPauth](https://github.com/Manfred/HTTPauth)\n- Add tests\n- Better document configuration options in README\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n\n---\n\n© 2014 [Rafaël Blais Masson](http://rafbm.com). Micky is released under the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafbm%2Fmicky","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafbm%2Fmicky","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafbm%2Fmicky/lists"}