fb_graph2 0.1.1 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5101130cc02d8296b40d43431d7ee92fa1376a5
4
- data.tar.gz: 68d6ec8b8aa8d4902f51d22d4a4ba516c673c54d
3
+ metadata.gz: 1d528a57c6a1d1e118bbe59cf75db11d833aeecb
4
+ data.tar.gz: 228de293b5fd4060274d3bcdf1571befd5b14b80
5
5
  SHA512:
6
- metadata.gz: 707151ca14d7eb56451c033971e29bf7cd626558da847902dca2db66861a0e7e0b3e84da75ae2572573bcb5329871f24a58c75aea0f698af3cd80a55e7131081
7
- data.tar.gz: ca94244c9da577f2a5b7a806c3cf32c7bec77cc7a80b8992b816a0da8db1510f34426d83e5a501d359ff5933bde611156ac2c72e2e09ad932e2020d1d7ec5a3d
6
+ metadata.gz: be86b435cffbc372cc7bef1dc88ca93c8e453d04056cce7ee04511cddad54b307e52fbd05b043e6733baa747e02aa70d742f0a37a3671a4e3aadd340ecfd03b9
7
+ data.tar.gz: 90e6bbfa860cc9ce11f0c1cf04926e01733553ecff8cb23009d6b541ab4115290df89568de57526da8326a59e634d5bcc1d8fad11954fdbea3a876a00ae68927
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1,10 +1,11 @@
1
1
  module FbGraph2
2
2
  class Collection < Array
3
- attr_accessor :before, :after, :next, :previous
3
+ attr_accessor :before, :after, :next, :previous, :order, :total_count
4
4
 
5
5
  def initialize(collection = [])
6
6
  collection = normalize collection
7
- setup_pagination collection[:paging]
7
+ paginate collection[:paging]
8
+ summarize collection[:summary]
8
9
  replace Array(collection[:data])
9
10
  end
10
11
 
@@ -24,7 +25,7 @@ module FbGraph2
24
25
  end
25
26
  end
26
27
 
27
- def setup_pagination(paging)
28
+ def paginate(paging)
28
29
  cursors = paging.try(:[], :cursors)
29
30
  self.before = cursors.try(:[], :before)
30
31
  self.after = cursors.try(:[], :after)
@@ -32,6 +33,13 @@ module FbGraph2
32
33
  self.previous = params_in paging.try(:[], :previous)
33
34
  end
34
35
 
36
+ def summarize(summary)
37
+ # NOTE: notifications edge returns "summary" as a blank Array.
38
+ summary = Hash(summary)
39
+ self.order = summary.try(:[], :order)
40
+ self.total_count = summary.try(:[], :total_count)
41
+ end
42
+
35
43
  def params_in(url)
36
44
  if url
37
45
  Rack::Utils.parse_nested_query(
@@ -1,6 +1,7 @@
1
1
  module FbGraph2
2
2
  class Edge < Collection
3
3
  attr_accessor :owner, :edge, :params, :options, :collection
4
+ delegate :order, :total_count, to: :collection
4
5
 
5
6
  def initialize(owner, edge, params = {}, options = {})
6
7
  self.owner = owner
@@ -41,7 +41,7 @@ module FbGraph2
41
41
  def edges
42
42
  @edges ||= self.class.included_modules.select do |_module_|
43
43
  _module_.name =~ /FbGraph2::Edge/
44
- end.collect(&:instance_methods).sort
44
+ end.collect(&:instance_methods).flatten.sort
45
45
  end
46
46
 
47
47
  def update(params = {}, options = {})
@@ -41,6 +41,18 @@ describe FbGraph2::Edge::Comments do
41
41
  end
42
42
  end
43
43
  end
44
+
45
+ context 'when summary requested' do
46
+ it 'should be summarized' do
47
+ comments = mock_graph :get, 'post_id/comments', 'post/comments_with_summary', access_token: 'token', params: {
48
+ summary: true
49
+ } do
50
+ post.comments(summary: true)
51
+ end
52
+ comments.order.should == 'chronological'
53
+ comments.total_count.should == 4
54
+ end
55
+ end
44
56
  end
45
57
 
46
58
  describe '#comment!' do
@@ -0,0 +1,148 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph2::Edge do
4
+ let(:me) { FbGraph2::User.me 'access_token' }
5
+ let(:post) { FbGraph2::Post.new 'post_id', access_token: 'access_token' }
6
+ let(:feed) do
7
+ mock_graph :get, 'me/feed', 'user/feed', access_token: 'access_token' do
8
+ me.feed
9
+ end
10
+ end
11
+ let(:comments) do
12
+ mock_graph :get, 'post_id/comments', 'post/comments_with_summary', access_token: 'access_token' do
13
+ post.comments
14
+ end
15
+ end
16
+
17
+ describe 'summary' do
18
+ subject { comments }
19
+ its(:order) { should == 'chronological' }
20
+ its(:total_count) { should == 4 }
21
+ end
22
+
23
+ describe 'pagination' do
24
+ context 'when next/previous-url-based' do
25
+ describe 'next' do
26
+ context 'when next page exists' do
27
+ it 'should fetch next page' do
28
+ feed.collection.next.should match(limit: '25', until: '1400651347')
29
+ _next_ = mock_graph :get, 'me/feed', 'blank_collection', access_token: 'access_token', params: {
30
+ limit: 25,
31
+ until: '1400651347'
32
+ } do
33
+ feed.next
34
+ end
35
+ _next_.should be_instance_of FbGraph2::Edge
36
+ end
37
+ end
38
+
39
+ context 'otherwise' do
40
+ let(:without_next) do
41
+ mock_graph :get, 'me/feed', 'blank_collection', access_token: 'access_token', params: {
42
+ limit: 25,
43
+ until: '1400651347'
44
+ } do
45
+ feed.next
46
+ end
47
+ end
48
+
49
+ it do
50
+ without_next.collection.next.should be_blank
51
+ without_next.next.should be_blank
52
+ end
53
+ end
54
+ end
55
+
56
+ describe 'previous' do
57
+ context 'when previous page exists' do
58
+ it 'should fetch previous page' do
59
+ feed.collection.previous.should match(limit: '25', since: '1401410484')
60
+ previous = mock_graph :get, 'me/feed', 'blank_collection', access_token: 'access_token', params: {
61
+ limit: 25,
62
+ since: '1401410484'
63
+ } do
64
+ feed.previous
65
+ end
66
+ previous.should be_instance_of FbGraph2::Edge
67
+ end
68
+ end
69
+
70
+ context 'otherwise' do
71
+ let(:without_previous) do
72
+ mock_graph :get, 'me/feed', 'blank_collection', access_token: 'access_token', params: {
73
+ limit: 25,
74
+ since: '1401410484'
75
+ } do
76
+ feed.previous
77
+ end
78
+ end
79
+
80
+ it do
81
+ without_previous.collection.previous.should be_blank
82
+ without_previous.previous.should be_blank
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ context 'when cursors-based' do
89
+ describe 'next' do
90
+ context 'when after cursor exists' do
91
+ it 'should fetch next page' do
92
+ comments.collection.after.should == 'NA=='
93
+ _next_ = mock_graph :get, 'post_id/comments', 'blank_collection', access_token: 'access_token', params: {
94
+ after: 'NA=='
95
+ } do
96
+ comments.next
97
+ end
98
+ _next_.should be_instance_of FbGraph2::Edge
99
+ end
100
+ end
101
+
102
+ context 'otherwise' do
103
+ let(:without_next) do
104
+ mock_graph :get, 'post_id/comments', 'blank_collection', access_token: 'access_token', params: {
105
+ after: 'NA=='
106
+ } do
107
+ comments.next
108
+ end
109
+ end
110
+
111
+ it do
112
+ without_next.collection.after.should be_blank
113
+ without_next.next.should be_blank
114
+ end
115
+ end
116
+ end
117
+
118
+ describe 'previous' do
119
+ context 'when before cursor exists' do
120
+ it 'should fetch previous page' do
121
+ comments.collection.before.should == 'MQ=='
122
+ previous = mock_graph :get, 'post_id/comments', 'blank_collection', access_token: 'access_token', params: {
123
+ before: 'MQ=='
124
+ } do
125
+ comments.previous
126
+ end
127
+ previous.should be_instance_of FbGraph2::Edge
128
+ end
129
+ end
130
+
131
+ context 'otherwise' do
132
+ let(:without_previous) do
133
+ mock_graph :get, 'post_id/comments', 'blank_collection', access_token: 'access_token', params: {
134
+ before: 'MQ=='
135
+ } do
136
+ comments.previous
137
+ end
138
+ end
139
+
140
+ it do
141
+ without_previous.collection.before.should be_blank
142
+ without_previous.previous.should be_blank
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -86,6 +86,26 @@ describe FbGraph2::Node do
86
86
  its(:access_token) { should == 'access_token' }
87
87
  end
88
88
 
89
+ describe '#edges' do
90
+ it do
91
+ instance.edges.should be_blank
92
+ end
93
+
94
+ context 'for FbGraph2::User' do
95
+ it do
96
+ FbGraph2::User.me('token').edges.should include :accounts, :feed, :feed!
97
+ end
98
+ end
99
+ end
100
+
101
+ describe '#update' do
102
+ it 'should call API with POST method' do
103
+ expect do
104
+ instance.update
105
+ end.to request_to 'identifier', :post
106
+ end
107
+ end
108
+
89
109
  describe '#destroy' do
90
110
  it 'should call API with DELETE method' do
91
111
  expect do
@@ -94,6 +114,38 @@ describe FbGraph2::Node do
94
114
  end
95
115
  end
96
116
 
117
+ describe '#build_params' do
118
+ context 'when an array of strings given' do
119
+ it 'should join fields option' do
120
+ mock_graph :get, 'identifier', 'user/me', params: {
121
+ fields: 'f1,f2,f3'
122
+ } do
123
+ instance.fetch(fields: ['f1', 'f2', 'f3'])
124
+ end
125
+ end
126
+ end
127
+
128
+ context 'when an array of symbols given' do
129
+ it 'should join fields option' do
130
+ mock_graph :get, 'identifier', 'user/me', params: {
131
+ fields: 'f1,f2,f3'
132
+ } do
133
+ instance.fetch(fields: [:f1, :f2, :f3])
134
+ end
135
+ end
136
+ end
137
+
138
+ context 'when a string given' do
139
+ it 'should join fields option' do
140
+ mock_graph :get, 'identifier', 'user/me', params: {
141
+ fields: 'f1,f2,f3'
142
+ } do
143
+ instance.fetch(fields: 'f1,f2,f3')
144
+ end
145
+ end
146
+ end
147
+ end
148
+
97
149
  describe '#handle_response' do
98
150
  context 'when error' do
99
151
  context 'when valid json' do
@@ -0,0 +1,57 @@
1
+ {
2
+ "data": [{
3
+ "id": "10152662663892277_10152662666892277",
4
+ "from": {
5
+ "id": "579612276",
6
+ "name": "Nov Matake"
7
+ },
8
+ "message": "hummm, it's not \"post\"...",
9
+ "can_remove": true,
10
+ "created_time": "2014-08-20T05:34:21+0000",
11
+ "like_count": 0,
12
+ "user_likes": false
13
+ }, {
14
+ "id": "10152662663892277_10152662686952277",
15
+ "from": {
16
+ "id": "579612276",
17
+ "name": "Nov Matake"
18
+ },
19
+ "message": "579612276_10152662663892277 = post\n10152662663892277 = status",
20
+ "can_remove": true,
21
+ "created_time": "2014-08-20T05:57:11+0000",
22
+ "like_count": 0,
23
+ "user_likes": false
24
+ }, {
25
+ "id": "10152662663892277_10152662687272277",
26
+ "from": {
27
+ "id": "579612276",
28
+ "name": "Nov Matake"
29
+ },
30
+ "message": "でも多分v2.1完成してない。 http://stackoverflow.com/questions/25270649/facebook-graph-api-v2-1-all-post-photos",
31
+ "can_remove": true,
32
+ "created_time": "2014-08-20T05:57:31+0000",
33
+ "like_count": 0,
34
+ "user_likes": false
35
+ }, {
36
+ "id": "10152662663892277_10152662687387277",
37
+ "from": {
38
+ "id": "579612276",
39
+ "name": "Nov Matake"
40
+ },
41
+ "message": "完成さしてからだせや!!",
42
+ "can_remove": true,
43
+ "created_time": "2014-08-20T05:57:48+0000",
44
+ "like_count": 0,
45
+ "user_likes": false
46
+ }],
47
+ "paging": {
48
+ "cursors": {
49
+ "after": "NA==",
50
+ "before": "MQ=="
51
+ }
52
+ },
53
+ "summary": {
54
+ "order": "chronological",
55
+ "total_count": 4
56
+ }
57
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb_graph2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-15 00:00:00.000000000 Z
11
+ date: 2014-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -321,6 +321,7 @@ files:
321
321
  - spec/fb_graph2/edge/television_spec.rb
322
322
  - spec/fb_graph2/edge/test_users_spec.rb
323
323
  - spec/fb_graph2/edge/videos_spec.rb
324
+ - spec/fb_graph2/edge_spec.rb
324
325
  - spec/fb_graph2/node_spec.rb
325
326
  - spec/fb_graph2/node_subclass_spec.rb
326
327
  - spec/fb_graph2/request_filter/authenticator_spec.rb
@@ -340,6 +341,7 @@ files:
340
341
  - spec/mock_json/page/milestones.json
341
342
  - spec/mock_json/page/promotable_posts.json
342
343
  - spec/mock_json/post/comments.json
344
+ - spec/mock_json/post/comments_with_summary.json
343
345
  - spec/mock_json/post/liked_and_commented.json
344
346
  - spec/mock_json/post/likes.json
345
347
  - spec/mock_json/post/shared_posts.json