{"id":18255451,"url":"https://github.com/roroche/iris","last_synced_at":"2025-04-04T17:31:16.602Z","repository":{"id":217038134,"uuid":"90409478","full_name":"RoRoche/Iris","owner":"RoRoche","description":"Convenient wrapper library to perform network queries using Retrofit and Android Priority Job Queue (Job Manager)","archived":false,"fork":false,"pushed_at":"2020-04-26T16:50:12.000Z","size":205,"stargazers_count":17,"open_issues_count":4,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-01-14T07:50:48.198Z","etag":null,"topics":["android","android-library","android-priority-jobqueue","dagger2","eventbus","priority-queue","retrofit2"],"latest_commit_sha":null,"homepage":"","language":"Java","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/RoRoche.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}},"created_at":"2017-05-05T19:23:03.000Z","updated_at":"2024-01-14T07:51:07.291Z","dependencies_parsed_at":"2024-01-14T08:05:11.282Z","dependency_job_id":null,"html_url":"https://github.com/RoRoche/Iris","commit_stats":null,"previous_names":["roroche/iris"],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoRoche%2FIris","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoRoche%2FIris/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoRoche%2FIris/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoRoche%2FIris/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RoRoche","download_url":"https://codeload.github.com/RoRoche/Iris/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223150654,"owners_count":17095959,"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":["android","android-library","android-priority-jobqueue","dagger2","eventbus","priority-queue","retrofit2"],"created_at":"2024-11-05T10:16:28.222Z","updated_at":"2024-11-05T10:16:28.838Z","avatar_url":"https://github.com/RoRoche.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Iris\n\nConvenient wrapper library to perform network queries using Retrofit and Android Priority Job Queue (Job Manager)\n\n[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Iris-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/5703)\n\n**STILL IN DEVELOPMENT**\n\n![logo](https://raw.githubusercontent.com/RoRoche/Iris/master/assets/logo.png)\n\n\u003c!-- run the following command line: markdown-toc -i README.md --\u003e\n\n\u003c!-- toc --\u003e\n\n- [Dependency](#dependency)\n- [How to use the Iris compiler](#how-to-use-the-iris-compiler)\n- [How to use Iris standalone (i.e., without its compiler)](#how-to-use-iris-standalone-ie-without-its-compiler)\n- [Benefits](#benefits)\n- [Logo credits](#logo-credits)\n\n\u003c!-- tocstop --\u003e\n\n## Dependency\n\nIn the top-level `build.gradle` file:\n\n```groovy\nbuildscript {\n    dependencies {\n        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'\n    }\n}\n```\n\nIn the project `build.gradle` file:\n\n```groovy\napply plugin: 'com.neenbedankt.android-apt'\n\nrepositories {\n    maven {\n        url 'https://dl.bintray.com/guddy/maven/'\n    }\n}\n\ndependencies {\n    compile 'fr.guddy.iris:iris:0.0.7'\n    apt 'fr.guddy.iris:compiler:0.0.7'\n}\n```\n\n## How to use the Iris compiler\n\n- Create a retrofit interface as usual\n\n```java\npublic interface ApiService {\n    @GET(\"users/{user}/repos\")\n    Call\u003cList\u003cRepoDTO\u003e\u003e listRepos(@NonNull @Path(\"user\") final String user);\n}\n```\n\nSupported annotations are `@DELETE`, `@GET`, `@HEADER`, `@HTTP`, `@PATCH`, `@POST`, `@PUT`.\n\n- The annotation processor will generate the following query class:\n\n```java\npublic abstract class AbstractQueryListRepos extends AbstractQuery\u003cList\u003cRepoDTO\u003e\u003e {\n  public final String user;\n\n  private transient List\u003cRepoDTO\u003e mResult;\n\n  protected AbstractQueryListRepos(final Params params, final String user) {\n    super(params);\n    this.user = user;\n  }\n\n  public List\u003cRepoDTO\u003e getResult() {\n    return mResult;\n  }\n\n  @Override\n  protected void execute() throws Throwable {\n    mResponse = getApiService().listRepos(user).execute();\n    mResult = mResponse.body();\n  }\n\n  @Override\n  protected void onQueryDidFinish() {\n  }\n\n  protected abstract ApiService getApiService();\n\n  public static final class EventQueryListReposDidFinish extends AbstractEventQueryDidFinish\u003cAbstractQueryListRepos\u003e {\n    public EventQueryListReposDidFinish(final AbstractQueryListRepos query) {\n      super(query);\n    }\n  }\n}\n```\n\n- The annotation processor will generate the following query class:\n\n```java\npublic class ApiServiceQueryFactory extends AbstractQueryFactory {\n  public ApiServiceQueryFactory(final JobManager pJobManager, final MerlinsBeard pMerlinsBeard) {\n    super(pJobManager, pMerlinsBeard);\n  }\n\n  public boolean startAbstractQueryListRepos(final AbstractQueryListRepos pQuery) {\n    return startQuery(pQuery);\n  }\n}\n```\n\n- now just subclass `AbstractQueryListRepos` as follows to provide the `ApiService` instance and deal with query ending:\n\n```java\npublic class QueryListRepos extends AbstractQueryListRepos {\n\n    public QueryListRepos(@NonNull final String pUser) {\n        super(new Params(1), pUser);\n    }\n\n    @Override\n    protected ApiService getApiService() {\n        return IrisApplication.getInstance()\n                .getApplicationComponent()\n                .apiService();\n    }\n\n    @Override\n    protected void onQueryDidFinish() {\n        IrisApplication.getInstance()\n                .getApplicationComponent()\n                .eventBus()\n                .post(new EventQueryListReposDidFinish(this));\n    }\n}\n```\n\n- start the query using the factory and test if it's return `true` or `false`:\n\n```java\nif(queryFactory.startAbstractQueryListRepos(new QueryListRepos(\"RoRoche\"))) {\n  // query started\n} else {\n  // no network and not a persistent query\n}\n```\n\n## How to use Iris standalone (i.e., without its compiler)\n\n- Subclass `AbstractQuery`\n\n```java\npublic class QueryGetRepos extends AbstractQuery\u003cList\u003cRepoDTO\u003e\u003e {\n\n    public final String user;\n\n    public QueryGetRepos(@NonNull final String pUser) {\n        super(new Params(1));\n        user = pUser;\n    }\n\n    @Override\n    protected void execute() throws Throwable {\n        // TODO perform network query thanks to retrofit\n    }\n\n    @Override\n    protected void onQueryDidFinish() {\n        // TODO deal with results\n    }\n}\n```\n\n- Subclass `AbstractEventQueryDidFinish`\n\n```java\npublic static final class EventQueryGetReposDidFinish extends AbstractEventQueryDidFinish\u003cQueryGetRepos\u003e {\n    public EventQueryGetReposDidFinish(final QueryGetRepos pQuery) {\n        super(pQuery);\n    }\n}\n```\n\n- Subclass `AbstractQueryFactory` :\n\n```java\npublic class QueryFactory extends AbstractQueryFactory {\n    public QueryFactory(final JobManager pJobManager, final MerlinsBeard pMerlinsBeard) {\n        super(pJobManager, pMerlinsBeard);\n    }\n\n    public boolean startQueryListRepos(@NonNull final String pUser) {\n        return startQuery(new QueryListRepos(pUser));\n    }\n}\n```\n\n## Benefits\n\n- processing the retrofit interface, the compiler generates all of the boilerplate code\n- developer can focus on the specific job to do when the HTTP request is finished (for example: save data to local storage, by overriding the `execute` method)\n- the \"Iris\" library can be used without its compiler\n- it improves the network layer with a normalized structure\n- it's DI ready (cf. sample app using Dagger2)\n- it's Event-buses ready (cf. sample app using greenrobot's EventBus)\n\n## Logo credits\n\nNature graphic by \u003ca href=\"http://www.flaticon.com/authors/freepik\"\u003eFreepik\u003c/a\u003e from \u003ca href=\"http://www.flaticon.com/\"\u003eFlaticon\u003c/a\u003e is licensed under \u003ca href=\"http://creativecommons.org/licenses/by/3.0/\" title=\"Creative Commons BY 3.0\"\u003eCC BY 3.0\u003c/a\u003e. Made with \u003ca href=\"http://logomakr.com\" title=\"Logo Maker\"\u003eLogo Maker\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froroche%2Firis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froroche%2Firis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froroche%2Firis/lists"}