{"id":19224821,"url":"https://github.com/flipkart-incubator/okhttp-stats","last_synced_at":"2025-04-21T00:31:28.777Z","repository":{"id":16725346,"uuid":"19482426","full_name":"flipkart-incubator/okhttp-stats","owner":"flipkart-incubator","description":"OkHttp Analytical library to get stats like average network speed. Also get global callbacks for network errors and successes. Can be used for logging errors to Fabric or Firebase analytical tools","archived":false,"fork":false,"pushed_at":"2020-06-26T03:53:12.000Z","size":755,"stargazers_count":95,"open_issues_count":5,"forks_count":16,"subscribers_count":139,"default_branch":"master","last_synced_at":"2025-04-01T07:12:19.640Z","etag":null,"topics":["analytical","error","network-monitoring","networking","okhttp","okhttp-stats","success"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flipkart-incubator.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-06T05:39:07.000Z","updated_at":"2025-03-03T11:05:39.000Z","dependencies_parsed_at":"2022-07-19T06:02:07.231Z","dependency_job_id":null,"html_url":"https://github.com/flipkart-incubator/okhttp-stats","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipkart-incubator%2Fokhttp-stats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipkart-incubator%2Fokhttp-stats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipkart-incubator%2Fokhttp-stats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipkart-incubator%2Fokhttp-stats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flipkart-incubator","download_url":"https://codeload.github.com/flipkart-incubator/okhttp-stats/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249979905,"owners_count":21355320,"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":["analytical","error","network-monitoring","networking","okhttp","okhttp-stats","success"],"created_at":"2024-11-09T15:12:57.731Z","updated_at":"2025-04-21T00:31:28.481Z","avatar_url":"https://github.com/flipkart-incubator.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"#okhttp-stats ![alt text](https://travis-ci.org/flipkart-incubator/okhttp-stats.svg?branch=master) [![](https://jitpack.io/v/flipkart-incubator/okhttp-stats.svg)](https://jitpack.io/#flipkart-incubator/okhttp-stats)\n\nOkHttp-Stats is an android library built on top of OkHttp3, which is responsible for intercepting all the network calls and for calculating network stats such as the average network speed of the user. This is more of an analytical tool which can be used to track the success and error response logs.\n\nCan be plugged in to any app which uses okhttp in their networking stack.\n\n## Gradle Dependency\n\nAdd it in your root build.gradle at the end of repositories:\n\n````java\n\tallprojects {\n\t\trepositories {\n\t\t\t...\n\t\t\tmaven { url \"https://jitpack.io\" }\n\t\t}\n\t}\n````\n\nAdd the dependency:\n\n````java\n\tdependencies {\n\t\tcompile 'com.github.flipkart-incubator:okhttp-stats:1.1.1'\n\t}\n````\n\n## How to works\n\nCreate a class that implements the ````OnResponseListener````. This is where you will get all the callbacks in case of success or error responses.\n\n````java\nprivate class OnResponseReceived implements OnResponseListener {\n\n        @Override\n        public void onResponseSuccess(NetworkInfo info, RequestStats requestStats) {\n            Log.d(MainActivity.class.getName(), \"onResponseSuccessReceived : \"\n                    + \"\\nId : \" + requestStats.id\n                    + \"\\nUrl : \" + requestStats.url\n                    + \"\\nMethod : \" + requestStats.methodType\n                    + \"\\nHost : \" + requestStats.hostName\n                    + \"\\nRequest Size : \" + requestStats.requestSize\n                    + \"\\nResponse Size : \" + requestStats.responseSize\n                    + \"\\nTime Taken: \" + (requestStats.endTime - requestStats.startTime)\n                    + \"\\nStatus Code : \" + requestStats.statusCode);\n        }\n\n        @Override\n        public void onResponseError(NetworkInfo info, RequestStats requestStats, Exception e) {\n            Log.d(MainActivity.class.getName(), \"onResponseErrorReceived : \"\n                    + \"\\nId : \" + requestStats.id\n                    + \"\\nUrl : \" + requestStats.url\n                    + \"\\nMethod : \" + requestStats.methodType\n                    + \"\\nHost : \" + requestStats.hostName\n                    + \"\\nRequest Size : \" + requestStats.requestSize\n                    + \"\\nResponse Size : \" + requestStats.responseSize\n                    + \"\\nTime Taken: \" + (requestStats.endTime - requestStats.startTime)\n                    + \"\\nStatus Code : \" + requestStats.statusCode\n                    + \"\\nException : \" + e.getMessage());\n        }\n    }\n````\n\nInitialize the NetworkInterceptor, and register your listener with the NetworkInterceptor.\n\n````java\n        \n        //listener\n        OnResponseReceived onResponseReceived = new OnResponseReceived();\n        \n        PersistentStatsHandler networkRequestStatsHandler = new PersistentStatsHandler(this);\n        //register your listener with the PersistentStatsHandler\n        networkRequestStatsHandler.addListener(onResponseReceived);\n        \n        NetworkInterpreter networkInterpreter = new DefaultInterpreter(new NetworkEventReporterImpl(networkRequestStatsHandler));\n\n        NetworkInterceptor networkInterceptor = new NetworkInterceptor.Builder()\n              .setNetworkInterpreter(networkInterpreter)\n              .setEnabled(true)\n              .build();\n        \n        //add the networkinterceptor to the okhttpclient\n        OkHttpClient okHttpClient = new OkHttpClient().newBuilder()\n              .addInterceptor(networkInterceptor)\n              .build();\n\n````\nNow, pass the okHttpClient (which has an interceptor added) to the okhttpstack, and you are done.\n\n\n## Getting Started Guide\n\nHead over to the [Wiki](https://github.com/Flipkart/okhttp-stats/wiki) page for the detailed documentation\n\n\n## Library Dependencies\n\n* [OkHttp](https://github.com/square/okhttp)\n* [JUnit](http://junit.org/), [Roboelectric](http://robolectric.org/), [Mockito](http://mockito.org/)\n\n\n## Contributing\n\n1. Fork the repo\n2. Apply the changes\n3. Submit your pull request\n\n\n## Releases\n\nCheckout the [Releases](https://github.com/flipkart-incubator/okhttp-stats/releases) tab for all release info.\n\n\n## Licence\n\n```\nThe MIT License (MIT)\n\nCopyright (c) 2016 Flipkart Internet Pvt. Ltd.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipkart-incubator%2Fokhttp-stats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflipkart-incubator%2Fokhttp-stats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipkart-incubator%2Fokhttp-stats/lists"}