0

I have 3 files: main.m, CGOAuth.h, CGOAuth.m (taken from https://github.com/guicocoa/cocoa-oauth)

In main.m I call (in the main method):

 [GCOAuth URLRequestForPath:@"websites" 
  HTTPMethod:@"GET" 
  parameters:nil scheme:@"https" 
  host:@"blah"           
  consumerKey:CONSUMER_KEY 
  consumerSecret:CONSUMER_SECRET 
  accessToken:accessToken 
  tokenSecret:tokenSecret];

The error I get is that it says that there is no class method for the selector URLRequestforPath... .

In GCOAuth.h, which I imported into main.m, is the declaration:

 + (NSURLRequest *)URLRequestForPath:(NSString *)path
                     HTTPMethod:(NSString *)HTTPMethod
                     parameters:(NSDictionary *)parameters
                         scheme:(NSString *)scheme
                           host:(NSString *)host
                    consumerKey:(NSString *)consumerKey
                 consumerSecret:(NSString *)consumerSecret
                    accessToken:(NSString *)accessToken
                    tokenSecret:(NSString *)tokenSecret;

And the implementation is in GCOAuth.m.

I've tried doing this:

[[GCOAuth alloc] URLRequestForPath:@"websites" 
  HTTPMethod:@"GET" 
  parameters:nil scheme:@"https" 
  host:@"blah"           
  consumerKey:CONSUMER_KEY 
  consumerSecret:CONSUMER_SECRET 
  accessToken:accessToken 
  tokenSecret:tokenSecret];

But I just get the error: no visible @interface declares the selector URLRequestForPath... .

I can't see what I'm doing wrong. If there is no class method for selector, why is Xcode's autocompletion offering the method up for me to use?

EDIT(here is the implementation from CGOAuth.m):

 + (NSURLRequest *)URLRequestForPath:(NSString *)path
                     HTTPMethod:(NSString *)HTTPMethod
                     parameters:(NSDictionary *)parameters
                         scheme:(NSString *)scheme
                           host:(NSString *)host
                    consumerKey:(NSString *)consumerKey
                 consumerSecret:(NSString *)consumerSecret
                    accessToken:(NSString *)accessToken
                    tokenSecret:(NSString *)tokenSecret {
// check parameters
if (host == nil || path == nil) { return nil; }

// create object
GCOAuth *oauth = [[GCOAuth alloc] initWithConsumerKey:consumerKey
                                       consumerSecret:consumerSecret
                                          accessToken:accessToken
                                          tokenSecret:tokenSecret];
oauth.HTTPMethod = HTTPMethod;
oauth.requestParameters = parameters;

NSString *encodedPath = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *URLString = [NSString stringWithFormat:@"%@://%@%@", scheme, host, encodedPath];
if ([[HTTPMethod uppercaseString] isEqualToString:@"GET"]) {
    // Handle GET
    if ([oauth.requestParameters count]) {
        NSString *query = [GCOAuth queryStringFromParameters:oauth.requestParameters];
        URLString = [NSString stringWithFormat:@"%@?%@", URLString, query];
    }
}
oauth.URL = [NSURL URLWithString:URLString];

NSMutableURLRequest *request = [oauth request];
if (![[HTTPMethod uppercaseString] isEqualToString:@"GET"] && [oauth.requestParameters count]) {
    // Add the parameters to the request body for non GET requests
    NSString *query = [GCOAuth queryStringFromParameters:oauth.requestParameters];
    NSData *data = [query dataUsingEncoding:NSUTF8StringEncoding];
    NSString *length = [NSString stringWithFormat:@"%lu", (unsigned long)[data length]];
    [request setHTTPBody:data];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setValue:length forHTTPHeaderField:@"Content-Length"];
}

// return
return request;

}

Here are some more things I've tried, but have not worked, restarting Xcode and doing a clean.

I know Xcode recognizes the method because (a) code completion gives me the name of the aforementioned method and (b) it comes up in the hierarchical view on the sidebar (on the left). Time is of the essence!

user678392
  • 1,981
  • 3
  • 28
  • 50

1 Answers1

0

Have you imported the CGOAuth.h in main class? Check that CGOAuth class exists in projects build Phase or not.

Prateek Prem
  • 1,544
  • 11
  • 14