Mais conteúdo relacionado Semelhante a Jeff Siarto: Party Like It’s 1984, An introduction to social APIs (20) Mais de SocialDevCamp Chicago (13) Jeff Siarto: Party Like It’s 1984, An introduction to social APIs1. Party Like It’s 1984
An introduction to social APIs
Jeff Siarto
Co-founder, Loudpixel
3. What are APIs?
★ “Application Programming Interface”
★ We’re talking about web APIs
★ Gives web apps an “interface” for
interacting with other software
★ Typically returns data in structured
formats like XML and JSON (Jason?)
4. APIs are structured
★ Don’t confuse APIs with crawlers and
robots (GoogleBot)
★ APIs deal with structured data (a user
has an name, email and phone)
★ Data is available in a specified format
and is usually documented
5. JSON
{
"first_name": "Jeff",
"last_name": "Siarto",
"titles": [
"Partner",
"Analyst",
"Designer"
],
"online": {
"website": "http://siarto.com",
"twitter": "@jsiarto",
"github": "http://github.com/jsiarto"
}
}
6. XML
<?xml version="1.0" encoding="UTF-8"?>
<first_name>Jeff</first_name>
<last_name>Siarto</last_name>
<titles>
<title>Partner</title>
<title>Analyst</title>
<title>Designer</title>
</titles>
<online>
<website>http://siarto.com</website>
<twitter>@jsiarto</twitter>
<github>http://github.com/jsiarto</github>
</online>
7. REST
★ Representational State Transfer
★ The web is built to utilize REST
★ Stateless
★ HTTP verbs: GET, POST, PUT, DELETE
8. RESTful Web Services
★ Representational State Transfer
★ The web is built to utilize REST
★ Stateless
★ HTTP verbs: GET, POST, PUT, DELETE
11. Telescreen
★ Rails 2.3.8
★ Basic mashup using RapLeaf, Twitter,
Gravatar and Google Maps
★ Search proletarians (users) by email
14. # environment.rb
config.gem “rapleaf_api”
# controller
rapleaf = RapleafApi::Api.new(‘API_KEY’)
# find a person
@person = rapleaf.query(:type => :person, :opts =>
{:email => ‘steve@apple.com’})
# view
@person.location # Chicago, Illinois, United States
15. RapLeaf Data
★ Basics: name, age, gender, location,
occupations, schools, earliest/latest
activity, friend count
★ Site Memberships: bebo, facebook, flickr,
friendster, hi5, linkedin, livejournal,
multiply, myspace, myyearbook, plaxo,
twitter
18. # top of controller
require ‘md5’
# controller method
# MD5 hash the user email address
email_hash = MD5.new(params[:prole])
# build a gravatar URI
@gravatar = "http://www.gravatar.com/avatar/#
{email_hash}?s=150"
# view
image_tag @gravatar
21. # build a google maps URI
image_tag("http://maps.google.com/maps/api/staticmap?
center=#{url_for(@person.location)}
&zoom=12&size=256x256&maptype=roadmap&sensor=false")
25. # top of controller
require 'net/http'
require 'uri'
# Parse Twitter username from RapLeaf
twitter_handle = @person.memberships(:primary)[12]
["profile_url"].gsub("http://twitter.com/", "")
unless twitter_handle.nil?
# Construct URI
uri = URI.parse("http://twitter.com/status/
user_timeline/#{twitter_handle}.json?count=3")
# Get JSON
@twitter = Net::HTTP.get_response(uri)
# Make JSON a Ruby object
@tweets = ActiveSupport::JSON.decode(@twitter.body)
26. # view
@tweets[0]['user']["description"]
# loop through tweets with .each
<% @tweets.each do |t| %>
<li>
<%= t['text'] %><br /><span class="status-url"><
%= link_to(t['created_at'], "http://twitter.com/#{t
['user']['screen_name']}/status/#{t['id']}") %></a>
</li>
<% end %>