use of com.google.gson.Gson in project scribejava by scribejava.
the class OAuth20ServiceTest method shouldProduceCorrectRequestAsync.
@Test
public void shouldProduceCorrectRequestAsync() throws ExecutionException, InterruptedException {
final OAuth20Service service = new ServiceBuilder().apiKey("your_api_key").apiSecret("your_api_secret").build(new OAuth20ApiUnit());
final OAuth2AccessToken token = service.getAccessTokenPasswordGrantAsync("user1", "password1", null).get();
final Gson json = new Gson();
assertNotNull(token);
final Map<String, String> map = json.fromJson(token.getRawResponse(), new TypeTokenImpl().getType());
assertEquals(OAuth20ServiceUnit.TOKEN, map.get(OAuthConstants.ACCESS_TOKEN));
assertEquals(OAuth20ServiceUnit.STATE, map.get(OAuthConstants.STATE));
assertEquals(OAuth20ServiceUnit.EXPIRES, map.get("expires_in"));
final String authorize = Base64Encoder.getInstance().encode(String.format("%s:%s", service.getConfig().getApiKey(), service.getConfig().getApiSecret()).getBytes(Charset.forName("UTF-8")));
assertEquals(OAuthConstants.BASIC + " " + authorize, map.get(OAuthConstants.HEADER));
assertEquals("user1", map.get("query-username"));
assertEquals("password1", map.get("query-password"));
assertEquals("password", map.get("query-grant_type"));
}
use of com.google.gson.Gson in project KeyBox by skavanagh.
the class SecureShellWS method onMessage.
@OnMessage
public void onMessage(String message) {
if (session.isOpen() && StringUtils.isNotEmpty(message)) {
Map jsonRoot = new Gson().fromJson(message, Map.class);
String command = (String) jsonRoot.get("command");
Integer keyCode = null;
Double keyCodeDbl = (Double) jsonRoot.get("keyCode");
if (keyCodeDbl != null) {
keyCode = keyCodeDbl.intValue();
}
for (String idStr : (ArrayList<String>) jsonRoot.get("id")) {
Integer id = Integer.parseInt(idStr);
//get servletRequest.getSession() for user
UserSchSessions userSchSessions = SecureShellAction.getUserSchSessionMap().get(sessionId);
if (userSchSessions != null) {
SchSession schSession = userSchSessions.getSchSessionMap().get(id);
if (keyCode != null) {
if (keyMap.containsKey(keyCode)) {
try {
schSession.getCommander().write(keyMap.get(keyCode));
} catch (IOException ex) {
log.error(ex.toString(), ex);
}
}
} else {
schSession.getCommander().print(command);
}
}
}
//update timeout
AuthUtil.setTimeout(httpSession);
}
}
use of com.google.gson.Gson in project plaid by nickbutcher.
the class DesignerNewsPrefs method createApi.
private void createApi() {
final OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new ClientAuthInterceptor(accessToken, BuildConfig.DESIGNER_NEWS_CLIENT_ID)).build();
final Gson gson = new Gson();
api = new Retrofit.Builder().baseUrl(DesignerNewsService.ENDPOINT).client(client).addConverterFactory(new DenvelopingConverter(gson)).addConverterFactory(GsonConverterFactory.create(gson)).build().create(DesignerNewsService.class);
}
use of com.google.gson.Gson in project plaid by nickbutcher.
the class BaseDataManager method createProductHuntApi.
private void createProductHuntApi() {
final OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new AuthInterceptor(BuildConfig.PROCUCT_HUNT_DEVELOPER_TOKEN)).build();
final Gson gson = new Gson();
productHuntApi = new Retrofit.Builder().baseUrl(ProductHuntService.ENDPOINT).client(client).addConverterFactory(new DenvelopingConverter(gson)).addConverterFactory(GsonConverterFactory.create(gson)).build().create(ProductHuntService.class);
}
use of com.google.gson.Gson in project android-demos by novoda.
the class JsonRequest method onResume.
@Override
protected void onResume() {
super.onResume();
Toast.makeText(this, "Querying droidcon on Twitter", Toast.LENGTH_SHORT).show();
Reader reader = new InputStreamReader(retrieveStream(url));
SearchResponse response = new Gson().fromJson(reader, SearchResponse.class);
List<String> searches = new ArrayList<String>();
Iterator<Result> i = response.results.iterator();
while (i.hasNext()) {
Result res = (Result) i.next();
searches.add(res.text);
}
ListView v = (ListView) findViewById(R.id.list);
v.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, searches.toArray(new String[searches.size()])));
}
Aggregations