SlideShare une entreprise Scribd logo
1  sur  58
The SoundCloud API
                                Cocoa Wrapper
                            How to build a connection framework for an
                               OAuth protected RESTful Web-API




Wednesday, March 18, 2009
Agenda

    1.Introduction
       The SoundCloud API

    2.Challenges
       Problems we solved

    3.Try it!
       Integrating SoundCloud sharing to your app



Wednesday, March 18, 2009
The SoundCloud API




Wednesday, March 18, 2009
The SoundCloud API

    • RESTful

            Resource based
        •

                 User, Track, Comment, ...
             •


            HTTP based
        •

                 GET, PUT, POST, DELETE
             •


            Data representation in JSON, XML
        •




Wednesday, March 18, 2009
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
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
OAuth




Wednesday, March 18, 2009
OAuth
    • Token            based API authentication + authorization
            Exchange tokens rather than login & password
        •

            Authorization on server side
        •




Wednesday, March 18, 2009
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
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
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
Challenges




Wednesday, March 18, 2009
Challenges
    1.Nice code




Wednesday, March 18, 2009
Challenges
    1.Nice code

    2.Integrating OAuth
            Signing API requests
        •

            Implementing the token authorization
        •




Wednesday, March 18, 2009
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
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
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
1. Nice code




Wednesday, March 18, 2009
1. Nice code

    • Meant             for 3rd party developers
            Few classes that are easy to understand
        •

            Stable interface
        •




Wednesday, March 18, 2009
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
Architecture

                      Client AppDelegate         Some Client Controller


                            Authentication
                                                       API Delegate
                              Delegate




Wednesday, March 18, 2009
Architecture

                      Client AppDelegate         Some Client Controller


                            Authentication
                                                       API Delegate
                              Delegate




                                                    SoundCloud API




Wednesday, March 18, 2009
Architecture

                      Client AppDelegate         Some Client Controller


                            Authentication
                                                       API Delegate
                              Delegate




                            SoundCloud API
                                                    SoundCloud API
                             Configuration



Wednesday, March 18, 2009
Architecture

                      Client AppDelegate         Some Client Controller


                            Authentication
                                                       API Delegate
                              Delegate




                            SoundCloud API
                                                    SoundCloud API
                             Configuration



Wednesday, March 18, 2009
2. Integrating OAuth




Wednesday, March 18, 2009
2. Integrating OAuth

    • Problems

            Signing Requests
        •

            Implementing token authorization
        •




Wednesday, March 18, 2009
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
OAuth token flow
                            Client Application   SoundCloud




Wednesday, March 18, 2009
OAuth token flow
                              Client Application     SoundCloud
                     Step 1     Asking for request
      Getting unauthorized            token
             request token




Wednesday, March 18, 2009
OAuth token flow
                              Client Application     SoundCloud
                     Step 1     Asking for request
                                                       Generating
      Getting unauthorized            token
             request token                            request token




Wednesday, March 18, 2009
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
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
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
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
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
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
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
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
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
4.Asynchronous Communication




Wednesday, March 18, 2009
4.Asynchronous Communication



                                                    Connection
                                Your Class
                                                    Connection
                            Connection Management
                                Data fetching
                              Request generation
                                                    Connection



Wednesday, March 18, 2009
4.Asynchronous Communication



                                                    Connection
                            SoundCloud API
                                                    Connection
                            Connection Management
                                Data fetching
                              Request generation
                                                    Connection



Wednesday, March 18, 2009
4.Asynchronous Communication



                                                    Connection
                            SoundCloud API
         Your Class
                                                    Connection
           Lean & Mean      Connection Management
                                Data fetching
                              Request generation
                                                    Connection



Wednesday, March 18, 2009
4.Asynchronous Communication

                                  OAuth


                                                    Connection
                            SoundCloud API
         Your Class
                                                    Connection
           Lean & Mean      Connection Management
                                Data fetching
                              Request generation
                                                    Connection

                                 Uploads
Wednesday, March 18, 2009
5. Cross platform Xcode project




Wednesday, March 18, 2009
5. Cross platform Xcode project
    • Targets

            Framework for Mac
        •

            Fat static library for iPhone Device & Simulator
        •




Wednesday, March 18, 2009
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
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
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
Try it !




Wednesday, March 18, 2009
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
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
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
Further reading




Wednesday, March 18, 2009
Further reading
    • The         repository
            http://github.com/soundcloud/cocoa-api-wrapper/
        •




Wednesday, March 18, 2009
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
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
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

Contenu connexe

En vedette

Evolutionary Architecture at Work
Evolutionary  Architecture at WorkEvolutionary  Architecture at Work
Evolutionary Architecture at Work
Phil Calçado
 
SoundCloud: A Success Story
SoundCloud: A Success StorySoundCloud: A Success Story
SoundCloud: A Success Story
Ryan Kam
 
An example of Future composition in a real app
An example of Future composition in a real appAn example of Future composition in a real app
An example of Future composition in a real app
Phil Calçado
 

En vedette (8)

Sound cloud analysis
Sound cloud analysisSound cloud analysis
Sound cloud analysis
 
Soundcloud
SoundcloudSoundcloud
Soundcloud
 
Evolutionary Architecture at Work
Evolutionary  Architecture at WorkEvolutionary  Architecture at Work
Evolutionary Architecture at Work
 
SoundCloud: A Success Story
SoundCloud: A Success StorySoundCloud: A Success Story
SoundCloud: A Success Story
 
An example of Future composition in a real app
An example of Future composition in a real appAn example of Future composition in a real app
An example of Future composition in a real app
 
The Sound of Big Data - SoundCloud case study
The Sound of Big Data - SoundCloud case studyThe Sound of Big Data - SoundCloud case study
The Sound of Big Data - SoundCloud case study
 
SoundCloud's Toolbox for Microservices
SoundCloud's Toolbox for MicroservicesSoundCloud's Toolbox for Microservices
SoundCloud's Toolbox for Microservices
 
Microservices @ SoundCloud
Microservices @ SoundCloudMicroservices @ SoundCloud
Microservices @ SoundCloud
 

Similaire à SoundCloud Cocoa API Wrapper

How LinkedIn changed its security model in order to offer an API
How LinkedIn changed its security model  in order to offer an APIHow LinkedIn changed its security model  in order to offer an API
How LinkedIn changed its security model in order to offer an API
LinkedIn
 
APIs_ An Introduction.pptx
APIs_ An Introduction.pptxAPIs_ An Introduction.pptx
APIs_ An Introduction.pptx
AkashThorat25
 
Saas webinar-dec6-01
Saas webinar-dec6-01Saas webinar-dec6-01
Saas webinar-dec6-01
Paul Madsen
 
Aloha on-rails-2009
Aloha on-rails-2009Aloha on-rails-2009
Aloha on-rails-2009
John Woodell
 

Similaire à SoundCloud Cocoa API Wrapper (20)

How LinkedIn changed its security model in order to offer an API
How LinkedIn changed its security model  in order to offer an APIHow LinkedIn changed its security model  in order to offer an API
How LinkedIn changed its security model in order to offer an API
 
The Twitter API: A Presentation to Adobe
The Twitter API: A Presentation to AdobeThe Twitter API: A Presentation to Adobe
The Twitter API: A Presentation to Adobe
 
Implementing OAuth
Implementing OAuthImplementing OAuth
Implementing OAuth
 
APIs_ An Introduction.pptx
APIs_ An Introduction.pptxAPIs_ An Introduction.pptx
APIs_ An Introduction.pptx
 
Webinar - Utilizzo delle WebApi dell'Orchestrator.pdf
Webinar - Utilizzo delle WebApi dell'Orchestrator.pdfWebinar - Utilizzo delle WebApi dell'Orchestrator.pdf
Webinar - Utilizzo delle WebApi dell'Orchestrator.pdf
 
Saas webinar-dec6-01
Saas webinar-dec6-01Saas webinar-dec6-01
Saas webinar-dec6-01
 
[REPEAT 1] Managing Identity Management, Authentication, & Authorization for ...
[REPEAT 1] Managing Identity Management, Authentication, & Authorization for ...[REPEAT 1] Managing Identity Management, Authentication, & Authorization for ...
[REPEAT 1] Managing Identity Management, Authentication, & Authorization for ...
 
Bitpagos Ruby Gem
Bitpagos Ruby GemBitpagos Ruby Gem
Bitpagos Ruby Gem
 
Plone in the Cloud - an on-demand CMS hosted on Amazon EC2
Plone in the Cloud - an on-demand CMS hosted on Amazon EC2Plone in the Cloud - an on-demand CMS hosted on Amazon EC2
Plone in the Cloud - an on-demand CMS hosted on Amazon EC2
 
Aloha on-rails-2009
Aloha on-rails-2009Aloha on-rails-2009
Aloha on-rails-2009
 
Designing for API Doomsday
Designing for API DoomsdayDesigning for API Doomsday
Designing for API Doomsday
 
Adding the Sec to Your DevOps Pipelines (SEC332-R1) - AWS re:Invent 2018
Adding the Sec to Your DevOps Pipelines (SEC332-R1) - AWS re:Invent 2018Adding the Sec to Your DevOps Pipelines (SEC332-R1) - AWS re:Invent 2018
Adding the Sec to Your DevOps Pipelines (SEC332-R1) - AWS re:Invent 2018
 
Jason yammer api
Jason yammer apiJason yammer api
Jason yammer api
 
Developing on StackMob - Flying Monkey Interactive Evaluates BaaS
Developing on StackMob - Flying Monkey Interactive Evaluates BaaS Developing on StackMob - Flying Monkey Interactive Evaluates BaaS
Developing on StackMob - Flying Monkey Interactive Evaluates BaaS
 
Set Up a Communications Platform on AWS with AI-Enhanced Services (TLC302) - ...
Set Up a Communications Platform on AWS with AI-Enhanced Services (TLC302) - ...Set Up a Communications Platform on AWS with AI-Enhanced Services (TLC302) - ...
Set Up a Communications Platform on AWS with AI-Enhanced Services (TLC302) - ...
 
App-solute Testing: Making App Testing with Akamai Easy
App-solute Testing: Making App Testing with Akamai EasyApp-solute Testing: Making App Testing with Akamai Easy
App-solute Testing: Making App Testing with Akamai Easy
 
Luna and Third Party Tools for Troubleshooting Web Application Issues
Luna and Third Party Tools for Troubleshooting Web Application IssuesLuna and Third Party Tools for Troubleshooting Web Application Issues
Luna and Third Party Tools for Troubleshooting Web Application Issues
 
Building a Great Web API - Evan Cooke - QCON 2011
Building a Great Web API - Evan Cooke - QCON 2011Building a Great Web API - Evan Cooke - QCON 2011
Building a Great Web API - Evan Cooke - QCON 2011
 
HTML5 and Google Chrome - DevFest09
HTML5 and Google Chrome - DevFest09HTML5 and Google Chrome - DevFest09
HTML5 and Google Chrome - DevFest09
 
Builders' Day- Mastering Kubernetes on AWS
Builders' Day- Mastering Kubernetes on AWSBuilders' Day- Mastering Kubernetes on AWS
Builders' Day- Mastering Kubernetes on AWS
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

SoundCloud Cocoa API Wrapper

  • 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
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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

Notes de l'éditeur