fb_graph2 0.5.0 → 0.5.1

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: e72dbfaf8442748adfa67ef0061aaeff34cdbb27
4
- data.tar.gz: bac4bd42aab70b1ebbfd2389dfdd322fe9272810
3
+ metadata.gz: 5bb39956c63a81088235822b5b6859f6010e6974
4
+ data.tar.gz: 63d1315b27dfa5bc4af79950bbe17d2cb5599871
5
5
  SHA512:
6
- metadata.gz: db1bc100cdbc354df7e41a12debfe3671334564428557bf18ef89e50cbd2f2bee75bee5da01d3e9fe194e115ccc697e3fe7a8e8eff7ecedaac2e7020051e11d8
7
- data.tar.gz: fbe23403fc3aa170dd0957209d6395f5e5c29389752db4cd66edf622c18996d7d3dc2cfd4e408e5aed525adccb50890f854ce18b225f4a0f282a85d67b392a0a
6
+ metadata.gz: 5eddbfa8f5409d0f99cf6e0af07cd8921be2345b0ffebf5168a854de3c894b1f62ca27b5ebf81e7b1b0cf1ce436953e236b204985d8690532d42c84b081f2b17
7
+ data.tar.gz: 61ba1c2b63262ddeb685912544639c3a1315880b8e516185d283445c5089aff4b02d5e22ebb32e82a81f67387066b77e0539dd90da54c3b92e9f54e972162611
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.5.1
@@ -73,6 +73,10 @@ module FbGraph2
73
73
  Collection.new(raw).collect! do |_raw_|
74
74
  User.new _raw_[:id], _raw_
75
75
  end
76
+ when :tags
77
+ Collection.new(raw).collect! do |_raw_|
78
+ Struct::Tag.new _raw_
79
+ end
76
80
  else
77
81
  # NOTE: handle these attributes in each class
78
82
  next
@@ -0,0 +1,12 @@
1
+ module FbGraph2
2
+ class Conversation < Node
3
+ include Edge::Messages
4
+
5
+ register_attributes(
6
+ raw: [:snippet, :message_count, :unread_count, :can_reply, :is_subscribed],
7
+ time: [:updated_time],
8
+ users: [:participants, :senders],
9
+ tags: [:tags]
10
+ )
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module FbGraph2
2
+ class Edge
3
+ module Conversations
4
+ def conversations(params = {})
5
+ conversations = self.edge :conversations, params
6
+ conversations.collect! do |conversation|
7
+ Conversation.new(conversation[:id], conversation).authenticate self.access_token
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ module FbGraph2
2
+ class Edge
3
+ module Messages
4
+ def assign(attributes)
5
+ super
6
+ if attributes.include? :messages
7
+ @_cached_messages = Collection.new attributes[:messages]
8
+ end
9
+ end
10
+
11
+ def messages(params = {})
12
+ messages = if @_cached_messages.present? && params.blank?
13
+ @_cached_messages
14
+ else
15
+ self.edge :messages, params
16
+ end
17
+ messages.collect! do |message|
18
+ Message.new(message[:id], message).authenticate self.access_token
19
+ end
20
+ end
21
+
22
+ def message!(params = {})
23
+ message = self.post params, edge: :messages
24
+ Message.new(message[:id], params.merge(message)).authenticate self.access_token
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,6 +1,7 @@
1
1
  module FbGraph2
2
2
  class Exception < StandardError
3
- attr_accessor :status, :type, :code
3
+ attr_accessor :status, :type, :code, :error_subcode
4
+ alias_method :error_code, :code
4
5
 
5
6
  class << self
6
7
  def detect(status, body = {}, headers = {})
@@ -43,6 +44,7 @@ module FbGraph2
43
44
  self.status = status
44
45
  self.type = error[:type]
45
46
  self.code = error[:code]
47
+ self.error_subcode = error[:error_subcode]
46
48
  end
47
49
 
48
50
  class BadRequest < Exception
@@ -78,4 +80,4 @@ module FbGraph2
78
80
  /invalid_request/ => InvalidRequest
79
81
  }
80
82
  end
81
- end
83
+ end
@@ -1,9 +1,11 @@
1
1
  module FbGraph2
2
2
  class Message < Node
3
3
  register_attributes(
4
- raw: [:message],
4
+ raw: [:message, :subject],
5
5
  time: [:created_time],
6
- profile: [:from]
6
+ profile: [:from],
7
+ profiles: [:to],
8
+ tags: [:tags]
7
9
  )
8
10
  end
9
11
  end
@@ -3,6 +3,7 @@ module FbGraph2
3
3
  include Edge::Admins
4
4
  include Edge::Albums
5
5
  include Edge::Blocked
6
+ include Edge::Conversations
6
7
  include Edge::Events
7
8
  include Edge::Feed
8
9
  include Edge::GlobalBrandChildren
@@ -0,0 +1,9 @@
1
+ module FbGraph2
2
+ class Struct
3
+ class Tag < Struct
4
+ register_attributes(
5
+ raw: [:name]
6
+ )
7
+ end
8
+ end
9
+ end
@@ -20,7 +20,11 @@ module FbGraph2
20
20
  Group
21
21
  when 'event'
22
22
  Event
23
+ when 'application'
24
+ App
25
+ else
26
+ Node
23
27
  end
24
28
  end
25
29
  end
26
- end
30
+ end
@@ -1,5 +1,8 @@
1
1
  module FbGraph2
2
2
  class Thread < Node
3
+ include Edge::Messages
4
+ alias_method :comments, :messages
5
+
3
6
  register_attributes(
4
7
  raw: [:unread, :unseen],
5
8
  time: [:updated_time],
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph2::Edge::Conversations do
4
+ context 'Conversations' do
5
+ let(:page) { FbGraph2::Page.new("page_id").authenticate('token') }
6
+
7
+ describe '#conversations' do
8
+ it 'should return an Array of authenticated FbGraph2::Conversation objects' do
9
+
10
+ conversations = mock_graph :get, 'page_id/conversations', 'page/conversations', access_token: 'token' do
11
+ page.conversations
12
+ end
13
+
14
+ conversations.each { |conversation| expect(conversation.access_token).to eq('token') }
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph2::Edge::Messages do
4
+ context 'Messages' do
5
+ let(:conversation) { FbGraph2::Conversation.new("conversation_id").authenticate('token') }
6
+
7
+ describe '#messages' do
8
+ it 'should return an Array of authenticated FbGraph2::Message objects' do
9
+
10
+ messages = mock_graph :get, 'conversation_id/messages', 'conversation/messages', access_token: 'token' do
11
+ conversation.messages
12
+ end
13
+
14
+ expect(messages.first.access_token).to eq('token')
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph2::Exception do
4
+ it 'should properly set its message for inspect' do
5
+ err = FbGraph2::Exception.new(400, 'This is the error message')
6
+ err.inspect.should == '#<FbGraph2::Exception: This is the error message>'
7
+ end
8
+
9
+ context 'when response body is given' do
10
+ it 'should setup type, error code, and subcode from error' do
11
+ err = FbGraph2::Exception.new(400, 'This is the original message',
12
+ {
13
+ :type => 'SomeError',
14
+ :message => 'This is the error message',
15
+ :code => 190,
16
+ :error_subcode => 460
17
+ }
18
+ )
19
+ err.status.should == 400
20
+ err.type.should == 'SomeError'
21
+ err.error_code.should == 190
22
+ err.error_subcode.should == 460
23
+ end
24
+ end
25
+
26
+ describe ".detect" do
27
+ it 'should detect the appropriate class from the error status' do
28
+ [400,401,404,500].each do |error_code|
29
+ err = FbGraph2::Exception.detect(error_code, error: { message: "Error #{error_code}"})
30
+ err.class.should == FbGraph2::Exception.detect_from_status(error_code)
31
+ end
32
+ end
33
+
34
+ it 'should detect the appropriate class from headers' do
35
+ %w{not_found invalid_token, invalid_request}.each do |error|
36
+ header = {"WWW-Authenticate" => "OAuth 'Facebook Platform' '#{error}' Error!"}
37
+ err = FbGraph2::Exception.detect('a code', {error: {message: "an error occurred"}}, header)
38
+ err.class.should == FbGraph2::Exception.detect_from_header(header, nil)
39
+ end
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph2::TaggedProfile do
4
+ describe '.initialize' do
5
+ {
6
+ user: FbGraph2::User,
7
+ page: FbGraph2::Page,
8
+ event: FbGraph2::Event,
9
+ application: FbGraph2::App,
10
+ unknown: FbGraph2::Node
11
+ }.each do |type, klass|
12
+ context "when type=#{type}" do
13
+ it "should return instances of the #{klass}" do
14
+ tag = FbGraph2::TaggedProfile.new(1, type: type.to_s)
15
+ expect(tag.object).to be_a klass
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,33 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "id": "m_mid.1427484003966:6a7d41f350be02b202",
5
+ "created_time": "2015-03-27T19:20:04+0000",
6
+ "tags": {
7
+ "data": [
8
+ {"name": "inbox"},
9
+ {"name": "source:web"}
10
+ ]
11
+ },
12
+ "from": {
13
+ "name": "Bryan Brunetti",
14
+ "email": "123456\u0040facebook.com",
15
+ "id": "643757367"
16
+ },
17
+ "to": {
18
+ "data": [
19
+ {
20
+ "name": "Desk Three",
21
+ "email": "775794712516982\u0040facebook.com",
22
+ "id": "775794712516982"
23
+ }
24
+ ]
25
+ },
26
+ "message": "testing a message"
27
+ }
28
+ ],
29
+ "paging": {
30
+ "previous": "https:\/\/graph.facebook.com\/v2.0\/t_mid.1426199405718:7ed3d5c7813b41e484\/messages?limit=25&since=1427484004&__paging_token=enc_AdBRZAAMNJk6afsV9fngFvUvCruCFRtYbsQjQDUFCYEd4CHjwrXUD33IkK80S68qMg8IO8YWa5cZB5n8KbZBLbMQXZCPFOyYoobd2Ij11bvI6PywwAZDZD&__previous=1",
31
+ "next": "https:\/\/graph.facebook.com\/v2.0\/t_mid.1426199405718:7ed3d5c7813b41e484\/messages?limit=25&until=1426199405&__paging_token=enc_AdD0AeYOoGBAn90kScirgzHTxGTnZCBaHYH5fDk2ESd90FesTLZAas06iG6NqMjTecoIAzs20zsfL4fmREIkC1HD0nSZA6E9TqF1aju7UYRDh7GgAZDZD"
32
+ }
33
+ }
@@ -0,0 +1,152 @@
1
+ {
2
+ "data":[
3
+ {
4
+ "message_count":4,
5
+ "id":"t_mid.1414517590484:4a52ecd944c0691a57",
6
+ "updated_time":"2015-03-27T19:13:37+0000",
7
+ "messages":{
8
+ "data":[
9
+ {
10
+ "id":"m_mid.1427483617197:8c924a0cf2ac0b3c24",
11
+ "created_time":"2015-03-27T19:13:37+0000",
12
+ "tags":{
13
+ "data":[
14
+ {
15
+ "name":"inbox"
16
+ },
17
+ {
18
+ "name":"source:web"
19
+ }
20
+ ]
21
+ },
22
+ "from":{
23
+ "name":"Bryan Brunetti",
24
+ "email":"123456\u0040facebook.com",
25
+ "id":"643757367"
26
+ },
27
+ "to":{
28
+ "data":[
29
+ {
30
+ "name":"MJJ Designs",
31
+ "email":"202484463134297\u0040facebook.com",
32
+ "id":"202484463134297"
33
+ }
34
+ ]
35
+ },
36
+ "message":"Test Message"
37
+ },
38
+ {
39
+ "id":"m_mid.1414519282171:23add76eb638bec943",
40
+ "created_time":"2014-10-28T18:01:22+0000",
41
+ "tags":{
42
+ "data":[
43
+ {
44
+ "name":"inbox"
45
+ },
46
+ {
47
+ "name":"read"
48
+ },
49
+ {
50
+ "name":"sent"
51
+ },
52
+ {
53
+ "name":"source:web"
54
+ }
55
+ ]
56
+ },
57
+ "from":{
58
+ "name":"MJJ Designs",
59
+ "email":"202484463134297\u0040facebook.com",
60
+ "id":"202484463134297"
61
+ },
62
+ "to":{
63
+ "data":[
64
+ {
65
+ "name":"Mike Jandreau",
66
+ "email":"512920166\u0040facebook.com",
67
+ "id":"512920166"
68
+ }
69
+ ]
70
+ },
71
+ "message":"Replying back with a hopeful reopen."
72
+ },
73
+ {
74
+ "id":"m_mid.1414519100772:3b7a73dc20d9d0bb46",
75
+ "created_time":"2014-10-28T17:58:20+0000",
76
+ "tags":{
77
+ "data":[
78
+ {
79
+ "name":"inbox"
80
+ },
81
+ {
82
+ "name":"read"
83
+ },
84
+ {
85
+ "name":"sent"
86
+ },
87
+ {
88
+ "name":"source:web"
89
+ }
90
+ ]
91
+ },
92
+ "from":{
93
+ "name":"MJJ Designs",
94
+ "email":"202484463134297\u0040facebook.com",
95
+ "id":"202484463134297"
96
+ },
97
+ "to":{
98
+ "data":[
99
+ {
100
+ "name":"Mike Jandreau",
101
+ "email":"512920166\u0040facebook.com",
102
+ "id":"512920166"
103
+ }
104
+ ]
105
+ },
106
+ "message":"Replying back and resolving."
107
+ },
108
+ {
109
+ "id":"m_mid.1414517590484:4a52ecd944c0691a57",
110
+ "created_time":"2014-10-28T17:33:10+0000",
111
+ "tags":{
112
+ "data":[
113
+ {
114
+ "name":"inbox"
115
+ },
116
+ {
117
+ "name":"read"
118
+ },
119
+ {
120
+ "name":"source:web"
121
+ }
122
+ ]
123
+ },
124
+ "from":{
125
+ "name":"Bryan Brunetti",
126
+ "email":"643757367\u0040facebook.com",
127
+ "id":"643757367"
128
+ },
129
+ "to":{
130
+ "data":[
131
+ {
132
+ "name":"MJJ Designs",
133
+ "email":"202484463134297\u0040facebook.com",
134
+ "id":"202484463134297"
135
+ }
136
+ ]
137
+ },
138
+ "message":"Hello, I am testing a message."
139
+ }
140
+ ],
141
+ "paging":{
142
+ "previous":"https:\/\/graph.facebook.com\/v2.0\/t_mid.1414517590484:4a52ecd944c0691a57\/messages?limit=25&since=1427483617&__paging_token=enc_AdAUyfn3MU8FZB1vc7ZBfTsAB4yvvJPyeAc3PQh3pNXBxOo5yrj8LRprCYjOagSFXG63UIFG5f9Yp9heZCDpVfduwJAQXx2w77AkZAsZC9uBUACQkWQZDZD&__previous=1",
143
+ "next":"https:\/\/graph.facebook.com\/v2.0\/t_mid.1414517590484:4a52ecd944c0691a57\/messages?limit=25&until=1414517590&__paging_token=enc_AdB5RShUekeWj57vQTtM0Ad1VAfDvX8ia51FBXTOL4krk1NZB2mximxaHhKOd7hPqupZBuaD32mZCSuG324adXoh8zsZAxSDaQDxzEZCuj2r1XLNgrwZDZD"
144
+ }
145
+ }
146
+ }
147
+ ],
148
+ "paging":{
149
+ "previous":"https:\/\/graph.facebook.com\/v2.0\/202484463134297\/conversations?fields=messages,message_count&limit=100&since=1427483617&__paging_token=enc_AdBi2J3tFiiykxpWS3oAdtHA9sg2eAZCNDaSOLko4ma6xLygs674cSHPsGw3ZAaqAWCFwtpOMGgZAgvfxScJdvS0xgcgOtu0UG5iV53I0kUusJ9PgZDZD&__previous=1",
150
+ "next":"https:\/\/graph.facebook.com\/v2.0\/202484463134297\/conversations?fields=messages,message_count&limit=100&since=1426881131&until=1427483617&__paging_token=enc_AdBi2J3tFiiykxpWS3oAdtHA9sg2eAZCNDaSOLko4ma6xLygs674cSHPsGw3ZAaqAWCFwtpOMGgZAgvfxScJdvS0xgcgOtu0UG5iV53I0kUusJ9PgZDZD"
151
+ }
152
+ }
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nov matake
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-06 00:00:00.000000000 Z
11
+ date: 2015-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -177,6 +177,7 @@ files:
177
177
  - lib/fb_graph2/auth/signed_request.rb
178
178
  - lib/fb_graph2/collection.rb
179
179
  - lib/fb_graph2/comment.rb
180
+ - lib/fb_graph2/conversation.rb
180
181
  - lib/fb_graph2/domain.rb
181
182
  - lib/fb_graph2/edge.rb
182
183
  - lib/fb_graph2/edge/accounts.rb
@@ -193,6 +194,7 @@ files:
193
194
  - lib/fb_graph2/edge/blocked.rb
194
195
  - lib/fb_graph2/edge/books.rb
195
196
  - lib/fb_graph2/edge/comments.rb
197
+ - lib/fb_graph2/edge/conversations.rb
196
198
  - lib/fb_graph2/edge/declined.rb
197
199
  - lib/fb_graph2/edge/dispute.rb
198
200
  - lib/fb_graph2/edge/docs.rb
@@ -216,6 +218,7 @@ files:
216
218
  - lib/fb_graph2/edge/locations.rb
217
219
  - lib/fb_graph2/edge/maybe.rb
218
220
  - lib/fb_graph2/edge/members.rb
221
+ - lib/fb_graph2/edge/messages.rb
219
222
  - lib/fb_graph2/edge/milestones.rb
220
223
  - lib/fb_graph2/edge/movies.rb
221
224
  - lib/fb_graph2/edge/music.rb
@@ -298,6 +301,7 @@ files:
298
301
  - lib/fb_graph2/struct/setting.rb
299
302
  - lib/fb_graph2/struct/static_resource.rb
300
303
  - lib/fb_graph2/struct/subscription.rb
304
+ - lib/fb_graph2/struct/tag.rb
301
305
  - lib/fb_graph2/struct/work.rb
302
306
  - lib/fb_graph2/tagged_profile.rb
303
307
  - lib/fb_graph2/thread.rb
@@ -320,6 +324,7 @@ files:
320
324
  - spec/fb_graph2/edge/blocked_spec.rb
321
325
  - spec/fb_graph2/edge/books_spec.rb
322
326
  - spec/fb_graph2/edge/comments_spec.rb
327
+ - spec/fb_graph2/edge/conversations_spec.rb
323
328
  - spec/fb_graph2/edge/declined_spec.rb
324
329
  - spec/fb_graph2/edge/events_spec.rb
325
330
  - spec/fb_graph2/edge/feed_spec.rb
@@ -335,6 +340,7 @@ files:
335
340
  - spec/fb_graph2/edge/links_spec.rb
336
341
  - spec/fb_graph2/edge/maybe_spec.rb
337
342
  - spec/fb_graph2/edge/members_spec.rb
343
+ - spec/fb_graph2/edge/messages_spec.rb
338
344
  - spec/fb_graph2/edge/milestones_spec.rb
339
345
  - spec/fb_graph2/edge/movies_spec.rb
340
346
  - spec/fb_graph2/edge/music_spec.rb
@@ -359,12 +365,14 @@ files:
359
365
  - spec/fb_graph2/edge/test_users_spec.rb
360
366
  - spec/fb_graph2/edge/videos_spec.rb
361
367
  - spec/fb_graph2/edge_spec.rb
368
+ - spec/fb_graph2/exception_spec.rb
362
369
  - spec/fb_graph2/node_spec.rb
363
370
  - spec/fb_graph2/node_subclass_spec.rb
364
371
  - spec/fb_graph2/page_spec.rb
365
372
  - spec/fb_graph2/request_filter/authenticator_spec.rb
366
373
  - spec/fb_graph2/request_filter/debugger_spec.rb
367
374
  - spec/fb_graph2/searchable_spec.rb
375
+ - spec/fb_graph2/tagged_profile_spec.rb
368
376
  - spec/fb_graph2/token_metadata_spec.rb
369
377
  - spec/fb_graph2/user_spec.rb
370
378
  - spec/fb_graph2/util_spec.rb
@@ -375,6 +383,7 @@ files:
375
383
  - spec/mock_json/app/subscriptions.json
376
384
  - spec/mock_json/app/test_users.json
377
385
  - spec/mock_json/blank_collection.json
386
+ - spec/mock_json/conversation/messages.json
378
387
  - spec/mock_json/error/400/191.json
379
388
  - spec/mock_json/error/400/2500.json
380
389
  - spec/mock_json/error/invalid_format.json
@@ -387,6 +396,7 @@ files:
387
396
  - spec/mock_json/page/admins.json
388
397
  - spec/mock_json/page/block_succeeded.json
389
398
  - spec/mock_json/page/blocked.json
399
+ - spec/mock_json/page/conversations.json
390
400
  - spec/mock_json/page/milestones.json
391
401
  - spec/mock_json/page/offers.json
392
402
  - spec/mock_json/page/promotable_posts.json