下記記事で利用しているAmazon API Gatewayの利用詳細となります。
関連記事
目的
自前実装に比べて、セキュリティを担保しつつメンテナンスコストを低くしたい
概要図

Amazon API Gatewayを利用すると他所のAPIを一括管理するだけでなく、自社のAPIをよりセキュアに利用/アクセス回数のスロットリング/キャッシュを行う事も出来、CloudWatchでアクセス状況も見れるとの事なので、自社のレガシAPIのエンハンス用途にも良いとの事でした(公式マニュアル)
Amazon API Gatewayに新しくAPIを作成しResourcesを定義
本来会社名部分をパラメータ化すべきですが、、、テストという事で

Jsonレスポンスのスキーマを作成

APIのデプロイ及びAndroid用SDKをGenerateする

ダウンロードしたファイルを解凍するとpom.xmlファイルがあるのでMavenでビルド
mavenが入っていない場合、Macでhomebrewが入っていれば brew install maven
MacBook:Mycompany-Client-0.0.2 takashi$ pwd /Users/takashi/Downloads/Mycompany-Client-0.0.2 $ ls LICENSE.txt README.md pom.xml target NOTICE.txt build.gradle src $ mvn install ... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ ...
ビルドされたファイルをAndroidStudioのlib下にコピー
AndroidStudioでプロジェクトを新規作成、Project表示としてlibs下にコピー
及び build.gradle の dependencies を確認
ビルドで生成されたファイル郡

Android Studioで開いているプロジェクトのLibs下にコピー

Manifestのパーミッションを確認
下記が入っている事を確認
<uses-permission android:name="android.permission.INTERNET"/>
MainActivityにコードを書く
スキーマとして定義した物が名前引き可能です。
実行するとgithub apiからgetFollowersの値を取得してくれます。

ソースコード
import するパッケージ名やAPI名、メソッド名はご自身の設定に合わせて下さい。
package net.skyarch.myapplication; import android.os.AsyncTask; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import com.amazonaws.mobileconnectors.apigateway.ApiClientFactory; import net.skyarch.api.SkyarchAPIClient; public class MainActivity extends AppCompatActivity { protected final String TAG = "API Gateway SDK Test"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { //Githubから follower数を取得 ApiClientFactory factory = new ApiClientFactory(); final SkyarchAPIClient client = factory.build(SkyarchAPIClient.class); int followerCount = client.githubGet().getFollowers(); Log.d(TAG, "git followers" + Integer.toString(followerCount)); client.githubGet(). return null; } }.execute(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } }
参考記事
Amazon API Gatewayの利用方法
http://dev.classmethod.jp/cloud/aws/api-gateway-with-android/