diaspora-api 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/diaspora-api.rb +15 -25
- metadata +2 -2
data/lib/diaspora-api.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
#
|
5
5
|
# Copyright 2014 cmrd Senya (senya@riseup.net)
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# This program is free software: you can redistribute it and/or modify
|
8
8
|
# it under the terms of the GNU General Public License as published by
|
9
9
|
# the Free Software Foundation, either version 3 of the License, or
|
@@ -30,10 +30,10 @@ class DiasporaApi::Client
|
|
30
30
|
@attributes
|
31
31
|
@podhost
|
32
32
|
@cookie
|
33
|
-
|
33
|
+
|
34
34
|
def initialize
|
35
35
|
@providername = "d*-rubygem"
|
36
|
-
@cookie = nil
|
36
|
+
@cookie = nil
|
37
37
|
end
|
38
38
|
|
39
39
|
def login(podhost, username, password)
|
@@ -50,7 +50,7 @@ class DiasporaApi::Client
|
|
50
50
|
end
|
51
51
|
|
52
52
|
scookie = /_diaspora_session=[[[:alnum:]]%-]+; /.match(response.response['set-cookie'])
|
53
|
-
atok =
|
53
|
+
atok = /<input name="authenticity_token" type="hidden" value="([a-zA-Z0-9=\/+]+)" \/>/.match(response.body)[1]
|
54
54
|
|
55
55
|
request = Net::HTTP::Post.new(uri.request_uri)
|
56
56
|
request.set_form_data('utf8' => '✓', 'user[username]' => username, 'user[password]' => password, 'user[remember_me]' => 1, 'commit' => 'Signin', 'authenticity_token' => atok)
|
@@ -62,12 +62,16 @@ class DiasporaApi::Client
|
|
62
62
|
puts "Login failed. Server replied with code " + response.code
|
63
63
|
return false
|
64
64
|
else
|
65
|
+
if not response.response['set-cookie'].include? "remember_user_token"
|
66
|
+
puts "Login failed. Wrong password?"
|
67
|
+
return false
|
68
|
+
end
|
65
69
|
@cookie = /remember_user_token=[[[:alnum:]]%-]+; /.match(response.response['set-cookie'])
|
66
70
|
get_attributes
|
67
71
|
return true
|
68
72
|
end
|
69
73
|
end
|
70
|
-
|
74
|
+
|
71
75
|
def post(msg, aspect)
|
72
76
|
if(aspect != "public")
|
73
77
|
for asp in @attributes["aspects"]
|
@@ -76,11 +80,11 @@ class DiasporaApi::Client
|
|
76
80
|
end
|
77
81
|
end
|
78
82
|
end
|
79
|
-
|
83
|
+
|
80
84
|
uri = URI.parse(@podhost + "/status_messages")
|
81
85
|
http = Net::HTTP.new(uri.host, uri.port)
|
82
86
|
http.use_ssl = true
|
83
|
-
|
87
|
+
|
84
88
|
request = Net::HTTP::Post.new(uri.request_uri,initheader = {'Content-Type' =>'application/json'})
|
85
89
|
request['Cookie'] = @cookie
|
86
90
|
|
@@ -88,19 +92,19 @@ class DiasporaApi::Client
|
|
88
92
|
|
89
93
|
return http.request(request)
|
90
94
|
end
|
91
|
-
|
95
|
+
|
92
96
|
def get_attributes
|
93
97
|
uri = URI.parse(@podhost + "/stream")
|
94
98
|
http = Net::HTTP.new(uri.host, uri.port)
|
95
99
|
http.use_ssl = true
|
96
|
-
|
100
|
+
|
97
101
|
request = Net::HTTP::Get.new(uri.request_uri)
|
98
102
|
request['Cookie'] = @cookie
|
99
103
|
|
100
104
|
response = http.request(request)
|
101
105
|
names = ["gon.user", "window.current_user_attributes"]
|
102
106
|
i = nil
|
103
|
-
|
107
|
+
|
104
108
|
for name in names
|
105
109
|
i = response.body.index(name)
|
106
110
|
break if i != nil
|
@@ -121,22 +125,8 @@ class DiasporaApi::Client
|
|
121
125
|
i += 1
|
122
126
|
end until n == 0
|
123
127
|
end_json = i - 1
|
124
|
-
|
128
|
+
|
125
129
|
@attributes = JSON.parse(response.body[start_json..end_json])
|
126
130
|
end
|
127
131
|
end
|
128
132
|
end
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: diaspora-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'Ruby gem to work with Diaspora*. Note: this is not wrapping an official
|
15
15
|
API, since there is no such thing. The gem just makes HTTPS requests and parses
|