I am learning both ASObjC and objC at the same time. Simpler stuff is straight forward, however I am running into problems trying to translate some longer objective-c over.
I’m attempting to play with Ebay’s API… I have it working from an example I found online written in objC
Now time to get it into applescriptobjc
I have tried all sorts of variations and keep throwing all sorts of “unrecognized selector sent to object”
Hope that once I see how this should be translate I can figure it out the rest!
Thanks
set theData to current application's NSURLConnection's sendSynchronousRequest_returningResponse_error_(theHttp,reference, reference)
I am getting this error in response
[NSXMLDocument length]: unrecognized selector sent to instance 0x6100000d6ab0
An uncaught exception was raised
[NSXMLDocument length]: unrecognized selector sent to instance 0x6100000d6ab0
I am assuming it is to do with passing reference values as such?
I am currently running os x Mavericks.
Thanks!
Browser: Safari 537.74.9
Operating System: Mac OS X (10.8)
tell current application’s class “NSURL” to set theurl to its URLWithString_(“https://api.sandbox.ebay.com/ws/api.dll”)
tell current application’s class “NSMutableURLRequest” to set theHttp to requestWithURL_(theurl)
The way to use out values is to use the keyword reference as you have done, but the method then returns the values in a list. So you need something like:
set {theData, theResponse, theError} to current application's NSURLConnection's sendSynchronousRequest_returningResponse_error_(theHttp,reference, reference)
Yet all your example code is using pre-Mavericks syntax. That works OK, but it suggests you’re not compiling your code in an external editor to check it. I’d suggest you do.
Over the past week or so I have been working on other sections of this larger project, jumping back to attempt to figure out where I have went wrong from time to time… no luck whatsoever so I figured I would post the whole stand alone ASOBJC that I have been attempting to get working. Commented out is each line that I attempt to translate over. Then the translation attempt below it.
property DevID : "DEV ID HERE"
property AppID : "APP ID HERE"
property CertID : "CERT ID HERE"
--NSXMLElement *theRequest = [[NSXMLElement alloc] initWithName:@"GetSessionIDRequest"];
set theRequest to current application's NSXMLElement's alloc()'s initWithName:"GetSessionIDRequest"
--[theRequest setAttributesAsDictionary:[NSDictionary dictionaryWithObject:@"urn:ebay:apis:eBLBaseComponents" forKey:@"xmlns"]];
theRequest's setAttributesAsDictionary:{xmlns:"urn:ebay:apis:eBLBaseComponents"}
--NSXMLElement *theCredentials = [[NSXMLElement alloc] initWithName:@"eBayAuthToken" stringValue:@"The Auth Token"];
set theCredentials to current application's NSXMLElement's alloc()'s initWithName:"RequesterCredentials"
--[theRequest addChild:theCredentials];
theRequest's addChild:theCredentials
--NSXMLDocument *theXml = [[NSXMLDocument alloc] initWithRootElement:theRequest];
set theXml to current application's NSXMLDocument's alloc()'s initWithRootElement:theRequest
--[theXml setCharacterEncoding:@"utf-8"];
theXml's setCharacterEncoding:"utf-8"
--[theXml setVersion:@"1.0"];
theXml's setVersion:"1.0"
--NSMutableURLRequest *theHttp = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://api.sandbox.ebay.com/ws/api.dll"]];
set theHttp to ((current application's NSMutableURLRequest's alloc)'s initWithURL:(current application's NSURL's URLWithString:"https://api.sandbox.ebay.com/ws/api.dll"))
--[theHttp setHTTPMethod:@"POST"];
theHttp's setHTTPMethod:"POST"
--[theHttp addValue:@"419" forHTTPHeaderField:@"X-EBAY-API-COMPATIBILITY-LEVEL"];
theHttp's addValue:"419" forHTTPHeaderField:"X-EBAY-API-COMPATIBILITY-LEVEL"
--[theHttp addValue:DevID forHTTPHeaderField:@"X-EBAY-API-SESSION-CERTIFICATE"];
theHttp's addValue:DevID forHTTPHeaderField:"X-EBAY-API-SESSION-CERTIFICATE"
--[theHttp addValue:AppID forHTTPHeaderField:@"X-EBAY-API-SESSION-CERTIFICATE"];
theHttp's addValue:AppID forHTTPHeaderField:"X-EBAY-API-SESSION-CERTIFICATE"
--[theHttp addValue:CertID forHTTPHeaderField:@"X-EBAY-API-SESSION-CERTIFICATE"];
theHttp's addValue:CertID forHTTPHeaderField:"X-EBAY-API-SESSION-CERTIFICATE"
--[theHttp addValue:DevID forHTTPHeaderField:@"X-EBAY-API-DEV-NAME"];
theHttp's addValue:DevID forHTTPHeaderField:"X-EBAY-API-DEV-NAME"
--[theHttp addValue:AppID forHTTPHeaderField:@"X-EBAY-API-APP-NAME"];
theHttp's addValue:AppID forHTTPHeaderField:"X-EBAY-API-APP-NAME"
--[theHttp addValue:CertID forHTTPHeaderField:@"X-EBAY-API-CERT-NAME"];
theHttp's addValue:CertID forHTTPHeaderField:"X-EBAY-API-CERT-NAME"
--[theHttp addValue:@"GetSessionID" forHTTPHeaderField:@"X-EBAY-API-CALL-NAME"];
theHttp's addValue:"VerifyAddItem" forHTTPHeaderField:"X-EBAY-API-CALL-NAME"
--[theHttp addValue:@"0" forHTTPHeaderField:@"X-EBAY-API-SITEID"];
theHttp's addValue:"0" forHTTPHeaderField:"X-EBAY-API-SITEID"
--[theHttp addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"];
theHttp's addValue:"text/xml" forHTTPHeaderField:"Content-Type"
--[theHttp setHTTPBody:[theXml XMLData]];
theHttp's setHTTPBody:(theXml's XMLData)
--NSURLResponse *theResponse = nil;
--NSError *theError;
--NSData *theData = nil;
--theData = [NSURLConnection sendSynchronousRequest:theHttp returningResponse:&response error:&error];
set {theData, theResponse, theError} to current application's NSURLConnection's sendSynchronousRequest:theHttp returningResponse:(reference) |error|:(missing value)
--// If the request was successful, show the data.
-- if ([theData length] > 0) {
-- NSXMLDocument *theResult = [[NSXMLDocument alloc] initWithData:theData options:0 error:&error];
--NSLog(@"Received %@", theResult);
if theData's length > 0 then
set theResult to ((current application's NSXMLDocument)'s alloc)'s initWithData:theData options:0
log "Received: " & theResult
end if
That sounds like you initially type it in the wrong case, have it in the wrong case elsewhere in the script, or have a terminology conflict. Try using pipes. And don’t leave off the trailing ():
Thank you Shane!
Everything is up and working now.
The whole pipe thing is what got me…
I understand to use them when there is an applescript keyword… I guess I have to pipe things that I feel might be clashing or Is there a list of clashing methods?
No, there is no list – it depends on things like what scripting additions you have installed.
Another shameless plug, but that’s why ASObjC Explorer for Mavericks is the ideal external editor: it loads all the terminology at launch, and its code-completion adds whatever pipes are needed for you.