コード例 #1
0
  /**
   * Edit the photos contained in the photoset.
   *
   * <p>This will replace the photos in the photoset with the photos in the array.
   *
   * @param photosetId the photoset to change.
   * @param photoId the ID of the primary photo.
   * @param photoList photos that the set should contain.
   * @throws Exception if there are any errors
   */
  public void editPhotos(String photosetId, String photoId, List<Photo> photoList)
      throws Exception {
    logger.info(
        "Executing editPhotos on photoset "
            + photosetId
            + ", using primary photo "
            + photoId
            + ", and "
            + photoList.size()
            + " photos.");
    //	RequestContext rc = FlickrHelper.getInstance().getRequestContext();
    //	PhotosetsInterface pi = FlickrHelper.getInstance().getPhotosetsInterface();
    //	pi.editPhotos(photosetId, photoId, photoIds);

    List<String> idList = new ArrayList<String>();
    for (Photo p : photoList) {
      idList.add(p.getPhotoId());
    }

    //	PhotosetsApi.getInstance().editPhotos(photosetId, photoId, idList);
    Response response =
        JinxFactory.getInstance().getPhotosetsApi().editPhotos(photosetId, photoId, idList);
    if (response.getCode() != 0) {
      throw new Exception(
          "Error editing photos. Code " + response.getCode() + ":" + response.getMessage());
    }
  }
コード例 #2
0
  /**
   * Add a photo to a photoset.
   *
   * @param ssPhotoset the photoset to add the photo to.
   * @param photo the photo to add.
   * @throws Exception if there are any errors, or if either parameter is null.
   */
  public void addPhoto(SSPhotoset ssPhotoset, Photo photo) throws Exception {
    if (ssPhotoset == null) {
      throw new Exception("addPhoto: PARAMETER CANNOT BE NULL.");
    }
    if (photo == null) {
      throw new Exception("addPhoto: PHOTO CANNOT BE NULL.");
    }

    //	RequestContext rc = FlickrHelper.getInstance().getRequestContext();
    //	PhotosetsInterface pi = FlickrHelper.getInstance().getPhotosetsInterface();

    try {
      //	    pi.addPhoto(ssPhotoset.getId(), photo.getId());
      //	    PhotosetsApi.getInstance().addPhoto(ssPhotoset.getId(), photo.getId());
      Response response =
          JinxFactory.getInstance()
              .getPhotosetsApi()
              .addPhoto(ssPhotoset.getPhotosetId(), photo.getPhotoId());
      if (response.getCode() == 0) {
        logger.info("Photo " + photo.getTitle() + " added to set " + ssPhotoset.getTitle());
      } else if (response.getCode() == 3) {
        logger.info("Photo " + photo.getTitle() + " already in set, not added.");
      }
    } catch (JinxException fe) {
      logger.warn("Unexpected flickr error", fe);
    } catch (Exception e) {
      logger.error("Unexpected error.", e);
    }
  }
コード例 #3
0
 /**
  * Adds the specified photo to the specified photoset.
  *
  * @param photosetId the id of the photoset to add the photo to.
  * @param photoId the id of the photo to add to the photoset.
  * @throws Exception if there are any errors.
  */
 public void addPhoto(String photosetId, String photoId) throws Exception {
   //	RequestContext rc = FlickrHelper.getInstance().getRequestContext();
   //	PhotosetsInterface pi = FlickrHelper.getInstance().getPhotosetsInterface();
   //	pi.addPhoto(photosetId, photoId);
   Response response = JinxFactory.getInstance().getPhotosetsApi().addPhoto(photosetId, photoId);
   if (response.getCode() != 0) {
     throw new Exception(
         "Unable to add photo. Code " + response.getCode() + ":" + response.getMessage());
   }
   //	PhotosetsApi.getInstance().addPhoto(photosetId, photoId);
 }
コード例 #4
0
  /**
   * Reorder photosets.
   *
   * @param photosetIdList
   * @throws Exception
   */
  public void orderSets(List<String> photosetIdList) throws Exception {
    logger.info("Reordering photosets.");
    //	RequestContext rc = FlickrHelper.getInstance().getRequestContext();
    //	PhotosetsInterface pi = FlickrHelper.getInstance().getPhotosetsInterface();
    //	pi.orderSets(photosetIds);

    //	PhotosetsApi.getInstance().orderSets(photosetIdList);
    Response response = JinxFactory.getInstance().getPhotosetsApi().orderSets(photosetIdList);
    if (response.getCode() != 0) {
      throw new Exception(
          "There was an error while ordering sets. Code "
              + response.getCode()
              + ":"
              + response.getMessage());
    }
  }
コード例 #5
0
  /**
   * Delete the specified photoset from Flickr.
   *
   * @param ssPhotoset the photoset to delete.
   * @throws Exception if there are any errors.
   */
  public void delete(SSPhotoset ssPhotoset) throws Exception {
    if (ssPhotoset == null) {
      throw new Exception("delete: PARAMETER CANNOT BE NULL.");
    }

    //	RequestContext rc = FlickrHelper.getInstance().getRequestContext();
    //	PhotosetsInterface pi = FlickrHelper.getInstance().getPhotosetsInterface();
    //	pi.delete(ssPhotoset.getId());
    //	PhotosetsApi.getInstance().delete(ssPhotoset.getId());
    Response response =
        JinxFactory.getInstance().getPhotosetsApi().delete(ssPhotoset.getPhotosetId());
    if (response.getCode() != 0) {
      throw new Exception(
          "Error deleting photoset. Code " + response.getCode() + ":" + response.getMessage());
    }
  }
コード例 #6
0
  /**
   * Edit the title and description of an existing set.
   *
   * @param ssPhotoset the photoset to edit
   * @throws Exception if there are any errors
   */
  public void editMeta(SSPhotoset ssPhotoset) throws Exception {
    //	RequestContext rc = FlickrHelper.getInstance().getRequestContext();
    //	PhotosetsInterface pi = FlickrHelper.getInstance().getPhotosetsInterface();
    //	pi.editMeta(ssPhotoset.getId(), ssPhotoset.getTitle(), ssPhotoset.getDescription());

    //	PhotosetsApi.getInstance().editMeta(ssPhotoset.getId(), ssPhotoset.getTitle(),
    // ssPhotoset.getDescription());
    Response response =
        JinxFactory.getInstance()
            .getPhotosetsApi()
            .editMeta(
                ssPhotoset.getPhotosetId(), ssPhotoset.getTitle(), ssPhotoset.getDescription());
    if (response.getCode() != 0) {
      throw new Exception(
          "There was an error while editing set. Code "
              + response.getCode()
              + ":"
              + response.getMessage());
    }
  }
コード例 #7
0
  /**
   * Remove the specified photo from the photoset.
   *
   * @param ssPhotoset the photoset to remove the photo from.
   * @param photoId the ID of the photo to be removed.
   * @throws Exception if there are any errors, or if either parameter is null.
   */
  public void removePhoto(SSPhotoset ssPhotoset, String photoId) throws Exception {
    if (ssPhotoset == null) {
      throw new Exception("removePhoto: PARAMETER CANNOT BE NULL.");
    }
    if (photoId == null) {
      throw new Exception("removePhoto: PHOTO CANNOT BE NULL.");
    }

    //	RequestContext rc = FlickrHelper.getInstance().getRequestContext();
    //	PhotosetsInterface pi = FlickrHelper.getInstance().getPhotosetsInterface();
    //	pi.removePhoto(ssPhotoset.getId(), photoId);
    //	PhotosetsApi.getInstance().removePhoto(ssPhotoset.getId(), photoId);
    Response response =
        JinxFactory.getInstance()
            .getPhotosetsApi()
            .removePhoto(ssPhotoset.getPhotosetId(), photoId);
    if (response.getCode() == 0) {
      logger.info("Photo " + photoId + " removed from set " + ssPhotoset.getPhotosetId());
    } else {
      throw new Exception(
          "Error removing photo. Code " + response.getCode() + ":" + response.getMessage());
    }
  }
コード例 #8
0
  /**
   * The group discussion reply/topic API's are somewhat dependant on each other, so this test
   * exercises all of the group discussion API calls in one place. This tests signed calls to a
   * private group.
   *
   * @throws Exception
   */
  @Test
  public void testGroupsDiscussApiSignedRequests() throws Exception {
    String subject = "Jinx unit test " + System.currentTimeMillis();
    String message = "This is an automated test of Jinx. Generated at " + new Date();

    // add
    Response response = groupsDiscussTopicsApi.add(PRIVATE_GROUP_NSID, subject, message);
    assertNotNull(response);
    assertEquals("ok", response.getStat());
    assertEquals(0, response.getCode());

    // list
    Topics topics = groupsDiscussTopicsApi.getList(PRIVATE_GROUP_NSID, 0, 0, true);
    assertNotNull(topics);
    assertEquals("ok", topics.getStat());
    assertEquals(0, topics.getCode());
    assertEquals(PRIVATE_GROUP_NSID, topics.getGroupId());
    List<Topic> list = topics.getTopicList();
    assertNotNull(list);
    // find our new topic in the list
    Topic myTopic = null;
    for (Topic t : list) {
      if (t.getSubject().equals(subject)) {
        myTopic = t;
      }
    }
    assertNotNull(myTopic);

    // info
    TopicInfo topicInfo = groupsDiscussTopicsApi.getInfo(myTopic.getTopicId(), true);
    assertNotNull(topicInfo);
    assertEquals("ok", topicInfo.getStat());
    assertEquals(0, topicInfo.getCode());
    assertEquals(myTopic.getTopicId(), topicInfo.getTopic().getTopicId());

    // now test reply api using the new topic
    String replyMessage = "This reply is from the Jinx unit tests. Generated at " + new Date();
    // add
    response = groupsDiscussRepliesApi.add(myTopic.getTopicId(), replyMessage);
    assertNotNull(response);
    assertEquals("ok", response.getStat());
    assertEquals(0, response.getCode());

    // get list
    Replies replies = groupsDiscussRepliesApi.getList(myTopic.getTopicId(), 0, 0, true);
    assertNotNull(replies);
    assertEquals("ok", replies.getStat());
    assertEquals(0, replies.getCode());
    assertNotNull(replies.getTopic());
    assertEquals(myTopic.getTopicId(), replies.getTopic().getTopicId());
    assertNotNull(replies.getReplyList());
    assertTrue(replies.getReplyList().size() > 0);
    // find my reply in the list
    Reply myReply = null;
    for (Reply reply : replies.getReplyList()) {
      if (reply.getMessage().equals(replyMessage)) {
        myReply = reply;
      }
    }
    assertNotNull(myReply);

    // edit
    String newReplyMessage = "This is an edited reply for replyId " + myReply.getReplyId();
    response =
        groupsDiscussRepliesApi.edit(myTopic.getTopicId(), myReply.getReplyId(), newReplyMessage);
    assertNotNull(response);
    assertEquals("ok", response.getStat());
    assertEquals(0, response.getCode());

    // get info
    ReplyInfo replyInfo =
        groupsDiscussRepliesApi.getInfo(myTopic.getTopicId(), myReply.getReplyId());
    assertNotNull(replyInfo);
    assertEquals("ok", replyInfo.getStat());
    assertEquals(0, replyInfo.getCode());
    assertNotNull(replyInfo.getReply());
    assertEquals(myReply.getReplyId(), replyInfo.getReply().getReplyId());

    // delete
    response = groupsDiscussRepliesApi.delete(myTopic.getTopicId(), myReply.getReplyId());
    assertNotNull(response);
    assertEquals("ok", response.getStat());
    assertEquals(0, response.getCode());
  }