SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Retrofit 2
Bruno Vieira
O que devemos saber
New Url Pattern
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
https://api.dribbble.com/shots?access_token=...
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1/")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1/")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1/")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
New Url Pattern
public interface WebServiceApi{
@GET("shots")
Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken);
}
public class WebServiceManagerImpl implements WebServiceManager {
private void setupApi() {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.dribbble.com/v1/")
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
webServiceApi = retrofit.create(WebServiceApi.class);
}
}
https://api.dribbble.com/v1/shots?access_token=...
New Url Pattern
Dynamic URL
public interface WebServiceApi{
@GET
Call<JokeVO> getAJoke(@Url String url);
}
Bippples
https://github.com/OBrunoVieira/Bippples
Dribbble
+
Chuck Norris Database
https://github.com/OBrunoVieira/Bippples
Bippples
https://github.com/OBrunoVieira/Bippples
OkHttp
OkHttp
Retrofit 1.9 - Is optional
Retrofit 2.x - Is required
Importing a specific version:
compile ('com.squareup.retrofit2:retrofit:2.0.2') {
exclude module: 'okhttp'
}
compile 'com.squareup.okhttp3:okhttp:3.2.0'
OkHttp
Interceptors
public OkHttpClient clientInterceptor() {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(this);
...
return httpClient.build();
}
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
request = request.newBuilder()
.addHeader("Authorization", "123454324rtxccvbfdsfgvbcx!@#!@#!@#")
.build();
return chain.proceed(request);
}
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Environment.SERVER_URL)
.client(clientInterceptor())
.build();
OkHttp
Interceptors
public OkHttpClient clientInterceptor() {
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(this);
...
return httpClient.build();
}
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
request = request.newBuilder()
.addHeader("Authorization", "123454324rtxccvbfdsfgvbcx!@#!@#!@#")
.build();
return chain.proceed(request);
}
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Environment.SERVER_URL)
.client(clientInterceptor())
.build();
OkHttp.Interceptors
No Logging
OkHttp.Interceptors
No Logging, but..
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
public OkHttpClient clientInterceptor() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(Environment.LOG_LEVEL);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(interceptor);
...
return httpClient.build();
}
OkHttp.Interceptors
No Logging, but..
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
public OkHttpClient clientInterceptor() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(Environment.LOG_LEVEL);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(interceptor);
...
return httpClient.build();
}
OkHttp.Interceptors
No Logging, but..
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
public OkHttpClient clientInterceptor() {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(Environment.LOG_LEVEL);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(interceptor);
...
return httpClient.build();
}
Converters
Converters
No converter by default
compile "com.github.aurae.retrofit2:converter-logansquare:1.4.0"
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Environment.SERVER_URL)
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
Converters
No converter by default
compile "com.github.aurae.retrofit2:converter-logansquare:1.4.0"
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Environment.SERVER_URL)
.addConverterFactory(LoganSquareConverterFactory.create())
.client(webServiceInterceptor.clientInterceptor())
.build();
Requests
Requests
Synchronous and Asynchronous
Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken);
List<ShotsVO> shotsList = call.execute.body;
Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken);
call.enqueue(new Callback<List<ShotsVO>>(){
@Override
public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){
...
}
...
}
Requests
Attention!
Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken);
call.enqueue(new Callback<List<ShotsVO>>(){
@Override
public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){
...
}
@Override
public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) {
...
}
}
https://github.com/OBrunoVieira/Bippples
Requests
Cancel
Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken);
call.enqueue(new Callback<List<ShotsVO>>(){
@Override
public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){
...
}
@Override
public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) {
...
}
}
call.cancel();
Requests
Cancel
Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken);
call.enqueue(new Callback<List<ShotsVO>>(){
@Override
public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){
...
}
@Override
public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) {
...
}
}
call.cancel();
=)
Source
http://square.github.io/retrofit/
https://inthecheesefactory.com/blog/retrofit-2.0/en
http://www.iayon.com/consuming-rest-api-with-retrofit-2-0-in-
android/
https://github.com/square/retrofit/blob/master/CHANGELOG.md
www.concretesolutions.com.br
blog.concretesolutions.com.br
Rio de Janeiro – Rua São José, 90 – cj. 2121
Centro – (21) 2240-2030
São Paulo - Rua Sansão Alves dos Santos, 433
4º andar - Brooklin - (11) 4119-0449

Weitere ähnliche Inhalte

Was ist angesagt?

Service Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C ZiegelerService Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C Ziegeler
mfrancis
 

Was ist angesagt? (20)

Service Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C ZiegelerService Oriented Web Development with OSGi - C Ziegeler
Service Oriented Web Development with OSGi - C Ziegeler
 
Sensu wrapper-sensu-summit
Sensu wrapper-sensu-summitSensu wrapper-sensu-summit
Sensu wrapper-sensu-summit
 
How to send gzipped requests with boto3
How to send gzipped requests with boto3How to send gzipped requests with boto3
How to send gzipped requests with boto3
 
Asynchronen Code testen
Asynchronen Code testenAsynchronen Code testen
Asynchronen Code testen
 
Easy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWTEasy REST APIs with Jersey and RestyGWT
Easy REST APIs with Jersey and RestyGWT
 
HTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The DeadHTTPBuilder NG: Back From The Dead
HTTPBuilder NG: Back From The Dead
 
Groovy Powered Clean Code
Groovy Powered Clean CodeGroovy Powered Clean Code
Groovy Powered Clean Code
 
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech TalkContract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
Contract-driven development with OpenAPI 3 and Vert.x | DevNation Tech Talk
 
Tdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema RubyTdc 2013 - Ecossistema Ruby
Tdc 2013 - Ecossistema Ruby
 
Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017Making the most of your gradle build - Gr8Conf 2017
Making the most of your gradle build - Gr8Conf 2017
 
Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017Making the most of your gradle build - Greach 2017
Making the most of your gradle build - Greach 2017
 
Analysing Github events with Neo4j
Analysing Github events with Neo4jAnalysing Github events with Neo4j
Analysing Github events with Neo4j
 
Salesforce Integration using REST SOAP and HTTP callouts
Salesforce Integration using REST SOAP and HTTP calloutsSalesforce Integration using REST SOAP and HTTP callouts
Salesforce Integration using REST SOAP and HTTP callouts
 
Rntb20200805
Rntb20200805Rntb20200805
Rntb20200805
 
React native-firebase startup-mtup
React native-firebase startup-mtupReact native-firebase startup-mtup
React native-firebase startup-mtup
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitives
 
Spark Day 2017- Spark 의 과거, 현재, 미래
Spark Day 2017- Spark 의 과거, 현재, 미래Spark Day 2017- Spark 의 과거, 현재, 미래
Spark Day 2017- Spark 의 과거, 현재, 미래
 
Shibuya,trac セッション
Shibuya,trac セッションShibuya,trac セッション
Shibuya,trac セッション
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
NestJS
NestJSNestJS
NestJS
 

Andere mochten auch

Andere mochten auch (20)

Volley vs Retrofit
Volley vs RetrofitVolley vs Retrofit
Volley vs Retrofit
 
introduce Okhttp
introduce Okhttpintroduce Okhttp
introduce Okhttp
 
Simplificando chamadas HTTP com o Retrofit
Simplificando chamadas HTTP com o RetrofitSimplificando chamadas HTTP com o Retrofit
Simplificando chamadas HTTP com o Retrofit
 
Retrofit
RetrofitRetrofit
Retrofit
 
Realm @Android
Realm @Android Realm @Android
Realm @Android
 
Android DevConference - Dagger 2: uso avançado em projetos Android
Android DevConference - Dagger 2: uso avançado em projetos AndroidAndroid DevConference - Dagger 2: uso avançado em projetos Android
Android DevConference - Dagger 2: uso avançado em projetos Android
 
Retro vs Volley
Retro vs VolleyRetro vs Volley
Retro vs Volley
 
Visteme con 'Clean Architecture' que tengo prisas
Visteme con 'Clean Architecture' que tengo prisasVisteme con 'Clean Architecture' que tengo prisas
Visteme con 'Clean Architecture' que tengo prisas
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
大鱼架构演进
大鱼架构演进大鱼架构演进
大鱼架构演进
 
Reactive programming with RxJava
Reactive programming with RxJavaReactive programming with RxJava
Reactive programming with RxJava
 
Retrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃん
Retrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃんRetrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃん
Retrofit2 &OkHttp 
でAndroidのHTTP通信が快適だにゃん
 
Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss Java Libraries You Can’t Afford to Miss
Java Libraries You Can’t Afford to Miss
 
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
Flask, Redis, Retrofit을 이용한 Android 로그인 서비스 구현하기
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
RxJava - introduction & design
RxJava - introduction & designRxJava - introduction & design
RxJava - introduction & design
 
Reactive programming on Android
Reactive programming on AndroidReactive programming on Android
Reactive programming on Android
 
Seismic retrofit methods
Seismic retrofit methodsSeismic retrofit methods
Seismic retrofit methods
 
Reactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJavaReactive Programming on Android - RxAndroid - RxJava
Reactive Programming on Android - RxAndroid - RxJava
 
Java 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava ComparisonJava 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava Comparison
 

Ähnlich wie Retrofit 2 - O que devemos saber

Automated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.xAutomated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.x
Tatsuya Maki
 
Spca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceSpca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_service
NCCOMMS
 
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
celenarouzie
 
Connecting to the network
Connecting to the networkConnecting to the network
Connecting to the network
Mu Chun Wang
 

Ähnlich wie Retrofit 2 - O que devemos saber (20)

Web api's
Web api'sWeb api's
Web api's
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networking
 
ASP.NET MVC Internals
ASP.NET MVC InternalsASP.NET MVC Internals
ASP.NET MVC Internals
 
Servlets
ServletsServlets
Servlets
 
Implement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyoImplement Service Broker with Spring Boot #cf_tokyo
Implement Service Broker with Spring Boot #cf_tokyo
 
Automated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.xAutomated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.x
 
Quick Fetch API Introduction
Quick Fetch API IntroductionQuick Fetch API Introduction
Quick Fetch API Introduction
 
Android dev 3
Android dev 3Android dev 3
Android dev 3
 
CDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptorCDI e as ideias pro futuro do VRaptor
CDI e as ideias pro futuro do VRaptor
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
 
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 202010 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
10 Excellent Ways to Secure Spring Boot Applications - Okta Webinar 2020
 
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R AugeHTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
HTTP Whiteboard - OSGI Compendium 6.0 - How web apps should have been! - R Auge
 
Spca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_serviceSpca2014 hillier build your_own_rest_service
Spca2014 hillier build your_own_rest_service
 
API 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdfAPI 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdf
 
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docxWeb CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
Web CrawlersrcedusmulylecrawlerController.javaWeb Crawler.docx
 
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
TechDays 2016 - Developing websites using asp.net core mvc6 and entity framew...
 
twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC#46 一探 C# 11 與 .NET 7 的神奇twMVC#46 一探 C# 11 與 .NET 7 的神奇
twMVC#46 一探 C# 11 與 .NET 7 的神奇
 
Connecting to the network
Connecting to the networkConnecting to the network
Connecting to the network
 
FrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) SwiftFrenchKit 2017: Server(less) Swift
FrenchKit 2017: Server(less) Swift
 
Serverless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applicationsServerless Angular, Material, Firebase and Google Cloud applications
Serverless Angular, Material, Firebase and Google Cloud applications
 

Kürzlich hochgeladen

Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Call Girls In Delhi Whatsup 9873940964 Enjoy Unlimited Pleasure
 
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
nirzagarg
 
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
@Chandigarh #call #Girls 9053900678 @Call #Girls in @Punjab 9053900678
 
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
nirzagarg
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
nilamkumrai
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Chandigarh Call girls 9053900678 Call girls in Chandigarh
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
nirzagarg
 

Kürzlich hochgeladen (20)

best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
Thalassery Escorts Service ☎️ 6378878445 ( Sakshi Sinha ) High Profile Call G...
 
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Salem Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
📱Dehradun Call Girls Service 📱☎️ +91'905,3900,678 ☎️📱 Call Girls In Dehradun 📱
 
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
Shikrapur - Call Girls in Pune Neha 8005736733 | 100% Gennuine High Class Ind...
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men  🔝mehsana🔝   Escorts...
➥🔝 7737669865 🔝▻ mehsana Call-girls in Women Seeking Men 🔝mehsana🔝 Escorts...
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
 
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
All Time Service Available Call Girls Mg Road 👌 ⏭️ 6378878445
 
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...Nanded City ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready ...
Nanded City ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready ...
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
💚😋 Bilaspur Escort Service Call Girls, 9352852248 ₹5000 To 25K With AC💚😋
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 

Retrofit 2 - O que devemos saber

  • 1. Retrofit 2 Bruno Vieira O que devemos saber
  • 3. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 4. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 5. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 6. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } } https://api.dribbble.com/shots?access_token=...
  • 7. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1/") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 8. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1/") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 9. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1/") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } }
  • 10. New Url Pattern public interface WebServiceApi{ @GET("shots") Call<List<ShotsVO>> getShotsList(@Query("access_token") String accessToken); } public class WebServiceManagerImpl implements WebServiceManager { private void setupApi() { Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://api.dribbble.com/v1/") .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build(); webServiceApi = retrofit.create(WebServiceApi.class); } } https://api.dribbble.com/v1/shots?access_token=...
  • 11. New Url Pattern Dynamic URL public interface WebServiceApi{ @GET Call<JokeVO> getAJoke(@Url String url); }
  • 15. OkHttp Retrofit 1.9 - Is optional Retrofit 2.x - Is required Importing a specific version: compile ('com.squareup.retrofit2:retrofit:2.0.2') { exclude module: 'okhttp' } compile 'com.squareup.okhttp3:okhttp:3.2.0'
  • 16. OkHttp Interceptors public OkHttpClient clientInterceptor() { OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(this); ... return httpClient.build(); } public Response intercept(Chain chain) throws IOException { Request request = chain.request(); request = request.newBuilder() .addHeader("Authorization", "123454324rtxccvbfdsfgvbcx!@#!@#!@#") .build(); return chain.proceed(request); } Retrofit retrofit = new Retrofit.Builder() .baseUrl(Environment.SERVER_URL) .client(clientInterceptor()) .build();
  • 17. OkHttp Interceptors public OkHttpClient clientInterceptor() { OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(this); ... return httpClient.build(); } public Response intercept(Chain chain) throws IOException { Request request = chain.request(); request = request.newBuilder() .addHeader("Authorization", "123454324rtxccvbfdsfgvbcx!@#!@#!@#") .build(); return chain.proceed(request); } Retrofit retrofit = new Retrofit.Builder() .baseUrl(Environment.SERVER_URL) .client(clientInterceptor()) .build();
  • 19. OkHttp.Interceptors No Logging, but.. compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' public OkHttpClient clientInterceptor() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(Environment.LOG_LEVEL); OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(interceptor); ... return httpClient.build(); }
  • 20. OkHttp.Interceptors No Logging, but.. compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' public OkHttpClient clientInterceptor() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(Environment.LOG_LEVEL); OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(interceptor); ... return httpClient.build(); }
  • 21. OkHttp.Interceptors No Logging, but.. compile 'com.squareup.okhttp3:logging-interceptor:3.2.0' public OkHttpClient clientInterceptor() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(Environment.LOG_LEVEL); OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(interceptor); ... return httpClient.build(); }
  • 23. Converters No converter by default compile "com.github.aurae.retrofit2:converter-logansquare:1.4.0" Retrofit retrofit = new Retrofit.Builder() .baseUrl(Environment.SERVER_URL) .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build();
  • 24. Converters No converter by default compile "com.github.aurae.retrofit2:converter-logansquare:1.4.0" Retrofit retrofit = new Retrofit.Builder() .baseUrl(Environment.SERVER_URL) .addConverterFactory(LoganSquareConverterFactory.create()) .client(webServiceInterceptor.clientInterceptor()) .build();
  • 26. Requests Synchronous and Asynchronous Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken); List<ShotsVO> shotsList = call.execute.body; Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken); call.enqueue(new Callback<List<ShotsVO>>(){ @Override public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){ ... } ... }
  • 27. Requests Attention! Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken); call.enqueue(new Callback<List<ShotsVO>>(){ @Override public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){ ... } @Override public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) { ... } } https://github.com/OBrunoVieira/Bippples
  • 28. Requests Cancel Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken); call.enqueue(new Callback<List<ShotsVO>>(){ @Override public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){ ... } @Override public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) { ... } } call.cancel();
  • 29. Requests Cancel Call<List<ShotsVO>> call = webServiceManager.getWebServiceApiInstance().getShotsList(accessToken); call.enqueue(new Callback<List<ShotsVO>>(){ @Override public void onResponse(Call<List<ShotsVO>> call, Response<List<ShotsVO>> response){ ... } @Override public void onFailure(Call<List<ShotsVO>> call, Throwable throwable) { ... } } call.cancel();
  • 30. =)
  • 32. www.concretesolutions.com.br blog.concretesolutions.com.br Rio de Janeiro – Rua São José, 90 – cj. 2121 Centro – (21) 2240-2030 São Paulo - Rua Sansão Alves dos Santos, 433 4º andar - Brooklin - (11) 4119-0449