Learzhu / Novate

A safety client by Https for android, (Android网路库,基于Retrofit和RxJava打的的链式网络库, 支持okhttp的调用风格,又兼容Retrofit注解方式,并支持rxJava链式操作。方便扩展,并能实现高速加载)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Novate

  a safety client by Https for Android, (Android网路库,基于Retrofit和RxJava打的的链式网络库, 支持okhttp的调用风格,又兼容Retrofit注解方式,并支持rxJava链式操作。方便扩展,并能实现高速加载)

Summary

  • Join based API, reduce API redundancy
  • Offline caching
  • Support a variety of ways to access the network (a get, put, post, delete)
  • Support file download and upload
  • Unified support request header to join
  • The unity of the support to return the result
  • Support custom extensions API
  • Support the unified request access to the network flow control

#dependencies

Eclipse:

Download the laster JAR:( com.tamic.novate:novate:-1.x.aar)

copy to libs dirPath!

AS Gradle:  

  • root:

       repositories {
          maven { url "https://jitpack.io" }
          jcenter()
      }
    
  • app:

       dependencies {
          .....
    

            compile 'com.tamic.novate:novate:1.x.x(laster version)'

     }

Snapshots of the development version are available in Sonatype's snapshots repository.

Retrofit requires at minimum Java 7 or Android 2.3.

last vension: https://bintray.com/neglectedbyboss/maven/Novate


中文文档

基于Retrofit和RxJava封装的链式网络库, 支持okhttp的调用分格式,又兼容Retrofit注解方式,并支持rxJava链式操作,

并于扩展,并能实现高速加载!   为何起名 Novate?

Novate的英文原意是用新事物代替 我的目的是用新的东西来代替Retrofit的有些不易操作的地方,因此起名新奇的东西,所以结合了原来的Http用法习惯,又加入了Retrofit的特性,因此起名 :Novate

功能

  • 加入基础API,减少Api冗余
  • 支持离线缓存
  • 支持多种方式访问网络(get,put,post ,delete)
  • 支持Json字符串,表单提交
  • 支持文件下载和上传
  • 支持请求头统一加入
  • 支持对返回结果的统一处理
  • 支持自定义的扩展API
  • 支持统一请求访问网络的流程控制

  请求网络无需关心是否在主线程和非UI线程,操作UI直接可在回调处理, 保留了HttpClient的编码习惯,又加入了Builder模式编程!

用法

    Novate novate = new Novate.Builder(this)
            .baseUrl(baseUrl)
            .build();

GET

    novate.executeGet("pathUrl", parameters, new Novate.ResponseCallBack<NovateResponse<MyModel>>() {
    
        .....
    
    });

POST

    novate.executePost("pathUrl", parameters, new Novate.ResponseCallBack<NovateResponse<MyModel>>() {
    
       .............
    
    });

BODY

ovate.body(url, uesrBean, new BaseSubscriber<ResponseBody>() {
        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onNext(ResponseBody responseBody) {

        }
    });

#FORM#

    novate.Form(url, new HashMap<String, Object>(), new BaseSubscriber<ResponseBody>() {
        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onNext(ResponseBody responseBody) {

        }
    });

JSON

      novate.json(url, jsonString, new BaseSubscriber<ResponseBody>() {
        @Override
        public void onError(Throwable e) {
            
        }

        @Override
        public void onNext(ResponseBody responseBody) {

        }
    });        

UpLoad

upLoadImage

RequestBody requestFile =
                RequestBody.create(MediaType.parse("image/jpg"), new File(you file path));

  novate.upload(url, requestFile, new BaseSubscriber<ResponseBody>{
  
    '''''''''''''''
  });

upLoadFile

     String mPath = "you File path ";
    String url = "";

    File file = new File(mPath);

    // 创建 RequestBody,用于封装 请求RequestBody
    RequestBody requestFile =
            RequestBody.create(MediaType.parse("multipart/form-data"), file);

     // MultipartBody.Part is used to send also the actual file name
    MultipartBody.Part body =
            MultipartBody.Part.createFormData("image", file.getName(), requestFile);

   // 添加描述
    String descriptionString = "hello, 这是文件描述";
    RequestBody description =
            RequestBody.create(
                    MediaType.parse("multipart/form-data"), descriptionString);

    // 执行

    novate.uploadFlie(url, description,  body,new BaseSubscriber<ResponseBody>(ExempleActivity.this) {.......
     });

upLoadFiles

    Map<String, RequestBody> maps = new HashMap<>();
    maps.put("file1", requestFile);
    novate.uploadFlies(url, maps, new BaseSubscriber<ResponseBody>(ExempleActivity.this) {
       ......
    } );

DownLoad

downLoad for MaxFile

  novate.download(downUrl, new DownLoadCallBack() {
  
     ''''''''''''
  });

downLoad for minFile

 novate.downloadMin(downUrl, new DownLoadCallBack() {
  
     ''''''''''''
  });

Custom Api

如果默认的BaseApiService无法满足你的需求时,novate同样支持你自己的ApiService。

MyApi

 public interface MyApi {

  @GET("url")
  Observable<MyBean> getdata(@QueryMap Map<String, String> maps);

 }

Execute

 MyApi myApi = novate.create(MyApi.class);

 novate.call(myAPI.getdata(parameters),
            new BaseSubscriber<MyBean>{
            '''''''
            });

}

#注意

如果你觉得此框架的业务码和错误码定的太死,其实框架已提供定制化方案,比如可以在你的项目中Assets中修改config文件:

如果想用自带的成功状态码0,不成功为非零的情况,可忽略一下配置。 { "isFormat": "false", "sucessCode": [ "1", "0", "1001" ], "error": { "1001": "网络异常" } }

如果不想对结果格式化检查,请将isFormat设置为:false

将修改sucessCode的成功业务吗,请将你的成功的业务码加入到sucessCode节点中。

错误码

需要对错误码进行自定义翻译,请配置相关error信息,具体可配置成:

             `{
           "isFormat": "false",
              "sucessCode": [
                "1",
             "0",
              "1001"
            ],
            "error": {
              "1001": "网络异常",
              "1002": "加入你的异常信息"
                     }
             }

#Update Log  

版本历史: https://bintray.com/neglectedbyboss/maven/Novate

  • V1.2.9*: 强化取消请求API.2017.1

  • V1.2.8*: 修需数据被备份的安全漏洞。 2017.1

  • V1.2.7*: 优化相关下载代码。优化cookie同步时对某些网站不兼容问题,2016.12

  • V1.2.6.x: 优化相关下载代码,并提交遗漏的put和delete方法,并将Http默认结果码会调到错误结果码中,增加对参数的泛型支持 。2016.12

  • V1.2.5-bata: 提供只对Response真实数据(T data)处理的功能,简化上层调用方式,但是不灵活,可选择使用,。2016.11

  • V1.2.3: 增加对缓存功能的配置开关,可选择的对api进行缓存。2016.11

  • V1.2.2: 解决对Response一些转换异常。2016.11

  • V1.2.1: 增加对json的提交的支持。2016.11

  • V1.2.0: 增加对Response数据结构格式,业务码,错误码的配置功能。提供自定义配置成功码和错误码功能。2016.11

  • V 1.1.1 : 更新对返回结果异常的判断分发出处理 2016.10

  • V1.1.0: 增加Response异常处理和容错处理。2016.10

  • V 1.0.2 :  增加body提交方式,增加小文件下载,增加表单方式提交功能,并新增设置是否同步cookie接口 . 2016.9

  • V1.0.1: 扩展下载接口,可以制定下载路径和文件名,包括修复下载抛异常问题。2016.8

  • V 1.0 :   基于retrofit和Rxjava完成以泛型基础的get, put, Post delete, upLoad, downLoad功能 2016.6

#License

Copyright 2013 Square, Inc.

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.   

更多介绍:http://www.jianshu.com/p/d7734390895e

About

A safety client by Https for android, (Android网路库,基于Retrofit和RxJava打的的链式网络库, 支持okhttp的调用风格,又兼容Retrofit注解方式,并支持rxJava链式操作。方便扩展,并能实现高速加载)

License:Apache License 2.0


Languages

Language:Java 100.0%