Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Added parameters to sendRequest #6

Merged
merged 2 commits into from about 3 years ago

2 participants

Rod Schmidt Philippe Casgrain
Rod Schmidt

Hi Phillip,

I needed to include some parameters to my friends request so I added a sendRequest:parameters method, changed sendRequest: to call sendRequest:parameters: and changed sendFacebookRequest: to use the parameters.

I think it would make a good addition as I'm sure others need to send parameters as well. I'm surprised it wasn't already there.

Philippe Casgrain
Owner

Sounds great! Can you please adjust your patch so it matches the coding style of the surrounding functions? I think it's 2 spaces per tabs (no tabs), braces go on their own line and I'm a bit particular about the spacing for parameters and stuff. Just take a look at the rest and be consistent.

Thanks!

Rod Schmidt

Ok, I adjusted the spacing and formatting.

Philippe Casgrain
Owner

Thank you! Looks great. I will integrate as soon as I have a few moments to do it properly.

Philippe Casgrain philippec referenced this pull request from a commit
Philippe Casgrain Merged pull request #6 from infiniteNIL/master.
Added parameters to sendRequest
2b582fc
Philippe Casgrain philippec merged commit 2b582fc into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 23 additions and 2 deletions. Show diff stats Hide diff stats

  1. +1 0  classes/PhFacebook.h
  2. +22 2 classes/PhFacebook.m
1  classes/PhFacebook.h
@@ -31,6 +31,7 @@
31 31 // request: the short version of the Facebook Graph API, e.g. "me/feed"
32 32 // see http://developers.facebook.com/docs/api
33 33 - (void) sendRequest: (NSString*) request;
  34 +- (void) sendRequest: (NSString*) request params: (NSDictionary*) params;
34 35
35 36
36 37 - (void) setAccessToken: (NSString*) accessToken expires: (NSTimeInterval) tokenExpires permissions: (NSString*) perms error: (NSString*) errorReason;
24 classes/PhFacebook.m
@@ -145,13 +145,24 @@ - (void) setAccessToken: (NSString*) accessToken expires: (NSTimeInterval) token
145 145 [self notifyDelegateForToken: _authToken withError: errorReason];
146 146 }
147 147
148   -- (void) sendFacebookRequest: (NSString*) request
  148 +- (void) sendFacebookRequest: (NSDictionary*) allParams
149 149 {
150 150 NSAutoreleasePool *pool = [NSAutoreleasePool new];
151 151
152 152 if (_authToken)
153 153 {
  154 + NSString *request = [allParams objectForKey: @"request"];
154 155 NSString *str = [NSString stringWithFormat: kFBGraphApiURL, request, _authToken.authenticationToken];
  156 +
  157 + NSDictionary *params = [allParams objectForKey:@"params"];
  158 + if (params != nil)
  159 + {
  160 + NSMutableString *strWithParams = [NSMutableString stringWithString: str];
  161 + for (NSString *p in [params allKeys])
  162 + [strWithParams appendFormat: @"&%@=%@", p, [params objectForKey: p]];
  163 + str = strWithParams;
  164 + }
  165 +
155 166 NSURLRequest *req = [NSURLRequest requestWithURL: [NSURL URLWithString: str]];
156 167 NSURLResponse *response = nil;
157 168 NSError *error = nil;
@@ -173,9 +184,18 @@ - (void) sendFacebookRequest: (NSString*) request
173 184 [pool drain];
174 185 }
175 186
  187 +- (void) sendRequest: (NSString*) request params: (NSDictionary*) params;
  188 +{
  189 + NSMutableDictionary *allParams = [NSMutableDictionary dictionaryWithObject: request forKey: @"request"];
  190 + if (params != nil)
  191 + [allParams setObject: params forKey: @"params"];
  192 +
  193 + [NSThread detachNewThreadSelector: @selector(sendFacebookRequest:) toTarget: self withObject: allParams];
  194 +}
  195 +
176 196 - (void) sendRequest: (NSString*) request
177 197 {
178   - [NSThread detachNewThreadSelector: @selector(sendFacebookRequest:) toTarget: self withObject: request];
  198 + [self sendRequest: request params: nil];
179 199 }
180 200
181 201 #pragma mark Notifications

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.