{"id":25440807,"url":"https://github.com/tinyhr/tiny_client","last_synced_at":"2025-11-01T11:30:34.640Z","repository":{"id":59157870,"uuid":"83510741","full_name":"TINYhr/tiny_client","owner":"TINYhr","description":"A tiny api client toolkit for ruby that supports only JSON content-type. ( Curb/JSON wrapper )","archived":false,"fork":false,"pushed_at":"2023-02-23T03:28:27.000Z","size":202,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":38,"default_branch":"master","last_synced_at":"2024-04-25T23:03:36.834Z","etag":null,"topics":["crud","curl","http","ruby"],"latest_commit_sha":null,"homepage":"https://tinyhr.github.io/tiny_client/","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/TINYhr.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-01T04:16:09.000Z","updated_at":"2022-02-18T04:11:47.000Z","dependencies_parsed_at":"2024-11-14T16:17:13.439Z","dependency_job_id":"19b0a4ae-6bfa-4b44-b16f-9ceb2c2143d3","html_url":"https://github.com/TINYhr/tiny_client","commit_stats":{"total_commits":142,"total_committers":9,"mean_commits":"15.777777777777779","dds":0.323943661971831,"last_synced_commit":"0c314f8097362122037ef438fdc7d82a9586f085"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TINYhr%2Ftiny_client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TINYhr%2Ftiny_client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TINYhr%2Ftiny_client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TINYhr%2Ftiny_client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TINYhr","download_url":"https://codeload.github.com/TINYhr/tiny_client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239286282,"owners_count":19613689,"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":["crud","curl","http","ruby"],"created_at":"2025-02-17T12:18:15.501Z","updated_at":"2025-11-01T11:30:34.597Z","avatar_url":"https://github.com/TINYhr.png","language":"Ruby","readme":"# TINYclient, a tiny HTTP/JSON crud client toolkit\n[![Gem Version](https://badge.fury.io/rb/tp_client.svg)](https://badge.fury.io/rb/tp_client) [![Build Status](https://travis-ci.org/TINYhr/tiny_client.svg)](https://travis-ci.org/TINYhr/tiny_client) [![Code Climate](https://codeclimate.com/github/TINYhr/tiny_client/badges/gpa.svg)](https://codeclimate.com/github/TINYhr/tiny_client)\n\nTINYclient is inspired by [Active Record](http://guides.rubyonrails.org/active_record_basics.html) and based on [Curb](https://github.com/taf2/curb).\n\n### Setup\n\n* Be sure that Curb/Curl works properly on your machine.\n* install the gem\n\n```sh\ngem install tp_client\n```\n\n* Or in Gemfile\n\n```ruby\n# As gem main class is different from gem name, we must require file name explicitly\ngem 'tp_client', '~\u003e 0.3.0', require: 'tiny_client'\n```\n\nPlease notice, we have 2 similar gems:\n\n* [tp_client](https://rubygems.org/gems/tp_client) active, maintained by TINYpulse\n* [tiny_client](https://rubygems.org/gems/tiny_client) inactive. **PLEASE DO NOT USE tiny_client GEM**.\n\n### Getting Started\n\n\n#### Configuration\n\nYou can initialize your API by extending the `TinyClient::Configuration`\n\n\n```ruby\nclass MyConf \u003c TinyClient::Configuration\n  def initialize\n    @url = 'http://localhost:3000/api/1.0'\n    @headers = { 'Authorization' =\u003e 'token asdfasf4ffsafasdf@12rfsdfa' }\n    @limit = 100\n    @connect_timeout = 30 # seconds\n  end\nend\n\n```\n\nYou can use that configuration in your resource.\n\n\n```ruby\nclass Author \u003c TinyClient::Resource\n  conf MyConf.instance\n\n  path 'authors' # query will be made on http://localhost:3000/api/1.0/authors\n\n  fields :id, :name # your resource attributes\n\n  nested Books # your resource nested resource\nend\n\nclass Book \u003c TinyClient::Resource\n  conf MyConf.instance\n  path 'books'\n  fields :id, :title\nend\n```\n\n#### Usage\n\nNow you will be able to this:\n\n```ruby\nauthor = Author.show(1) # Get /authors/1.json\nauthor.name = 'P. K. D.'\nauthor.save!   # PUT /authors/1.json { \"author\" : { \"name\" : \"Bob\" } }\n\nbook = Book.new\nbook.title = 'Confessions of a crap artist'\nbook = author.add_book(book) # POST /authors/1/books.json { \"book\" : { \"title\" : \"..\" }\n\nbook.id.present? # true\n\nbooks = Book.index(limit: 10) # GET /books.json?limit=10\n\ned = Author.new\ned.name = 'Poe'\ned.save! # POST /authors.json { \"author\" : { \"name\" : \"Poe\" } }\ned.id.present?\n\ned_books = ed.books(limit: 10) # GET /authors/{ed.id}/books.json\nfirst = ed_books.first\nfirst.load! # GET /books/{first.id}.json\nfirst.name.present?\n\n# You can also navigate through all resources\n\nAuthor.index_all do |author| # It will retrieve all the authors, using limit, and offset query params to paginate\n # Do something for each author\nend\n\n\nAuthor.index_in_batches(limit: 1000) do |authors|\n  # retrieve authors by batch of 1000\nend\n\n```\n\n### Instance methods behavior\n\n#### load!\n\nIt will perform a get request on the resource id and set the resource fields value to the value retrived by the response.\n\n```\nauthor.load! # GET /authors/{author.id}.json -\u003e  { id: 1, name: 'Toto' ... }\nauthor.name # 'Toto'\n```\n\n#### save!\n\nIt will create the resource if `id` is not set, otherwise it will update it.\nThe resource fields value will be updated by the response body content.\n\n```\ntoto = MyModule::Author.new\ntoto.save! # POST /authors.json { author: {} }\n\ntoto.id # should have been set by through the reponse\n\ntoto.name = 'Toto'\ntoto.save! # PUT {author: {name: 'Toto'}} -\u003e /authors/{toto.id}.json\n```\n\nOnly `changed` values will be passed through the body content.\n\nYou can `clear` changes with `#clear_changes!`\nYou can now which fields has been marked has changed with `#changes`\n\nChanges is automatically clear when you perform a request ( i.e call, `#show #index #get #put #post save!` and so on)\n\n### Nested resource\n\nYou can add a nested resource thanks to the `nested` class methods.\n\n```ruby\nclass Author \u003c TinyClient::Resource\n  nested Books, Magazines\nend\n```\n\nIt will allows you to call your nested resource directly from an instance of your parent resource.\n\n```ruby\nauthor = Author.show(1)\nauthor.books(limit: 100)  # index GET /authors/1/books.json?limit=100\nbook = author.book(1)     # show  GET/authors/1/books/1.json\nbook.title = 'New title'\nauthor.update_book(book)  # update  PUT /authors/1/books/1.json -- { 'book': { 'title': 'New title' } }\nauthor.remove_book(book)  # destroy DELETE /authors/1/books/1.json\nauthor.add_book(book)     # create  POST /author/1/books.json -- { 'book': { 'title': 'New title' } }\nauthor.books_all.each     # x GET /authors/1/books.json?limit=.. -- Enumerator -- Retrieve ALL books using limit and offset to handle pagination\n```\n\nThis is equivalent to the following:\n\n```ruby\nauthor = Author.show(1)\nauthor.nested_index(Book, limit: 100)\nbook = author.nested_show(Book, 1)\nbook.title = 'New title'\nauthor.nested_update(book)\nauthor.nested_delete(book)\nauthor.nested_create(book)\nauthor.nested_all(Book, limit: 10) # retrieve all books, quering the server by batch of 10;\n```\n\n### Constraint \u0026 Support\n\n#### JSON only\n\nTinyClient supports only JSON data.\n`Accept: application/json` header is set.\n\n#### POST/PUT create/update\n\nThe content passed to the server will always be prefixed by the class name in lower case.\n\n```\ntoto = MyModule::Author.new\ntoto.save! # POST { author: {} }\n\n```\n\n#### Pagination / Buffer\n\nPagination, buffer is achieve through `limit` and `offset` params.\n\n```\nAuthor.index_all(limit: 100) # Will queries the server by batch of 100, until all authors has been retrieved through the enumerator.\n\n```\n\n#### Content-Encoding support\n\nTinyClient support `gzip` Content-Encoding. Response with `gzip` Content-Encoding will be automatically decompressed.\nYou can set the `Accept-Encoding: gzip` through the configuration headers.\n\n### Development\n\nYou can run the test using:\n\n```shell\nrake\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhr%2Ftiny_client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinyhr%2Ftiny_client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhr%2Ftiny_client/lists"}