android.net.Uri.Builder Java Examples

The following examples show how to use android.net.Uri.Builder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        The token of the logged in user.
 * @param action
 * @param parameters
 * @param handler      Response handler
 */

public static void flagContent(String collectionId, String contentId,
                               String token, LFSFlag action, RequestParams parameters,
                               JsonHttpResponseHandler handler) {

    String url = (new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("")) +
            contentId + (new Uri.Builder().appendPath("").appendPath("flag")
            .appendPath(flags[action.value()])
            .appendQueryParameter("lftoken", token)
            .appendQueryParameter("collection_id", collectionId));

    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
 
Example #2
Source File: ConversationsListFragment.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
private void confirmDeleteThread(final String from) {
  	
      AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
      builder.setTitle(R.string.confirm_dialog_title)
          .setIcon(android.R.drawable.ic_dialog_alert)
      .setCancelable(true)
      .setPositiveButton(R.string.delete, new OnClickListener() {
	@Override
	public void onClick(DialogInterface dialog, int which) {
		if(TextUtils.isEmpty(from)) {
		    getActivity().getContentResolver().delete(SipMessage.MESSAGE_URI, null, null);
		}else {
		    Builder threadUriBuilder = SipMessage.THREAD_ID_URI_BASE.buildUpon();
		    threadUriBuilder.appendEncodedPath(from);
		    getActivity().getContentResolver().delete(threadUriBuilder.build(), null, null);
		}
	}
})
      .setNegativeButton(R.string.no, null)
      .setMessage(TextUtils.isEmpty(from)
              ? R.string.confirm_delete_all_conversations
                      : R.string.confirm_delete_conversation)
      .show();
  }
 
Example #3
Source File: AdminClient.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
/**
 * Generates an auth endpoint with the specified parameters.
 *
 * @param userToken    The lftoken representing a user.
 * @param collectionId The Id of the collection to auth against.
 * @param articleId    The Id of the collection's article.
 * @param siteId       The Id of the article's site.
 * @return The auth endpoint with the specified parameters.
 * @throws UnsupportedEncodingException
 * @throws MalformedURLException
 */
public static String generateAuthEndpoint(String userToken,
                                          String collectionId,
                                          String articleId,
                                          String siteId) throws UnsupportedEncodingException {
    Builder uriBuilder = new Uri.Builder()
            .scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.adminDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api")
            .appendPath("v3.0")
            .appendPath("auth")
            .appendPath("");

    if (collectionId != null) {
        uriBuilder.appendQueryParameter("collectionId", collectionId)
                .appendQueryParameter("lftoken", userToken);
    } else {
        final String article64 = Helpers.generateBase64String(articleId);
        uriBuilder.appendQueryParameter("siteId", siteId)
                .appendQueryParameter("articleId", article64)
                .appendQueryParameter("lftoken", userToken);
    }
    Log.d("Admin URL", "" + uriBuilder.toString());
    return uriBuilder.toString();
}
 
Example #4
Source File: AbstractContentProviderStub.java    From letv with Apache License 2.0 6 votes vote down vote up
private Uri buildNewUri(Uri uri, String targetAuthority) {
    Builder b = new Builder();
    b.scheme(uri.getScheme());
    b.authority(targetAuthority);
    b.path(uri.getPath());
    if (VERSION.SDK_INT >= 11) {
        Set<String> names = uri.getQueryParameterNames();
        if (names != null && names.size() > 0) {
            for (String name : names) {
                if (!TextUtils.equals(name, ApkConstant.EXTRA_TARGET_AUTHORITY)) {
                    b.appendQueryParameter(name, uri.getQueryParameter(name));
                }
            }
        }
    } else {
        b.query(uri.getQuery());
    }
    b.fragment(uri.getFragment());
    return b.build();
}
 
Example #5
Source File: ContactListManagerAdapter.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
void insertBlockedContactToDataBase(Contact contact) {
    // Remove the blocked contact if it already exists, to avoid duplicates and
    // handle the odd case where a blocked contact's nickname has changed
    removeBlockedContactFromDataBase(contact);

    Uri.Builder builder = Imps.BlockedList.CONTENT_URI.buildUpon();
    ContentUris.appendId(builder,  mConn.getProviderId());
    ContentUris.appendId(builder, mConn.getAccountId());
    Uri uri = builder.build();

    String username = mAdaptee.normalizeAddress(contact.getAddress().getAddress());
    ContentValues values = new ContentValues(2);
    values.put(Imps.BlockedList.USERNAME, username);
    values.put(Imps.BlockedList.NICKNAME, contact.getName());

    mResolver.insert(uri, values);

    mValidatedBlockedContacts.add(username);
}
 
Example #6
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
/**
 * @param action
 * @param contentId
 * @param collectionId The Id of the collection.
 * @param userToken    The token of the logged in user.
 * @param parameters
 * @param networkID    Livefyre provided network name
 * @param handler      Response handler
 * @throws MalformedURLException
 */
public static void featureMessage(String action, String contentId,
                                  String collectionId, String userToken,
                                  HashMap<String, Object> parameters, String networkID, JsonHttpResponseHandler handler)
        throws MalformedURLException {
    RequestParams bodyParams = new RequestParams();
    bodyParams.put("lftoken", userToken);

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("collection")
            .appendPath(collectionId).appendPath(action)
            .appendPath(contentId).appendPath("")
            .appendQueryParameter("lftoken", userToken)
            .appendQueryParameter("collection_id", collectionId);

    Log.d("SDK", "" + uriBuilder);
    HttpClient.client.post(uriBuilder.toString(), bodyParams, handler);
}
 
Example #7
Source File: FileProvider.java    From letv with Apache License 2.0 6 votes vote down vote up
public Uri getUriForFile(File file) {
    try {
        String rootPath;
        String path = file.getCanonicalPath();
        Entry<String, File> mostSpecific = null;
        for (Entry<String, File> root : this.mRoots.entrySet()) {
            rootPath = ((File) root.getValue()).getPath();
            if (path.startsWith(rootPath) && (mostSpecific == null || rootPath.length() > ((File) mostSpecific.getValue()).getPath().length())) {
                mostSpecific = root;
            }
        }
        if (mostSpecific == null) {
            throw new IllegalArgumentException("Failed to find configured root that contains " + path);
        }
        rootPath = ((File) mostSpecific.getValue()).getPath();
        if (rootPath.endsWith("/")) {
            path = path.substring(rootPath.length());
        } else {
            path = path.substring(rootPath.length() + 1);
        }
        return new Builder().scheme(WidgetRequestParam.REQ_PARAM_COMMENT_CONTENT).authority(this.mAuthority).encodedPath(Uri.encode((String) mostSpecific.getKey()) + LetvUtils.CHARACTER_BACKSLASH + Uri.encode(path, "/")).build();
    } catch (IOException e) {
        throw new IllegalArgumentException("Failed to resolve canonical path for " + file);
    }
}
 
Example #8
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
/**
 * @param collectionId The Id of the collection.
 * @param contentId
 * @param token        The token of the logged in user.
 * @param action
 * @param parameters
 * @param handler      Response handler
 */

public static void postAction(String collectionId, String contentId,
                              String token, LFSActions action, RequestParams parameters,
                              JsonHttpResponseHandler handler) {
    // Build the URL
    String url = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("") + contentId +
            (new Uri.Builder().appendPath(actions[action.value()]).appendPath("")
                    .appendQueryParameter("lftoken", token)
                    .appendQueryParameter("collection_id", collectionId));


    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
 
Example #9
Source File: AbstractContentProviderStub.java    From DroidPlugin with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Uri buildNewUri(Uri uri, String targetAuthority) {
    Uri.Builder b = new Builder();
    b.scheme(uri.getScheme());
    b.authority(targetAuthority);
    b.path(uri.getPath());

    if (VERSION.SDK_INT >= VERSION_CODES.HONEYCOMB) {
        Set<String> names = uri.getQueryParameterNames();
        if (names != null && names.size() > 0) {
            for (String name : names) {
                if (!TextUtils.equals(name, Env.EXTRA_TARGET_AUTHORITY)) {
                    b.appendQueryParameter(name, uri.getQueryParameter(name));
                }
            }
        }
    } else {
        b.query(uri.getQuery());
    }
    b.fragment(uri.getFragment());
    return b.build();
}
 
Example #10
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
public static boolean messageExists (ContentResolver resolver, String id)
{
    boolean result = false;

    Uri.Builder builder = Messages.OTR_MESSAGES_CONTENT_URI_BY_PACKET_ID.buildUpon();
    builder.appendPath(id);

    Cursor c = resolver.query(builder.build(),null, null, null, null);
    if (c != null)
    {
        if (c.getCount() > 0)
            result = true;

        c.close();
    }

    return result;
}
 
Example #11
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
public static int updateConfirmInDb(ContentResolver resolver, long threadId, String msgId, boolean isDelivered) {
    Uri.Builder builder = Imps.Messages.OTR_MESSAGES_CONTENT_URI_BY_PACKET_ID.buildUpon();
    builder.appendPath(msgId);

    ContentValues values = new ContentValues(1);
    values.put(Imps.Messages.IS_DELIVERED, isDelivered);
    values.put(Messages.THREAD_ID,threadId);
    int result = resolver.update(builder.build(), values, null, null);

    if (result == 0)
    {
        builder = Messages.CONTENT_URI_MESSAGES_BY_PACKET_ID.buildUpon();
        builder.appendPath(msgId);
        result = resolver.update(builder.build(), values, null, null);
    }

    return result;
}
 
Example #12
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
public static boolean setEmptyPassphrase(Context ctx, boolean noCreate) {
    String pkey = "";

    Uri uri = Provider.CONTENT_URI_WITH_ACCOUNT;

    Builder builder = uri.buildUpon().appendQueryParameter(ImApp.CACHEWORD_PASSWORD_KEY, pkey);
    if (noCreate) {
        builder.appendQueryParameter(ImApp.NO_CREATE_KEY, "1");
    }
    uri = builder.build();

    Cursor cursor = ctx.getContentResolver().query(uri, null, null, null, null);
    if (cursor != null) {
        cursor.close();
        return true;
    }
    return false;
}
 
Example #13
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 6 votes vote down vote up
public static int updateMessageInDb(ContentResolver resolver, String id, int type, long time, long contactId) {

        Uri.Builder builder = Imps.Messages.OTR_MESSAGES_CONTENT_URI_BY_PACKET_ID.buildUpon();
        builder.appendPath(id);

        ContentValues values = new ContentValues(2);
        values.put(Imps.Messages.TYPE, type);
        values.put(Imps.Messages.THREAD_ID, contactId);
        if (time != -1)
            values.put(Imps.Messages.DATE, time);

        int result = resolver.update(builder.build(), values, null, null);

        if (result == 0)
        {
            builder = Imps.Messages.CONTENT_URI_MESSAGES_BY_PACKET_ID.buildUpon();
            builder.appendPath(id);
            result = resolver.update(builder.build(), values, null, null);
        }

        return result;
    }
 
Example #14
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 6 votes vote down vote up
/**
 * @param action
 * @param contentId
 * @param collectionId The Id of the collection.
 * @param userToken    The token of the logged in user.
 * @param parameters
 * @param handler      Response handler
 * @throws MalformedURLException
 */

public static void featureMessage(String action, String contentId,
                                  String collectionId, String userToken,
                                  HashMap<String, Object> parameters, JsonHttpResponseHandler handler)
        throws MalformedURLException {
    RequestParams bodyParams = new RequestParams();
    bodyParams.put("lftoken", userToken);

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("collection")
            .appendPath(collectionId).appendPath(action)
            .appendPath(contentId).appendPath("")
            .appendQueryParameter("lftoken", userToken)
            .appendQueryParameter("collection_id", collectionId);

    Log.d("SDK", "" + uriBuilder);
    HttpClient.client.post(uriBuilder.toString(), bodyParams, handler);
}
 
Example #15
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 5 votes vote down vote up
/**
 * @param authorId   Author of Post
 * @param token      Livefyre Token
 * @param parameters Parameters includes network,
 * @param handler    Response handler
 */

public static void flagAuthor(String authorId, String token,
                              RequestParams parameters, JsonHttpResponseHandler handler) {
    // Build the URL

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + LivefyreConfig.getConfiguredNetworkID())
            .appendPath("api").appendPath("v3.0").appendPath("author");
    String url = uriBuilder + "/" + authorId + (new Uri.Builder().appendPath("ban").appendPath("").appendQueryParameter("lftoken", token));

    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
 
Example #16
Source File: EventsDelegate.java    From spark-sdk-android with Apache License 2.0 5 votes vote down vote up
Uri buildSingleDeviceEventUri(@Nullable String eventNamePrefix, String deviceId) {
    Builder builder = devicesBaseUri.buildUpon()
            .appendPath(deviceId)
            .appendPath(EVENTS);
    if (truthy(eventNamePrefix)) {
        builder.appendPath(eventNamePrefix);
    }
    return builder.build();
}
 
Example #17
Source File: RequestBuilder.java    From letv with Apache License 2.0 5 votes vote down vote up
public HTTPAgent buildUnBindThird(String appid, String uid, String tkt, String tappname, String tappid) {
    Builder ub = getBuilder("uac/m/third", "method", "unbindthird");
    HTTPAgent.Builder hb = new HTTPAgent.Builder();
    append(hb, "appid", appid);
    append(hb, "uid", uid);
    append(hb, "tkt", tkt);
    append(hb, "tappname", tappname);
    append(hb, "tappid", tappid);
    return new PostAgent(ub.build(), Passport.getHosts(), hb.buildJSON());
}
 
Example #18
Source File: RequestBuilder.java    From letv with Apache License 2.0 5 votes vote down vote up
public HTTPAgent buildupdateDeviceId(String uid, String tkt, String newdevid, String olddevid, String appid) {
    Builder ub = getBuilder("uac/m/update_devid");
    HTTPAgent.Builder hb = new HTTPAgent.Builder();
    append(hb, "uid", uid);
    append(hb, "tkt", tkt);
    append(hb, "newdevid", newdevid);
    append(hb, "olddevid", olddevid);
    append(hb, "appid", appid);
    return new PostAgent(ub.build(), Passport.getHosts(), hb.buildJSON());
}
 
Example #19
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 5 votes vote down vote up
/**
 * @param collectionId The Id of the collection.
 * @param userToken    The token of the logged in user.
 * @param endpoint
 * @param networkID    Livefyre provided network name.
 * @return
 * @throws MalformedURLException
 */
public static String generateWriteURL(
        String collectionId, String userToken, String endpoint, String networkID)
        throws MalformedURLException {
    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("collection")
            .appendPath(collectionId).appendPath("post");
    if (LFSConstants.LFSPostTypeReview.equals(endpoint))
        uriBuilder.appendPath(endpoint).appendPath("");
    else
        uriBuilder.appendPath("");
    Log.d("Write URL", "" + uriBuilder.toString());
    return uriBuilder.toString();
}
 
Example #20
Source File: RequestBuilder.java    From letv with Apache License 2.0 5 votes vote down vote up
public HTTPAgent buildGetExchangeRecords(String uid, String tkt, String appId, String startDate, int pageOffset, int pageSize, int pageNum) {
    Builder ub = getBuilder("uac/m/score/get_exchange_records");
    HTTPAgent.Builder hb = new HTTPAgent.Builder();
    append(hb, "uid", uid);
    append(hb, "tkt", tkt);
    append(hb, "appid", appId);
    append(hb, "start_date", startDate);
    append(hb, "page_offset", "" + pageOffset);
    append(hb, "page_size", "" + pageSize);
    append(hb, "page_number", "" + pageNum);
    return new PostAgent(ub.build(), Passport.getHosts(), hb.buildJSON());
}
 
Example #21
Source File: RequestBuilder.java    From letv with Apache License 2.0 5 votes vote down vote up
public HTTPAgent buildGetExchangeRate(String uid, String tkt, String appId) {
    Builder ub = getBuilder("uac/m/score/get_exchange_rate");
    HTTPAgent.Builder hb = new HTTPAgent.Builder();
    append(hb, "uid", uid);
    append(hb, "tkt", tkt);
    append(hb, "appid", appId);
    return new PostAgent(ub.build(), Passport.getHosts(), hb.buildJSON());
}
 
Example #22
Source File: RequestBuilder.java    From letv with Apache License 2.0 5 votes vote down vote up
public HTTPAgent buildForwardPhoneGetActivateCodeSafe(String phone, String appId, String captchakey, String captchacode) {
    Builder ub = getBuilder("uac/m/forward/phone/get_activate_code_safe");
    HTTPAgent.Builder hb = new HTTPAgent.Builder();
    append(hb, "phone", phone);
    append(hb, "appid", appId);
    append(hb, "captchakey", captchakey);
    append(hb, "captchacode", captchacode);
    return new PostAgent(ub.build(), Passport.getHosts(), hb.buildJSON());
}
 
Example #23
Source File: RequestBuilder.java    From letv with Apache License 2.0 5 votes vote down vote up
public HTTPAgent buildGetTokenImplicit(String uid, String tkt, String appId, String scope) {
    Builder ub = getBuilder("uac/m/oauth2/authorize");
    HTTPAgent.Builder hb = new HTTPAgent.Builder();
    append(hb, "response_type", UserInfoDb.TOKEN);
    append(hb, "uid", uid);
    append(hb, "tkt", tkt);
    append(hb, "appid", appId);
    append(hb, "redirect_uri", "http://auther.coolyun.com");
    append(hb, "scope", scope);
    append(hb, "display", "mobile");
    return new PostAgent(ub.build(), Passport.getHosts(), hb.buildJSON());
}
 
Example #24
Source File: WriteClient.java    From StreamHub-Android-SDK with MIT License 5 votes vote down vote up
/**
 * @param authorId   Author of Post
 * @param token      Livefyre Token
 * @param parameters
 * @param networkID  Livefyre provided network name
 * @param handler    Response handler
 */
public static void flagAuthor(String authorId, String token,
                              RequestParams parameters, String networkID, JsonHttpResponseHandler handler) {
    // Build the URL

    final Builder uriBuilder = new Uri.Builder().scheme(LivefyreConfig.scheme)
            .authority(LivefyreConfig.quillDomain + "." + networkID)
            .appendPath("api").appendPath("v3.0").appendPath("author");
    String url = uriBuilder + "/" + authorId + (new Uri.Builder().appendPath("ban").appendPath("").appendQueryParameter("lftoken", token));

    Log.d("Action SDK call", "" + url);
    Log.d("Action SDK call", "" + parameters);
    HttpClient.client.post(url, parameters, handler);
}
 
Example #25
Source File: RequestBuilder.java    From letv with Apache License 2.0 5 votes vote down vote up
public HTTPAgent buildFindpwdPhoneGetActivateCodeSafe(String phone, String appId, String captchakey, String captchacode) {
    Builder ub = getBuilder("uac/m/findpwd/phone/get_activate_code_safe");
    HTTPAgent.Builder hb = new HTTPAgent.Builder();
    append(hb, "phone", phone);
    append(hb, "appid", appId);
    append(hb, "captchakey", captchakey);
    append(hb, "captchacode", captchacode);
    return new PostAgent(ub.build(), Passport.getHosts(), hb.buildJSON());
}
 
Example #26
Source File: RequestBuilder.java    From letv with Apache License 2.0 5 votes vote down vote up
public HTTPAgent buildBindPhoneGetActivateCodeSafe(String phone, String appId, String captchakey, String captchacode) {
    Builder ub = getBuilder("uac/m/bind/phone/get_activate_code_safe");
    HTTPAgent.Builder hb = new HTTPAgent.Builder();
    append(hb, "phone", phone);
    append(hb, "appid", appId);
    append(hb, "captchakey", captchakey);
    append(hb, "captchacode", captchacode);
    return new PostAgent(ub.build(), Passport.getHosts(), hb.buildJSON());
}
 
Example #27
Source File: Imps.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isUnencrypted(Context context) {
    try {
        Cursor cursor = null;

        Uri uri = Imps.Provider.CONTENT_URI_WITH_ACCOUNT;

        Builder builder = uri.buildUpon();
        builder.appendQueryParameter(ImApp.CACHEWORD_PASSWORD_KEY, "");
        builder = builder.appendQueryParameter(ImApp.NO_CREATE_KEY, "1");

        uri = builder.build();

        cursor = context.getContentResolver().query(
                uri, null, Imps.Provider.CATEGORY + "=?" /* selection */,
                new String[] { ImApp.IMPS_CATEGORY } /* selection args */,
                null);

        if (cursor != null)
        {
           cursor.close();
            return true;
        }
        else
        {
            return false;
        }

    } catch (Exception e) {
        // Only complain if we thought this password should succeed

         Log.e(ImApp.LOG_TAG, e.getMessage(), e);

        // needs to be unlocked
        return false;
    }
}
 
Example #28
Source File: RequestBuilder.java    From letv with Apache License 2.0 5 votes vote down vote up
public HTTPAgent buildUpdateUserItem(String uid, String tkt, String key, String value, String appId) {
    Builder ub = getBuilder("uac/m/change/user_info");
    HTTPAgent.Builder hb = new HTTPAgent.Builder();
    append(hb, "uid", uid);
    append(hb, "tkt", tkt);
    append(hb, key, value);
    append(hb, "appid", appId);
    return new PostAgent(ub.build(), Passport.getHosts(), hb.buildJSON());
}
 
Example #29
Source File: InstaUtils.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
public static String login(String username, String pass) throws Exception {
    getInitCookies(ig);

    URLConnection connection = new URL(igAuth).openConnection();
    if(connection instanceof HttpURLConnection){
        HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
        httpURLConnection.setRequestMethod(HttpPost.METHOD_NAME);
        httpURLConnection = addPostHeaders(httpURLConnection);

        String query = new Builder().appendQueryParameter("username", username).appendQueryParameter("password", pass).build().getEncodedQuery();
        OutputStream outputStream = httpURLConnection.getOutputStream();
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, HTTP.UTF_8));
        bufferedWriter.write(query);
        bufferedWriter.flush();
        bufferedWriter.close();
        outputStream.close();
        httpURLConnection.connect();

        if(httpURLConnection.getResponseCode() != HttpStatus.SC_OK){
            return "bad_request";
        }

        extractAndSetCookies(httpURLConnection);
        JSONObject jsonObject = new JSONObject(buildResultString(httpURLConnection));
        if(jsonObject.get("user").toString().isEmpty()){
            return BuildConfig.VERSION_NAME;
        }

        return jsonObject.get("authenticated").toString();
    }

    throw new IOException("Url is not valid");
}
 
Example #30
Source File: RequestBuilder.java    From letv with Apache License 2.0 5 votes vote down vote up
public HTTPAgent buildUnBindDevice(String appid, String uid, String tkt, String devlist, String version) {
    Builder ub = getBuilder("uac/m/device/unbind_device");
    HTTPAgent.Builder hb = new HTTPAgent.Builder();
    append(hb, "appid", appid);
    append(hb, "uid", uid);
    append(hb, "tkt", tkt);
    append(hb, "devlist", devlist);
    append(hb, "version", version);
    return new PostAgent(ub.build(), Passport.getHosts(), hb.buildJSON());
}