Android Open Source - StreamHub-Android-Reviews-App Write Client






From Project

Back to project page StreamHub-Android-Reviews-App.

License

The source code is released under:

MIT License

If you think the Android project StreamHub-Android-Reviews-App listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package livefyre.streamhub;
//from   w ww .ja  v  a  2  s.  c o m
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;
import android.net.Uri;
import android.net.Uri.Builder;
import android.util.Log;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;

/**
 * @author kvanainc1
 * 
 */
public class WriteClient {

  static String[] actions = { "edit", // 0
      "approve", // 1
      "unapprove", // 2
      "hide", // 3
      "delete", // 4
      "bozo", // 5
      "ignore-flags", // 6
      "add-note", // 7
      "like", // 8
      "unlike", // 9
      "flag", // 10
      "mention", // 11
      "share", // 12
      "vote" // 13
  };
  static String[] flags = { "spam", // 0
      "offensive", // 1
      "disagree", // 2
      "off-topic" // 3
  };

  /**
   * Post content to a Livefyre collection.
   * 
   * @param networkId
   *            The collection's network as identified by domain, i.e.
   *            livefyre.com.
   * @param collectionId
   *            The Id of the collection.
   * @param parentId
   *            The id of the content to which this content is a reply. If not
   *            necessary (that is, this is a top level post, then set to
   *            empty string ("").
   * @param token
   *            The token of the logged in user.
   * @param body
   *            A string version of the HTML body
   * @param handler
   *            Response handler
   * @throws UnsupportedEncodingException
   * @throws MalformedURLException
   */
  public static void postContent(String networkId, String collectionId,
      String parentId, String userToken,
      HashMap<String, Object> parameters, JsonHttpResponseHandler handler)
      throws MalformedURLException {
    // add body parameters
    RequestParams bodyParams = new RequestParams();

    // if (parameters.containsKey(LFSConstants.LFSPostType)) {

    // if (parameters.get(LFSConstants.LFSPostType) ==
    // LFSConstants.LFSPostTypeRating) {

    bodyParams.put(LFSConstants.LFSPostBodyKey,
        (String) parameters.get(LFSConstants.LFSPostBodyKey));

    // //Get Title
    if (parameters.containsKey("attachments")) {
      bodyParams.put("attachments",
          (String) parameters.get("attachments"));
    }

    if (parameters.containsKey(LFSConstants.LFSPostTitleKey)) {
      bodyParams.put(LFSConstants.LFSPostTitleKey,
          (String) parameters.get(LFSConstants.LFSPostTitleKey));
    }

    // // Get Rating

    if (parameters.containsKey(LFSConstants.LFSPostTypeReview)) {
      JSONObject rating = new JSONObject();
      try {
        rating.put("default",
            parameters.get(LFSConstants.LFSPostTypeReview));
        // String rateJson=JSONObject.quote(rating.toString());
        bodyParams.put("rating", rating.toString());
      } catch (JSONException e) {
        e.printStackTrace();
      }
    }

    // // Get Parent id if available.

    if (parentId != null && parentId.length() != 0) {
      bodyParams.put("parent_id", parentId);
    }

    if (parameters.containsKey(LFSConstants.LFSPostUserTokenKey))
      bodyParams.put("lftoken",
          (String) parameters.get(LFSConstants.LFSPostUserTokenKey));
    else {

      android.os.Process.killProcess(android.os.Process.myPid());
    }

    Log.d("", "" + bodyParams);
    HttpClient.client.post(
        generateWriteURL(networkId, collectionId, userToken, parameters
            .get(LFSConstants.LFSPostType).toString()), bodyParams,
        handler);

  }

  /**
   * 
   * @param collectionId
   * @param contentId
   * @param token
   * @param action
   * @param parameters
   * @param handler
   */

  public static void flagContent(String collectionId, String contentId,
      String token, LFSFlag action, RequestParams parameters,
      JsonHttpResponseHandler handler) {
    // String url =
    // "http://quill.client-solutions.fyre.co/api/v3.0/message/"
    // + contentId
    // + "/flag/"
    // + flags[action.value()]
    // + "/"
    // + (new Uri.Builder().appendQueryParameter("lftoken", token)
    // .appendQueryParameter("collection_id", collectionId));

     String url = (new Uri.Builder().scheme(Config.scheme)
        .authority(Config.quillDomain + "." + Config.networkId)
        .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);
  }

  /**
   * 
   * @param networkId
   * @param collectionId
   * @param userToken
   * @param endpoint
   * @return
   * @throws MalformedURLException
   */

  public static String generateWriteURL(String networkId,
      String collectionId, String userToken, String endpoint)
      throws MalformedURLException {
    final Builder uriBuilder = new Uri.Builder().scheme(Config.scheme)
        .authority(Config.quillDomain + "." + Config.networkId)
        .appendPath("api").appendPath("v3.0").appendPath("collection")
        .appendPath(collectionId).appendPath("post");
    if (LFSConstants.LFSPostTypeReview == endpoint)
      uriBuilder.appendPath(endpoint).appendPath("");
    else
      uriBuilder.appendPath("");
    Log.d("Write URL", "" + uriBuilder.toString());
    return uriBuilder.toString();
  }

  /**
   * 
   * @param action
   * @param contentId
   * @param collectionId
   * @param userToken
   * @param parameters
   * @param 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);

    // String url =
    // "http://quill.client-solutions.fyre.co/api/v3.0/collection/"
    // + collectionId
    // + "/"
    // + action
    // + "/"
    // + contentId
    // + "/"
    // + (new Uri.Builder().appendQueryParameter("lftoken", userToken));

    final Builder uriBuilder = new Uri.Builder().scheme(Config.scheme)
        .authority(Config.quillDomain + "." + Config.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);
  }

  /**
   * 
   * @param collectionId
   * @param contentId
   * @param token
   * @param action
   * @param parameters
   * @param 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(Config.scheme)
        .authority(Config.quillDomain + "." + Config.networkId)
        .appendPath("api").appendPath("v3.0").appendPath("message").appendPath("")+contentId+
        (new Uri.Builder().appendPath(actions[action.value()]).appendPath("")
        .appendQueryParameter("lftoken", token)
        .appendQueryParameter("collection_id", collectionId));

    //
    // String url = "http://quill.labs.fyre.co/api/v3.0/message/"
    // + contentId
    // + "/"
    // + actions[action.value()]
    // + "/"
    // + (new Uri.Builder().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);
  }

  /**
   * 
   * @param authorId
   *            Author of Post
   * @param token
   *            Livefyre Token
   * @param parameters
   *            Perameters includes network,
   * @param handler
   */

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

//    String url = "http://quill.client-solutions.fyre.co/api/v3.0/author/"
//        + authorId + "/ban/"
//        + (new Uri.Builder().appendQueryParameter("lftoken", token));

    
    
    final Builder uriBuilder = new Uri.Builder().scheme(Config.scheme)
        .authority(Config.quillDomain + "." + Config.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);
  }

}




Java Source Code List

com.filepicker.sdk.AuthActivity.java
com.filepicker.sdk.AuthError.java
com.filepicker.sdk.BuildConfig.java
com.filepicker.sdk.BuildConfig.java
com.filepicker.sdk.CacheElement.java
com.filepicker.sdk.DataCache.java
com.filepicker.sdk.FPFile.java
com.filepicker.sdk.FPService.java
com.filepicker.sdk.FilePickerAPI.java
com.filepicker.sdk.FilePicker.java
com.filepicker.sdk.FixedSizeList.java
com.filepicker.sdk.Folder.java
com.filepicker.sdk.Inode.java
com.filepicker.sdk.NonThumbnailGridBlockView.java
com.filepicker.sdk.Service.java
com.filepicker.sdk.ThumbnailView.java
livefyre.AppSingleton.java
livefyre.BaseActivity.java
livefyre.DeviceNotConnectedException.java
livefyre.DownloadAllImagesTask.java
livefyre.LFSAppConstants.java
livefyre.LFSConfig.java
livefyre.LFUtils.java
livefyre.LivefyreApplication.java
livefyre.NotifyingScrollView.java
livefyre.ImagesCache.DownloadImageTask.java
livefyre.ImagesCache.ImagesCache.java
livefyre.activities.Edit.java
livefyre.activities.LivefyreSplash.java
livefyre.activities.NewReview.java
livefyre.activities.Reply.java
livefyre.activities.ReviewInDetail.java
livefyre.activities.ReviewsActivity.java
livefyre.adapters.ReviewInDetailAdapter.java
livefyre.adapters.ReviewListAdapter.java
livefyre.fadingactionbar.FadingActionBarHelperBase.java
livefyre.fadingactionbar.FadingActionBarHelper.java
livefyre.fadingactionbar.ListViewActivity.java
livefyre.fadingactionbar.ObservableScrollView.java
livefyre.fadingactionbar.ObservableScrollable.java
livefyre.fadingactionbar.ObservableWebViewWithHeader.java
livefyre.fadingactionbar.OnScrollChangedCallback.java
livefyre.fadingactionbar.RootLayout.java
livefyre.fadingactionbar.Utils.java
livefyre.models.AuthorsBean.java
livefyre.models.ContentBean.java
livefyre.models.ContentTypeEnum.java
livefyre.models.OembedBean.java
livefyre.models.ReviewStatus.java
livefyre.models.Vote.java
livefyre.parsers.AdminClintParser.java
livefyre.parsers.ContentParser.java
livefyre.parsers.ContentUpdateListener.java
livefyre.streamhub.AdminClient.java
livefyre.streamhub.BootstrapClient.java
livefyre.streamhub.BuildConfig.java
livefyre.streamhub.BuildConfig.java
livefyre.streamhub.Config.java
livefyre.streamhub.Helpers.java
livefyre.streamhub.HttpClient.java
livefyre.streamhub.LFSActions.java
livefyre.streamhub.LFSConstants.java
livefyre.streamhub.LFSFlag.java
livefyre.streamhub.StreamClient.java
livefyre.streamhub.WriteClient.java