{"id":18656569,"url":"https://github.com/zendesk/api_client","last_synced_at":"2025-04-11T18:30:54.529Z","repository":{"id":1985821,"uuid":"2917842","full_name":"zendesk/api_client","owner":"zendesk","description":"HTTP API Client Builder","archived":false,"fork":false,"pushed_at":"2023-01-04T17:44:21.000Z","size":148,"stargazers_count":17,"open_issues_count":1,"forks_count":12,"subscribers_count":85,"default_branch":"master","last_synced_at":"2025-03-25T16:51:36.741Z","etag":null,"topics":["gem","ruby","sell"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zendesk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2011-12-05T16:18:15.000Z","updated_at":"2025-01-07T11:05:30.000Z","dependencies_parsed_at":"2023-01-13T11:33:29.171Z","dependency_job_id":null,"html_url":"https://github.com/zendesk/api_client","commit_stats":null,"previous_names":["futuresimple/api_client"],"tags_count":64,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Fapi_client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Fapi_client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Fapi_client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zendesk%2Fapi_client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zendesk","download_url":"https://codeload.github.com/zendesk/api_client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248458362,"owners_count":21107063,"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":["gem","ruby","sell"],"created_at":"2024-11-07T07:24:04.707Z","updated_at":"2025-04-11T18:30:53.976Z","avatar_url":"https://github.com/zendesk.png","language":"Ruby","readme":"ApiClient ![Tests](https://github.com/zendesk/api_client/workflows/Tests/badge.svg)\n=========\n\nApiClient is an experimental builder for HTTP API clients. The goal is to provide a easy to use engine for constructing queries and map the responses to instances of Hashie::Mash subclasses.\n\nBasically you should be able to build a client for any HTTP based API, without the need for handling connections, parsing responses or instantiating objects. All you need to do is choose where the request should go and enhance your client classes. See the examples dir for usage examples.\n\nCurrent state is alpha - it works, but the query interface is not final and is subject to change at any time. Hell, even the can even change without prior notice. You were warned.\n\n## How API Client works\n\nApiClient gives you two classes that you can inherit from:\n\n* ApiClient::Base\n\n  This class gives you the most basic access. It is a Hashie::Mash\n  subclass. On the class level, it exposes a variety of request\n  methods (like get, post, put, delete)\n\n* ApiClient::Resource::Base\n\n  This class extends ApiClient::Base giving it ActiveRecord-like class methods\n  (find, find_all, create, update, destroy) as well as instance methods\n  (save, destroy).\n\n## Making requests\n\nBy design, all request methods are singleton methods. They either return Ruby\nobjects or objects of the class they are called on.\n\n### `ApiClient::Base.get(path, params = {})`\n\nMake a GET request to a specified path. You can pass params as the second\nargument. It will parse the representation and return a Ruby object.\n\n#### Example\n\n```ruby\nApiClient::Base.get('/apples/1.json')\n# =\u003e returns a parsed Hash\n```\n\n### `ApiClient::Base.post(path, params = {})`\n\nMake a POST request to a specified path. You can pass params as the second\nargument. It will parse the representation and return a Ruby object.\n\n#### Example\n\n```ruby\nApiClient::Base.post('/apples/1.json', :name =\u003e 'Lobo')\n# =\u003e returns a parsed Hash\n```\n\n### `ApiClient::Base.put(path, params = {})`\n\nMake a PUT request to a specified path. You can pass params as the second\nargument. It will parse the representation and return a Ruby object.\n\n#### Example\n\n```ruby\nApiClient::Base.put('/apples/1.json', :name =\u003e 'Lobo')\n# =\u003e returns a parsed Hash\n```\n\n### `ApiClient::Base.delete(path, params = {})`\n\nMake a DELETE request to a specified path. You can pass params as the second\nargument. It will parse the representation and return a Ruby object.\n\n#### Example\n\n```ruby\nApiClient::Base.delete('/apples/1.json')\n# =\u003e returns a parsed Hash\n```\n\n### `ApiClient::Base.fetch(path, params = {})`\n\nMake a GET request to a specified path. You can pass params as the second\nargument. It will parse the representation, pass it to the build method and\nreturn and object of the class it was called on.\n\n#### Example\n\n```ruby\nApiClient::Base.fetch('/apples/1.json')\n# =\u003e returns a ApiClient::Base object\n\nclass Apple \u003c ApiClient::Base\nend\n\nApple.fetch('/apples/1.json')\n# =\u003e returns an Apple object\n```\n\n## Scoping and Chaining\n\nApiClient allows you to apply scoping to your request using 3 methods:\n\n* ApiClient::Base.params(pars = {})\n\n  This method allows you to add parameters to a request. If the request is a\n  GET request, it will be added in the query. Otherwise, it will be sent in\n  the request body.\n\n  It returns a ApiClient::Scope object attached to a class you started with.\n\n* ApiClient::Base.options(opts = {})\n\n  Allows passing options to the connection object behind the ApiClient. Useful\n  when working with OAuth for passing the token.\n\n  It returns a ApiClient::Scope object attached to a class you started with.\n\n* ApiClient::Base.headers(heads = {})\n\n  Allows setting headers in the request. Useful when you need to add a token\n  as the header\n\n  It returns a ApiClient::Scope object attached to a class you started with.\n\n* ApiClient::Base.raw_body(body = nil)\n\n  Allows setting non-hash body in the request. Useful for binary payloads.\n  Notice: it overrides all parameters set via params method!\n\n  It returns a ApiClient::Scope object attached to a class you started with.\n\nAll of these methods return a ApiClient::Scope object. When you call any request\nmethods on this object (get, post, put, delete), the request will apply the\noptions, params and headers.\n\n### Examples\n\n#### Params, headers and a GET request\n\n```ruby\nApiClient::Base.\n  params({ :page =\u003e 1 }).\n  headers('Auth-Token', 'mytoken').\n  get('/stuff.json') # =\u003e returns a parsed Array object\n```\n\n## Logging\n\nTo log requests set the `ApiClient.logger`. To log request payloads and headers set level to `Logger::DEBUG`\n\n```ruby\nrequire 'logger'\nApiClient.logger = Logger.new('api_client.log')\nApiClient.logger.level = Logger::INFO\n\n```\n\n## Releasing new version of gem\n\n1. Update version in [lib/api_client/version.rb](lib/api_client/version.rb) and push to `master`\n2. Create new GitHub release with tag name starting with `v` and the version, for example `v1.0.0`\n3. Gem will be automatically built and pushed to rubygems.org with GitHub Action\n\n## Copyright and license\n\nCopyright 2011 Zendesk\n\nLicensed under the [Apache License, Version 2.0](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzendesk%2Fapi_client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzendesk%2Fapi_client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzendesk%2Fapi_client/lists"}