RESTful Web Services by Richardson Leonard & Ruby Sam

RESTful Web Services by Richardson Leonard & Ruby Sam

Author:Richardson, Leonard & Ruby, Sam [Richardson, Leonard]
Language: eng
Format: mobi
Tags: COMPUTERS / Systems Architecture / General
Publisher: O'Reilly Media
Published: 2008-12-16T16:00:00+00:00


# An HTTP-based Ruby client for my social bookmarking service

class BookmarkClient

def initialize(service_root)

@service_root = service_root

end

# Turn a Ruby hash into a form-encoded set of key-value pairs.

def form_encoded(hash)

encoded = []

hash.each do |key, value|

encoded << CGI.escape(key) + '=' + CGI.escape(value)

end

return encoded.join('&')

end

# Create a new user.

def new_user(username, password, full_name, email)

representation = form_encoded({ "user[name]" => username,

"user[password]" => password,

"user[full_name]" => full_name,

"user[email]" => email })

puts representation

begin

response = open(@service_root + '/users', :method => :post,

:body => representation)

puts "User #{username} created at #{response.meta['location']}"

rescue OpenURI::HTTPError => e

response_code = e.io.status[0].to_i

if response_code == "409" # Conflict

puts "Sorry, there's already a user called #{username}."

else

raise e

end

end

end



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Deep Learning with Python by François Chollet(12570)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7778)
Grails in Action by Glen Smith Peter Ledbrook(7696)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6413)
Kotlin in Action by Dmitry Jemerov(5062)
WordPress Plugin Development Cookbook by Yannick Lefebvre(3790)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3327)
Learning React: Functional Web Development with React and Redux by Banks Alex & Porcello Eve(3087)
Mastering Bitcoin: Programming the Open Blockchain by Andreas M. Antonopoulos(2868)
The Art Of Deception by Kevin Mitnick(2605)
Drugs Unlimited by Mike Power(2467)
Kali Linux - An Ethical Hacker's Cookbook: End-to-end penetration testing solutions by Sharma Himanshu(2312)
The Innovators: How a Group of Hackers, Geniuses, and Geeks Created the Digital Revolution by Walter Isaacson(2301)
Writing for the Web: Creating Compelling Web Content Using Words, Pictures and Sound (Eva Spring's Library) by Lynda Felder(2261)
SEO 2018: Learn search engine optimization with smart internet marketing strategies by Adam Clarke(2192)
A Blueprint for Production-Ready Web Applications: Leverage industry best practices to create complete web apps with Python, TypeScript, and AWS by Dr. Philip Jones(2158)
JavaScript by Example by S Dani Akash(2138)
DarkMarket by Misha Glenny(2083)
Wireless Hacking 101 by Karina Astudillo(2077)
Full-Stack React Projects by Shama Hoque(1990)