Using Data That Isn't Yours

  • 98 views
Uploaded on

Stubby shows you how to use super-duper basic web services.

Stubby shows you how to use super-duper basic web services.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
98
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
3
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Transcript

  • 1. Using Data That Isn’t YoursHow to consume web services to augment your web sites and apps. An Adventure With Stubby
  • 2. Stubby stubby@cogsprocket.net StubbyTheGreat
  • 3. What’s a Web Service A web service is a component in a web application that allows the owner to share data with remote applications. It’s like a drive-thru library...“If you want my books I’ll give you a chute where you can pick them up.”
  • 4. Where Are They? EVERYWHERE. Twitter FacebookGoogle Calendar YouTube Dribbble Your Blog
  • 5. Different Kinds of Services• REST - Representational State Transfer • Ruby on Rails does this by design• SOAP - Simple Object Access Protocol • Native to .NET, not well supported in other platforms• RSS - Really Simple Syndication • XML service that power blog subs and podcasts
  • 6. Know How To Get It•Find the service you want to consume• Read the documentation • https://dev.twitter.com/docs
  • 7. Things To Look Out For• Services with poor or no documentation• Request rate limits• Data return formats• Service types not supported by your language
  • 8. The Basics...•Check the API for the service you want to consume• Pull the data into your application• Iterate through the data returned• Output or store the data• Super duper easy, right?
  • 9. The Anatamy Of A Requesthttp://api.twitter.com/1/statuses/user_timeline.json?screen_name=<screen_name> How To Make The Request $data = file_get_contents(<api_url>);
  • 10. What You’ll Likely Get A StringYeah... You were probably hoping for something more exotic....
  • 11. Bad news...A string of data is something, but it’s not anything super duper useful...
  • 12. What You’ll Likely Get Here’s a problem... Let’s fix it with objects.•JSON - Javascript Object Notation • Make the data readable with json_decode()• XML - Extensible Markup Language • Make the data readable with simplexml_load_string()
  • 13. What JSON Looks Like $results->created_at $results->text
  • 14. What XML Looks Like $results->created_at $results->text
  • 15. What’s Next?!Now that you’ve got an object you can totally iterate through it. // Super-scary iteration for($i=0; $i <= 15; $i++) { // Do something awesome }
  • 16. “for()” Can Be Scary You can totally use foreach() // Less-than-scary iteration foreach($results as $result) { // Do something awesome }foreach() will iterate through everything
  • 17. How I Like To Do it... You can totally use foreach() // Madman iteration foreach($results as $result) { $this->{$value} = $result->... }Makes $object->VariableName... (‘Cause I treat code like objects)
  • 18. What To Do With The Data• Output it! • You got it for a reason, give it a good ol’ “echo” and let the world see• Store it! • Probably a good idea to store any data for at least 5 minutes...
  • 19. What Could Go Wrong? The service could be unavailable...
  • 20. What Could Go Wrong?The remote end could block your access
  • 21. Be Like Stubby Behave yourself...• Cache your data• Limit the number of requests you make per hour• Use a local iterator • Local iterators duplicate the service and handle caching