forked from mmangino/facebooker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.rb
987 lines (862 loc) · 30.5 KB
/
parser.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
require 'facebooker/session'
begin
require 'nokogiri'
rescue Exception
require 'rexml/document'
end
module Facebooker
class Parser
module REXMLElementExtensions # :nodoc:
def content
self.text || ''
end
def [] key
attributes[key]
end
def text?
false
end
end
module REXMLTextExtensions # :nodoc:
def text?
true
end
end
if Object.const_defined?(:REXML) && REXML.const_defined?(:Element)
::REXML::Element.__send__(:include, REXMLElementExtensions)
::REXML::Text.__send__(:include, REXMLTextExtensions)
end
def self.parse(method, data)
Errors.process(data)
parser = Parser::PARSERS[method]
raise "Can't find a parser for '#{method}'" unless parser
parser.process(data)
end
def self.array_of(response_element, element_name)
values_to_return = []
response_element.children.each do |element|
next if element.text?
next unless element.name == element_name
values_to_return << yield(element)
end
values_to_return
end
def self.array_of_text_values(response_element, element_name)
array_of(response_element, element_name) do |element|
element.content.strip
end
end
def self.array_of_hashes(response_element, element_name)
array_of(response_element, element_name) do |element|
hashinate(element)
end
end
def self.element(name, data)
data = data.body rescue data # either data or an HTTP response
if Object.const_defined?(:Nokogiri)
xml = Nokogiri::XML(data.strip)
if node = xml.at(name)
return node
end
if xml.root.name == name
return xml.root
end
else
doc = REXML::Document.new(data)
doc.elements.each(name) do |element|
return element
end
end
raise "Element #{name} not found in #{data}"
end
def self.hash_or_value_for(element)
if element.children.size == 1 && element.children.first.text?
element.content.strip
else
# We can have lists in not list item
if element['list'] == 'true'
element.children.reject{|c| c.text? }.map { |subchild| hash_or_value_for(subchild)}
else
hashinate(element)
end
end
end
def self.hashinate(response_element)
response_element.children.reject{|c| c.text? }.inject({}) do |hash, child|
# If the node hasn't any child, and is not a list, we want empty strings, not empty hashes,
# except if attributes['nil'] == true
hash[child.name] =
if (child['nil'] == 'true')
nil
elsif (child.children.size == 1 && child.children.first.text?) || (child.children.size == 0 && child['list'] != 'true')
anonymous_field_from(child, hash) || child.content.strip
elsif child['list'] == 'true'
child.children.reject{|c| c.text? }.map { |subchild| hash_or_value_for(subchild)}
else
child.children.reject{|c| c.text? }.inject({}) do |subhash, subchild|
subhash[subchild.name] = hash_or_value_for(subchild)
subhash
end
end #if (child.attributes)
hash
end #do |hash, child|
end
def self.hash_by_key_or_value_for(element, convert_1_to_true=false)
if element.children.size == 0
{ element['key'] => nil }
elsif element.children.size == 1 && element.children.first.text?
{ element['key'] => (convert_1_to_true ? element.content.strip == '1' : element.content.strip) }
else
hashinate_by_key(element, convert_1_to_true)
end
end
# A modification to hashinate. The new dashboard API returns XML in a different format than
# the other calls. What used to be the element name has become an attribute called "key".
def self.hashinate_by_key(response_element, convert_1_to_true=false)
response_element.children.reject{|c| c.text? }.inject({}) do |hash, child|
# If the node hasn't any child, and is not a list, we want empty strings, not empty hashes,
# except if attributes['nil'] == true
hash[child['key']] =
if (child['nil'] == 'true')
nil
elsif (child.children.size == 1 && child.children.first.text?) || (child.children.size == 0 && child['list'] != 'true')
anonymous_field_from(child, hash) || (convert_1_to_true ? child.content.strip == '1' : child.content.strip)
elsif child['list'] == 'true' && child.children.reject {|subchild| subchild.text?}.all? { |subchild| !subchild.text? && subchild['key'].nil? }
child.children.reject{|c| c.text? }.map { |subchild| hash_by_key_or_value_for(subchild, convert_1_to_true)}
elsif child['list'] == 'true'
hash_by_key_or_value_for(child, convert_1_to_true)
else
child.children.reject{|c| c.text? }.inject({}) do |subhash, subchild|
subhash[subchild['key']] = hash_by_key_or_value_for(subchild, convert_1_to_true)
subhash
end
end
hash
end
end
def self.booleanize(response)
response == "1" ? true : false
end
def self.anonymous_field_from(child, hash)
if child.name == 'anon'
(hash[child.name] || []) << child.content.strip
end
end
end
class RevokeAuthorization < Parser#:nodoc:
def self.process(data)
booleanize(data)
end
end
class RevokeExtendedPermission < Parser#:nodoc:
def self.process(data)
booleanize(element('auth_revokeExtendedPermission_response', data).content.strip)
end
end
class CreateToken < Parser#:nodoc:
def self.process(data)
element('auth_createToken_response', data).content.strip
end
end
class RegisterUsers < Parser
def self.process(data)
array_of_text_values(element("connect_registerUsers_response", data), "connect_registerUsers_response_elt")
end
end
class UnregisterUsers < Parser
def self.process(data)
array_of_text_values(element("connect_unregisterUsers_response", data), "connect_unregisterUsers_response_elt")
end
end
class GetUnconnectedFriendsCount < Parser
def self.process(data)
hash_or_value_for(element("connect_getUnconnectedFriendsCount_response",data)).to_i
end
end
class GetSession < Parser#:nodoc:
def self.process(data)
hashinate(element('auth_getSession_response', data))
end
end
class IsAppUser < Parser#:nodoc:
def self.process(data)
element('users_isAppUser_response', data).content == '1'
end
end
class GetFriends < Parser#:nodoc:
def self.process(data)
array_of_text_values(element('friends_get_response', data), 'uid')
end
end
class FriendListsGet < Parser#:nodoc:
def self.process(data)
array_of_hashes(element('friends_getLists_response', data), 'friendlist')
end
end
class UserInfo < Parser#:nodoc:
def self.process(data)
array_of_hashes(element('users_getInfo_response', data), 'user')
end
end
class UserStandardInfo < Parser#:nodoc:
def self.process(data)
array_of_hashes(element('users_getStandardInfo_response', data), 'standard_user_info')
end
end
class GetLoggedInUser < Parser#:nodoc:
def self.process(data)
Integer(element('users_getLoggedInUser_response', data).content.strip)
end
end
class PagesIsAdmin < Parser#:nodoc:
def self.process(data)
element('pages_isAdmin_response', data).content.strip == '1'
end
end
class PagesGetInfo < Parser#:nodoc:
def self.process(data)
array_of_hashes(element('pages_getInfo_response', data), 'page')
end
end
class PagesIsFan < Parser#:nodoc:
def self.process(data)
element('pages_isFan_response', data).content.strip == '1'
end
end
class PublishStoryToUser < Parser#:nodoc:
def self.process(data)
element('feed_publishStoryToUser_response', data).content.strip
end
end
class StreamPublish < Parser#:nodoc:
def self.process(data)
element('stream_publish_response', data).content.strip
end
end
class StreamAddComment < Parser#:nodoc:
def self.process(data)
element('stream_addComment_response', data).content.strip
end
end
class StreamAddLike < Parser#:nodoc:
def self.process(data)
element('stream_addLike_response', data).content.strip
end
end
class StreamRemoveLike < Parser#:nodoc:
def self.process(data)
booleanize(element('stream_removeLike_response', data).content.strip)
end
end
class RegisterTemplateBundle < Parser#:nodoc:
def self.process(data)
element('feed_registerTemplateBundle_response', data).content.to_i
end
end
class GetRegisteredTemplateBundles < Parser
def self.process(data)
array_of_hashes(element('feed_getRegisteredTemplateBundles_response',data), 'template_bundle')
end
end
class DeactivateTemplateBundleByID < Parser#:nodoc:
def self.process(data)
element('feed_deactivateTemplateBundleByID_response', data).content.strip == '1'
end
end
class PublishUserAction < Parser#:nodoc:
def self.process(data)
element('feed_publishUserAction_response', data).children[1].content.strip == "1"
end
end
class UploadNativeStrings < Parser#:nodoc:
def self.process(data)
element('intl_uploadNativeStrings_response', data).content.strip
end
end
class PublishActionOfUser < Parser#:nodoc:
def self.process(data)
element('feed_publishActionOfUser_response', data).content.strip
end
end
class PublishTemplatizedAction < Parser#:nodoc:
def self.process(data)
element('feed_publishTemplatizedAction_response', data).children[1].content.strip
end
end
class SetAppProperties < Parser#:nodoc:
def self.process(data)
element('admin_setAppProperties_response', data).content.strip
end
end
class GetAppProperties < Parser#:nodoc:
def self.process(data)
element('admin_getAppProperties_response', data).content.strip
end
end
class SetRestrictionInfo < Parser#:nodoc:
def self.process(data)
element('admin_setRestrictionInfo_response', data).content.strip
end
end
class GetRestrictionInfo < Parser#:nodoc:
def self.process(data)
element('admin_getRestrictionInfo_response', data).content.strip
end
end
class GetAllocation < Parser#:nodoc:
def self.process(data)
element('admin_getAllocation_response', data).content.strip
end
end
class GetPublicInfo < Parser#:nodoc:
def self.process(data)
hashinate(element('application_getPublicInfo_response', data))
end
end
class CommentsAdd < Parser#:nodoc:
def self.process(data)
element('comments_add_response', data).content.strip
end
end
class CommentsRemove < Parser#:nodoc:
def self.process(data)
booleanize(data)
end
end
class CommentsGet < Parser#:nodoc:
def self.process(data)
array_of_hashes(element('comments_get_response', data), 'comment')
end
end
class BatchRun < Parser #:nodoc:
class << self
def current_batch=(current_batch)
Thread.current[:facebooker_current_batch]=current_batch
end
def current_batch
Thread.current[:facebooker_current_batch]
end
end
def self.process(data)
array_of_text_values(element('batch_run_response',data),"batch_run_response_elt").each_with_index do |response,i|
batch_request=current_batch[i]
body=Struct.new(:body).new
body.body=response
begin
batch_request.result=Parser.parse(batch_request.method,body)
rescue Exception=>ex
batch_request.exception_raised=ex
end
end
end
end
class GetAppUsers < Parser#:nodoc:
def self.process(data)
array_of_text_values(element('friends_getAppUsers_response', data), 'uid')
end
end
class MessageGetThreadsInFolder < Parser#:nodoc:
def self.process(data)
array_of_hashes(element('message_getThreadsInFolder_response', data), 'thread')
end
end
class NotificationsGet < Parser#:nodoc:
def self.process(data)
hashinate(element('notifications_get_response', data))
end
end
class NotificationsSend < Parser#:nodoc:
def self.process(data)
element('notifications_send_response', data).content.strip
end
end
class NotificationsSendEmail < Parser#:nodoc:
def self.process(data)
element('notifications_sendEmail_response', data).content.strip
end
end
class GetTags < Parser#nodoc:
def self.process(data)
array_of_hashes(element('photos_getTags_response', data), 'photo_tag')
end
end
class AddTags < Parser#nodoc:
def self.process(data)
element('photos_addTag_response', data)
end
end
class GetPhotos < Parser#nodoc:
def self.process(data)
array_of_hashes(element('photos_get_response', data), 'photo')
end
end
class GetAlbums < Parser#nodoc:
def self.process(data)
array_of_hashes(element('photos_getAlbums_response', data), 'album')
end
end
class GetStream < Parser #:nodoc:
def self.process(data)
response = {}
response[:albums] = array_of_hashes(element('stream_get_response/albums', data), 'album')
response[:posts] = array_of_hashes(element('stream_get_response/posts', data), 'stream_post')
response[:profile] = array_of_hashes(element('stream_get_response/profiles', data), 'profile')
response
end
end
class CreateAlbum < Parser#:nodoc:
def self.process(data)
hashinate(element('photos_createAlbum_response', data))
end
end
class UploadPhoto < Parser#:nodoc:
def self.process(data)
hashinate(element('photos_upload_response', data))
end
end
class UploadVideo < Parser#:nodoc:
def self.process(data)
hashinate(element('video_upload_response', data))
end
end
class SendRequest < Parser#:nodoc:
def self.process(data)
element('notifications_sendRequest_response', data).content.strip
end
end
class ProfileFBML < Parser#:nodoc:
def self.process(data)
element('profile_getFBML_response', data).content.strip
end
end
class ProfileFBMLSet < Parser#:nodoc:
def self.process(data)
element('profile_setFBML_response', data).content.strip
end
end
class ProfileInfo < Parser#:nodoc:
def self.process(data)
hashinate(element('profile_getInfo_response info_fields', data))
end
end
class ProfileInfoSet < Parser#:nodoc:
def self.process(data)
element('profile_setInfo_response', data).content.strip
end
end
class FqlQuery < Parser#nodoc
def self.process(data)
root = element('fql_query_response', data)
first_child = root.children.reject{|c| c.text? }.first
first_child.nil? ? [] : [first_child.name, array_of_hashes(root, first_child.name)]
end
end
class FqlMultiquery < Parser#nodoc
def self.process(data)
root = element('fql_multiquery_response', data)
root.children.reject { |child| child.text? }.map do |elm|
elm.children.reject { |child| child.text? }.map do |query|
if 'name' == query.name
query.text
else
list = query.children.reject { |child| child.text? }
if list.length == 0
[]
else
[list.first.name, array_of_hashes(query, list.first.name)]
end
end
end
end
end
end
class SetRefHandle < Parser#:nodoc:
def self.process(data)
element('fbml_setRefHandle_response', data).content.strip
end
end
class RefreshRefURL < Parser#:nodoc:
def self.process(data)
element('fbml_refreshRefUrl_response', data).content.strip
end
end
class RefreshImgSrc < Parser#:nodoc:
def self.process(data)
element('fbml_refreshImgSrc_response', data).content.strip
end
end
class SetCookie < Parser#:nodoc:
def self.process(data)
element('data_setCookie_response', data).content.strip
end
end
class GetCookies < Parser#:nodoc:
def self.process(data)
array_of_hashes(element('data_getCookies_response', data), 'cookies')
end
end
class EventsRsvp < Parser#:nodoc:
def self.process(data)
element('events_rsvp_response', data).content.strip
end
end
class EventsCreate < Parser#:nodoc:
def self.process(data)
element('events_create_response', data).content.strip
end
end
class EventsCancel < Parser#:nodoc:
def self.process(data)
element('events_cancel_response', data).content.strip
end
end
class EventsGet < Parser#:nodoc:
def self.process(data)
array_of_hashes(element('events_get_response', data), 'event')
end
end
class EventsEdit < Parser#:nodoc:
def self.process(data)
booleanize(element('events_edit_response', data).content)
end
end
class GroupGetMembers < Parser#:nodoc:
def self.process(data)
root = element('groups_getMembers_response', data)
result = ['members', 'admins', 'officers', 'not_replied'].map do |position|
array_of(root, position) {|element| element}.map do |element|
array_of_text_values(element, 'uid').map do |uid|
{:position => position}.merge(:uid => uid)
end
end
end.flatten
end
end
class EventMembersGet < Parser#:nodoc:
def self.process(data)
root = element('events_getMembers_response', data)
result = ['attending', 'declined', 'unsure', 'not_replied'].map do |rsvp_status|
array_of(root, rsvp_status) {|element| element}.map do |element|
array_of_text_values(element, 'uid').map do |uid|
{:rsvp_status => rsvp_status}.merge(:uid => uid)
end
end
end.flatten
end
end
class GroupsGet < Parser#:nodoc:
def self.process(data)
array_of_hashes(element('groups_get_response', data), 'group')
end
end
class AreFriends < Parser#:nodoc:
def self.process(data)
array_of_hashes(element('friends_areFriends_response', data), 'friend_info').inject({}) do |memo, hash|
memo[[Integer(hash['uid1']), Integer(hash['uid2'])].sort] = are_friends?(hash['are_friends'])
memo
end
end
private
def self.are_friends?(raw_value)
if raw_value == '1'
true
elsif raw_value == '0'
false
else
nil
end
end
end
class SetStatus < Parser
def self.process(data)
element('users_setStatus_response',data).content.strip == '1'
end
end
class GetStatus < Parser # :nodoc:
def self.process(data)
array_of_hashes(element('status_get_response',data),'user_status')
end
end
class GetPreference < Parser#:nodoc:
def self.process(data)
element('data_getUserPreference_response', data).content.strip
end
end
class SetPreference < Parser#:nodoc:
def self.process(data)
element('data_setUserPreference_response', data).content.strip
end
end
class UserHasPermission < Parser
def self.process(data)
element('users_hasAppPermission_response', data).content.strip
end
end
class SmsSend < Parser#:nodoc:
def self.process(data)
element('sms_send_response', data).content.strip == '0'
end
end
class SmsCanSend < Parser#:nodoc:
def self.process(data)
element('sms_canSend_response', data).content.strip
end
end
class DashboardGetCount < Parser
def self.process(data)
element('dashboard_getCount_response', data).content.strip
end
end
class DashboardSetCount < Parser
def self.process(data)
element('dashboard_setCount_response', data).content.strip == '1'
end
end
class DashboardIncrementCount < Parser
def self.process(data)
element('dashboard_incrementCount_response', data).content.strip == '1'
end
end
class DashboardDecrementCount < Parser
def self.process(data)
element('dashboard_decrementCount_response', data).content.strip == '1'
end
end
class DashboardMultiGetCount < Parser
def self.process(data)
hashinate_by_key(element('dashboard_multiGetCount_response', data))
end
end
class DashboardMultiSetCount < Parser
def self.process(data)
hashinate_by_key(element('dashboard_multiSetCount_response', data), true)
end
end
class DashboardMultiIncrementCount < Parser
def self.process(data)
hashinate_by_key(element('dashboard_multiIncrementCount_response', data), true)
end
end
class DashboardMultiDecrementCount < Parser
def self.process(data)
hashinate_by_key(element('dashboard_multiDecrementCount_response', data), true)
end
end
class DashboardAddGlobalNews < Parser
def self.process(data)
element('dashboard_addGlobalNews_response', data).content.strip
end
end
# Currently, always returns all
class DashboardGetGlobalNews < Parser
def self.process(data)
hashinate_by_key(element('dashboard_getGlobalNews_response', data))
end
end
class DashboardClearGlobalNews < Parser
def self.process(data)
hashinate_by_key(element('dashboard_clearGlobalNews_response', data), true)
end
end
class DashboardAddNews < Parser
def self.process(data)
element('dashboard_addNews_response', data).content.strip
end
end
class DashboardGetNews < Parser
def self.process(data)
hashinate_by_key(element('dashboard_getNews_response', data))
end
end
class DashboardClearNews < Parser
def self.process(data)
hashinate_by_key(element('dashboard_clearNews_response', data), true)
end
end
class DashboardMultiAddNews < Parser
def self.process(data)
hashinate_by_key(element('dashboard_multiAddNews_response', data))
end
end
class DashboardMultiClearNews < Parser
def self.process(data)
hashinate_by_key(element('dashboard_multiClearNews_response', data), true)
end
end
class DashboardMultiGetNews < Parser
def self.process(data)
hashinate_by_key(element('dashboard_multiGetNews_response', data))
end
end
class DashboardPublishActivity < Parser
def self.process(data)
element('dashboard_publishActivity_response', data).content.strip
end
end
class DashboardRemoveActivity < Parser
def self.process(data)
hashinate_by_key(element('dashboard_removeActivity_response', data), true)
end
end
class DashboardGetActivity < Parser
def self.process(data)
hashinate_by_key(element('dashboard_getActivity_response', data))
end
end
class Errors < Parser#:nodoc:
EXCEPTIONS = {
1 => Facebooker::Session::UnknownError,
2 => Facebooker::Session::ServiceUnavailable,
4 => Facebooker::Session::MaxRequestsDepleted,
5 => Facebooker::Session::HostNotAllowed,
10 => Facebooker::Session::AppPermissionError,
100 => Facebooker::Session::MissingOrInvalidParameter,
101 => Facebooker::Session::InvalidAPIKey,
102 => Facebooker::Session::SessionExpired,
103 => Facebooker::Session::CallOutOfOrder,
104 => Facebooker::Session::IncorrectSignature,
120 => Facebooker::Session::InvalidAlbumId,
200 => Facebooker::Session::PermissionError,
250 => Facebooker::Session::ExtendedPermissionRequired,
321 => Facebooker::Session::AlbumIsFull,
324 => Facebooker::Session::MissingOrInvalidImageFile,
325 => Facebooker::Session::TooManyUnapprovedPhotosPending,
330 => Facebooker::Session::TemplateDataMissingRequiredTokens,
340 => Facebooker::Session::TooManyUserCalls,
341 => Facebooker::Session::TooManyUserActionCalls,
342 => Facebooker::Session::InvalidFeedTitleLink,
343 => Facebooker::Session::InvalidFeedTitleLength,
344 => Facebooker::Session::InvalidFeedTitleName,
345 => Facebooker::Session::BlankFeedTitle,
346 => Facebooker::Session::FeedBodyLengthTooLong,
347 => Facebooker::Session::InvalidFeedPhotoSource,
348 => Facebooker::Session::InvalidFeedPhotoLink,
330 => Facebooker::Session::FeedMarkupInvalid,
360 => Facebooker::Session::FeedTitleDataInvalid,
361 => Facebooker::Session::FeedTitleTemplateInvalid,
362 => Facebooker::Session::FeedBodyDataInvalid,
363 => Facebooker::Session::FeedBodyTemplateInvalid,
364 => Facebooker::Session::FeedPhotosNotRetrieved,
366 => Facebooker::Session::FeedTargetIdsInvalid,
601 => Facebooker::Session::FQLParseError,
602 => Facebooker::Session::FQLFieldDoesNotExist,
603 => Facebooker::Session::FQLTableDoesNotExist,
604 => Facebooker::Session::FQLStatementNotIndexable,
605 => Facebooker::Session::FQLFunctionDoesNotExist,
606 => Facebooker::Session::FQLWrongNumberArgumentsPassedToFunction,
612 => Facebooker::Session::ReadMailboxExtendedPermissionRequired,
807 => Facebooker::Session::TemplateBundleInvalid
}
def self.process(data)
response_element = element('error_response', data) rescue nil
if response_element
hash = hashinate(response_element)
exception = EXCEPTIONS[Integer(hash['error_code'])] || StandardError
raise exception, hash['error_msg']
end
end
end
class Parser
PARSERS = {
'facebook.auth.revokeAuthorization' => RevokeAuthorization,
'facebook.auth.revokeExtendedPermission' => RevokeExtendedPermission,
'facebook.auth.createToken' => CreateToken,
'facebook.auth.getSession' => GetSession,
'facebook.connect.registerUsers' => RegisterUsers,
'facebook.connect.unregisterUsers' => UnregisterUsers,
'facebook.connect.getUnconnectedFriendsCount' => GetUnconnectedFriendsCount,
'facebook.users.getInfo' => UserInfo,
'facebook.users.getStandardInfo' => UserStandardInfo,
'facebook.users.setStatus' => SetStatus,
'facebook.status.get' => GetStatus,
'facebook.users.getLoggedInUser' => GetLoggedInUser,
'facebook.users.hasAppPermission' => UserHasPermission,
'facebook.users.isAppUser' => IsAppUser,
'facebook.pages.isAdmin' => PagesIsAdmin,
'facebook.pages.getInfo' => PagesGetInfo,
'facebook.pages.isFan' => PagesIsFan,
'facebook.friends.get' => GetFriends,
'facebook.friends.getLists' => FriendListsGet,
'facebook.friends.areFriends' => AreFriends,
'facebook.friends.getAppUsers' => GetAppUsers,
'facebook.feed.publishStoryToUser' => PublishStoryToUser,
'facebook.feed.publishActionOfUser' => PublishActionOfUser,
'facebook.feed.publishTemplatizedAction' => PublishTemplatizedAction,
'facebook.feed.registerTemplateBundle' => RegisterTemplateBundle,
'facebook.feed.deactivateTemplateBundleByID' => DeactivateTemplateBundleByID,
'facebook.feed.getRegisteredTemplateBundles' => GetRegisteredTemplateBundles,
'facebook.feed.publishUserAction' => PublishUserAction,
'facebook.message.getThreadsInFolder' => MessageGetThreadsInFolder,
'facebook.notifications.get' => NotificationsGet,
'facebook.notifications.send' => NotificationsSend,
'facebook.notifications.sendRequest' => SendRequest,
'facebook.profile.getFBML' => ProfileFBML,
'facebook.profile.setFBML' => ProfileFBMLSet,
'facebook.profile.getInfo' => ProfileInfo,
'facebook.profile.setInfo' => ProfileInfoSet,
'facebook.fbml.setRefHandle' => SetRefHandle,
'facebook.fbml.refreshRefUrl' => RefreshRefURL,
'facebook.fbml.refreshImgSrc' => RefreshImgSrc,
'facebook.data.setCookie' => SetCookie,
'facebook.data.getCookies' => GetCookies,
'facebook.admin.setAppProperties' => SetAppProperties,
'facebook.admin.getAppProperties' => GetAppProperties,
'facebook.admin.setRestrictionInfo' => SetRestrictionInfo,
'facebook.admin.getRestrictionInfo' => GetRestrictionInfo,
'facebook.admin.getAllocation' => GetAllocation,
'facebook.application.getPublicInfo' => GetPublicInfo,
'facebook.batch.run' => BatchRun,
'facebook.fql.query' => FqlQuery,
'facebook.fql.multiquery' => FqlMultiquery,
'facebook.photos.get' => GetPhotos,
'facebook.photos.getAlbums' => GetAlbums,
'facebook.photos.createAlbum' => CreateAlbum,
'facebook.photos.getTags' => GetTags,
'facebook.photos.addTag' => AddTags,
'facebook.photos.upload' => UploadPhoto,
'facebook.stream.get' => GetStream,
'facebook.stream.publish' => StreamPublish,
'facebook.stream.addComment' => StreamAddComment,
'facebook.stream.addLike' => StreamAddLike,
'facebook.stream.removeLike' => StreamRemoveLike,
'facebook.events.create' => EventsCreate,
'facebook.events.cancel' => EventsCancel,
'facebook.events.get' => EventsGet,
'facebook.events.edit' => EventsEdit,
'facebook.events.rsvp' => EventsRsvp,
'facebook.groups.get' => GroupsGet,
'facebook.events.getMembers' => EventMembersGet,
'facebook.groups.getMembers' => GroupGetMembers,
'facebook.notifications.sendEmail' => NotificationsSendEmail,
'facebook.data.getUserPreference' => GetPreference,
'facebook.data.setUserPreference' => SetPreference,
'facebook.video.upload' => UploadVideo,
'facebook.sms.send' => SmsSend,
'facebook.sms.canSend' => SmsCanSend,
'facebook.comments.add' => CommentsAdd,
'facebook.comments.remove' => CommentsRemove,
'facebook.comments.get' => CommentsGet,
'facebook.dashboard.setCount' => DashboardSetCount,
'facebook.dashboard.getCount' => DashboardGetCount,
'facebook.dashboard.incrementCount' => DashboardIncrementCount,
'facebook.dashboard.decrementCount' => DashboardDecrementCount,
'facebook.dashboard.multiGetCount' => DashboardMultiGetCount,
'facebook.dashboard.multiSetCount' => DashboardMultiSetCount,
'facebook.dashboard.multiIncrementCount' => DashboardMultiIncrementCount,
'facebook.dashboard.multiDecrementCount' => DashboardMultiDecrementCount,
'facebook.dashboard.addGlobalNews' => DashboardAddGlobalNews,
'facebook.dashboard.getGlobalNews' => DashboardGetGlobalNews,
'facebook.dashboard.clearGlobalNews' => DashboardClearGlobalNews,
'facebook.dashboard.addNews' => DashboardAddNews,
'facebook.dashboard.getNews' => DashboardGetNews,
'facebook.dashboard.clearNews' => DashboardClearNews,
'facebook.dashboard.multiAddNews' => DashboardMultiAddNews,
'facebook.dashboard.multiGetNews' => DashboardMultiGetNews,
'facebook.dashboard.multiClearNews' => DashboardMultiClearNews,
'facebook.dashboard.publishActivity' => DashboardPublishActivity,
'facebook.dashboard.removeActivity' => DashboardRemoveActivity,
'facebook.dashboard.getActivity' => DashboardGetActivity,
'facebook.intl.uploadNativeStrings' => UploadNativeStrings
}
end
end