myspace 1.0.0
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/History.txt +10 -0
- data/Manifest.txt +5 -0
- data/README.txt +55 -0
- data/Rakefile +19 -0
- data/lib/myspace.rb +646 -0
- metadata +68 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
myspace
|
2
|
+
by Fernando Barajas
|
3
|
+
(http://fernyb.net/myspace/api)
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A Simple basic way for access MySpace services
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
Sometimes it can be slow
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
Credentials
|
16
|
+
|
17
|
+
credentials = {
|
18
|
+
:username => 'email@address.com',
|
19
|
+
:password => 'SuperSecretPassword'
|
20
|
+
}
|
21
|
+
|
22
|
+
Update Status
|
23
|
+
@status = MySpace.update_status(credentials, 'Good Morning!')
|
24
|
+
|
25
|
+
Get Current Status
|
26
|
+
@status = MySpace.get_status(credentials)
|
27
|
+
puts @status[:current]
|
28
|
+
|
29
|
+
|
30
|
+
Retrieve Mail Box Messages, Returns a Hash with the list of message in the inbox
|
31
|
+
@status = MySpace.retrieve_mail(credentials, 2)
|
32
|
+
|
33
|
+
for num in (0..(@status[:image].size - 1))
|
34
|
+
sender = @status[:sender][num.to_s]
|
35
|
+
image = @status[:image][num.to_s]
|
36
|
+
date = @status[:date][num.to_s]
|
37
|
+
subject = @status[:subject][num.to_s]
|
38
|
+
link = @status[:link][num.to_s]
|
39
|
+
message_id = @status[:message_id][num.to_s]
|
40
|
+
max_pages = @status[:max_pages][num.to_s]
|
41
|
+
current_page = @status[:current_page][num.to_s]
|
42
|
+
|
43
|
+
puts max_pages, current_page, sender, image, subject, date, link, message_id, "\n"
|
44
|
+
end
|
45
|
+
|
46
|
+
Reply Back to a Message ID
|
47
|
+
It only accepts plain text
|
48
|
+
|
49
|
+
@status = MySpace.reply_to_mail(credentials, {:message_id => '123456789', :message => 'Hey I can reply back from my own application!. Thanx FernyB'})
|
50
|
+
puts @status
|
51
|
+
|
52
|
+
|
53
|
+
# Post a Bulletin
|
54
|
+
@status = MySpace.post_bulletin(credentials, {:subject => 'Hello', :message => 'I am FernyB!'})
|
55
|
+
puts @status
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# -*- ruby -*-
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require 'hoe'
|
7
|
+
require './lib/myspace.rb'
|
8
|
+
|
9
|
+
Hoe.new('myspace', Myspace::VERSION) do |p|
|
10
|
+
p.rubyforge_name = 'myspace'
|
11
|
+
p.author = 'Fernando Barajas'
|
12
|
+
p.email = 'fernyb@fernyb.net'
|
13
|
+
p.summary = 'FIX'
|
14
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
15
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
16
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
17
|
+
end
|
18
|
+
|
19
|
+
# vim: syntax=Ruby
|
data/lib/myspace.rb
ADDED
@@ -0,0 +1,646 @@
|
|
1
|
+
class Myspace
|
2
|
+
VERSION = '1.0.0'
|
3
|
+
end
|
4
|
+
|
5
|
+
#!/usr/bin/env ruby
|
6
|
+
#
|
7
|
+
# Author: FernyB
|
8
|
+
# URL: http://fernyb.net/
|
9
|
+
#
|
10
|
+
# A simple way to update your status on myspace.com
|
11
|
+
#
|
12
|
+
# For More Information
|
13
|
+
# Visit: http://fernyb.net/myspace/api
|
14
|
+
#
|
15
|
+
|
16
|
+
require 'rubygems'
|
17
|
+
require 'hpricot'
|
18
|
+
require 'net/http'
|
19
|
+
require 'uri'
|
20
|
+
require 'Date'
|
21
|
+
|
22
|
+
class Myspace
|
23
|
+
|
24
|
+
Version = '1.0.0'
|
25
|
+
Host = 'http://mobile.myspace.com'
|
26
|
+
|
27
|
+
# Initialize the class with the username and password
|
28
|
+
# Username is the email address you use for your myspace login
|
29
|
+
#
|
30
|
+
def initialize(user = {})
|
31
|
+
@username = user[:username]
|
32
|
+
@password = user[:password]
|
33
|
+
@html = nil
|
34
|
+
@cookie = nil
|
35
|
+
@response_code = nil
|
36
|
+
@headers = {}
|
37
|
+
@page_link = {:name => nil, :href => nil}
|
38
|
+
@mood_options = {}
|
39
|
+
@link_href = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns the username it was initialized with
|
43
|
+
#
|
44
|
+
def username
|
45
|
+
@username
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns the username it was initialized with
|
49
|
+
#
|
50
|
+
def password
|
51
|
+
@password
|
52
|
+
end
|
53
|
+
|
54
|
+
# Returns the cookie
|
55
|
+
def cookie
|
56
|
+
@cookie
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns the html
|
60
|
+
def html
|
61
|
+
@html
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns the response code
|
65
|
+
# ( We will always like to have 200 but incases we don't get that
|
66
|
+
# we can know it wasn't a 200 response and we can then take some sort of action )
|
67
|
+
#
|
68
|
+
def response_code
|
69
|
+
@response_code
|
70
|
+
end
|
71
|
+
|
72
|
+
# Parse the HTML to retrieve only links
|
73
|
+
# The Accesskey argument is to retrive a certain link on the page
|
74
|
+
def parse(accesskey = 1)
|
75
|
+
hp = Hpricot(@html)
|
76
|
+
@linksfound = []
|
77
|
+
@link = {}
|
78
|
+
@link["profile"]
|
79
|
+
(hp/:a).each do |link|
|
80
|
+
if link.innerHTML =~ /^\d+/
|
81
|
+
if link[:accesskey] == accesskey.to_s
|
82
|
+
@link["profile"] = link[:href]
|
83
|
+
@link_href = link[:href]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
@link["profile"]
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
# Parse profile page to retrieve name and href for a numbered link
|
92
|
+
#
|
93
|
+
def parse_page_profile(item_number, param = {})
|
94
|
+
@page_link = {:name => nil, :href => nil}
|
95
|
+
hp = Hpricot(@html)
|
96
|
+
(hp/:a).each do |link|
|
97
|
+
html_text = link.innerHTML
|
98
|
+
if html_text =~ /^\d+/
|
99
|
+
if html_text[item_number.to_s.index(item_number.to_s), html_text.index(".")] == item_number.to_s
|
100
|
+
@page_link = {:name => link.innerHTML, :href => Host + link[:href].to_s}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
@page_link
|
105
|
+
if param[:follow] === true
|
106
|
+
http_get_page({:href => @page_link[:href]})
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
# Parse Mail (mymail.wap) Links
|
113
|
+
#
|
114
|
+
def parse_page_mymail(link_text, param = {})
|
115
|
+
@page_link = {:name => nil, :href => nil}
|
116
|
+
hp = Hpricot(@html)
|
117
|
+
(hp/:a).each do |link|
|
118
|
+
html_text = link.innerHTML
|
119
|
+
if html_text.strip.downcase == link_text.to_s.downcase
|
120
|
+
@page_link = {:name => link.innerHTML, :href => Host.to_s + link[:href].to_s}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
@page_link
|
124
|
+
if param[:follow] === true
|
125
|
+
http_get_page({:href => @page_link[:href].to_s})
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
# Do A HTTP GET Request
|
132
|
+
#
|
133
|
+
def http_get_page(http = {})
|
134
|
+
headers = set_headers # Set HTTP Headers
|
135
|
+
headers["Cookie"] = @cookie # Set the cookie
|
136
|
+
|
137
|
+
request_url = URI.parse(http[:href].to_s)
|
138
|
+
get_params = request_url.to_s.split("?", 2)
|
139
|
+
get_url_params = get_params[1]
|
140
|
+
get_uri = request_url.path.to_s + "?" + get_url_params.to_s
|
141
|
+
|
142
|
+
post_request = Net::HTTP::Get.new(request_url.path)
|
143
|
+
headers.to_a.each do |k, v|
|
144
|
+
post_request.[]= k, v
|
145
|
+
end
|
146
|
+
|
147
|
+
h = Net::HTTP.new(request_url.host, 80)
|
148
|
+
resp, data = h.get(get_uri, post_request)
|
149
|
+
@response_code = resp.code
|
150
|
+
@html = data
|
151
|
+
end
|
152
|
+
|
153
|
+
# Parse the status update page to retrieve the html form
|
154
|
+
#
|
155
|
+
def submit_update_status(user = {})
|
156
|
+
#html = Hpricot(open("./status_mood.html"))
|
157
|
+
html = Hpricot(@html)
|
158
|
+
|
159
|
+
form = html.search("//form")
|
160
|
+
action = form.first['action']
|
161
|
+
method = form.first['method']
|
162
|
+
|
163
|
+
status_text = (form/"input#statusText")
|
164
|
+
querystring = (form/"input#querystring")
|
165
|
+
|
166
|
+
# Get the Select Options for Mood Status
|
167
|
+
select_option = (form/"select#moodSelect")
|
168
|
+
mood_option_name = select_option.first['name'] # The Name Of the HTML Select Field
|
169
|
+
@mood_options = {}
|
170
|
+
select_option.search('//option') do |option|
|
171
|
+
option_value = option.attributes['value']
|
172
|
+
option_text = option.innerHTML
|
173
|
+
@mood_options[option_value.to_s] = option_text.to_s
|
174
|
+
end
|
175
|
+
|
176
|
+
# Buld The Query String
|
177
|
+
# "statusText=".urlencode(trim($message_text))."&moodSelect=0&querystring=". urlencode($query_string);
|
178
|
+
message = user[:status]
|
179
|
+
mood_status_value = "0"
|
180
|
+
|
181
|
+
action_url = Host + action
|
182
|
+
|
183
|
+
params = {
|
184
|
+
status_text.first['name'].to_s => message,
|
185
|
+
mood_option_name.to_s => mood_status_value,
|
186
|
+
querystring.first['name'].to_s => querystring.first['value'].to_s
|
187
|
+
}
|
188
|
+
|
189
|
+
# Prepare to post status update
|
190
|
+
@headers = set_headers # Set Http Headers
|
191
|
+
@headers['Cookie'] = @cookie
|
192
|
+
|
193
|
+
action_url = URI.parse(action_url)
|
194
|
+
|
195
|
+
post_request = Net::HTTP::Post.new(action_url.path)
|
196
|
+
post_request.set_form_data(params)
|
197
|
+
@headers.to_a.each do |k, v|
|
198
|
+
post_request.[]= k, v
|
199
|
+
end
|
200
|
+
|
201
|
+
res = Net::HTTP.new(action_url.host, action_url.port)
|
202
|
+
res.start {|http|
|
203
|
+
resbody = http.request(post_request)
|
204
|
+
#@cookie = resbody.response.get_fields('Set-Cookie')
|
205
|
+
@response_code = resbody.response.code
|
206
|
+
@html = resbody.response.read_body
|
207
|
+
}
|
208
|
+
|
209
|
+
#
|
210
|
+
end
|
211
|
+
|
212
|
+
|
213
|
+
# Get the Number of Messages in your inbox
|
214
|
+
#
|
215
|
+
def mail_inbox_number_of_messages
|
216
|
+
html = Hpricot(@html)
|
217
|
+
#html = Hpricot(open("./my_mail.html"))
|
218
|
+
body = html.search("//body")
|
219
|
+
div_scan = body.search("//div")
|
220
|
+
|
221
|
+
# Scan For &lastrecordinpreviouspage=
|
222
|
+
@lastrecordinpreviouspage = ""
|
223
|
+
div_scan.to_s.scan(/lastrecordinpreviouspage=(\d+)"/) {|lastrecordinpreviouspage|
|
224
|
+
@lastrecordinpreviouspage = lastrecordinpreviouspage
|
225
|
+
}
|
226
|
+
|
227
|
+
page_text = div_scan[1].inner_text.to_s
|
228
|
+
|
229
|
+
@max_number_of_pages = 0
|
230
|
+
@current_page_number = 1
|
231
|
+
|
232
|
+
page_text.scan(/([a-zA-Z]+\s+)(\d+\s+)([a-zA-Z]+\s+)(\d+\s+)/) {|page, current_page, of, max_pages|
|
233
|
+
@current_page_number = current_page
|
234
|
+
@max_number_of_pages = max_pages
|
235
|
+
}
|
236
|
+
@current_page_number
|
237
|
+
@max_number_of_pages
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
|
242
|
+
# List Inbox Messages
|
243
|
+
# Will Return a Hash with Image, Sender, Date, Subject And Link
|
244
|
+
# Link is probably not so useful
|
245
|
+
#
|
246
|
+
# @inbox_list = {:image => {'0' => 'http://www.fernyb.net/image.jpg'}}
|
247
|
+
# @inbox_list = {:sender => {'0' => 'John Doe'}}
|
248
|
+
# @inbox_list = {:date => {'0' => '2008-29-12'}}
|
249
|
+
# @inbox_list = {:subject => {'0' => 'Hello World!'}}
|
250
|
+
# @inbox_list = {:link => {'0' => 'http://www.fernyb.net/read.wap?number=12345'}}
|
251
|
+
# @inbox_list = {:message_id => {'0' => '12345'}}
|
252
|
+
#
|
253
|
+
def list_inbox_messages(page = 1)
|
254
|
+
@inbox_list = {
|
255
|
+
:image => {},
|
256
|
+
:sender => {},
|
257
|
+
:date => {},
|
258
|
+
:subject => {},
|
259
|
+
:link => {},
|
260
|
+
:message_id => {},
|
261
|
+
:max_pages => {},
|
262
|
+
:current_page => {}
|
263
|
+
}
|
264
|
+
# GO AND FETCH THE PAGE NUMBER ONLY IF IT IS NOT 1
|
265
|
+
if page.to_i > 1
|
266
|
+
@current_page_number = page
|
267
|
+
#@max_number_of_pages
|
268
|
+
#puts "\n\n", @page_link[:href], "\n\n"
|
269
|
+
# &lastrecordinpreviouspage=425302517&pagenum=2
|
270
|
+
messages_url = @page_link[:href].to_s + "&lastrecordinpreviouspage=" + @lastrecordinpreviouspage.to_s + "&pagenum=" + page.to_s
|
271
|
+
http_get_page({:href => messages_url})
|
272
|
+
end
|
273
|
+
|
274
|
+
#html = Hpricot(open("./my_mail.html"))
|
275
|
+
html = Hpricot(@html)
|
276
|
+
|
277
|
+
body = html.search("//body")
|
278
|
+
table = body.search("//table")
|
279
|
+
tr = table.search("//tr")
|
280
|
+
i = 0
|
281
|
+
tr.to_a.each do |t|
|
282
|
+
# Extract the thumbnail images of the sender
|
283
|
+
image = (t/"td img").first['src']
|
284
|
+
|
285
|
+
# Extract the User Nickname of the sender
|
286
|
+
sender_name = (t/"td b").inner_text.strip
|
287
|
+
|
288
|
+
# Extract the link to the mail message
|
289
|
+
hreflink = (t/"td a")
|
290
|
+
link_to = Host + hreflink.first['href'].to_s
|
291
|
+
|
292
|
+
# Extract the Message ID for the mail message
|
293
|
+
message_id = ""
|
294
|
+
link_to.scan(/&messageid=(\d+)&/) do |id|
|
295
|
+
message_id = id
|
296
|
+
end
|
297
|
+
|
298
|
+
# Extract the Subject of the mail message
|
299
|
+
subject_text = hreflink.inner_text.to_s
|
300
|
+
|
301
|
+
# Extract the date of the message
|
302
|
+
datetext = (t/"td")
|
303
|
+
date_time = ""
|
304
|
+
datetext[1].to_s.scan(/<br\s+\/?>(\d+\/\d+\/\d+)/) do |date|
|
305
|
+
date_time = date.to_s.gsub(/\/+/, "-")
|
306
|
+
end
|
307
|
+
if date_time != "" || date_time != nil
|
308
|
+
date = Date::parse(date_time)
|
309
|
+
else
|
310
|
+
date = nil
|
311
|
+
end
|
312
|
+
|
313
|
+
# Add The Extracted Values to the Hash
|
314
|
+
@inbox_list[:image][i.to_s] = image.to_s
|
315
|
+
@inbox_list[:sender][i.to_s] = sender_name.to_s
|
316
|
+
@inbox_list[:date][i.to_s] = date.to_s
|
317
|
+
@inbox_list[:subject][i.to_s] = subject_text.to_s
|
318
|
+
@inbox_list[:link][i.to_s] = link_to.to_s
|
319
|
+
@inbox_list[:message_id][i.to_s] = message_id.to_s
|
320
|
+
@inbox_list[:max_pages][i.to_s] = @max_number_of_pages.to_s
|
321
|
+
@inbox_list[:current_page][i.to_s] = @current_page_number.to_s
|
322
|
+
|
323
|
+
i += 1
|
324
|
+
end
|
325
|
+
@inbox_list
|
326
|
+
end
|
327
|
+
|
328
|
+
|
329
|
+
# This method will update your status.
|
330
|
+
# You must pass your username, password and message
|
331
|
+
# Example: Myspace.update_status({:username => 'john@doe.com', :password => 'supersecret'}, 'Good Morning!')
|
332
|
+
#
|
333
|
+
def self.update_status(user = {}, status_update = "")
|
334
|
+
@myspace = self.new(:username => user[:username], :password => user[:password])
|
335
|
+
@myspace.login
|
336
|
+
@myspace.parse
|
337
|
+
@myspace.get_page_profile
|
338
|
+
@myspace.parse_page_profile(7, {:follow => true})
|
339
|
+
@myspace.submit_update_status({:status => status_update})
|
340
|
+
@myspace.response_code
|
341
|
+
end
|
342
|
+
|
343
|
+
# Get your current status
|
344
|
+
# Example: @status = Myspace.get_status({:username => 'john@doe.com', :password => 'supersecret'})
|
345
|
+
# Returns: current = {:current => stat.to_s}
|
346
|
+
# Can be Accessed: @status[:current]
|
347
|
+
#
|
348
|
+
def self.get_status(user = {})
|
349
|
+
@myspace = self.new(:username => user[:username], :password => user[:password])
|
350
|
+
@myspace.login
|
351
|
+
@myspace.parse
|
352
|
+
@myspace.get_page_profile
|
353
|
+
@myspace.current_status
|
354
|
+
end
|
355
|
+
|
356
|
+
# Parse and return your current status
|
357
|
+
#
|
358
|
+
def current_status
|
359
|
+
stat = ""
|
360
|
+
status = @html.to_s.scan(/<\/label>(.*)<br\s+\/><br\s+\/><img/) {|st|
|
361
|
+
stat = st
|
362
|
+
}
|
363
|
+
current = {:current => stat.to_s}
|
364
|
+
end
|
365
|
+
|
366
|
+
# Method For Posting a Bulletin
|
367
|
+
#
|
368
|
+
def self.post_bulletin(user = {}, message = {})
|
369
|
+
@myspace = self.new(:username => user[:username], :password => user[:password])
|
370
|
+
@myspace.login
|
371
|
+
@myspace.parse(2) # Will parse to retrieve link with accesskey = 2
|
372
|
+
@myspace.get_page_profile
|
373
|
+
@myspace.parse_page_mymail('Post Bulletin', {:follow => true})
|
374
|
+
@myspace.new_bulletin_post(message[:subject], message[:message])
|
375
|
+
end
|
376
|
+
|
377
|
+
# Method For Sending a HTTP Request to post a new bulletin
|
378
|
+
#
|
379
|
+
def new_bulletin_post(subject = nil, body = nil)
|
380
|
+
#html_form = Hpricot(open("./new_bulletin.html"))
|
381
|
+
html_form = Hpricot(@html)
|
382
|
+
|
383
|
+
form = html_form.search("form#mailcreateform")
|
384
|
+
action_url = Host.to_s + form.first['action'].to_s
|
385
|
+
method = form.first['method'].to_s
|
386
|
+
element = form.search("input")
|
387
|
+
|
388
|
+
subject_input = (html_form/"input#subjectInput")
|
389
|
+
body_input = (html_form/"textarea#bodyInput")
|
390
|
+
querystring = (html_form/"input#querystring")
|
391
|
+
params = {
|
392
|
+
subject_input.first['name'].to_s => subject.to_s,
|
393
|
+
body_input.first['name'].to_s => body.to_s,
|
394
|
+
querystring.first['name'].to_s => querystring.first['value'].to_s
|
395
|
+
}
|
396
|
+
# Do Post
|
397
|
+
@headers = set_headers
|
398
|
+
@headers['cookie'] = @cookie
|
399
|
+
|
400
|
+
action_url = URI.parse(action_url)
|
401
|
+
|
402
|
+
post_request = Net::HTTP::Post.new(action_url.path)
|
403
|
+
post_request.set_form_data(params)
|
404
|
+
@headers.to_a.each do |k, v|
|
405
|
+
post_request.[]= k, v
|
406
|
+
end
|
407
|
+
|
408
|
+
res = Net::HTTP.new(action_url.host, action_url.port)
|
409
|
+
res.start {|http|
|
410
|
+
resbody = http.request(post_request)
|
411
|
+
#@cookie = resbody.response.get_fields('Set-Cookie')
|
412
|
+
@html = resbody.response.read_body
|
413
|
+
}
|
414
|
+
@html
|
415
|
+
end
|
416
|
+
|
417
|
+
|
418
|
+
# Method for retrieving messages mail
|
419
|
+
# Example: MySpace.retrieve_mail({:username => 'john@doe.com', :password => 'supersecret'}, 1)
|
420
|
+
# The Second Parameter is the page number you want to retrieve the default is 1
|
421
|
+
#
|
422
|
+
def self.retrieve_mail(user = {}, page = 1)
|
423
|
+
if user[:username] == nil || user[:password] == nil
|
424
|
+
return nil
|
425
|
+
end
|
426
|
+
@myspace = self.new(:username => user[:username], :password => user[:password])
|
427
|
+
@myspace.login
|
428
|
+
@myspace.parse(2) # Will parse to retrieve link with accesskey = 2
|
429
|
+
@myspace.get_page_profile
|
430
|
+
|
431
|
+
# Will parse file: mymail.wap
|
432
|
+
@myspace.parse_page_mymail('inbox', {:follow => true})
|
433
|
+
@myspace.mail_inbox_number_of_messages
|
434
|
+
#@current_page_number @max_number_of_pages
|
435
|
+
@myspace.list_inbox_messages(page) # Default is 1
|
436
|
+
end
|
437
|
+
|
438
|
+
# Method For Reading a Message ID
|
439
|
+
#
|
440
|
+
def self.read_mail(user = {}, message_id = "")
|
441
|
+
@myspace = self.new(:username => user[:username], :password => user[:password])
|
442
|
+
@myspace.login
|
443
|
+
@myspace.parse(2) # Will parse to retrieve link with accesskey = 2
|
444
|
+
@myspace.get_weird_looking_parameter_and_read(message_id)
|
445
|
+
@myspace.parse_and_return_mail
|
446
|
+
end
|
447
|
+
|
448
|
+
# Method For Replying Back to message
|
449
|
+
#
|
450
|
+
def self.reply_to_mail(user = {}, message = {})
|
451
|
+
@myspace = self.new(:username => user[:username], :password => user[:password])
|
452
|
+
@myspace.login
|
453
|
+
@myspace.parse(2) # Will parse to retrieve link with accesskey = 2
|
454
|
+
@myspace.get_weird_looking_parameter_and_read(message[:message_id].to_s)
|
455
|
+
@myspace.get_reply_back_mail_page(message[:message])
|
456
|
+
end
|
457
|
+
|
458
|
+
# Method for Fetching the Reply Back Page
|
459
|
+
#
|
460
|
+
def get_reply_back_mail_page(message = nil)
|
461
|
+
# 1. Search For Reply Back LInk and Extract the URL
|
462
|
+
html = Hpricot(@html)
|
463
|
+
link = (html/"a#replyLink").first['href'].to_s
|
464
|
+
reply_link = Host + link
|
465
|
+
|
466
|
+
# 2. Do a HTTP GET Request for the Reply Back Page
|
467
|
+
http_get_page(:href => reply_link)
|
468
|
+
#@html = open("./replyback.html").read
|
469
|
+
|
470
|
+
# 3. Extract the Action URL, Retrieve the Form Elements and fill in the parameters
|
471
|
+
html_form = Hpricot(@html)
|
472
|
+
form = html_form.search("form#mailcreateform")
|
473
|
+
action_url = Host + form.first['action'].to_s
|
474
|
+
|
475
|
+
method = form.first['method'].to_s
|
476
|
+
|
477
|
+
element = form.search("input")
|
478
|
+
|
479
|
+
# Input - Subject
|
480
|
+
subject = html_form.search("input#subjectInput")
|
481
|
+
# Input - QueryString
|
482
|
+
query_string = html_form.search("input#querystring")
|
483
|
+
# Input - Body
|
484
|
+
body = html_form.search("textarea#bodyInput")
|
485
|
+
|
486
|
+
params = {
|
487
|
+
subject.first['name'].to_s => subject.first['value'].to_s,
|
488
|
+
query_string.first['name'].to_s => query_string.first['value'].to_s,
|
489
|
+
body.first['name'].to_s => message
|
490
|
+
}
|
491
|
+
|
492
|
+
@headers = set_headers
|
493
|
+
@headers['cookie'] = @cookie
|
494
|
+
|
495
|
+
action_url = URI.parse(action_url)
|
496
|
+
|
497
|
+
post_request = Net::HTTP::Post.new(action_url.path)
|
498
|
+
post_request.set_form_data(params)
|
499
|
+
@headers.to_a.each do |k, v|
|
500
|
+
post_request.[]= k, v
|
501
|
+
end
|
502
|
+
|
503
|
+
res = Net::HTTP.new(action_url.host, action_url.port)
|
504
|
+
res.start {|http|
|
505
|
+
resbody = http.request(post_request)
|
506
|
+
#@cookie = resbody.response.get_fields('Set-Cookie')
|
507
|
+
@html = resbody.response.read_body
|
508
|
+
}
|
509
|
+
@html
|
510
|
+
end
|
511
|
+
|
512
|
+
|
513
|
+
# Method For Parsing and returning the message
|
514
|
+
#
|
515
|
+
def get_weird_looking_parameter_and_read(message_id = "")
|
516
|
+
url = @link_href.split(/\?/, 2)
|
517
|
+
wl = url[1].split(/&friendid/, 2)
|
518
|
+
@weird_param = wl[0].to_s
|
519
|
+
link_to_read_message = "http://mobile.myspace.com/domestic/premium/messaging/maildetail.wap?" + @weird_param +"&useimages=True&messageid=" + message_id.to_s
|
520
|
+
|
521
|
+
# Go And Fetch the HTML for the Mail Message
|
522
|
+
http_get_page(:href => link_to_read_message)
|
523
|
+
@response_code
|
524
|
+
@html
|
525
|
+
end
|
526
|
+
|
527
|
+
# Parse and Return the Mail Message
|
528
|
+
def parse_and_return_mail
|
529
|
+
#html = Hpricot(open("./maildetail.html"))
|
530
|
+
html = Hpricot(@html)
|
531
|
+
body = html.search("//body")
|
532
|
+
table = body.search("//table")
|
533
|
+
|
534
|
+
# Extract the Senders Image
|
535
|
+
sender_image = table.search("//tr td img").first['src']
|
536
|
+
|
537
|
+
# Extract the Senders Name
|
538
|
+
sender_name = table.search("//tr td a").inner_text
|
539
|
+
|
540
|
+
# Extract The Senders Date
|
541
|
+
date_time = ""
|
542
|
+
table.search("//tr td")[1].to_s.scan(/<br\s+\/?>(\d+\/\d+\/\d+)/) do |date|
|
543
|
+
date_time = date.to_s.gsub(/\/+/, "-")
|
544
|
+
end
|
545
|
+
if date_time != "" || date_time != nil
|
546
|
+
sender_date = Date::parse(date_time)
|
547
|
+
else
|
548
|
+
sender_date = nil
|
549
|
+
end
|
550
|
+
|
551
|
+
body_html = body.search("//div p")
|
552
|
+
|
553
|
+
# Extract The Subject Line
|
554
|
+
# Extract The Body Message
|
555
|
+
sender_subject_line = ""
|
556
|
+
sender_message_body = ""
|
557
|
+
|
558
|
+
body_html.to_s.scan(/<b>Subject:<\/b><br\s+\/?>(.*)<br\s+\/?><br\s+\/?><b>Body:<\/b>(.*)/) do |subject, body|
|
559
|
+
sender_subject_line = subject
|
560
|
+
end
|
561
|
+
|
562
|
+
sender_message_body = body_html.to_s.gsub(/<br\s+\/?>/, "\n").split('<b>Body:</b>', 2)[1].split('</p><p>', 2)[0]
|
563
|
+
|
564
|
+
@mail_message = {
|
565
|
+
:sender_image => sender_image.to_s,
|
566
|
+
:sender_name => sender_name.to_s,
|
567
|
+
:sender_date => sender_date.to_s,
|
568
|
+
:sender_subject_line => sender_subject_line.to_s,
|
569
|
+
:sender_message => sender_message_body.to_s
|
570
|
+
}
|
571
|
+
end
|
572
|
+
|
573
|
+
|
574
|
+
# Retrieve the Profile HTML page
|
575
|
+
#
|
576
|
+
def get_page_profile
|
577
|
+
request_url = Host + @link['profile'].to_s
|
578
|
+
profile_url = request_url
|
579
|
+
headers = set_headers # Set HTTTP Headers
|
580
|
+
headers["Cookie"] = @cookie
|
581
|
+
|
582
|
+
request_url = URI.parse(request_url.to_s)
|
583
|
+
get_params = request_url.to_s.split("?", 2)
|
584
|
+
get_url_params = get_params[1].to_s
|
585
|
+
get_uri = request_url.path + "?" + get_url_params
|
586
|
+
|
587
|
+
post_request = Net::HTTP::Get.new(request_url.path)
|
588
|
+
headers.to_a.each do |k, v|
|
589
|
+
post_request.[]= k, v
|
590
|
+
end
|
591
|
+
|
592
|
+
h = Net::HTTP.new(request_url.host, 80)
|
593
|
+
resp, data = h.get(get_uri, post_request)
|
594
|
+
@response_code = resp.code
|
595
|
+
@html = data
|
596
|
+
end
|
597
|
+
|
598
|
+
# Login into MySpace
|
599
|
+
#
|
600
|
+
def login
|
601
|
+
login_url = "http://mobile.myspace.com/domestic/login.wap"
|
602
|
+
set_headers # Set Http Headers
|
603
|
+
|
604
|
+
params = {
|
605
|
+
"emailTextBox" => "#{@username}",
|
606
|
+
"passwordTextBox" => "#{@password}",
|
607
|
+
"rememberMe" => "true",
|
608
|
+
"loginCommand" => "Log In",
|
609
|
+
"querystring" => "jklaajkkjwioppznzknllkk=&friendid=-1&useimages=True&ispost=True"
|
610
|
+
}
|
611
|
+
|
612
|
+
login_url = URI.parse(login_url)
|
613
|
+
|
614
|
+
post_request = Net::HTTP::Post.new(login_url.path)
|
615
|
+
post_request.set_form_data(params)
|
616
|
+
@headers.to_a.each do |k, v|
|
617
|
+
post_request.[]= k, v
|
618
|
+
end
|
619
|
+
|
620
|
+
res = Net::HTTP.new(login_url.host, login_url.port)
|
621
|
+
res.start {|http|
|
622
|
+
resbody = http.request(post_request)
|
623
|
+
@cookie = resbody.response.get_fields('Set-Cookie')
|
624
|
+
@html = resbody.response.read_body
|
625
|
+
}
|
626
|
+
@html
|
627
|
+
end
|
628
|
+
|
629
|
+
private
|
630
|
+
|
631
|
+
# Set http headers
|
632
|
+
def set_headers
|
633
|
+
@headers = {
|
634
|
+
"User-Agent" => "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A537a Safari/419.3",
|
635
|
+
"Accept" => "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
|
636
|
+
"Accept-Language" => "en-us,en;q=0.5",
|
637
|
+
"Accept-Encoding" => "utf-8",
|
638
|
+
"Accept-Charset" => "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
|
639
|
+
"Keep-Alive" => "0",
|
640
|
+
"Connection" => "close",
|
641
|
+
"Referer" => "http://mobile.myspace.com/"
|
642
|
+
}
|
643
|
+
end
|
644
|
+
|
645
|
+
end
|
646
|
+
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: myspace
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Fernando Barajas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-01-10 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: hoe
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.4.0
|
23
|
+
version:
|
24
|
+
description: "== FEATURES/PROBLEMS: Sometimes it can be slow == SYNOPSIS: Credentials credentials = { :username => 'email@address.com', :password => 'SuperSecretPassword' }"
|
25
|
+
email: fernyb@fernyb.net
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
34
|
+
files:
|
35
|
+
- History.txt
|
36
|
+
- Manifest.txt
|
37
|
+
- README.txt
|
38
|
+
- Rakefile
|
39
|
+
- lib/myspace.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: " by Fernando Barajas"
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options:
|
44
|
+
- --main
|
45
|
+
- README.txt
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project: myspace
|
63
|
+
rubygems_version: 1.0.1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 2
|
66
|
+
summary: FIX
|
67
|
+
test_files: []
|
68
|
+
|