This is the first dumb client code written against the API, intended to show authors of client libraries how to access the Dopplr API. It's deprecated.

 

A nice method_missing-style library is  available for people wanting to get actual work done in Ruby. See Improved Ruby Client.

 
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'net/https'
require 'json'
require 'camping'
require 'mongrel'

Camping.goes :Dopplrapi

module Dopplrapi::Controllers
class Page < R '/dopplrapi'
def get
@token = @input.token
if @token.nil?
redirect "https://www.dopplr.com/api/AuthSubRequest?next=http%3A%2F%2Fwww.hackdiary.com%2Fdopplrapi&scope=http%3A%2F%2Fwww.dopplr.com%2F&session=1"
else
http = Net::HTTP.new("www.dopplr.com", 443)
http.use_ssl = true

http.start do |http|
# upgrade one-time token to session token
path = "/api/AuthSubSessionToken"
req = Net::HTTP::Get.new(path, { 'Authorization' => 'AuthSub token="' + @token +'"' })
response = http.request(req)
resp = response.body
resp.match(/Token=(.*)/)
@session_token = $1

# list trips for mattb
path = "/api/trips_info/mattb"
req = Net::HTTP::Get.new(path, { 'Authorization' => 'AuthSub token="' + @session_token +'"' })
response = http.request(req)
puts response.body

# tag trip 326 as bar+baz
path = "/api/trip_tag/326?tags=bar+baz"
req = Net::HTTP::Get.new(path, { 'Authorization' => 'AuthSub token="' + @session_token +'"' })
response = http.request(req)

# get all mattb trips tagged as upcoming:event=*
path = "/api/tag/mattb?tag=upcoming:event=*"
req = Net::HTTP::Get.new(path, { 'Authorization' => 'AuthSub token="' + @session_token +'"' })
response = http.request(req)

# get traveller info
path = "/api/traveller_info"
req = Net::HTTP::Get.new(path, { 'Authorization' => 'AuthSub token="' + @session_token +'"' })
response = http.request(req)
resp = response.body

xml = XmlSimple.xml_in(resp)
@message = "Your name is " + xml['traveller'][0]['name'][0]

# revoke our session token and go home
path = "/api/AuthSubRevokeToken"
req = Net::HTTP::Get.new(path, { 'Authorization' => 'AuthSub token="' + @session_token +'"' })
response = http.request(req)

end
render :welcome
end
end
end
end

module Dopplrapi::Views
def welcome
html do
head do
title "Dopplrapi"
end
body do
h1 "Dopplr API test"
p @message
end
end
end
end


Page Information

  • 10 months ago [history]
  • View page source
  • You're not logged in
  • No tags yet learn more

Wiki Information

Recent PBwiki Blog Posts