FbRuby 0.0.2
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.
- checksums.yaml +7 -0
- data/Gemfile +6 -0
- data/LICENSE +21 -0
- data/README.md +876 -0
- data/lib/FbRuby/chats.rb +369 -0
- data/lib/FbRuby/comments.rb +178 -0
- data/lib/FbRuby/createaccount.rb +142 -0
- data/lib/FbRuby/exceptions.rb +25 -0
- data/lib/FbRuby/facebook.rb +453 -0
- data/lib/FbRuby/groups.rb +260 -0
- data/lib/FbRuby/login.rb +297 -0
- data/lib/FbRuby/messenger.rb +272 -0
- data/lib/FbRuby/posts.rb +267 -0
- data/lib/FbRuby/settings.rb +282 -0
- data/lib/FbRuby/tempmail.rb +56 -0
- data/lib/FbRuby/user.rb +550 -0
- data/lib/FbRuby/utils.rb +412 -0
- data/lib/FbRuby.rb +21 -0
- metadata +114 -0
@@ -0,0 +1,282 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'date'
|
3
|
+
require_relative 'utils.rb'
|
4
|
+
require_relative 'exceptions.rb'
|
5
|
+
|
6
|
+
$url = URI("https://mbasic.facebook.com/")
|
7
|
+
|
8
|
+
|
9
|
+
module FbRuby
|
10
|
+
module Settings
|
11
|
+
# Kunci Profile akun facebook
|
12
|
+
#
|
13
|
+
# @param fbobj [Facebook] Facebook object
|
14
|
+
# @param locked [Boolean] Kunci profile
|
15
|
+
def self.LockProfile(fbobj,locked = true)
|
16
|
+
html = fbobj.sessions.get(URI.join($url, "me")).parse_html
|
17
|
+
lock = html.at_css("a[href^='/private_sharing/home_view']")
|
18
|
+
raise FbRuby::Exceptions::FacebookError.new("Tidak dapat mengunci / membuka kunci profile anda!") if lock.nil?
|
19
|
+
html = fbobj.sessions.get(URI.join($url, lock['href']))
|
20
|
+
form = html.parse_html.at_css("form[action^='/private_sharing_mutation']")
|
21
|
+
if !form.nil? and locked
|
22
|
+
data = {}
|
23
|
+
form.css("input[type = 'hidden']").each{|i| data[i['name']] = i['value']}
|
24
|
+
submit = fbobj.sessions.post_without_sessions(URI.join($url, form['action']))
|
25
|
+
|
26
|
+
return submit.ok?
|
27
|
+
elsif form.nil? and !locked
|
28
|
+
unlock = html.parse_html.at_css("a[href^='/private_sharing/revert/unlock_profile']")
|
29
|
+
buka = fbobj.sessions.get(URI.join($url, unlock['href'])).parse_html
|
30
|
+
unlockForm = buka.at_css("form[action^='/private_sharing/unlock_profile_rpp']")
|
31
|
+
unlockData = {}
|
32
|
+
unlockForm.css("input[type = 'hidden']").each{|i| unlockData[i['name']] = i['value']}
|
33
|
+
unlockAction = fbobj.sessions.post(URI.join($url, unlockForm['action']), data = unlockData)
|
34
|
+
|
35
|
+
return unlockAction.ok?
|
36
|
+
elsif !form.nil? and !locked
|
37
|
+
raise FbRuby::Exceptions::FacebookError.new("Tidak dapat membuka kunci profile, karena anda belum mengunci profile tersebut!")
|
38
|
+
elsif form.nil? and locked
|
39
|
+
raise FbRuby::Exceptions::FacebookError.new("Tidak dapat mengunci profile, karena profile ini sudah di kunci!!!m")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Atur bahasa facebook
|
44
|
+
#
|
45
|
+
# @param fbobj [Facebook] Facebook object
|
46
|
+
# @param locale [String] Locale bahasa yang ingin di ganti
|
47
|
+
def self.SetLanguage(fbobj, locale)
|
48
|
+
html = fbobj.sessions.get(URI.join($url, "/language")).parse_html
|
49
|
+
form = html.at_css("form[action^='/intl/save_locale'][action*='loc=#{locale}']")
|
50
|
+
data = {}
|
51
|
+
raise FbRuby::Exceptions::FacebookError.new("Invalid Locale!!!") if form.nil?
|
52
|
+
form.css("input[type = 'hidden']").each{|i| data[i['name']] = i['value']}
|
53
|
+
begin
|
54
|
+
ganti = fbobj.sessions.post_without_sessions(URI.join($url, form['action']), data = data)
|
55
|
+
return ganti.ok?
|
56
|
+
rescue RestClient::Found
|
57
|
+
return true
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Dapatkan locale bahasa
|
62
|
+
# @param fbobj [Facebook] Facebook object
|
63
|
+
def self.GetLocale(fbobj = nil)
|
64
|
+
locale = {}
|
65
|
+
sessions = (fbobj.nil? ? FbRuby::Utils::Session.new : fbobj.sessions)
|
66
|
+
html = sessions.get(URI.join($url, "/language")).parse_html
|
67
|
+
loc = html.css("form[action^='/intl/save_locale/'][action*='loc']")
|
68
|
+
|
69
|
+
for lang in loc
|
70
|
+
locale[lang['action'].match(/loc=(\w+)/)[1]] = lang.at_css("input[type = 'submit']")['value']
|
71
|
+
end
|
72
|
+
|
73
|
+
return locale
|
74
|
+
end
|
75
|
+
|
76
|
+
# Ganti kata sandi akun
|
77
|
+
#
|
78
|
+
# @param fbobj [Facebook] Facebook object
|
79
|
+
# @param old_pass [String] Kata sandi lama
|
80
|
+
# @param new_pass [String] Kata sandi baru
|
81
|
+
# @param keep_session [Boolean] Keep Session
|
82
|
+
def self.ChangePassword(fbobj, old_pass, new_pass, keep_session = false)
|
83
|
+
html = fbobj.sessions.get(URI.join($url, "/settings/security/password")).parse_html
|
84
|
+
form = html.at_css("form[action^='/password/change']")
|
85
|
+
data = {"password_old"=>old_pass,"password_new"=>new_pass,"password_confirm"=>new_pass}
|
86
|
+
form.css("input[name][value]").each{|i| data[i['name']] = i['value']}
|
87
|
+
ganti = fbobj.sessions.post(URI.join($url, form['action']), data = data)
|
88
|
+
gantiHtml = ganti.parse_html
|
89
|
+
|
90
|
+
if ganti.request.url.include? ('/settings/security/password') or ganti.request.url.include?('secured_action/block/')
|
91
|
+
err = "Terjadi Kesalahan :("
|
92
|
+
div_err = gantiHtml.at_css("div[id = 'root'][class], div[id = 'root'][role = 'main']")
|
93
|
+
err = div_err.at_css("div[class]").text if !div_err.nil?
|
94
|
+
|
95
|
+
raise FbRuby::Exceptions::FacebookError.new(err)
|
96
|
+
else
|
97
|
+
formSession = gantiHtml.at_css("form[action^='/settings/account/password/survey']")
|
98
|
+
dataSession = {"session_invalidation_options"=>(keep_session ? 'keep_sessions' : 'review_sessions')}
|
99
|
+
formSession.css("input[type = 'hidden']").each{|i| dataSession[i['name']] = i['value']}
|
100
|
+
submit = fbobj.sessions.post_without_sessions(URI.join($url, formSession['action'])).parse_html
|
101
|
+
|
102
|
+
if keep_session
|
103
|
+
return submit.ok?
|
104
|
+
else
|
105
|
+
review = submit.at_css("a[href^='/settings/security_login/sessions/log_out_all/confirm']")
|
106
|
+
return fbobj.sessions.get(URI.join($url, review['href'])).ok?
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# Atur Facebook site
|
112
|
+
#
|
113
|
+
# @param fbobj [Facebook] Facebook Object
|
114
|
+
# @param set_to [String] Versi Facebook "reguler" atau "basic"
|
115
|
+
def self.SetFacebookSite(fbobj, set_to)
|
116
|
+
site_list = ['reguler','basic']
|
117
|
+
raise FbRuby::Exceptions::FacebookError.new("Facebook site tidak valid!!") if !site_list.include?(set_to)
|
118
|
+
|
119
|
+
begin
|
120
|
+
html = fbobj.sessions.get(URI.join($url, "/settings/site")).parse_html
|
121
|
+
rescue then html = fbobj.sessions.get_without_sessions(URI.join($url, "/settings/site")).parse_html
|
122
|
+
end
|
123
|
+
|
124
|
+
form = html.at_css("form[action^='/a/preferences.php']")
|
125
|
+
data = {}
|
126
|
+
form.css("input[type = 'hidden'][name][value]").each{|i| data[i['name']] = i['value']}
|
127
|
+
basic = form.css("input[name = 'basic_site_devices']")
|
128
|
+
index = site_list.index(set_to)
|
129
|
+
data[basic[index]['name']] = basic[index]['value']
|
130
|
+
return fbobj.sessions.post(URI.join($url, form['action']), data = data).ok?
|
131
|
+
end
|
132
|
+
|
133
|
+
|
134
|
+
# Ganti Foto Profile akun
|
135
|
+
#
|
136
|
+
# @param fbobj [Facebook] Facebook object
|
137
|
+
# @param profile_picture [String] Path foto
|
138
|
+
def self.UpdateProfilePicture(fbobj, profile_picture)
|
139
|
+
html = fbobj.sessions.get(URI.join($url, "/me?v=info")).parse_html
|
140
|
+
gantiUrl = html.at_css("a[href^='/profile_picture']")
|
141
|
+
if gantiUrl.nil?
|
142
|
+
gantiUrl = html.at_css("a[href^='/photo.php'][id]")
|
143
|
+
raise FbRuby::Exceptions::FacebookError.new("Tidak dapat mengganti foto profile!") if gantiUrl.nil?
|
144
|
+
photo = fbobj.sessions.get(URI.join($url, gantiUrl['href'])).parse_html.at_css("a[href^='/photos/change/profile_picture']")
|
145
|
+
imgHtml = fbobj.sessions.get(URI.join($url, photo['href'])).parse_html
|
146
|
+
else
|
147
|
+
imgHtml = fbobj.sessions.get(URI.join($url, gantiUrl['href'])).parse_html
|
148
|
+
end
|
149
|
+
|
150
|
+
uploadForm = imgHtml.at_css("form[action*='z-upload'], form[action*='upload.facebook.com']")
|
151
|
+
uploadData = {}
|
152
|
+
uploadForm.css("input[type = 'hidden']").each{|i| uploadData[i['name']] = i['value']}
|
153
|
+
fileName = uploadForm.at_css("input[type = 'file']")['name']
|
154
|
+
|
155
|
+
return FbRuby::Utils::upload_photo(fbobj.sessions, URI.join($url,uploadForm['action']), profile_picture, uploadData).last.ok?
|
156
|
+
end
|
157
|
+
|
158
|
+
# Ganti Foto Sampul akun
|
159
|
+
#
|
160
|
+
# @param fbobj [Facebook] Facebook object
|
161
|
+
# @param cover_picture [String] Path foto sampul
|
162
|
+
def self.UpdateCoverPicture(fbobj, cover_picture)
|
163
|
+
html = fbobj.sessions.get(URI.join($url, "me")).parse_html
|
164
|
+
coverUrl = html.at_css("a[href^='/cover_photo']")
|
165
|
+
raise FbRuby::Exceptions::FacebookError.new("Tidak dapat mengganti foto sampul :(") if coverUrl.nil?
|
166
|
+
coverHtml = fbobj.sessions.get(URI.join($url, coverUrl['href'])).parse_html
|
167
|
+
pilihCover = coverHtml.at_css("a[href^='/photos/upload'][href*='cover_photo']")
|
168
|
+
coverHtml = fbobj.sessions.get(URI.join($url, pilihCover['href'])).parse_html unless pilihCover.nil?
|
169
|
+
coverForm = coverHtml.at_css("form[action^='/timeline/cover/upload']")
|
170
|
+
coverData = {}
|
171
|
+
coverForm.css("input[type = 'hidden']").each{|i| coverData[i['name']] = i['value']}
|
172
|
+
|
173
|
+
begin
|
174
|
+
return FbRuby::Utils::upload_photo(fbobj.sessions, URI.join($url,coverForm['action']), cover_picture, coverData).last.ok?
|
175
|
+
rescue FbRuby::Exceptions::PageNotFound
|
176
|
+
return true
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# Perbarui bio akun facebook
|
181
|
+
#
|
182
|
+
# @param fbobj [Facebook] Facebook Object
|
183
|
+
# @param bio [String] Bio, maksimal jumblah karakter adalah 101
|
184
|
+
# @param publish_feed [Boolean] Publish update ke beranda
|
185
|
+
def self.UpdateBio(fbobj, bio, publish_feed = false)
|
186
|
+
raise FbRuby::Exceptions::FacebookError.new("Bio facebook maksimal 101 karakter!!") if bio.length > 101
|
187
|
+
raise FbRuby::Exceptions::FacebookError.new("Bio facebook minimal 1 karakter") if bio.length.zero?
|
188
|
+
html = fbobj.sessions.get(URI.join($url, "/profile/basic/intro/bio/")).parse_html
|
189
|
+
form = html.at_css("form[action^='/profile/intro/bio/save']")
|
190
|
+
data = {"bio"=>bio}
|
191
|
+
data["publish_to_feed"] = "on" if publish_feed
|
192
|
+
form.css("input[type = 'hidden'][name][value]").each{|i| data[i['name']] = i['value']}
|
193
|
+
return fbobj.sessions.post(URI.join($url, form['action']), data = data).ok?
|
194
|
+
end
|
195
|
+
|
196
|
+
# Perbarui Kutipan Favorit
|
197
|
+
#
|
198
|
+
# @param fbobj [Facebook] Facebook Object
|
199
|
+
# @param quote [String] Kutipan Favorit
|
200
|
+
def self.UpdateQuote(fbobj, quote)
|
201
|
+
raise FbRuby::Exceptions::FacebookError.new("Panjang Quote minimal adalah 1 karakter!") if quote.length.zero?
|
202
|
+
html = fbobj.sessions.get(URI.join($url, 'profile/edit/infotab/section/forms/?section=quote')).parse_html
|
203
|
+
form = html.at_css("form[action^='/profile/edit/quote']")
|
204
|
+
data = {"quote"=>quote,"save"=>"submit"}
|
205
|
+
form.css("input[type = 'hidden'][name][value]").each{|i| data[i['name']] = i['value']}
|
206
|
+
return fbobj.sessions.post(URI.join($url, form["action"]), data = data).ok?
|
207
|
+
end
|
208
|
+
|
209
|
+
# Perbarui status hubungan
|
210
|
+
#
|
211
|
+
# @param fbobj [Facebook] Facebook Object
|
212
|
+
# @param status [String] Status hubungan
|
213
|
+
# @param partner [String] Id akun facebook dari pasangan
|
214
|
+
def self.UpdateRelationship(fbobj, status, partner = nil)
|
215
|
+
status.downcase!
|
216
|
+
action = ["none","single","in a relationship","in an open relationship","married","engaged","it's complicated","widowed","separated","divorced","in a civil union","in a domestic partnership"]
|
217
|
+
raise FbRuby::Exceptions::FacebookError.new("Status hubungan tidak valid!!!") unless action.include?(status)
|
218
|
+
html = fbobj.sessions.get(URI.join($url, "/editprofile.php?type=basic&edit=relationship&action=#{action.index(status)}")).parse_html
|
219
|
+
form = html.at_css("form[action^='/a/editprofile.php']")
|
220
|
+
data = {"save"=>"submit"}
|
221
|
+
form.css("input[type = 'hidden'][name][value]").each{|i| data[i['name']] = i['value']}
|
222
|
+
data["id"] = partner unless partner.nil?
|
223
|
+
return fbobj.sessions.post(URI.join($url, form['action']), data = data).ok?
|
224
|
+
end
|
225
|
+
|
226
|
+
# Perbarui Anniversary
|
227
|
+
#
|
228
|
+
# @param fbobj [Facebook] Facebook Object
|
229
|
+
# @param date [String, DateTime] Tanggal Anniversary, format nya adalah dd/mm/yyyy
|
230
|
+
def self.UpdateAnniversary(fbobj, date)
|
231
|
+
date = (date.kind_of?(DateTime) ? date : DateTime.strptime(date, "%d/%m/%Y"))
|
232
|
+
raise FbRuby::Exceptions::FacebookError.new("Format tanggal tidak valid!!!") if date > DateTime.now
|
233
|
+
html = fbobj.sessions.get(URI.join($url, '/editprofile.php?type=basic&edit=anniversary')).parse_html
|
234
|
+
form = html.at_css("form[action^='/a/editprofile.php']")
|
235
|
+
data = {"month"=>date.mon,"day"=>date.day,"year"=>date.year,"save"=>"Submit"}
|
236
|
+
form.css("input[type = 'hidden'][name][value]").each{|i| data[i['name']] = i['value']}
|
237
|
+
return fbobj.sessions.post(URI.join($url, form["action"]), data = data).ok?
|
238
|
+
end
|
239
|
+
|
240
|
+
# Perbarui About me
|
241
|
+
#
|
242
|
+
# @param fbobj [Facebook] Facebook Object
|
243
|
+
# @param aboutme [String] About me
|
244
|
+
def self.UpdateAboutme(fbobj, aboutme)
|
245
|
+
raise FbRuby::Exceptions::FacebookError.new("Panjang minimal about me adalah 1 karakter!") if aboutme.length.zero?
|
246
|
+
html = fbobj.sessions.get(URI.join($url, '/profile/edit/infotab/section/forms/?section=bio')).parse_html
|
247
|
+
form = html.at_css("form[action^='/profile/edit/aboutme']")
|
248
|
+
data = {"bio"=>aboutme,"save"=>"submit"}
|
249
|
+
form.css("input[type = 'hidden'][name][value]").each{|i| data[i['name']] = i['value']}
|
250
|
+
return fbobj.sessions.post(URI.join($url, form['action']), data = data).ok?
|
251
|
+
end
|
252
|
+
|
253
|
+
# Perbarui kota saat ini
|
254
|
+
#
|
255
|
+
# @param fbobj [Facebook] Facebook Object
|
256
|
+
# @param newcity [String] Kota saat ini
|
257
|
+
def self.UpdateCurrentCity(fbobj,newcity)
|
258
|
+
html = fbobj.sessions.get(URI.join($url, '/editprofile.php?type=basic&edit=current_city')).parse_html
|
259
|
+
form = html.at_css("form[action^='/a/editprofile.php']")
|
260
|
+
data = {"current_city[]"=>newcity,"save"=>"submit"}
|
261
|
+
form.css("input[type = 'hidden'][name][value]").each{|i| data[i['name']] = i['value']}
|
262
|
+
submit = fbobj.sessions.post(URI.join($url, form['action']), data = data)
|
263
|
+
raise FbRuby::Exceptions::FacebookError.new("Kota dengan nama #{newcity} tidak di temukan!") if !submit.parse_html.at_css("form[action^='/a/editprofile.php']").nil?
|
264
|
+
return submit.ok?
|
265
|
+
end
|
266
|
+
|
267
|
+
# Perbarui Kota Asal
|
268
|
+
#
|
269
|
+
# @param fbobj [Facebook] Facebook Object
|
270
|
+
# @param hometown [String] Kota asal
|
271
|
+
def self.UpdateHometown(fbobj, hometown)
|
272
|
+
html = fbobj.sessions.get(URI.join($url, '/editprofile.php?type=basic&edit=hometown')).parse_html
|
273
|
+
form = html.at_css("form[action^='/a/editprofile.php']")
|
274
|
+
data = {"hometown[]"=>hometown,"save"=>"submit"}
|
275
|
+
form.css("input[type = 'hidden'][name][value]").each{|i| data[i['name']] = i['value']}
|
276
|
+
submit = fbobj.sessions.post(URI.join($url, form['action']), data = data)
|
277
|
+
raise FbRuby::Exceptions::FacebookError.new("Kota dengan nama #{newcity} tidak di temukan!") if !submit.parse_html.at_css("form[action^='/a/editprofile.php']").nil?
|
278
|
+
return submit.ok?
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require_relative "utils.rb"
|
3
|
+
|
4
|
+
module FbRuby
|
5
|
+
# class TempMail di gunakan untuk mendapatkan email sementara
|
6
|
+
class TempMail
|
7
|
+
|
8
|
+
@@domain = ["mailto.plus","fexpost.com","fexbox.org","mailbox.in.ua","rover.info","chitthi.in","fextemp.com","any.pink","merepost.com"].freeze
|
9
|
+
attr_reader :domain, :sessions, :email
|
10
|
+
|
11
|
+
def self.domain
|
12
|
+
return @@domain
|
13
|
+
end
|
14
|
+
|
15
|
+
# Inisialisasi object TempMail
|
16
|
+
#
|
17
|
+
# @param prefix [String] Nama awalan email
|
18
|
+
# @param domain [String] Domain email
|
19
|
+
def initialize(prefix = nil, domain = nil)
|
20
|
+
raise ArgumentError.new("Invalid Domain") if !domain.nil? and !@@domain.include? (domain)
|
21
|
+
@sessions = FbRuby::Utils::Session.new
|
22
|
+
@prefix = (prefix.nil? ? FbRuby::Utils::randomString(12) : prefix.strip)
|
23
|
+
@domain = (domain.nil? ? @@domain.sample : domain.strip)
|
24
|
+
@email = "#{@prefix}@#{@domain}"
|
25
|
+
@host = URI("https://tempmail.plus/api/")
|
26
|
+
end
|
27
|
+
|
28
|
+
# Dapatkan pesan email baru
|
29
|
+
#
|
30
|
+
# @param limit [Integer] Jumblah pesan yang ingin di ambil
|
31
|
+
def get_new_message(limit = 10)
|
32
|
+
return @sessions.get(URI.join(@host,"mails?email=#{@email}&limit=#{limit}")).json
|
33
|
+
end
|
34
|
+
|
35
|
+
# Lihat pesan email
|
36
|
+
#
|
37
|
+
# @param mail_id [String] Id dari pesan email
|
38
|
+
def view_mail(mail_id)
|
39
|
+
return @sessions.get(URI.join(@host, "mails/#{mail_id}?email=#{@email}")).json
|
40
|
+
end
|
41
|
+
|
42
|
+
# Mengembalikan string representasi dari objek TempMail.
|
43
|
+
#
|
44
|
+
# @return [String] Representasi string dari objek TempMail.
|
45
|
+
def to_s
|
46
|
+
return "CryptoGmail : prefix=#{@prefix} domain=#{@domain} email=#{@email}"
|
47
|
+
end
|
48
|
+
|
49
|
+
# Mengembalikan string representasi dari objek TempMail.
|
50
|
+
#
|
51
|
+
# @return [String] Representasi string dari objek TempMail.
|
52
|
+
def inspect
|
53
|
+
return to_s
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|