Search in sources :

Example 51 with Gson

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"));
}
Also used : OAuth2AccessToken(com.github.scribejava.core.model.OAuth2AccessToken) Gson(com.google.gson.Gson) ServiceBuilder(com.github.scribejava.core.builder.ServiceBuilder) Test(org.junit.Test)

Example 52 with Gson

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);
    }
}
Also used : UserSchSessions(com.keybox.manage.model.UserSchSessions) SchSession(com.keybox.manage.model.SchSession) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 53 with Gson

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);
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) ClientAuthInterceptor(io.plaidapp.data.api.ClientAuthInterceptor) DesignerNewsService(io.plaidapp.data.api.designernews.DesignerNewsService) Gson(com.google.gson.Gson) DenvelopingConverter(io.plaidapp.data.api.DenvelopingConverter)

Example 54 with Gson

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);
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) ProductHuntService(io.plaidapp.data.api.producthunt.ProductHuntService) AuthInterceptor(io.plaidapp.data.api.AuthInterceptor) Gson(com.google.gson.Gson) DenvelopingConverter(io.plaidapp.data.api.DenvelopingConverter)

Example 55 with Gson

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()])));
}
Also used : ListView(android.widget.ListView) InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Gson(com.google.gson.Gson) SearchResponse(com.novoda.model.SearchResponse) Result(com.novoda.model.Result)

Aggregations

Gson (com.google.gson.Gson)1309 Test (org.junit.Test)280 HashMap (java.util.HashMap)227 GsonBuilder (com.google.gson.GsonBuilder)174 JsonObject (com.google.gson.JsonObject)157 IOException (java.io.IOException)147 CommandWrapper (ClientServerApi.CommandWrapper)123 ArrayList (java.util.ArrayList)121 CommandExecuter (CommandHandler.CommandExecuter)119 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)118 JsonSyntaxException (com.google.gson.JsonSyntaxException)103 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)96 JsonElement (com.google.gson.JsonElement)78 Type (java.lang.reflect.Type)77 Map (java.util.Map)63 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)53 SmartCode (BasicCommonClasses.SmartCode)50 InputStreamReader (java.io.InputStreamReader)49 List (java.util.List)49 TypeToken (com.google.gson.reflect.TypeToken)44