apollo-lib-network

Android libraries to make your life easier!

Лицензия

Лицензия

Категории

Категории

Сеть Apollo Контейнер Микросервисы
Группа

Группа

com.apollo-lib
Идентификатор

Идентификатор

network
Последняя версия

Последняя версия

0.1.0
Дата

Дата

Тип

Тип

aar
Описание

Описание

apollo-lib-network
Android libraries to make your life easier!
Ссылка на сайт

Ссылка на сайт

https://github.com/fabianofranca/apollo-lib
Система контроля версий

Система контроля версий

https://github.com/fabianofranca/apollo-lib

Скачать network

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.apollo-lib/network/ -->
<dependency>
    <groupId>com.apollo-lib</groupId>
    <artifactId>network</artifactId>
    <version>0.1.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.apollo-lib/network/
implementation 'com.apollo-lib:network:0.1.0'
// https://jarcasting.com/artifacts/com.apollo-lib/network/
implementation ("com.apollo-lib:network:0.1.0")
'com.apollo-lib:network:aar:0.1.0'
<dependency org="com.apollo-lib" name="network" rev="0.1.0">
  <artifact name="network" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.apollo-lib', module='network', version='0.1.0')
)
libraryDependencies += "com.apollo-lib" % "network" % "0.1.0"
[com.apollo-lib/network "0.1.0"]

Зависимости

compile (1)

Идентификатор библиотеки Тип Версия
com.android.support » appcompat-v7 jar 23.0.1

Модули Проекта

Данный проект не имеет модулей.

Apollo-lib

Android libraries to make your life easier!

Network 0.1.0

Gradle

compile 'com.apollo-lib:network:0.1.0'

####HTTP

#####GET

Http.Builder builder = new Http.Builder("http://dummyhost.com/posts/1");

HttpRequestConfig config = builder.get();

Http.send(config);

#####POST

Http.Builder builder = new Http.Builder("http://dummyhost.com/posts");

JSONObject json = new JSONObject();
	
json.accumulate("title", "foo");
json.accumulate("body", "bar");
json.accumulate("userId", 1);

HttpRequestConfig config = builder.post(json.toString());

Http.send(config);

#####PUT

Http.Builder builder = new Http.Builder("http://dummyhost.com/posts/1");

JSONObject json = new JSONObject();

json.accumulate("title", "foo");
json.accumulate("body", "bar");
json.accumulate("userId", 1);

HttpRequestConfig config = builder.put(json.toString());

Http.send(config);

#####DELETE

Http.Builder builder = new Http.Builder("http://dummyhost.com/posts/1");

HttpRequestConfig config = builder.delete();

Http.send(config);

#####UPLOAD

byte[] file = getFile();

Http.Builder builder = new Http.Builder("http://dummyhost.com/images");

HttpRequestConfig config = builder.upload(file);

Http.send(config);

#####HEADERS

Http.Builder builder = new Http.Builder("https://dummyhost.com/posts");

JSONObject json = new JSONObject();

json.accumulate("title", "foo");
json.accumulate("body", "bar");
json.accumulate("userId", 1);

HttpRequestConfig config = builder.post(json.toString());

config.addHeader("X-Application-Id", "T1zX12r2dasdareeafSasda2zG8QxCkaOQ2jIFVQLA3HZ7J");
config.addHeader("X-REST-API-Key", "Wn5rpappoDAsdq34DAAsdasasA6R4ZUnzdubMc");

HttpResult result =  Http.send(config);

#####INTERCEPTORS

public static class DefaultInterceptor implements HttpInterceptor {

    @Override
    public void onOpening(HttpRequestConfig httpRequestConfig) {
		httpRequestConfig.addHeader("X-Application-Id", "T1zX12r2dasdareeafSasda2zG8QxCkaOQ2jIFVQLA3HZ7J");
		httpRequestConfig.addHeader("X-REST-API-Key", "Wn5rpappoDAsdq34DAAsdasasA6R4ZUnzdubMc");        
    }

    @Override
    public void onConnecting(HttpURLConnection httpURLConnection, HttpRequestConfig httpRequestConfig) {  }

    @Override
    public void onConnected(HttpURLConnection httpURLConnection, HttpRequestConfig httpRequestConfig) {  }

    @Override
    public HttpResult onResult(HttpURLConnection httpURLConnection, HttpRequestConfig httpRequestConfig, HttpResult httpResult) {
        return httpResult;
    }
}

...

Http.getInterceptors().add(new DefaultInterceptor());

Http.Builder builder = new Http.Builder("https://dummyhost.com/posts");

JSONObject json = new JSONObject();

json.accumulate("title", "foo");
json.accumulate("body", "bar");
json.accumulate("userId", 1);

HttpRequestConfig config = builder.post(json.toString());

HttpResult result =  Http.send(config);

#####REQUEST INTERCEPTORS

public static class RequestInterceptor implements HttpInterceptor {

    @Override
    public void onOpening(HttpRequestConfig httpRequestConfig) {
    }

    @Override
    public void onConnecting(HttpURLConnection httpURLConnection, HttpRequestConfig httpRequestConfig) {  }

    @Override
    public void onConnected(HttpURLConnection httpURLConnection, HttpRequestConfig httpRequestConfig) {  }

    @Override
    public HttpResult onResult(HttpURLConnection httpURLConnection, HttpRequestConfig httpRequestConfig, HttpResult httpResult) {
        return new HttpResult(httpResult.getStatus(), "{ 'name': 'INTERCEPTED'} ", null) ;
    }
}

...

Http.Builder builder = new Http.Builder("https://dummyhost.com/posts");

HttpRequestConfig config = builder.get();

config.getInterceptors().add(new RequestInterceptor());

HttpResult result =  Http.send(config);

#####CALL INTERCEPTORS

Http.Builder builder = new Http.Builder("https://dummyhost.com/posts");

HttpRequestConfig config = builder.get();


// THE LAST PARAMETER INDICATES THAT OTHERS INTERCEPTORS ARE IGNORED
HttpResult result =  Http.send(config, new HttpInterceptor {
    @Override
    public void onOpening(HttpRequestConfig httpRequestConfig) { }

    @Override
    public void onConnecting(HttpURLConnection httpURLConnection, HttpRequestConfig httpRequestConfig) {  }

    @Override
    public void onConnected(HttpURLConnection httpURLConnection, HttpRequestConfig httpRequestConfig) {  }

    @Override
    public HttpResult onResult(HttpURLConnection httpURLConnection, HttpRequestConfig httpRequestConfig, HttpResult httpResult) {
        return new HttpResult(httpResult.getStatus(), "{ 'name': 'INTERCEPTED'} ", null) ;
    }    
},
true);

License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Версии библиотеки

Версия
0.1.0
0.0.4
0.0.3
0.0.2