mapsqueak 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mapsqueak.rb +23 -17
- metadata +1 -1
data/lib/mapsqueak.rb
CHANGED
@@ -39,23 +39,29 @@ class MapSqueakSession
|
|
39
39
|
|
40
40
|
# sign in by email/password.
|
41
41
|
# note that a remember_token will be saved in a cookie file
|
42
|
-
def sign_in(email,password)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
42
|
+
def sign_in(email,password,format=:xml)
|
43
|
+
case format
|
44
|
+
when :xml
|
45
|
+
signin_xml = Document.new
|
46
|
+
signin_xml.add_element('session')
|
47
|
+
signin_xml.root << xml_element('email',email)
|
48
|
+
|
49
|
+
# allow nil passwords right now
|
50
|
+
signin_xml.root << xml_element('password',password.to_s)
|
51
|
+
puts signin_xml.to_s
|
52
|
+
|
53
|
+
@cookie_file = "#{email}.cookies"
|
54
|
+
|
55
|
+
curl_str = "curl --data \'#{signin_xml.to_s}\' #{self.host}/sessions.xml -H \"Content-Type: application/xml\" --cookie-jar #{@cookie_file}"
|
56
|
+
|
57
|
+
result = `#{curl_str}`
|
58
|
+
puts result
|
59
|
+
doc = Document.new(result)
|
60
|
+
@user_id = XPath.first(doc,"hash/user-id").text
|
61
|
+
when :post
|
62
|
+
curl_str = "curl -F email=#{email} -F password=\'#{password}\' #{self.host}/sessions --cookie-jar #{@cookie_file}"
|
63
|
+
`#{curl_str}`
|
64
|
+
end
|
59
65
|
end
|
60
66
|
|
61
67
|
# sign the current user out.
|