fb_graph 2.1.5 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fb_graph (2.1.4)
4
+ fb_graph (2.1.5)
5
5
  httpclient (>= 2.2.0.2)
6
6
  rack-oauth2 (>= 0.9.4)
7
7
 
@@ -28,8 +28,8 @@ GEM
28
28
  multi_json (~> 1.0)
29
29
  addressable (2.2.6)
30
30
  attr_required (0.0.3)
31
- bcrypt-ruby (3.0.0)
32
- bcrypt-ruby (3.0.0-java)
31
+ bcrypt-ruby (3.0.1)
32
+ bcrypt-ruby (3.0.1-java)
33
33
  bouncy-castle-java (1.5.0146.1)
34
34
  builder (3.0.0)
35
35
  crack (0.1.8)
@@ -40,15 +40,14 @@ GEM
40
40
  i18n (0.6.0)
41
41
  jruby-openssl (0.7.4)
42
42
  bouncy-castle-java
43
- json (1.5.4)
44
- json (1.5.4-java)
43
+ json (1.6.0)
45
44
  multi_json (1.0.3)
46
45
  rack (1.3.2)
47
46
  rack-cache (1.0.3)
48
47
  rack (>= 0.4)
49
48
  rack-mount (0.8.3)
50
49
  rack (>= 1.0.0)
51
- rack-oauth2 (0.9.5)
50
+ rack-oauth2 (0.10.1)
52
51
  activesupport (>= 2.3)
53
52
  attr_required (>= 0.0.3)
54
53
  httpclient (>= 2.2.0.2)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.5
1
+ 2.1.6
@@ -4,12 +4,15 @@ module FbGraph
4
4
  def inbox(options = {})
5
5
  threads = self.connection(:inbox, options)
6
6
  threads.map! do |thread|
7
- # NOTE:
8
- # Inbox API doesn't return thread object until their message platform becomes broadly available.
9
- # Use Post instead of Thread for now.
10
- Post.new(thread[:id], thread.merge(
11
- :access_token => options[:access_token] || self.access_token
12
- ))
7
+ if thread[:message]
8
+ Thread::BeforeTransition.new(thread[:id], thread.merge(
9
+ :access_token => options[:access_token] || self.access_token
10
+ ))
11
+ else
12
+ Thread.new(thread[:id], thread.merge(
13
+ :access_token => options[:access_token] || self.access_token
14
+ ))
15
+ end
13
16
  end
14
17
  end
15
18
  end
@@ -4,12 +4,15 @@ module FbGraph
4
4
  def outbox(options = {})
5
5
  threads = self.connection(:outbox, options)
6
6
  threads.map! do |thread|
7
- # NOTE:
8
- # Inbox API doesn't return thread object until their message platform becomes broadly available.
9
- # Use Post instead of Thread for now.
10
- Post.new(thread[:id], thread.merge(
11
- :access_token => options[:access_token] || self.access_token
12
- ))
7
+ if thread[:message]
8
+ Thread::BeforeTransition.new(thread[:id], thread.merge(
9
+ :access_token => options[:access_token] || self.access_token
10
+ ))
11
+ else
12
+ Thread.new(thread[:id], thread.merge(
13
+ :access_token => options[:access_token] || self.access_token
14
+ ))
15
+ end
13
16
  end
14
17
  end
15
18
  end
@@ -24,5 +24,54 @@ module FbGraph
24
24
  @_senders_ = Collection.new(attributes[:senders])
25
25
  @_tags_ = Collection.new(attributes[:tags])
26
26
  end
27
+
28
+ # NOTE:
29
+ # Facebook is under transision of their message platform.
30
+ # This is current thread model in Graph API.
31
+ # In near future, this will be replaced with FbGraph::Thread model.
32
+ class BeforeTransition < Node
33
+ attr_accessor :subject, :message, :from, :to, :unread, :unseen, :updated_time
34
+
35
+ def initialize(identifier, attributes = {})
36
+ super
37
+ @subject = attributes[:subject]
38
+ @message = attributes[:message]
39
+ if (from = attributes[:from])
40
+ @from = if from[:start_time]
41
+ Event.new(from[:id], from)
42
+ else
43
+ User.new(from[:id], from)
44
+ end
45
+ end
46
+ @to = []
47
+ Collection.new(attributes[:to]).each do |to|
48
+ @to << User.new(to[:id], to)
49
+ end
50
+ if attributes[:updated_time]
51
+ @created_time = Time.parse(attributes[:updated_time]).utc
52
+ end
53
+ @unread = attributes[:unread] == 1
54
+ @unseen = attributes[:unseen] == 1
55
+ @_messages_ = Collection.new(attributes[:comments])
56
+ end
57
+
58
+ # NOTE:
59
+ # This is a connection named "comments" but returns "messages" and different from normal "comments" connection.
60
+ # Therefore I put this connection here not under FbGraph::Connections.
61
+ def messages(options = {})
62
+ messages = if @_messages_ && options.blank?
63
+ self.connection(:comments, options.merge(:cached_collection => @_messages_))
64
+ else
65
+ self.connection(:comments, options)
66
+ end
67
+ messages.map! do |message|
68
+ Message.new(message[:id], message.merge(
69
+ :access_token => options[:access_token] || self.access_token
70
+ ))
71
+ end
72
+ end
73
+ # for pagination, a method which name is same as the connection name is needed.
74
+ alias_method :comments, :messages
75
+ end
27
76
  end
28
77
  end
@@ -1,15 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FbGraph::Connections::Inbox, '#inbox' do
4
- # NOTE:
5
- # This connection returns Post instead of Thread for now.
6
- # See inbox.rb for more details.
7
- it 'should return threads as FbGraph::Post' do
8
- mock_graph :get, 'me/inbox', 'users/inbox/me_private', :access_token => 'access_token' do
9
- threads = FbGraph::User.me('access_token').inbox
10
- threads.each do |thread|
11
- thread.should be_instance_of(FbGraph::Post)
4
+ context 'before message platform transition' do
5
+ it 'should return threads as FbGraph::Thread::BeforeTransition' do
6
+ mock_graph :get, 'me/inbox', 'users/inbox/before_transition', :access_token => 'access_token' do
7
+ threads = FbGraph::User.me('access_token').inbox
8
+ threads.each do |thread|
9
+ thread.should be_instance_of(FbGraph::Thread::BeforeTransition)
10
+ end
12
11
  end
13
12
  end
14
13
  end
14
+
15
+ # TODO: after transition, check JSON format and put test here
15
16
  end
@@ -1,15 +1,16 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FbGraph::Connections::Outbox, '#outbox' do
4
- # NOTE:
5
- # This connection returns Post instead of Thread for now.
6
- # See outbox.rb for more details.
7
- it 'should return threads as FbGraph::Post' do
8
- mock_graph :get, 'me/outbox', 'users/outbox/me_private', :access_token => 'access_token' do
9
- threads = FbGraph::User.me('access_token').outbox
10
- threads.each do |thread|
11
- thread.should be_instance_of(FbGraph::Post)
4
+ context 'before message platform transition' do
5
+ it 'should return threads as FbGraph::Thread::BeforeTransition' do
6
+ mock_graph :get, 'me/outbox', 'users/outbox/me_private', :access_token => 'access_token' do
7
+ threads = FbGraph::User.me('access_token').outbox
8
+ threads.each do |thread|
9
+ thread.should be_instance_of(FbGraph::Thread::BeforeTransition)
10
+ end
12
11
  end
13
12
  end
14
13
  end
14
+
15
+ # TODO: after transition, check JSON format and put test here
15
16
  end
@@ -83,4 +83,34 @@ describe FbGraph::Thread, '.new' do
83
83
  FbGraph::User.new('1575327134', :name => 'Nov Matake', :email => 'abc@facebook.com')
84
84
  ]
85
85
  end
86
+
87
+
88
+ describe FbGraph::Thread::BeforeTransition do
89
+ describe '#messages' do
90
+ it 'should use cached contents as default' do
91
+ lambda do
92
+ FbGraph::Thread::BeforeTransition.new(12345, :access_token => 'access_token').messages
93
+ end.should_not request_to '12345/comments?access_token=access_token'
94
+ end
95
+
96
+ it 'should not use cached contents when options are specified' do
97
+ lambda do
98
+ FbGraph::Thread::BeforeTransition.new(12345).messages(:no_cache => true)
99
+ end.should request_to '12345/comments?no_cache=true'
100
+ end
101
+
102
+ it 'should return threads as FbGraph::Message' do
103
+ mock_graph :get, '12345/comments', 'thread/messages/private', :params => {:no_cache => 'true'}, :access_token => 'access_token' do
104
+ messages = FbGraph::Thread::BeforeTransition.new(12345, :access_token => 'access_token').messages(:no_cache => true)
105
+ messages.each do |message|
106
+ message.should be_instance_of(FbGraph::Message)
107
+ end
108
+ lambda do
109
+ messages.next
110
+ end.should request_to '12345/comments'
111
+ end
112
+ end
113
+ end
114
+ end
115
+
86
116
  end
@@ -1,5 +1,26 @@
1
1
  {
2
2
  "data": [
3
+ {
4
+ "id": "1234567890",
5
+ "from": {
6
+ "name": "Some Event",
7
+ "start_time": "2011-08-19T21:00:00",
8
+ "end_time": "2011-08-20T04:00:00",
9
+ "location": "Somewhere",
10
+ "id": "1234567890"
11
+ },
12
+ "to": {
13
+ "data": [{
14
+ "name": "Nov",
15
+ "id": "579612276"
16
+ }]
17
+ },
18
+ "subject": "Subject",
19
+ "message": "Message",
20
+ "updated_time": "2011-08-21T08:24:30+0000",
21
+ "unread": 1,
22
+ "unseen": 0
23
+ },
3
24
  {
4
25
  "id": "1390404535644",
5
26
  "from": {
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: fb_graph
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.1.5
5
+ version: 2.1.6
6
6
  platform: ruby
7
7
  authors:
8
8
  - nov matake
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-09-12 00:00:00 Z
13
+ date: 2011-09-14 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httpclient
@@ -468,7 +468,7 @@ files:
468
468
  - spec/mock_json/users/home/me_private_next.json
469
469
  - spec/mock_json/users/home/me_private_previous.json
470
470
  - spec/mock_json/users/home/me_public.json
471
- - spec/mock_json/users/inbox/me_private.json
471
+ - spec/mock_json/users/inbox/before_transition.json
472
472
  - spec/mock_json/users/interests/matake_private.json
473
473
  - spec/mock_json/users/likes/arjun_private.json
474
474
  - spec/mock_json/users/likes/arjun_public.json
@@ -759,7 +759,7 @@ test_files:
759
759
  - spec/mock_json/users/home/me_private_next.json
760
760
  - spec/mock_json/users/home/me_private_previous.json
761
761
  - spec/mock_json/users/home/me_public.json
762
- - spec/mock_json/users/inbox/me_private.json
762
+ - spec/mock_json/users/inbox/before_transition.json
763
763
  - spec/mock_json/users/interests/matake_private.json
764
764
  - spec/mock_json/users/likes/arjun_private.json
765
765
  - spec/mock_json/users/likes/arjun_public.json