In fact, Ruby Write API program is very simple, if the API itself is relatively standard, rather than a mess.
class apidemo # Defining Interfaces API_QERUY = [ :userAdd # User profile Add ] # implement Ghost Method def method_missing (method_name , *args, &block) API_QERUY.each do |v| if v.to_s == method_name.to_s return api_request (V.to_s, args.first) end end super end # Returns the result parsing, here returns the XML, therefore uses Nokogiri this gem to parse the XML, is very convenient. def api_request (OPERATION, ARGV) query = "" argv.each do |a| query += "&" + a.first.to_s + "=" + a.last.to_s end uri = uri.escape ("version=1&type=xml&key=" +api_key + query) @doc = nokogiri::html (open (api_url + operation + uri) puts @doc. to_s if rails.env.development? # Development mode output results for easy commissioning self end # Get returned code def code if @doc @doc. At ("code") .content.to_i end end # determine if the return result is successful def success? if @doc     &Nbsp; self.code == 200 end endend
How do I call it?
APIDEMO.NEW.USERADD (username: ' Moli '). Success?
If you want to add more APIs, you can
Api_qeruy
can be added in
Ruby Writing API Program