• Save
SoundCloud Cocoa API Wrapper
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

SoundCloud Cocoa API Wrapper

on

  • 7,844 views

Cocoaheads Berlin ...

Cocoaheads Berlin
March 12th 2009

About implementing an API wrapper for a OAuth protected Web API in Objective-C for Mac and iPhone.

http://github.com/soundcloud/cocoa-api-wrapper

Statistics

Views

Total Views
7,844
Views on SlideShare
7,513
Embed Views
331

Actions

Likes
6
Downloads
0
Comments
1

7 Embeds 331

http://blog.soundcloud.com 307
http://www.slideshare.net 13
https://blog.soundcloud.com 4
http://www.slideee.com 3
http://andrew.planet.ee 2
http://translate.googleusercontent.com 1
http://www.slashdocs.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • i just downloaded the latest version of Coccoa API for iOS, i tried logging in, i keed getting this '-[NXOAuth2PostBodyStream open] Stream has been reopened after close' and the app crashes after that.

    What would be the problem, i check the login, its valid.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

SoundCloud Cocoa API Wrapper Presentation Transcript

  • 1. The SoundCloud API Cocoa Wrapper How to build a connection framework for an OAuth protected RESTful Web-API Wednesday, March 18, 2009
  • 2. Agenda 1.Introduction The SoundCloud API 2.Challenges Problems we solved 3.Try it! Integrating SoundCloud sharing to your app Wednesday, March 18, 2009
  • 3. The SoundCloud API Wednesday, March 18, 2009
  • 4. The SoundCloud API • RESTful Resource based • User, Track, Comment, ... • HTTP based • GET, PUT, POST, DELETE • Data representation in JSON, XML • Wednesday, March 18, 2009
  • 5. The SoundCloud API • RESTful Resource based • User, Track, Comment, ... • HTTP based • GET, PUT, POST, DELETE • Data representation in JSON, XML • • OAuth protected Wednesday, March 18, 2009
  • 6. REST Example • Resource: Tracks Resource Method /tracks GET, POST /tracks/{track_id} GET, PUT, DELETE • Creating a new Track POST /tracks • curl -u joey:hairspray 'http://api.sandbox-soundcloud.com/tracks' -F track[asset_data]=@step_by_step.aif -F track[title]=Superstitious Response • < HTTP/1.1 201 Created < Location: http://api.sandbox-soundcloud.com/tracks/13 Wednesday, March 18, 2009
  • 7. OAuth Wednesday, March 18, 2009
  • 8. OAuth • Token based API authentication + authorization Exchange tokens rather than login & password • Authorization on server side • Wednesday, March 18, 2009
  • 9. OAuth • Token based API authentication + authorization Exchange tokens rather than login & password • Authorization on server side • • Client applications registered on server Consumer key + secret • Wednesday, March 18, 2009
  • 10. OAuth • Token based API authentication + authorization Exchange tokens rather than login & password • Authorization on server side • • Client applications registered on server Consumer key + secret • • HTTP requests signed by authorized tokens Wednesday, March 18, 2009
  • 11. OAuth • Token based API authentication + authorization Exchange tokens rather than login & password • Authorization on server side • • Client applications registered on server Consumer key + secret • • HTTP requests signed by authorized tokens • Tokens can be revoked Wednesday, March 18, 2009
  • 12. Challenges Wednesday, March 18, 2009
  • 13. Challenges 1.Nice code Wednesday, March 18, 2009
  • 14. Challenges 1.Nice code 2.Integrating OAuth Signing API requests • Implementing the token authorization • Wednesday, March 18, 2009
  • 15. Challenges 1.Nice code 2.Integrating OAuth Signing API requests • Implementing the token authorization • 3.Posting large (80+Mb) data to the server Memory issues & upload progress • Wednesday, March 18, 2009
  • 16. Challenges 1.Nice code 2.Integrating OAuth Signing API requests • Implementing the token authorization • 3.Posting large (80+Mb) data to the server Memory issues & upload progress • 4.Sending requests asynchronously Wednesday, March 18, 2009
  • 17. Challenges 1.Nice code 2.Integrating OAuth Signing API requests • Implementing the token authorization • 3.Posting large (80+Mb) data to the server Memory issues & upload progress • 4.Sending requests asynchronously 5.Cross platform Xcode project (3 platforms) Wednesday, March 18, 2009
  • 18. 1. Nice code Wednesday, March 18, 2009
  • 19. 1. Nice code • Meant for 3rd party developers Few classes that are easy to understand • Stable interface • Wednesday, March 18, 2009
  • 20. 1. Nice code • Meant for 3rd party developers Few classes that are easy to understand • Stable interface • • API might change Not implementing model or controller logic • Just implementing communication layer • JSON / XML parsing is up to the developer • Wednesday, March 18, 2009
  • 21. Architecture Client AppDelegate Some Client Controller Authentication API Delegate Delegate Wednesday, March 18, 2009
  • 22. Architecture Client AppDelegate Some Client Controller Authentication API Delegate Delegate SoundCloud API Wednesday, March 18, 2009
  • 23. Architecture Client AppDelegate Some Client Controller Authentication API Delegate Delegate SoundCloud API SoundCloud API Configuration Wednesday, March 18, 2009
  • 24. Architecture Client AppDelegate Some Client Controller Authentication API Delegate Delegate SoundCloud API SoundCloud API Configuration Wednesday, March 18, 2009
  • 25. 2. Integrating OAuth Wednesday, March 18, 2009
  • 26. 2. Integrating OAuth • Problems Signing Requests • Implementing token authorization • Wednesday, March 18, 2009
  • 27. 2. Integrating OAuth • Problems Signing Requests • Implementing token authorization • • Solution to signing Using OAuthConsumer reference implementation • Added keychain support for Mac & iPhone (& Simulator) • Replaced crypto algorithms • Wednesday, March 18, 2009
  • 28. OAuth token flow Client Application SoundCloud Wednesday, March 18, 2009
  • 29. OAuth token flow Client Application SoundCloud Step 1 Asking for request Getting unauthorized token request token Wednesday, March 18, 2009
  • 30. OAuth token flow Client Application SoundCloud Step 1 Asking for request Generating Getting unauthorized token request token request token Wednesday, March 18, 2009
  • 31. OAuth token flow Client Application SoundCloud Step 1 Asking for request Generating Getting unauthorized token request token request token Step 2 Sent user to browser Obtaining user with token in URL authorization via browser Wednesday, March 18, 2009
  • 32. OAuth token flow Client Application SoundCloud Step 1 Asking for request Generating Getting unauthorized token request token request token Step 2 Sent user to browser Obtaining user with token in URL User logs in authorization via browser + authorizes token Wednesday, March 18, 2009
  • 33. OAuth token flow Client Application SoundCloud Step 1 Asking for request Generating Getting unauthorized token request token request token Step 2 Sent user to browser Obtaining user with token in URL User logs in authorization via browser + authorizes token Redirecting to callback URL with custom URL scheme Wednesday, March 18, 2009
  • 34. OAuth token flow Client Application SoundCloud Step 1 Asking for request Generating Getting unauthorized token request token request token Step 2 Sent user to browser Obtaining user with token in URL User logs in authorization via browser + authorizes token Redirecting to callback URL with Application is triggered custom URL scheme by URL scheme Wednesday, March 18, 2009
  • 35. OAuth token flow Client Application SoundCloud Step 1 Asking for request Generating Getting unauthorized token request token request token Step 2 Sent user to browser Obtaining user with token in URL User logs in authorization via browser + authorizes token Redirecting to callback URL with Application is triggered custom URL scheme by URL scheme App initiates exchange Step 3 of request token Exchanging tokens Wednesday, March 18, 2009
  • 36. OAuth token flow Client Application SoundCloud Step 1 Asking for request Generating Getting unauthorized token request token request token Step 2 Sent user to browser Obtaining user with token in URL User logs in authorization via browser + authorizes token Redirecting to callback URL with Application is triggered custom URL scheme by URL scheme App initiates exchange Step 3 of request token Exchanging tokens Generating access token Wednesday, March 18, 2009
  • 37. OAuth token flow Client Application SoundCloud Step 1 Asking for request Generating Getting unauthorized token request token request token Step 2 Sent user to browser Obtaining user with token in URL User logs in authorization via browser + authorizes token Redirecting to callback URL with Application is triggered custom URL scheme by URL scheme App initiates exchange Step 3 of request token Exchanging tokens Generating access token Step 4 Stores access token Storing access token for further usage Wednesday, March 18, 2009
  • 38. 3.Large files • Audio files are large! 60 min recording is very large, even compressed • • The problem with lage files iPhone memory limits • Upload progress not supported by NSURLConnection • • The solution: NSInputStream Be aware!! Not easy to subclass • Wednesday, March 18, 2009
  • 39. Post Body Stream • Data transfered as multipart • SCPostBodyStream as wrapper around array of stream parts • Stream parts NSString, NSURL (file URL), NSData • • Upload progress by counting bytes in read method Wednesday, March 18, 2009
  • 40. 4.Asynchronous Communication Wednesday, March 18, 2009
  • 41. 4.Asynchronous Communication Connection Your Class Connection Connection Management Data fetching Request generation Connection Wednesday, March 18, 2009
  • 42. 4.Asynchronous Communication Connection SoundCloud API Connection Connection Management Data fetching Request generation Connection Wednesday, March 18, 2009
  • 43. 4.Asynchronous Communication Connection SoundCloud API Your Class Connection Lean & Mean Connection Management Data fetching Request generation Connection Wednesday, March 18, 2009
  • 44. 4.Asynchronous Communication OAuth Connection SoundCloud API Your Class Connection Lean & Mean Connection Management Data fetching Request generation Connection Uploads Wednesday, March 18, 2009
  • 45. 5. Cross platform Xcode project Wednesday, March 18, 2009
  • 46. 5. Cross platform Xcode project • Targets Framework for Mac • Fat static library for iPhone Device & Simulator • Wednesday, March 18, 2009
  • 47. 5. Cross platform Xcode project • Targets Framework for Mac • Fat static library for iPhone Device & Simulator • • Problems Only one Base SDK per project • Base SDK defines which frameworks are allowed • Wednesday, March 18, 2009
  • 48. 5. Cross platform Xcode project • Targets Framework for Mac • Fat static library for iPhone Device & Simulator • • Problems Only one Base SDK per project • Base SDK defines which frameworks are allowed • • Solution Manually linking frameworks • Wednesday, March 18, 2009
  • 49. 5. Cross platform Xcode project • Targets Framework for Mac • Fat static library for iPhone Device & Simulator • • Problems Only one Base SDK per project • Base SDK defines which frameworks are allowed • • Solution Manually linking frameworks • Wednesday, March 18, 2009
  • 50. Try it ! Wednesday, March 18, 2009
  • 51. Try it ! • Licensed under Apache License You‘re free to use it • Can be integrated into closed projects • Just mention us somewhere • Wednesday, March 18, 2009
  • 52. Try it ! • Licensed under Apache License You‘re free to use it • Can be integrated into closed projects • Just mention us somewhere • • Wrapper comes with iPhone and Mac demo projects Wednesday, March 18, 2009
  • 53. Try it ! • Licensed under Apache License You‘re free to use it • Can be integrated into closed projects • Just mention us somewhere • • Wrapper comes with iPhone and Mac demo projects Lets see some code! Wednesday, March 18, 2009
  • 54. Further reading Wednesday, March 18, 2009
  • 55. Further reading • The repository http://github.com/soundcloud/cocoa-api-wrapper/ • Wednesday, March 18, 2009
  • 56. Further reading • The repository http://github.com/soundcloud/cocoa-api-wrapper/ • • On OAuth http://oauth.net • http://fireeagle.yahoo.net/developer/documentation/ • http://code.google.com/p/oauth/ • Wednesday, March 18, 2009
  • 57. Further reading • The repository http://github.com/soundcloud/cocoa-api-wrapper/ • • On OAuth http://oauth.net • http://fireeagle.yahoo.net/developer/documentation/ • http://code.google.com/p/oauth/ • • Twitter: @stigi, @gernot, @soundcloud Wednesday, March 18, 2009
  • 58. Further reading • The repository http://github.com/soundcloud/cocoa-api-wrapper/ • • On OAuth http://oauth.net • http://fireeagle.yahoo.net/developer/documentation/ • http://code.google.com/p/oauth/ • • Twitter: @stigi, @gernot, @soundcloud • Of course: http://www.soundcloud.com Wednesday, March 18, 2009