apollo-lib-network

Android libraries to make your life easier!

License

License

Categories

Categories

Net Apollo Container Microservices
GroupId

GroupId

com.apollo-lib
ArtifactId

ArtifactId

network
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

aar
Description

Description

apollo-lib-network
Android libraries to make your life easier!
Project URL

Project URL

https://github.com/fabianofranca/apollo-lib
Source Code Management

Source Code Management

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

Download network

How to add to project

<!-- 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"]

Dependencies

compile (1)

Group / Artifact Type Version
com.android.support » appcompat-v7 jar 23.0.1

Project Modules

There are no modules declared in this project.

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.

Versions

Version
0.1.0
0.0.4
0.0.3
0.0.2