lib/contactlist/client.rb in contactlist-client-0.1.0 vs lib/contactlist/client.rb in contactlist-client-0.1.1

- old
+ new

@@ -1,21 +1,22 @@ 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://contacts.huangzhimin.com/' #REQUEST_URI = 'http://localhost:8080/ContactListService/contacts' Contact = Struct.new(:username, :email) def self.fetch(account, password, type) - response = get_response(REQUEST_URI, {'account' => account, 'password' => password, 'type' => type}) + response = get_response("account=#{account}&password=#{password}&type=#{type}") contacts = [] data = JSON.parse(response.body) raise ContactListException.new(data['error']) if data['error'] @@ -24,15 +25,14 @@ end contacts end private - def self.get_response(url, post_data) - response = Net::HTTP.post_form URI.parse(url), post_data - if Net::HTTPRedirection === response - response = get_response(response['location'], post_data) - end - response + 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