Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

New method to share content #28

Merged
merged 2 commits into from

2 participants

William Durand Sixten Otto
This page is out of date. Refresh to see the latest.
11 LinkedInClientLibrary/RDLinkedInEngine.h
View
@@ -62,5 +62,16 @@ extern const NSUInteger kRDLinkedInMaxStatusLength;
- (RDLinkedInConnectionID *)profileForPersonWithID:(NSString *)memberID;
- (RDLinkedInConnectionID *)updateStatus:(NSString *)newStatus;
+/**
+ * \fn - (RDLinkedInConnectionID *)shareUrl:(NSString *)submittedUrl imageUrl:(NSString *)submittedImageUrl title:(NSString*)title comment:(NSString*)comment
+ * \brief This method is able to share a content.
+ * \param NSString* submittedUrl The URL's content
+ * \param NSString* submittedImageUrl An image that illustrates the content
+ * \param NSString* title A title that will be shown instead of the URL
+ * \param NSString* comment A comment which will be like a user status
+ * \return RDLinkedInConnectionID*
+ * \see http://developer.linkedin.com/docs/DOC-1212
+ */
+- (RDLinkedInConnectionID *)shareUrl:(NSString *)submittedUrl imageUrl:(NSString *)submittedImageUrl title:(NSString*)title comment:(NSString*)comment;
@end
36 LinkedInClientLibrary/RDLinkedInEngine.m
View
@@ -164,6 +164,42 @@ - (RDLinkedInConnectionID *)updateStatus:(NSString *)newStatus {
return [self sendAPIRequestWithURL:url HTTPMethod:@"PUT" body:body];
}
+- (RDLinkedInConnectionID *)shareUrl:(NSString *)submittedUrl imageUrl:(NSString *)submittedImageUrl title:(NSString*)title comment:(NSString*)comment {
+ NSURL* url = [NSURL URLWithString:[kAPIBaseURL stringByAppendingString:@"/v1/people/~/shares"]];
+
+ comment = [comment length] > kRDLinkedInMaxStatusLength ? [comment substringToIndex:kRDLinkedInMaxStatusLength] : comment;
+
+ NSString *xml = [[NSString alloc] initWithFormat:@" \
+ <share> \
+ <comment>%@</comment> \
+ <content> \
+ <title>%@</title> \
+ <submitted-url>%@</submitted-url> \
+ <submitted-image-url>%@</submitted-image-url>\
+ </content> \
+ <visibility> \
+ <code>anyone</code> \
+ </visibility> \
+ </share>",
+ comment,
+ title,
+ submittedUrl,
+ submittedImageUrl];
+
+ // Cleaning the XML content
+ xml = [xml stringByReplacingOccurrencesOfString:@"\n" withString:@""];
+ xml = [xml stringByReplacingOccurrencesOfString:@" " withString:@""];
+
+ xml = [[NSString alloc]
+ initWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n%@",xml];
+
+ NSData *data = [xml dataUsingEncoding:NSUTF8StringEncoding];
+
+ //NSLog(@"xml=%@", xml);
+ //NSLog(@"data=%@", data);
+
+ return [self sendAPIRequestWithURL:url HTTPMethod:@"POST" body:data];
+}
#pragma mark private
Something went wrong with that request. Please try again.