Creating a SocialHub Comment that is send to SocialHub

$comment = new SocialHubComment();
$comment_wrapper = entity_metadata_wrapper('socialhub_comment', $comment);

// Required properties.
$comment_wrapper->created->set(time());
// The post object or sid this comment belongs to.
$comment_wrapper->post->set($post);

// Optional parent comment property.
$comment_wrapper->parent->set(NULL);

// Optional author properties.
$comment_wrapper->author->set('Me');
$comment_wrapper->author_link->set('http://example.com/me');
$comment_wrapper->author_picture_url->set('http://example.com/me.jpg');

// Optional social-network authentication.
$comment_wrapper->token->set('some-authentication-token');
$comment_wrapper->token_network->set('FACEBOOK');

// The actual comment content.
$comment_wrapper->plain_content->set('plain content');
$comment_wrapper->html_content->set('<b>html content</b>');

// Save this comment (This actually triggers the API request).
$comment->save();

Altering a SocialHub comment that is send to SocialHub / received from SocialHub

/**
 * Implements hook_socialhub_comment_insert().
 *
 * Same applies to
 * @see hook_socialhub_comment_presave()
 * @see hook_socialhub_comment_update()
 * @see hook_socialhub_comment_delete()
 */
function MODULE_socialhub_comment_insert(SocialHubComment $comment, $source) {
  if ($source == SocialHubEntityController::INTERNAL) {
    // This is going to be send to SocialHub.
  }
  else if ($source == SocialHubEntityController::EXTERNAL) {
    // This came from SocialHub.
  }
}

Updating an existing comment

$comment = socialhub_comment_load($id);

$comment_wrapper->plain_content->set('updated plain content');
$comment_wrapper->html_content->set('<b>updated html content</b>');

$comment->save();

Deleting an existing comment

$comment = socialhub_comment_load($id);
$comment->delete();

Getting API-corresponding representation of an entity

$comment = socialhub_comment_load($id);
$api_data = $comment->getApiData();

Setting API-corresponding representation on an entity

$api_data = array(
  'postId' => 'some-unique-post-id',
  'author' => 'David Neuhaus',
  'authorLink' => 'http://example.com/node/1', 
  'content' => array(
    'plain' => 'This is absolutely insane!',
    'html' => '<a href="http://socialhub.io">This</a> is absolutely insane!',
  ),
);
$comment = new SocialHubComment();
$comment->setApiData($api_data);
$comment->save();

Using SocialHub reference to connect SocialHub comments and Drupal comments

$socialhub_comment = new SocialHubComment();
$socialhub_comment_wrapper = entity_metadata_wrapper('socialhub_comment', $socialhub_comment);
$socialhub_comment_wrapper->created->set(strtotime('now'));
$socialhub_comment_wrapper->post->set($post);

// Set the Drupal comment to reference to by comment object or cid.
$socialhub_comment_wrapper->socialhub_reference_comment->set($comment);

$socialhub_comment_wrapper->save();

Loading all SocialHub comments referenced to a Drupal comment

$comments = socialhub_reference_comments($cid);