fb_graph2 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/fb_graph2/app_link_host.rb +1 -1
  4. data/lib/fb_graph2/attribute_assigner.rb +6 -6
  5. data/lib/fb_graph2/collection.rb +29 -4
  6. data/lib/fb_graph2/edge.rb +20 -0
  7. data/lib/fb_graph2/edge/accounts.rb +1 -1
  8. data/lib/fb_graph2/edge/achievements.rb +1 -1
  9. data/lib/fb_graph2/edge/activities.rb +1 -1
  10. data/lib/fb_graph2/edge/admins.rb +1 -1
  11. data/lib/fb_graph2/edge/albums.rb +1 -1
  12. data/lib/fb_graph2/edge/app_event_types.rb +1 -1
  13. data/lib/fb_graph2/edge/app_link_hosts.rb +1 -1
  14. data/lib/fb_graph2/edge/app_requests.rb +1 -1
  15. data/lib/fb_graph2/edge/applications.rb +1 -1
  16. data/lib/fb_graph2/edge/attending.rb +1 -1
  17. data/lib/fb_graph2/edge/banned.rb +1 -1
  18. data/lib/fb_graph2/edge/blocked.rb +1 -1
  19. data/lib/fb_graph2/edge/books.rb +1 -1
  20. data/lib/fb_graph2/edge/comments.rb +1 -1
  21. data/lib/fb_graph2/edge/declined.rb +1 -1
  22. data/lib/fb_graph2/edge/docs.rb +1 -1
  23. data/lib/fb_graph2/edge/events.rb +1 -1
  24. data/lib/fb_graph2/edge/family.rb +1 -1
  25. data/lib/fb_graph2/edge/feed.rb +1 -1
  26. data/lib/fb_graph2/edge/files.rb +1 -1
  27. data/lib/fb_graph2/edge/friend_lists.rb +1 -1
  28. data/lib/fb_graph2/edge/friends.rb +6 -1
  29. data/lib/fb_graph2/edge/games.rb +1 -1
  30. data/lib/fb_graph2/edge/global_brand_children.rb +1 -1
  31. data/lib/fb_graph2/edge/groups.rb +1 -1
  32. data/lib/fb_graph2/edge/home.rb +1 -1
  33. data/lib/fb_graph2/edge/inbox.rb +1 -1
  34. data/lib/fb_graph2/edge/interests.rb +1 -1
  35. data/lib/fb_graph2/edge/invitable_friends.rb +1 -1
  36. data/lib/fb_graph2/edge/invited.rb +1 -1
  37. data/lib/fb_graph2/edge/likes.rb +2 -2
  38. data/lib/fb_graph2/edge/links.rb +1 -1
  39. data/lib/fb_graph2/edge/locations.rb +1 -1
  40. data/lib/fb_graph2/edge/maybe.rb +1 -1
  41. data/lib/fb_graph2/edge/members.rb +1 -1
  42. data/lib/fb_graph2/edge/milestones.rb +1 -1
  43. data/lib/fb_graph2/edge/movies.rb +1 -1
  44. data/lib/fb_graph2/edge/music.rb +1 -1
  45. data/lib/fb_graph2/edge/noreply.rb +1 -1
  46. data/lib/fb_graph2/edge/notifications.rb +1 -1
  47. data/lib/fb_graph2/edge/offers.rb +1 -1
  48. data/lib/fb_graph2/edge/outbox.rb +1 -1
  49. data/lib/fb_graph2/edge/payment_transactions.rb +1 -1
  50. data/lib/fb_graph2/edge/permissions.rb +1 -1
  51. data/lib/fb_graph2/edge/photos.rb +1 -1
  52. data/lib/fb_graph2/edge/pokes.rb +1 -1
  53. data/lib/fb_graph2/edge/posts.rb +1 -1
  54. data/lib/fb_graph2/edge/promotable_posts.rb +1 -1
  55. data/lib/fb_graph2/edge/roles.rb +1 -1
  56. data/lib/fb_graph2/edge/scores.rb +1 -1
  57. data/lib/fb_graph2/edge/shared_posts.rb +1 -1
  58. data/lib/fb_graph2/edge/static_resources.rb +1 -1
  59. data/lib/fb_graph2/edge/statuses.rb +1 -1
  60. data/lib/fb_graph2/edge/subscriptions.rb +1 -1
  61. data/lib/fb_graph2/edge/taggable_friends.rb +1 -1
  62. data/lib/fb_graph2/edge/tagged.rb +1 -1
  63. data/lib/fb_graph2/edge/tagged_places.rb +1 -1
  64. data/lib/fb_graph2/edge/tags.rb +1 -1
  65. data/lib/fb_graph2/edge/television.rb +1 -1
  66. data/lib/fb_graph2/edge/test_users.rb +1 -1
  67. data/lib/fb_graph2/edge/translations.rb +1 -1
  68. data/lib/fb_graph2/edge/videos.rb +1 -1
  69. data/lib/fb_graph2/struct/app_event_type.rb +1 -1
  70. data/spec/fb_graph2/edge/accounts_spec.rb +1 -0
  71. data/spec/fb_graph2/edge/achievements_spec.rb +1 -0
  72. data/spec/fb_graph2/edge/activities_spec.rb +1 -0
  73. data/spec/fb_graph2/edge/admins_spec.rb +1 -0
  74. data/spec/fb_graph2/edge/albums_spec.rb +1 -0
  75. data/spec/fb_graph2/edge/blocked_spec.rb +1 -0
  76. data/spec/fb_graph2/edge/books_spec.rb +1 -0
  77. data/spec/fb_graph2/edge/comments_spec.rb +1 -0
  78. data/spec/fb_graph2/edge/events_spec.rb +1 -0
  79. data/spec/fb_graph2/edge/feed_spec.rb +1 -0
  80. data/spec/fb_graph2/edge/friend_lists_spec.rb +1 -0
  81. data/spec/fb_graph2/edge/friends_spec.rb +21 -1
  82. data/spec/fb_graph2/edge/groups_spec.rb +1 -0
  83. data/spec/fb_graph2/edge/home_spec.rb +1 -0
  84. data/spec/fb_graph2/edge/interests_spec.rb +1 -0
  85. data/spec/fb_graph2/edge/invitable_friends_spec.rb +1 -0
  86. data/spec/fb_graph2/edge/likes_spec.rb +3 -1
  87. data/spec/fb_graph2/edge/links_spec.rb +1 -0
  88. data/spec/fb_graph2/edge/milestones_spec.rb +1 -0
  89. data/spec/fb_graph2/edge/movies_spec.rb +1 -0
  90. data/spec/fb_graph2/edge/music_spec.rb +1 -0
  91. data/spec/fb_graph2/edge/notifications_spec.rb +1 -0
  92. data/spec/fb_graph2/edge/permissions_spec.rb +1 -0
  93. data/spec/fb_graph2/edge/photos_spec.rb +1 -0
  94. data/spec/fb_graph2/edge/pokes_spec.rb +1 -0
  95. data/spec/fb_graph2/edge/posts_spec.rb +1 -0
  96. data/spec/fb_graph2/edge/promotable_posts_spec.rb +1 -0
  97. data/spec/fb_graph2/edge/scores_spec.rb +1 -0
  98. data/spec/fb_graph2/edge/shared_posts_spec.rb +1 -0
  99. data/spec/fb_graph2/edge/statuses_spec.rb +1 -0
  100. data/spec/fb_graph2/edge/subscriptions_spec.rb +1 -0
  101. data/spec/fb_graph2/edge/taggable_friends_spec.rb +1 -0
  102. data/spec/fb_graph2/edge/television_spec.rb +1 -0
  103. data/spec/fb_graph2/edge/test_users_spec.rb +1 -0
  104. data/spec/fb_graph2/edge/videos_spec.rb +1 -0
  105. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc5d3c2c9db1f215157ae1db4631bc68713a8acd
4
- data.tar.gz: 4bdda11d0b45da1de00c6d047c0aaa18d0bcebcf
3
+ metadata.gz: b5101130cc02d8296b40d43431d7ee92fa1376a5
4
+ data.tar.gz: 68d6ec8b8aa8d4902f51d22d4a4ba516c673c54d
5
5
  SHA512:
6
- metadata.gz: 1da28587bf9edf922972307a8d163f42e8e3df5d27a468104c6080d293f81c2371ab945d14b805aa9df7936366ec4f0182e028785d83538d1e3f4da57de0dd17
7
- data.tar.gz: a5618e8d32e7f9d6a51c7a9f56e6c14054c9db4ceb2e105c5ea8607731673f50453cc972296b72f48568263d27bed64b7b13249db5055ad0a9974a18d62fe62b
6
+ metadata.gz: 707151ca14d7eb56451c033971e29bf7cd626558da847902dca2db66861a0e7e0b3e84da75ae2572573bcb5329871f24a58c75aea0f698af3cd80a55e7131081
7
+ data.tar.gz: ca94244c9da577f2a5b7a806c3cf32c7bec77cc7a80b8992b816a0da8db1510f34426d83e5a501d359ff5933bde611156ac2c72e2e09ad932e2020d1d7ec5a3d
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -17,7 +17,7 @@ module FbGraph2
17
17
  private
18
18
 
19
19
  def collect_links(attributes, link_attr)
20
- Collection.new(attributes[link_attr]).collect do |link|
20
+ Collection.new(attributes[link_attr]).collect! do |link|
21
21
  klass = case link_attr
22
22
  when :ios, :iphone, :ipad
23
23
  Struct::AppLink::Native::IOS
@@ -33,7 +33,7 @@ module FbGraph2
33
33
  when :timestamp
34
34
  Time.at raw
35
35
  when :actions
36
- Collection.new(raw).collect do |_raw_|
36
+ Collection.new(raw).collect! do |_raw_|
37
37
  Struct::Action.new _raw_
38
38
  end
39
39
  when :album
@@ -45,17 +45,17 @@ module FbGraph2
45
45
  when :group
46
46
  Group.new raw[:id], raw
47
47
  when :image_sources
48
- Collection.new(raw).collect do |_raw_|
48
+ Collection.new(raw).collect! do |_raw_|
49
49
  Struct::ImageSource.new _raw_
50
50
  end
51
51
  when :messages
52
- Collection.new(raw).collect do |_raw_|
52
+ Collection.new(raw).collect! do |_raw_|
53
53
  Message.new _raw_[:id], _raw_
54
54
  end
55
55
  when :page
56
56
  Page.new raw[:id], raw
57
57
  when :pages
58
- Collection.new(raw).collect do |_raw_|
58
+ Collection.new(raw).collect! do |_raw_|
59
59
  Page.new _raw_[:id], _raw_
60
60
  end
61
61
  when :photo
@@ -65,13 +65,13 @@ module FbGraph2
65
65
  when :profile
66
66
  as_profile raw
67
67
  when :profiles
68
- Collection.new(raw).collect do |_raw_|
68
+ Collection.new(raw).collect! do |_raw_|
69
69
  as_profile _raw_
70
70
  end
71
71
  when :user
72
72
  User.new raw[:id], raw
73
73
  when :users
74
- Collection.new(raw).collect do |_raw_|
74
+ Collection.new(raw).collect! do |_raw_|
75
75
  User.new _raw_[:id], _raw_
76
76
  end
77
77
  else
@@ -1,9 +1,17 @@
1
1
  module FbGraph2
2
2
  class Collection < Array
3
- attr_reader :previous, :next, :total_count, :unread_count, :updated_time, :cursors
3
+ attr_accessor :before, :after, :next, :previous
4
4
 
5
- def initialize(collection)
6
- collection = case collection
5
+ def initialize(collection = [])
6
+ collection = normalize collection
7
+ setup_pagination collection[:paging]
8
+ replace Array(collection[:data])
9
+ end
10
+
11
+ private
12
+
13
+ def normalize(collection)
14
+ case collection
7
15
  when Hash
8
16
  collection
9
17
  when Array
@@ -14,7 +22,24 @@ module FbGraph2
14
22
  else
15
23
  raise ArgumentError.new("Invalid collection")
16
24
  end
17
- replace Array(collection[:data])
25
+ end
26
+
27
+ def setup_pagination(paging)
28
+ cursors = paging.try(:[], :cursors)
29
+ self.before = cursors.try(:[], :before)
30
+ self.after = cursors.try(:[], :after)
31
+ self.next = params_in paging.try(:[], :next)
32
+ self.previous = params_in paging.try(:[], :previous)
33
+ end
34
+
35
+ def params_in(url)
36
+ if url
37
+ Rack::Utils.parse_nested_query(
38
+ URI.parse(url).query
39
+ ).inject({}) do |params, (key, value)|
40
+ params.merge! key => value
41
+ end.with_indifferent_access
42
+ end
18
43
  end
19
44
  end
20
45
  end
@@ -10,6 +10,26 @@ module FbGraph2
10
10
  self.collection = options.delete(:collection) || Collection.new
11
11
  replace collection
12
12
  end
13
+
14
+ def next(_options_ = {})
15
+ if collection.next.present?
16
+ owner.send edge, options.merge(collection.next).merge(_options_)
17
+ elsif collection.after.present?
18
+ owner.send edge, options.merge(after: collection.after).merge(_options_)
19
+ else
20
+ self.class.new owner, edge
21
+ end
22
+ end
23
+
24
+ def previous(_options_ = {})
25
+ if self.collection.previous.present?
26
+ owner.send edge, options.merge(collection.previous).merge(_options_)
27
+ elsif collection.before.present?
28
+ owner.send edge, options.merge(before: collection.before).merge(_options_)
29
+ else
30
+ self.class.new owner, edge
31
+ end
32
+ end
13
33
  end
14
34
  end
15
35
 
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Accounts
4
4
  def accounts(params = {})
5
5
  pages = self.edge :accounts, params
6
- pages.collect do |page|
6
+ pages.collect! do |page|
7
7
  Page.new(page[:id], page).authenticate page[:access_token]
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Achievements
4
4
  def achievements(params = {})
5
5
  achievements = self.edge :achievements, params
6
- achievements.collect do |achievement|
6
+ achievements.collect! do |achievement|
7
7
  Achievement.new(achievement[:id], achievement).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Activities
4
4
  def activities(params = {})
5
5
  pages = self.edge :activities, params
6
- pages.collect do |page|
6
+ pages.collect! do |page|
7
7
  Page.new(page[:id], page).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Admins
4
4
  def admins(params = {})
5
5
  users = self.edge :admins, params
6
- users.collect do |user|
6
+ users.collect! do |user|
7
7
  User.new(user[:id], user).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Albums
4
4
  def albums(params = {})
5
5
  albums = self.edge :albums, params
6
- albums.collect do |album|
6
+ albums.collect! do |album|
7
7
  Album.new(album[:id], album).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module AppEventTypes
4
4
  def app_event_types(params = {})
5
5
  types = self.edge :app_event_types, params
6
- types.collect do |type|
6
+ types.collect! do |type|
7
7
  Struct::AppEventType.new type
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module AppLinkHosts
4
4
  def app_link_hosts(params = {})
5
5
  hosts = self.edge :app_link_hosts, params
6
- hosts.collect do |host|
6
+ hosts.collect! do |host|
7
7
  AppLinkHost.new(hosts[:id], hosts).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module AppRequests
4
4
  def app_requests(params = {})
5
5
  requests = self.edge :apprequests, params
6
- requests.collect do |request|
6
+ requests.collect! do |request|
7
7
  Request.new(request[:id], request).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Applications
4
4
  def applications(params = {})
5
5
  apps = self.edge :applications, params, edge_scope: :developer
6
- apps.collect do |app|
6
+ apps.collect! do |app|
7
7
  App.new(app[:id], app).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Attending
4
4
  def attending(params = {})
5
5
  users = self.edge :attending, params
6
- users.collect do |user|
6
+ users.collect! do |user|
7
7
  User.new(user[:id], user).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Banned
4
4
  def banned(params = {})
5
5
  users = self.edge :banned, params
6
- users.collect do |user|
6
+ users.collect! do |user|
7
7
  User.new(user[:id], user).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Blocked
4
4
  def blocked(params = {})
5
5
  users = self.edge :blocked, params
6
- users.collect do |user|
6
+ users.collect! do |user|
7
7
  User.new(user[:id], user).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Books
4
4
  def books(params = {})
5
5
  pages = self.edge :books, params
6
- pages.collect do |page|
6
+ pages.collect! do |page|
7
7
  Page.new(page[:id], page).authenticate self.access_token
8
8
  end
9
9
  end
@@ -14,7 +14,7 @@ module FbGraph2
14
14
  else
15
15
  self.edge :comments, params
16
16
  end
17
- comments.collect do |comment|
17
+ comments.collect! do |comment|
18
18
  Comment.new(comment[:id], comment).authenticate self.access_token
19
19
  end
20
20
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Declined
4
4
  def declined(params = {})
5
5
  users = self.edge :declined, params
6
- users.collect do |user|
6
+ users.collect! do |user|
7
7
  User.new(user[:id], user).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Docs
4
4
  def docs(params = {})
5
5
  docs = self.edge :docs, params
6
- docs.collect do |doc|
6
+ docs.collect! do |doc|
7
7
  GroupDoc.new(doc[:id], doc).authenticate self.access_token
8
8
  end
9
9
  end
@@ -4,7 +4,7 @@ module FbGraph2
4
4
  def events(*args)
5
5
  params = args.extract_options!
6
6
  events = self.edge :events, params, edge_scope: args.first
7
- events.collect do |event|
7
+ events.collect! do |event|
8
8
  Event.new(event[:id], event).authenticate self.access_token
9
9
  end
10
10
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Family
4
4
  def family(params = {})
5
5
  users = self.edge :family, params
6
- users.collect do |user|
6
+ users.collect! do |user|
7
7
  User.new(user[:id], user).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Feed
4
4
  def feed(params = {})
5
5
  posts = self.edge :feed, params
6
- posts.collect do |post|
6
+ posts.collect! do |post|
7
7
  Post.new(post[:id], post).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Files
4
4
  def files(params = {})
5
5
  files = self.edge :files, params
6
- files.collect do |file|
6
+ files.collect! do |file|
7
7
  Struct::GroupFile.new file
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module FriendLists
4
4
  def friend_lists(params = {})
5
5
  friend_lists = self.edge :friendlists, params
6
- friend_lists.collect do |friend_list|
6
+ friend_lists.collect! do |friend_list|
7
7
  FriendList.new(friend_list[:id], friend_list).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,10 +3,15 @@ module FbGraph2
3
3
  module Friends
4
4
  def friends(params = {})
5
5
  users = self.edge :friends, params
6
- users.collect do |user|
6
+ users.collect! do |user|
7
7
  User.new(user[:id], user).authenticate self.access_token
8
8
  end
9
9
  end
10
+
11
+ def friend?(user, params = {})
12
+ users = self.edge :friends, params, edge_scope: user
13
+ users.present?
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Games
4
4
  def games(params = {})
5
5
  pages = self.edge :games, params
6
- pages.collect do |page|
6
+ pages.collect! do |page|
7
7
  Page.new(page[:id], page).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module GlobalBrandChildren
4
4
  def global_brand_children(params = {})
5
5
  pages = self.edge :global_brand_children, params
6
- pages.collect do |page|
6
+ pages.collect! do |page|
7
7
  Page.new(page[:id], page).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Groups
4
4
  def groups(params = {})
5
5
  groups = self.edge :groups, params
6
- groups.collect do |group|
6
+ groups.collect! do |group|
7
7
  Group.new(group[:id], group).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Home
4
4
  def home(params = {})
5
5
  posts = self.edge :home, params
6
- posts.collect do |post|
6
+ posts.collect! do |post|
7
7
  Post.new(post[:id], post).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Inbox
4
4
  def inbox(params = {})
5
5
  threads = self.edge :inbox, params
6
- threads.collect do |thread|
6
+ threads.collect! do |thread|
7
7
  Thread.new(thread[:id], thread).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Interests
4
4
  def interests(params = {})
5
5
  pages = self.edge :interests, params
6
- pages.collect do |page|
6
+ pages.collect! do |page|
7
7
  Page.new(page[:id], page).authenticate self.access_token
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module InvitableFriends
4
4
  def invitable_friends(params = {})
5
5
  invitable_friends = self.edge :invitable_friends, params
6
- invitable_friends.collect do |friend|
6
+ invitable_friends.collect! do |friend|
7
7
  Struct::Friend.new friend
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@ module FbGraph2
3
3
  module Invited
4
4
  def invited(params = {})
5
5
  users = self.edge :invited, params
6
- users.collect do |user|
6
+ users.collect! do |user|
7
7
  User.new(user[:id], user).authenticate self.access_token
8
8
  end
9
9
  end