fb_graph 1.3.9 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ module FbGraph
2
+ module Connections
3
+ module FormerParticipants
4
+ def former_participants(options = {})
5
+ users = if @_former_participants_ && options.blank?
6
+ self.connection(:former_participants, options.merge(:cached_collection => @_former_participants_))
7
+ else
8
+ self.connection(:former_participants, options)
9
+ end
10
+ users.map! do |user|
11
+ User.new(user.delete(:id), user.merge(
12
+ :access_token => options[:access_token] || self.access_token
13
+ ))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module FbGraph
2
+ module Connections
3
+ module Messages
4
+ def messages(options = {})
5
+ messages = if @_messages_ && options.blank?
6
+ self.connection(:messages, options.merge(:cached_collection => @_messages_))
7
+ else
8
+ self.connection(:messages, options)
9
+ end
10
+ messages.map! do |message|
11
+ Message.new(message.delete(:id), message.merge(
12
+ :access_token => options[:access_token] || self.access_token
13
+ ))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module FbGraph
2
+ module Connections
3
+ module Participants
4
+ def participants(options = {})
5
+ users = if @_participants_ && options.blank?
6
+ self.connection(:participants, options.merge(:cached_collection => @_participants_))
7
+ else
8
+ self.connection(:participants, options)
9
+ end
10
+ users.map! do |user|
11
+ User.new(user.delete(:id), user.merge(
12
+ :access_token => options[:access_token] || self.access_token
13
+ ))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ module FbGraph
2
+ module Connections
3
+ module Senders
4
+ def senders(options = {})
5
+ users = if @_senders_ && options.blank?
6
+ self.connection(:senders, options.merge(:cached_collection => @_senders_))
7
+ else
8
+ self.connection(:senders, options)
9
+ end
10
+ users.map! do |user|
11
+ User.new(user.delete(:id), user.merge(
12
+ :access_token => options[:access_token] || self.access_token
13
+ ))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module FbGraph
2
+ module Connections
3
+ module Threads
4
+ def threads(options = {})
5
+ threads = self.connection(:threads, options)
6
+ threads.map! do |thread|
7
+ Thread.new(thread.delete(:id), thread.merge(
8
+ :access_token => options[:access_token] || self.access_token
9
+ ))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ module FbGraph
2
+ class Message < Node
3
+ # TODO:
4
+ # include Connections::Attachments
5
+ # include Connections::Shares
6
+
7
+ attr_accessor :subject, :message, :from, :to, :tags, :created_time
8
+
9
+ def initialize(identifier, attributes = {})
10
+ super
11
+ @subject = attributes[:subject]
12
+ @message = attributes[:message]
13
+ if (from = attributes[:from])
14
+ @from = User.new(from.delete(:id), from)
15
+ end
16
+ @to = []
17
+ if attributes[:to]
18
+ Collection.new(attributes[:to]).each do |to|
19
+ @to << User.new(to.delete(:id), to)
20
+ end
21
+ end
22
+ @tags = []
23
+ if attributes[:tags]
24
+ Collection.new(attributes[:tags]).each do |tag|
25
+ @tags << Tag.new(tag)
26
+ end
27
+ end
28
+ if attributes[:created_time]
29
+ @created_time = Time.parse(attributes[:created_time]).utc
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ module FbGraph
2
+ class Thread < Node
3
+ include Connections::Messages
4
+ include Connections::Participants
5
+ include Connections::FormerParticipants
6
+ include Connections::Senders
7
+
8
+ attr_accessor :subject, :snippet, :message_count, :unread_count, :tags, :updated_time
9
+
10
+ def initialize(identifier, attributes = {})
11
+ super
12
+ @subject = attributes[:subject] # NOTE: Probably obsolete
13
+ @snippet = attributes[:snippet]
14
+ @message_count = attributes[:message_count]
15
+ @unread_count = attributes[:unread_count].to_i
16
+ @tags = []
17
+ if attributes[:tags]
18
+ Collection.new(attributes[:tags]).each do |tag|
19
+ @tags << Tag.new(tag)
20
+ end
21
+ end
22
+ if attributes[:updated_time]
23
+ @updated_time = Time.parse(attributes[:updated_time]).utc
24
+ end
25
+
26
+ # cached connection
27
+ @_messages_ = Collection.new(attributes[:messages])
28
+ @_participants_ = Collection.new(attributes[:participants])
29
+ @_former_participants_ = Collection.new(attributes[:former_articipants])
30
+ @_senders_ = Collection.new(attributes[:senders])
31
+ end
32
+ end
33
+ end
data/lib/fb_graph/user.rb CHANGED
@@ -25,6 +25,7 @@ module FbGraph
25
25
  include Connections::Statuses
26
26
  include Connections::Tagged
27
27
  include Connections::Television
28
+ include Connections::Threads
28
29
  include Connections::Videos
29
30
  # --
30
31
  # TODO
data/lib/fb_graph.rb CHANGED
@@ -69,6 +69,7 @@ require 'fb_graph/friend_list'
69
69
  require 'fb_graph/group'
70
70
  require 'fb_graph/insight'
71
71
  require 'fb_graph/link'
72
+ require 'fb_graph/message'
72
73
  require 'fb_graph/note'
73
74
  require 'fb_graph/page'
74
75
  require 'fb_graph/photo'
@@ -78,6 +79,7 @@ require 'fb_graph/project'
78
79
  require 'fb_graph/status'
79
80
  require 'fb_graph/tag'
80
81
  require 'fb_graph/test_user'
82
+ require 'fb_graph/thread'
81
83
  require 'fb_graph/user'
82
84
  require 'fb_graph/video'
83
85
 
@@ -0,0 +1,14 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "name": "Nov Matake",
5
+ "email": "abc\u0040facebook.com",
6
+ "id": "579612276"
7
+ },
8
+ {
9
+ "name": "Nov Matake",
10
+ "email": "xyz\u0040facebook.com",
11
+ "id": "1575327134"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": "m_25aaa73097e54594addb418c7bfbd05c",
5
+ "subject": "test",
6
+ "created_time": "2011-02-04T15:11:05+0000",
7
+ "tags": {
8
+ "data": [
9
+ {
10
+ "name": "inbox"
11
+ },
12
+ {
13
+ "name": "source:web"
14
+ }
15
+ ]
16
+ },
17
+ "from": {
18
+ "name": "Nov Matake",
19
+ "email": "1575327134\u0040facebook.com",
20
+ "id": "1575327134"
21
+ },
22
+ "to": {
23
+ "data": [
24
+ {
25
+ "name": "Nov Matake",
26
+ "email": "579612276\u0040facebook.com",
27
+ "id": "579612276"
28
+ },
29
+ {
30
+ "name": "Nov Matake",
31
+ "email": "1575327134\u0040facebook.com",
32
+ "id": "1575327134"
33
+ }
34
+ ]
35
+ },
36
+ "message": "test"
37
+ }
38
+ ],
39
+ "paging": {
40
+ "previous": "https://graph.facebook.com/t_25aaa73097e54594addb418c7bfbd05c/messages?access_token=134145643294322\u00257C456a137963c052c8427dadae-579612276\u00257CY7w4XI3Ocmcg8z2eFW85PP7c8Q8&limit=25&since=2011-02-04T15\u00253A11\u00253A05\u00252B0000",
41
+ "next": "https://graph.facebook.com/t_25aaa73097e54594addb418c7bfbd05c/messages?access_token=134145643294322\u00257C456a137963c052c8427dadae-579612276\u00257CY7w4XI3Ocmcg8z2eFW85PP7c8Q8&limit=25&until=2011-02-04T15\u00253A11\u00253A04\u00252B0000"
42
+ }
43
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "name": "Nov Matake",
5
+ "email": "abc\u0040facebook.com",
6
+ "id": "579612276"
7
+ },
8
+ {
9
+ "name": "Nov Matake",
10
+ "email": "xyz\u0040facebook.com",
11
+ "id": "1575327134"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "name": "Nov Matake",
5
+ "email": "abc\u0040facebook.com",
6
+ "id": "579612276"
7
+ },
8
+ {
9
+ "name": "Nov Matake",
10
+ "email": "xyz\u0040facebook.com",
11
+ "id": "1575327134"
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,86 @@
1
+ {
2
+ "data": [{
3
+ "id": "t_25aaa73097e54594addb418c7bfbd05c",
4
+ "subject": "test",
5
+ "snippet": "test",
6
+ "updated_time": "2011-02-04T15:11:05+0000",
7
+ "message_count": 1,
8
+ "unread_count": 1,
9
+ "tags": {
10
+ "data": [
11
+ {
12
+ "name": "inbox"
13
+ },
14
+ {
15
+ "name": "source:web"
16
+ }
17
+ ]
18
+ },
19
+ "participants": {
20
+ "data": [
21
+ {
22
+ "name": "Nov Matake",
23
+ "email": "579612276\u0040facebook.com",
24
+ "id": "579612276"
25
+ },
26
+ {
27
+ "name": "Nov Matake",
28
+ "email": "1575327134\u0040facebook.com",
29
+ "id": "1575327134"
30
+ }
31
+ ]
32
+ },
33
+ "senders": {
34
+ "data": [
35
+ {
36
+ "name": "Nov Matake",
37
+ "email": "1575327134\u0040facebook.com",
38
+ "id": "1575327134"
39
+ }
40
+ ]
41
+ },
42
+ "messages": {
43
+ "data": [
44
+ {
45
+ "id": "m_25aaa73097e54594addb418c7bfbd05c",
46
+ "subject": "test",
47
+ "created_time": "2011-02-04T15:11:05+0000",
48
+ "tags": {
49
+ "data": [
50
+ {
51
+ "name": "inbox"
52
+ },
53
+ {
54
+ "name": "source:web"
55
+ }
56
+ ]
57
+ },
58
+ "from": {
59
+ "name": "Nov Matake",
60
+ "email": "1575327134\u0040facebook.com",
61
+ "id": "1575327134"
62
+ },
63
+ "to": {
64
+ "data": [
65
+ {
66
+ "name": "Nov Matake",
67
+ "email": "579612276\u0040facebook.com",
68
+ "id": "579612276"
69
+ },
70
+ {
71
+ "name": "Nov Matake",
72
+ "email": "1575327134\u0040facebook.com",
73
+ "id": "1575327134"
74
+ }
75
+ ]
76
+ },
77
+ "message": "test"
78
+ }
79
+ ],
80
+ "paging": {
81
+ "previous": "https://graph.facebook.com/?access_token=134145643294322\u00257C456a137963c052c8427dadae-579612276\u00257CY7w4XI3Ocmcg8z2eFW85PP7c8Q8&limit=25&since=2011-02-04T15\u00253A11\u00253A05\u00252B0000",
82
+ "next": "https://graph.facebook.com/?access_token=134145643294322\u00257C456a137963c052c8427dadae-579612276\u00257CY7w4XI3Ocmcg8z2eFW85PP7c8Q8&limit=25&until=2011-02-04T15\u00253A11\u00253A04\u00252B0000"
83
+ }
84
+ }
85
+ }]
86
+ }
@@ -5,7 +5,7 @@ describe FbGraph::Connections::AppRequests, '#app_requests' do
5
5
  fake_json(:get, 'me/apprequests?access_token=access_token', 'users/app_requests/me_private')
6
6
  end
7
7
 
8
- it 'should return notes as FbGraph::Note' do
8
+ it 'should return app_requests as FbGraph::AppRequest' do
9
9
  app_requests = FbGraph::User.me('access_token').app_requests
10
10
  app_requests.each do |app_request|
11
11
  app_request.should be_instance_of(FbGraph::AppRequest)
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), '../../spec_helper')
2
+
3
+ describe FbGraph::Connections::FormerParticipants, '#former_participants' do
4
+ before do
5
+ fake_json(:get, '12345/former_participants?access_token=access_token&no_cache=true', 'thread/former_participants/private')
6
+ end
7
+
8
+ it 'should use cached contents as default' do
9
+ lambda do
10
+ FbGraph::Thread.new(12345, :access_token => 'access_token').former_participants
11
+ end.should_not request_to '12345/former_participants?access_token=access_token'
12
+ end
13
+
14
+ it 'should not use cached contents when options are specified' do
15
+ lambda do
16
+ FbGraph::Thread.new(12345).former_participants(:no_cache => true)
17
+ end.should request_to '12345/former_participants?no_cache=true'
18
+ end
19
+
20
+ it 'should return former_participants as FbGraph::User' do
21
+ former_participants = FbGraph::Thread.new(12345, :access_token => 'access_token').former_participants(:no_cache => true)
22
+ former_participants.each do |former_participant|
23
+ former_participant.should be_instance_of(FbGraph::User)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), '../../spec_helper')
2
+
3
+ describe FbGraph::Connections::Messages, '#messages' do
4
+ before do
5
+ fake_json(:get, '12345/messages?access_token=access_token&no_cache=true', 'thread/messages/private')
6
+ end
7
+
8
+ it 'should use cached contents as default' do
9
+ lambda do
10
+ FbGraph::Thread.new(12345, :access_token => 'access_token').messages
11
+ end.should_not request_to '12345/messages?access_token=access_token'
12
+ end
13
+
14
+ it 'should not use cached contents when options are specified' do
15
+ lambda do
16
+ FbGraph::Thread.new(12345).messages(:no_cache => true)
17
+ end.should request_to '12345/messages?no_cache=true'
18
+ end
19
+
20
+ it 'should return threads as FbGraph::Message' do
21
+ messages = FbGraph::Thread.new(12345, :access_token => 'access_token').messages(:no_cache => true)
22
+ messages.each do |message|
23
+ message.should be_instance_of(FbGraph::Message)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), '../../spec_helper')
2
+
3
+ describe FbGraph::Connections::Participants, '#participants' do
4
+ before do
5
+ fake_json(:get, '12345/participants?access_token=access_token&no_cache=true', 'thread/participants/private')
6
+ end
7
+
8
+ it 'should use cached contents as default' do
9
+ lambda do
10
+ FbGraph::Thread.new(12345, :access_token => 'access_token').participants
11
+ end.should_not request_to '12345/participants?access_token=access_token'
12
+ end
13
+
14
+ it 'should not use cached contents when options are specified' do
15
+ lambda do
16
+ FbGraph::Thread.new(12345).participants(:no_cache => true)
17
+ end.should request_to '12345/participants?no_cache=true'
18
+ end
19
+
20
+ it 'should return participants as FbGraph::User' do
21
+ participants = FbGraph::Thread.new(12345, :access_token => 'access_token').participants(:no_cache => true)
22
+ participants.each do |participant|
23
+ participant.should be_instance_of(FbGraph::User)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), '../../spec_helper')
2
+
3
+ describe FbGraph::Connections::Senders, '#senders' do
4
+ before do
5
+ fake_json(:get, '12345/senders?access_token=access_token&no_cache=true', 'thread/senders/private')
6
+ end
7
+
8
+ it 'should use cached contents as default' do
9
+ lambda do
10
+ FbGraph::Thread.new(12345, :access_token => 'access_token').senders
11
+ end.should_not request_to '12345/senders?access_token=access_token'
12
+ end
13
+
14
+ it 'should not use cached contents when options are specified' do
15
+ lambda do
16
+ FbGraph::Thread.new(12345).senders(:no_cache => true)
17
+ end.should request_to '12345/senders?no_cache=true'
18
+ end
19
+
20
+ it 'should return senders as FbGraph::User' do
21
+ senders = FbGraph::Thread.new(12345, :access_token => 'access_token').senders(:no_cache => true)
22
+ senders.each do |sender|
23
+ sender.should be_instance_of(FbGraph::User)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ require File.join(File.dirname(__FILE__), '../../spec_helper')
2
+
3
+ describe FbGraph::Connections::Threads, '#threads' do
4
+ before do
5
+ fake_json(:get, 'me/threads?access_token=access_token', 'users/threads/me_private')
6
+ end
7
+
8
+ it 'should return threads as FbGraph::Thread' do
9
+ threads = FbGraph::User.me('access_token').threads
10
+ threads.each do |thread|
11
+ thread.should be_instance_of(FbGraph::Thread)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ require File.join(File.dirname(__FILE__), '../spec_helper')
2
+
3
+ describe FbGraph::Message, '.new' do
4
+ it 'should setup all supported attributes' do
5
+ attributes = {
6
+ :id => "12345",
7
+ :subject => "test",
8
+ :created_time => "2011-02-04T15:11:05+0000",
9
+ :tags => {
10
+ :data => [{
11
+ :name => "inbox"
12
+ }, {
13
+ :name => "source:web"
14
+ }]
15
+ },
16
+ :from => {
17
+ :name => "Nov Matake",
18
+ :email => "abc@facebook.com",
19
+ :id => "1575327134"
20
+ },
21
+ :to => {
22
+ :data => [{
23
+ :name => "Nov Matake",
24
+ :email => "xyz@facebook.com",
25
+ :id => "579612276"
26
+ }, {
27
+ :name => "Nov Matake",
28
+ :email => "abc@facebook.com",
29
+ :id => "1575327134"
30
+ }]
31
+ },
32
+ :message => "test test"
33
+ }
34
+ message = FbGraph::Message.new(attributes.delete(:id), attributes)
35
+ message.identifier.should == '12345'
36
+ message.subject.should == 'test'
37
+ message.message.should == 'test test'
38
+ message.created_time.should == Time.parse('2011-02-04T15:11:05+0000')
39
+ message.tags.should == [
40
+ FbGraph::Tag.new(:name => 'inbox'),
41
+ FbGraph::Tag.new(:name => 'source:web')
42
+ ]
43
+ message.from.should == FbGraph::User.new('1575327134', :name => 'Nov Matake', :email => 'abc@facebook.com')
44
+ message.to.should == [
45
+ FbGraph::User.new('579612276', :name => 'Nov Matake', :email => 'xyz@facebook.com'),
46
+ FbGraph::User.new('1575327134', :name => 'Nov Matake', :email => 'abc@facebook.com')
47
+ ]
48
+ end
49
+ end
@@ -0,0 +1,86 @@
1
+ require File.join(File.dirname(__FILE__), '../spec_helper')
2
+
3
+ describe FbGraph::Thread, '.new' do
4
+ it 'should setup all supported attributes' do
5
+ attributes = {
6
+ :id => "12345",
7
+ :snippet => 'test message',
8
+ :message_count => 2,
9
+ :unread_count => 1,
10
+ :updated_time => "2011-02-04T15:11:05+0000",
11
+ :tags => {
12
+ :data => [{
13
+ :name => "inbox"
14
+ }, {
15
+ :name => "source:web"
16
+ }]
17
+ },
18
+ :participants => {
19
+ :data => [{
20
+ :name => "Nov Matake",
21
+ :email => "xyz@facebook.com",
22
+ :id => "579612276"
23
+ }, {
24
+ :name => "Nov Matake",
25
+ :email => "abc@facebook.com",
26
+ :id => "1575327134"
27
+ }]
28
+ },
29
+ :senders => {
30
+ :data => [{
31
+ :name => "Nov Matake",
32
+ :email => "abc@facebook.com",
33
+ :id => "1575327134"
34
+ }]
35
+ },
36
+ :messages => {
37
+ :data => [{
38
+ :id => "m_25aaa73097e54594addb418c7bfbd05c",
39
+ :subject => "test",
40
+ :created_time => "2011-02-04T15:11:05+0000",
41
+ :tags => {
42
+ :data => [{
43
+ :name => "inbox"
44
+ }, {
45
+ :name => "source:web"
46
+ }]
47
+ },
48
+ :from => {
49
+ :name => "Nov Matake",
50
+ :email => "abc@facebook.com",
51
+ :id => "1575327134"
52
+ },
53
+ :to => {
54
+ :data => [{
55
+ :name => "Nov Matake",
56
+ :email => "xyz@facebook.com",
57
+ :id => "579612276"
58
+ }, {
59
+ :name => "Nov Matake",
60
+ :email => "abc@facebook.com",
61
+ :id => "1575327134"
62
+ }]
63
+ },
64
+ :message => "test"
65
+ }],
66
+ :paging => {
67
+ :previous => "https://graph.facebook.com/?access_token=access_token",
68
+ :next => "https://graph.facebook.com/?access_token=access_token"
69
+ }
70
+ }
71
+ }
72
+ thread = FbGraph::Thread.new(attributes.delete(:id), attributes)
73
+ thread.identifier.should == '12345'
74
+ thread.snippet.should == 'test message'
75
+ thread.message_count.should == 2
76
+ thread.unread_count.should == 1
77
+ thread.updated_time.should == Time.parse('2011-02-04T15:11:05+0000')
78
+ thread.tags.should == [
79
+ FbGraph::Tag.new(:name => 'inbox'),
80
+ FbGraph::Tag.new(:name => 'source:web')
81
+ ]
82
+ thread.senders.should == [
83
+ FbGraph::User.new('1575327134', :name => 'Nov Matake', :email => 'abc@facebook.com')
84
+ ]
85
+ end
86
+ end
@@ -0,0 +1,23 @@
1
+ require File.join(File.dirname(__FILE__), 'spec_helper')
2
+
3
+ describe RestClient do
4
+ before do
5
+ module RestClient
6
+ class Request
7
+ def self.execute(options = {})
8
+ if options[:verify_ssl] == OpenSSL::SSL::VERIFY_PEER
9
+ :secure
10
+ else
11
+ :insecure
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ it 'should support SSL' do
19
+ [:get, :post, :put, :delete].each do |method|
20
+ RestClient.send(method, 'https://example.com', {}).should == :secure
21
+ end
22
+ end
23
+ end