Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

New method to share content #28

Merged
merged 2 commits into from about 2 years ago

2 participants

William Durand Sixten Otto
This page is out of date. Refresh to see the latest.
11 LinkedInClientLibrary/RDLinkedInEngine.h
@@ -62,5 +62,16 @@ extern const NSUInteger kRDLinkedInMaxStatusLength;
62 62 - (RDLinkedInConnectionID *)profileForPersonWithID:(NSString *)memberID;
63 63
64 64 - (RDLinkedInConnectionID *)updateStatus:(NSString *)newStatus;
  65 +/**
  66 + * \fn - (RDLinkedInConnectionID *)shareUrl:(NSString *)submittedUrl imageUrl:(NSString *)submittedImageUrl title:(NSString*)title comment:(NSString*)comment
  67 + * \brief This method is able to share a content.
  68 + * \param NSString* submittedUrl The URL's content
  69 + * \param NSString* submittedImageUrl An image that illustrates the content
  70 + * \param NSString* title A title that will be shown instead of the URL
  71 + * \param NSString* comment A comment which will be like a user status
  72 + * \return RDLinkedInConnectionID*
  73 + * \see http://developer.linkedin.com/docs/DOC-1212
  74 + */
  75 +- (RDLinkedInConnectionID *)shareUrl:(NSString *)submittedUrl imageUrl:(NSString *)submittedImageUrl title:(NSString*)title comment:(NSString*)comment;
65 76
66 77 @end
36 LinkedInClientLibrary/RDLinkedInEngine.m
@@ -164,6 +164,42 @@ - (RDLinkedInConnectionID *)updateStatus:(NSString *)newStatus {
164 164 return [self sendAPIRequestWithURL:url HTTPMethod:@"PUT" body:body];
165 165 }
166 166
  167 +- (RDLinkedInConnectionID *)shareUrl:(NSString *)submittedUrl imageUrl:(NSString *)submittedImageUrl title:(NSString*)title comment:(NSString*)comment {
  168 + NSURL* url = [NSURL URLWithString:[kAPIBaseURL stringByAppendingString:@"/v1/people/~/shares"]];
  169 +
  170 + comment = [comment length] > kRDLinkedInMaxStatusLength ? [comment substringToIndex:kRDLinkedInMaxStatusLength] : comment;
  171 +
  172 + NSString *xml = [[NSString alloc] initWithFormat:@" \
  173 + <share> \
  174 + <comment>%@</comment> \
  175 + <content> \
  176 + <title>%@</title> \
  177 + <submitted-url>%@</submitted-url> \
  178 + <submitted-image-url>%@</submitted-image-url>\
  179 + </content> \
  180 + <visibility> \
  181 + <code>anyone</code> \
  182 + </visibility> \
  183 + </share>",
  184 + comment,
  185 + title,
  186 + submittedUrl,
  187 + submittedImageUrl];
  188 +
  189 + // Cleaning the XML content
  190 + xml = [xml stringByReplacingOccurrencesOfString:@"\n" withString:@""];
  191 + xml = [xml stringByReplacingOccurrencesOfString:@" " withString:@""];
  192 +
  193 + xml = [[NSString alloc]
  194 + initWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n%@",xml];
  195 +
  196 + NSData *data = [xml dataUsingEncoding:NSUTF8StringEncoding];
  197 +
  198 + //NSLog(@"xml=%@", xml);
  199 + //NSLog(@"data=%@", data);
  200 +
  201 + return [self sendAPIRequestWithURL:url HTTPMethod:@"POST" body:data];
  202 +}
167 203
168 204 #pragma mark private
169 205

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.