Sha256: 3ee1bd780d4d0792f4a2ed697d2504cbffcf484c1342805064da39d8d1350e28
Contents?: true
Size: 1001 Bytes
Versions: 1
Compression:
Stored size: 1001 Bytes
Contents
require 'net/http' require 'net/https' require 'uri' require 'rubygems' require 'json' module ContactList class Client #REQUEST_URI = 'http://contacts.huangzhimin.com/' #REQUEST_URI = 'http://localhost:8080/ContactListService/contacts' Contact = Struct.new(:username, :email) def self.fetch(account, password, type) response = get_response("account=#{account}&password=#{password}&type=#{type}") contacts = [] data = JSON.parse(response.body) raise ContactListException.new(data['error']) if data['error'] data['contacts'].each do |contact| contacts << Contact.new(contact['username'], contact['email']) end contacts end private def self.get_response(data) http = Net::HTTP.new('121.22.4.157', 8443) http.use_ssl = true path = '/ContactListService/contacts' response = http.post2(path, data) end end class ContactListException < Exception end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
contactlist-client-0.1.1 | lib/contactlist/client.rb |