publicinterfacegitapi{ @GET("/users/{user}") // here is the other url part.best way is to start using / publicvoidgetFeed(@Path("user") String user, Callback<gitmodel> response); // string user is for passing values from edittext for eg: user=basil2style,google // response is the response from the server which is now in the POJO }
package com.makeinfo.flowerpi; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; import android.widget.TextView; import com.makeinfo.flowerpi.API.gitapi; import com.makeinfo.flowerpi.model.gitmodel; import retrofit.Callback; import retrofit.RestAdapter; import retrofit.RetrofitError; import retrofit.client.Response; publicclassMainActivityextendsActionBarActivity{ Button click; TextView tv; EditText edit_user; ProgressBar pbar; String API = "https://api.github.com"; // BASE URL @Override protectedvoidonCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); click = (Button) findViewById(R.id.button); tv = (TextView) findViewById(R.id.tv); edit_user = (EditText) findViewById(R.id.edit); pbar = (ProgressBar) findViewById(R.id.pb); pbar.setVisibility(View.INVISIBLE); click.setOnClickListener(new View.OnClickListener() { @Override publicvoidonClick(View v){ String user = edit_user.getText().toString(); pbar.setVisibility(View.VISIBLE); // Retrofit section start from here... // create an adapter for retrofit with base url RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(API).build(); // creating a service for adapter with our GET class gitapi git = restAdapter.create(gitapi.class); // Now ,we need to call for response // Retrofit using gson for JSON-POJO conversion git.getFeed(user,new Callback<gitmodel>() { @Override publicvoidsuccess(gitmodel gitmodel, Response response){ // we get json object from github server to our POJO or model class tv.setText("Github Name :" + gitmodel.getName() + "\nWebsite :"+gitmodel.getBlog() + "\nCompany Name :"+gitmodel.getCompany()); pbar.setVisibility(View.INVISIBLE); // disable progressbar } @Override publicvoidfailure(RetrofitError error){ tv.setText(error.getMessage()); pbar.setVisibility(View.INVISIBLE); // disable progressbar } }); } }); } @Override publicbooleanonCreateOptionsMenu(Menu menu){ // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); returntrue; } @Override publicbooleanonOptionsItemSelected(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) { returntrue; } returnsuper.onOptionsItemSelected(item); } }