Что такое findslide.org?

FindSlide.org - это сайт презентаций, докладов, шаблонов в формате PowerPoint.


Для правообладателей

Обратная связь

Email: Нажмите что бы посмотреть 

Яндекс.Метрика

Презентация на тему How to bring to your project

How to bring to your project compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0'
Retrofit How to bring to your project  compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0' What you needModel class which is used to map the JSON data ModelSimple class with setters and getters  public class TimeZoneApiResponse { Interface public interface TimeZoneAPI {    @GET( Retrofit.Builder public TimeZoneAPI getTimeZoneAPI() {   return new Retrofit.Builder() Authorization /**  * An invocation of a Retrofit method that sends How to deal with a Call public interface Callback {  /** Sources & useful linkshttp://square.github.io/retrofit/http://www.vogella.com/tutorials/Retrofit/article.htmlhttp://www.jsonschema2pojo.org/
Слайды презентации

Слайд 2 How to bring to your project



compile 'com.squareup.retrofit2:retrofit:2.3.0' compile

How to bring to your project compile 'com.squareup.retrofit2:retrofit:2.3.0' compile 'com.squareup.retrofit2:converter-gson:2.3.0'

'com.squareup.retrofit2:converter-gson:2.3.0'


Слайд 3 What you need

Model class which is used to

What you needModel class which is used to map the JSON

map the JSON data to
Interfaces which defines the possible

HTTP operations
Retrofit.Builder class - Instance which uses the interface and the Builder API which allows defining the URL end point for the HTTP operation.




Слайд 4 Model
Simple class with setters and getters



public class

ModelSimple class with setters and getters public class TimeZoneApiResponse {

TimeZoneApiResponse { @SerializedName("status") @Expose private String

status; @SerializedName("message") @Expose private String message; @SerializedName("countryCode") @Expose private String countryCode;

public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getCountryCode() { return countryCode; } public void setCountryCode(String countryCode) { this.countryCode = countryCode; }


Слайд 5 Interface

public interface TimeZoneAPI { @GET("get-time-zone") Call

Interface public interface TimeZoneAPI {  @GET(

getTimeZone(@Query("key") String apiKey,

@Query("format") String format, @Query("by") String searchBy, @Query("lat") String latitude, @Query("lng") String longitude); }

There are five built-in annotations: GET, POST, PUT, DELETE, and HEAD
Another annotations for data providing: Query, Path, Body


Слайд 6 Retrofit.Builder

public TimeZoneAPI getTimeZoneAPI() { return new Retrofit.Builder()

Retrofit.Builder public TimeZoneAPI getTimeZoneAPI() {  return new Retrofit.Builder()

.baseUrl("http://api.timezonedb.com/v2/")

.client(initClient()) .addConverterFactory(GsonConverterFactory.create()) .build().create(TimeZoneAPI.class); }

@NonNull private OkHttpClient initClient() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); return new OkHttpClient.Builder() .connectTimeout(CLIENT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS) .addNetworkInterceptor(new StethoInterceptor()) .addInterceptor(interceptor) .build(); }


Слайд 7 Authorization

Authorization

Слайд 8 /** * An invocation of a Retrofit method

/** * An invocation of a Retrofit method that sends

that sends a request to a webserver and returns

a response. * Each call yields its own HTTP request and response pair. Use {@link #clone} to make multiple * calls with the same parameters to the same webserver; this may be used to implement polling or * to retry a failed call. * *

Calls may be executed synchronously with {@link #execute}, or asynchronously with {@link * #enqueue}. In either case the call can be canceled at any time with {@link #cancel}. A call that * is busy writing its request or reading its response may receive a {@link IOException}; this is * working as designed. * * @param Successful response body type. */ public interface Call extends Cloneable { /** * Synchronously send the request and return its response. * * @throws IOException if a problem occurred talking to the server. * @throws RuntimeException (and subclasses) if an unexpected error occurs creating the request * or decoding the response. */ Response execute() throws IOException; /** * Asynchronously send the request and notify {@code callback} of its response or if an error * occurred talking to the server, creating the request, or processing the response. */ void enqueue(Callback callback);

What you get when create a request



Слайд 9 How to deal with a Call

public interface Callback

How to deal with a Call public interface Callback { /**

{ /** * Invoked for a received HTTP

response. *

* Note: An HTTP response may still indicate an application-level failure such as a 404 or 500. * Call {@link Response#isSuccessful()} to determine if the response indicates success. */ void onResponse(Call call, Response response); /** * Invoked when a network exception occurred talking to the server or when an unexpected * exception occurred creating the request or processing the response. */ void onFailure(Call call, Throwable t); }


  • Имя файла: how-to-bring-to-your-project.pptx
  • Количество просмотров: 357
  • Количество скачиваний: 0