{"id":13395028,"url":"https://github.com/inf0rmer/blanket","last_synced_at":"2025-05-16T06:07:54.797Z","repository":{"id":24815601,"uuid":"28229924","full_name":"inf0rmer/blanket","owner":"inf0rmer","description":"A dead simple API wrapper","archived":false,"fork":false,"pushed_at":"2022-02-25T22:04:55.000Z","size":63,"stargazers_count":460,"open_issues_count":8,"forks_count":30,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-05-09T21:36:14.627Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/inf0rmer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-19T13:12:26.000Z","updated_at":"2025-04-23T16:56:39.000Z","dependencies_parsed_at":"2022-08-23T06:51:01.972Z","dependency_job_id":null,"html_url":"https://github.com/inf0rmer/blanket","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inf0rmer%2Fblanket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inf0rmer%2Fblanket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inf0rmer%2Fblanket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inf0rmer%2Fblanket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inf0rmer","download_url":"https://codeload.github.com/inf0rmer/blanket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478193,"owners_count":22077676,"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":[],"created_at":"2024-07-30T17:01:39.676Z","updated_at":"2025-05-16T06:07:49.755Z","avatar_url":"https://github.com/inf0rmer.png","language":"Ruby","funding_links":[],"categories":["API Client Development Tools","API Builder and Discovery","Ruby","API Builder"],"sub_categories":["Ruby"],"readme":"# Blanket\n[![Build Status](https://travis-ci.org/inf0rmer/blanket.svg?branch=master)](https://travis-ci.org/inf0rmer/blanket)\n[![Coverage Status](https://img.shields.io/coveralls/inf0rmer/blanket.svg)](https://coveralls.io/r/inf0rmer/blanket?branch=master)\n[![Code Climate](https://codeclimate.com/github/inf0rmer/blanket/badges/gpa.svg)](https://codeclimate.com/github/inf0rmer/blanket)\n[![Inline docs](http://inch-ci.org/github/inf0rmer/blanket.svg?branch=master)](http://inch-ci.org/github/inf0rmer/blanket)\n\n\nA dead simple API wrapper.\n\n**Table of Contents**\n\n- [Installation](#installation)\n- [Usage](#usage)\n\t- [Quick demo](#quick-demo)\n\t- [How it works](#how-it-works)\n\t- [Responses](#responses)\n\t- [Request Parameters](#request-parameters)\n\t- [Headers](#headers)\n\t- [Extensions](#extensions)\n\t- [Handling Exceptions](#handling-exceptions)\n- [Contributing](#contributing)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'blanket_wrapper'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install blanket_wrapper\n\n## Usage\n\n### Quick demo\n\n```ruby\nrequire 'blanket'\n\ngithub = Blanket.wrap(\"https://api.github.com\")\n\n# Get some user's info\nuser = github.users('inf0rmer').get\nuser.login\n# =\u003e \"inf0rmer\"\n\n# Get a user's repos\ngithub.users('inf0rmer').repos.get\n# =\u003e [{\n#  \"id\": 20000073,\n#  \"name\": \"BAPersistentOperationQueue\",\n#  ...\n# }]\n```\n\n### How it works\nBlanket uses some metaprogramming black magic to wrap an API. Everytime you call a method on a wrapped API, Blanket appends it as a part of the final URL:\n\n```ruby\ngithub = Blanket.wrap(\"https://api.github.com\")\ngithub.users('inf0rmer').repos.get\n```\n\nHere's how the final URL is built, the step by step:\n\n```ruby\ngithub = Blanket.wrap(\"https://api.github.com\")\n# =\u003e \"https://api.github.com\"\n\ngithub.users\n# =\u003e \"https://api.github.com/users\"\n\ngithub.users('inf0rmer')\n# =\u003e \"https://api.github.com/users/inf0rmer\"\n\ngithub.users('inf0rmer').repos\n# =\u003e \"https://api.github.com/users/inf0rmer/repos\"\n```\n\nThe final `get` method performs a GET HTTP request. You can also use it to append a final part to your request, so you can write something like:\n\nAs this magic works using `method_missing`, you can `send` slashed uri parts to the wrapper and it will play nicely. This is especially usefull when APIs give you URLs:\n```ruby\ngithub.get('users/inf0rmer/repos')\n# or, if you don't wnat to perform the request yet, or have to append more parts to the uri\ngithub.send('users/inf0rmer').repos#.get\n```\n\n```ruby\ngithub = Blanket.wrap(\"https://api.github.com\")\ngithub.users.get('inf0rmer')\n# =\u003e \"https://api.github.com/users/inf0rmer\"\n```\n\n### Responses\nAt the moment Blanket only accepts JSON responses. Every request returns a `Blanket::Response` instance, which parses the JSON internally and lets you access keys using dot syntax:\n\n```ruby\nuser = github.users('inf0rmer').get\n\nuser.login\n# =\u003e \"inf0rmer\"\n\nuser.url\n# =\u003e \"https://api.github.com/users/inf0rmer\"\n\n# It even works on nested keys\nrepo = github.repos('inf0rmer').get('blanket')\n\nrepo.owner.login\n# =\u003e \"inf0rmer\"\n```\n\nIf the response is an array, all `Enumerable` methods work as expected:\n\n```ruby\nrepos = github.users('inf0rmer').repos.get\n\nrepos.map(\u0026:name)\n# =\u003e [\"analytics-ios\", \"aztec\", \"fusebox\", ...]\n```\n\n### Request Body\nYou can make requests with body using the `body` option:\n\n```ruby\napi = Blanket::wrap(\"http://api.example.org\")\napi.messages.post(body: 'Hello')\n```\n\n### Request Parameters\nBlanket supports appending parameters to your requests:\n\n```ruby\napi.users(55).get(params: {foo: 'bar'})\n# =\u003e \"http://api.example.org/users/55?foo=bar\"\n```\n\nYou can also set default params for all your requests on initialization:\n\n```ruby\napi = Blanket::wrap(\"http://api.example.org\", params: {access_token: 'my secret token'})\n```\n\n### Headers\nHTTP Headers are always useful when accessing an API, so Blanket makes it easy for you to specify them, either globally or on a per-request basis:\n\n```ruby\n# All requests will carry the `token` header\napi = Blanket::wrap(\"http://api.example.org\", headers: {token: 'my secret token'})\n\n# This single request will carry the `foo` header\napi.users(55).get(headers: {foo: 'bar'})\n```\n\n### Extensions\nSome APIs require you to append an extension to your requests, such as `.json` or `.xml`. Blanket supports this use case, letting you define an extension for all your requests or override it for a single one:\n\n```ruby\n# All request URLs are suffixed with \".json\"\napi = Blanket::wrap(\"http://api.example.org\", extension: :json)\n\n# Requests to \"users_endpoint\" are suffixed with \".xml\" instead\nusers_endpoint = api.users(55)\nusers_endpoint.extension = :xml\n```\n\n### Handling Exceptions\n\nBlanket will raise exceptions for HTTP errors encountered while making requests. Exception subclasses are raised for well known errors (404, 500, etc.) but for other status codes a default `Blanket::Exception` will be raised instead.\n\n```ruby\nbegin\n  api.thingamajig.get\nrescue Blanket::ResourceNotFound =\u003e e\n  e.code\n  # =\u003e 404\n\n  e.message\n  # =\u003e \"404: Resource Not Found\"\n\n  # The HTTP body, ie. the error message sent by the server\n  e.body\n  # =\u003e \"Could not find this resource!\"\nend\n```\n\n## Contributing\n\n1. Fork it ( https://github.com/inf0rmer/blanket/fork )\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 a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finf0rmer%2Fblanket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finf0rmer%2Fblanket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finf0rmer%2Fblanket/lists"}