@Subscribe public void onCustom(CustomEvent customEvent) { if (customEvent.Sender == this) { return; } try { JSONObject eventJSON = new JSONObject(); eventJSON.put("name", customEvent.getName()); JSONObject extraJSON = new JSONObject(); if (customEvent.getExtra() != null) { for (String ex : customEvent.getExtra().keySet()) { extraJSON.put(ex, customEvent.getExtra().get(ex)); } } eventJSON.put("extra", extraJSON); UnityPlayer.UnitySendMessage("CoreEvents", "onCustomEvent", eventJSON.toString()); } catch (JSONException e) { SoomlaUtils.LogError( "SOOMLA SoomlaEventHandler", "This is BAD! couldn't create JSON for onMarketItemsRefreshFinished event."); } }
private static boolean resetStateFromJSON( JSONObject state, String targetListName, IItemStateApplier stateApplier) { if (!state.has(targetListName)) { return true; } SoomlaUtils.LogDebug(TAG, "Resetting state for " + targetListName); try { JSONObject itemsJSON = state.getJSONObject(targetListName); Iterator keysIter = itemsJSON.keys(); while (keysIter.hasNext()) { String itemId = (String) keysIter.next(); JSONObject itemValuesJSON = itemsJSON.getJSONObject(itemId); if (!stateApplier.applyState(itemId, itemValuesJSON)) { return false; } } } catch (JSONException e) { SoomlaUtils.LogError( TAG, "Unable to set state for " + targetListName + ". error: " + e.getLocalizedMessage()); return false; } return true; }
@Subscribe public void onRewardTaken(RewardTakenEvent rewardTakenEvent) { try { JSONObject eventJSON = new JSONObject(); eventJSON.put("rewardId", rewardTakenEvent.RewardId); UnityPlayer.UnitySendMessage("CoreEvents", "onRewardTaken", eventJSON.toString()); } catch (JSONException e) { SoomlaUtils.LogError( "SOOMLA SoomlaEventHandler", "This is BAD! couldn't create JSON for onRewardGiven event."); } }
public static HashMap<String, JSONObject> getWorlds(JSONObject model) { HashMap<String, JSONObject> worlds = new HashMap<String, JSONObject>(); try { JSONObject mainWorld = model.getJSONObject("mainWorld"); addWorldObjectToWorlds(worlds, mainWorld); } catch (JSONException e) { SoomlaUtils.LogError( TAG, "couldn't get something from model. error: " + e.getLocalizedMessage()); } return worlds; }
private UserProfile createUserProfile(User user, boolean withExtraFields) { String fullName = user.getName(); String firstName = ""; String lastName = ""; if (!TextUtils.isEmpty(fullName)) { String[] splitName = fullName.split(" "); if (splitName.length > 0) { firstName = splitName[0]; if (splitName.length > 1) { lastName = splitName[1]; } } } Map<String, Object> extraDict = Collections.<String, Object>emptyMap(); if (withExtraFields) { extraDict = new HashMap<String, Object>(); // TwitterException will throws when Twitter service or network is unavailable, or the user // has not authorized try { extraDict.put("access_token", twitter.getOAuthAccessToken().getToken()); } catch (TwitterException twitterExc) { SoomlaUtils.LogError(TAG, twitterExc.getErrorMessage()); } } // Twitter does not supply email access: https://dev.twitter.com/faq#26 UserProfile result = new UserProfile( RefProvider, String.valueOf(user.getId()), user.getScreenName(), "", firstName, lastName, extraDict); // No gender information on Twitter: // https://twittercommunity.com/t/how-to-find-male-female-accounts-in-following-list/7367 result.setGender(""); // No birthday on Twitter: // https://twittercommunity.com/t/how-can-i-get-email-of-user-if-i-use-api/7019/16 result.setBirthday(""); result.setLanguage(user.getLang()); result.setLocation(user.getLocation()); result.setAvatarLink(user.getBiggerProfileImageURL()); return result; }
private static void findInternalLists( HashMap<String, JSONObject> objects, String[] listClasses, String listName) { try { List<String> classes = Arrays.asList(listClasses); Set<JSONObject> valuesSet = new HashSet<JSONObject>(objects.values()); for (JSONObject objectJSON : valuesSet) { findInternalLists(objects, classes, listName, objectJSON); } } catch (JSONException e) { SoomlaUtils.LogError( TAG, "couldn't get internal lists for " + listName + ". error: " + e.getLocalizedMessage()); } }
public static JSONObject getLevelUpModel() { JSONObject modelJSON = null; String model = KeyValueStorage.getValue(DB_KEY_PREFIX + "model"); SoomlaUtils.LogDebug(TAG, "model: " + model); if (model == null) { return null; } try { modelJSON = new JSONObject(model); } catch (JSONException e) { SoomlaUtils.LogError(TAG, "Unable to parse LevelUp model into JSON"); } return modelJSON; }
/** {@inheritDoc} */ @Override public void configure(Map<String, String> providerParams) { autoLogin = false; if (providerParams != null) { twitterConsumerKey = providerParams.get("consumerKey"); twitterConsumerSecret = providerParams.get("consumerSecret"); // extract autoLogin String autoLoginStr = providerParams.get("autoLogin"); autoLogin = autoLoginStr != null && Boolean.parseBoolean(autoLoginStr); } SoomlaUtils.LogDebug( TAG, String.format( "ConsumerKey:%s ConsumerSecret:%s", twitterConsumerKey, twitterConsumerSecret)); if (TextUtils.isEmpty(twitterConsumerKey) || TextUtils.isEmpty(twitterConsumerSecret)) { SoomlaUtils.LogError( TAG, "You must provide the Consumer Key and Secret in the SoomlaProfile initialization parameters"); isInitialized = false; } else { isInitialized = true; } oauthCallbackURL = "oauth://soomla_twitter" + twitterConsumerKey; ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(twitterConsumerKey); configurationBuilder.setOAuthConsumerSecret(twitterConsumerSecret); Configuration configuration = configurationBuilder.build(); twitter = new AsyncTwitterFactory(configuration).getInstance(); if (!actionsListenerAdded) { SoomlaUtils.LogWarning(TAG, "added action listener"); twitter.addListener(actionsListener); actionsListenerAdded = true; } }
/** {@inheritDoc} */ @Override public void login( final Activity parentActivity, final AuthCallbacks.LoginListener loginListener) { if (!isInitialized) { SoomlaUtils.LogError( TAG, "Consumer key and secret were not defined, please provide them in initialization"); return; } SoomlaUtils.LogDebug(TAG, "login"); WeakRefParentActivity = new WeakReference<Activity>(parentActivity); RefProvider = getProvider(); RefLoginListener = loginListener; preformingAction = ACTION_LOGIN; mainRequestToken = null; twitter.setOAuthAccessToken(null); // Try logging in using store credentials String oauthToken = KeyValueStorage.getValue(getTwitterStorageKey(TWITTER_OAUTH_TOKEN)); String oauthTokenSecret = KeyValueStorage.getValue(getTwitterStorageKey(TWITTER_OAUTH_SECRET)); if (!TextUtils.isEmpty(oauthToken) && !TextUtils.isEmpty(oauthTokenSecret)) { twitter.setOAuthAccessToken(new AccessToken(oauthToken, oauthTokenSecret)); twitterScreenName = KeyValueStorage.getValue(getTwitterStorageKey(TWITTER_SCREEN_NAME)); loginListener.success(RefProvider); clearListener(ACTION_LOGIN); } else { // If no stored credentials start login process by requesting // a request token twitter.getOAuthRequestTokenAsync(oauthCallbackURL); } }