fb_graph2 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc282842ac8e4f9c5d5c23370f1d24c1081a314d
4
- data.tar.gz: 9a7ad863eda44a83f1daf55d2b27a9fc2a44a4ae
3
+ metadata.gz: 9323b5cf68713b7b9925a313bd0b11fd92741d86
4
+ data.tar.gz: 90f36a1eadacd73e791c69c3075a07f4a484452f
5
5
  SHA512:
6
- metadata.gz: 6ac13ec30238246300656403271e17e34e79f493d958a8279cad910ab145983423693fad330c5b283d0cb837bd859d29327b381b2084df7d5776b4086deade6b
7
- data.tar.gz: 44a5171f50873c25513a1ada57e250b60f1e4ac5f6b0d8d220ecb617f6b848bedb71ffb1a68f8ed4fda7ccf375bfb873318e5ca0e8f7429999c86d0347caf63c
6
+ metadata.gz: 5d7972960b233c4067b472d02e444797dffc74db28897dc6cb731b99f7002b50473ab7432d597889d3182046fff7d68118daff643b45a95f1bf1e7e43f335614
7
+ data.tar.gz: 9f78a3058fef522a4e1c018a8362660f0834f870def9ce9740fdf8c555c02af0cf31e5c1b686e33b1fad97b1dab157f5efcc1f2659c2d68a4aff2dfa55f00ab2
data/Rakefile CHANGED
@@ -15,4 +15,4 @@ task :spec do
15
15
  Rake::Task[:'coverage:report'].invoke unless ENV['TRAVIS_RUBY_VERSION']
16
16
  end
17
17
 
18
- task :default => :spec
18
+ task default: :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
5
5
  gem.email = ['nov@matake.jp']
6
6
  gem.summary = %q{Facebook Graph API v2.0 Wrapper in Ruby}
7
7
  gem.description = %q{Facebook Graph API v2.0 Wrapper in Ruby}
8
- gem.homepage = ''
8
+ gem.homepage = 'https://github.com/fb_graph2'
9
9
  gem.license = 'MIT'
10
10
 
11
11
  gem.files = `git ls-files -z`.split("\x0")
@@ -19,5 +19,6 @@ Gem::Specification.new do |gem|
19
19
  gem.add_runtime_dependency 'activesupport', '>= 4.0'
20
20
  gem.add_development_dependency 'rake'
21
21
  gem.add_development_dependency 'simplecov'
22
+ gem.add_development_dependency 'webmock'
22
23
  gem.add_development_dependency 'rspec', '>= 2'
23
24
  end
@@ -17,7 +17,7 @@ module FbGraph2
17
17
 
18
18
  def assign(attributes)
19
19
  self.raw_attributes = attributes
20
- self.class.registered_attributes.each do |type, keys|
20
+ Array(self.class.registered_attributes).each do |type, keys|
21
21
  keys.each do |key|
22
22
  raw = attributes[key]
23
23
  if raw.present?
@@ -25,7 +25,7 @@ module FbGraph2
25
25
  when :raw
26
26
  raw
27
27
  when :date
28
- Date.parse raw
28
+ Date.strptime raw, '%m/%d/%Y' rescue raw
29
29
  when :time
30
30
  Time.parse raw
31
31
  when :timestamp
@@ -46,8 +46,9 @@ module FbGraph2
46
46
  end
47
47
  when :user
48
48
  User.new raw[:id], raw
49
- when :custom
50
- # NOTE: handle custom attributes in each class
49
+ else
50
+ # NOTE: handle these attributes in each class
51
+ next
51
52
  end
52
53
  self.send :"#{key}=", value
53
54
  end
@@ -7,6 +7,11 @@ module FbGraph2
7
7
  Post.new(post[:id], post).authenticate self.access_token
8
8
  end
9
9
  end
10
+
11
+ def feed!(params = {})
12
+ post = post params, edge: :feed
13
+ Post.new(post[:id], params.merge(post)).authenticate self.access_token
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -48,10 +48,16 @@ module FbGraph2
48
48
  end
49
49
  end
50
50
 
51
+ def post(params = {}, options = {})
52
+ handle_response do
53
+ http_client.post build_endpoint(options), build_params(params)
54
+ end
55
+ end
56
+
51
57
  private
52
58
 
53
59
  def edge_for(edge, params = {}, options = {})
54
- collection = get params, options.merge(:edge => edge)
60
+ collection = get params, options.merge(edge: edge)
55
61
  Collection.new collection
56
62
  end
57
63
 
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph2::Edge::Accounts do
4
+ context 'included in User' do
5
+ describe '#accounts' do
6
+ let(:me) { FbGraph2::User.me('token') }
7
+ it 'should return pages with page token' do
8
+ accounts = mock_graph :get, 'me/accounts', 'user/accounts' do
9
+ me.accounts
10
+ end
11
+ account = accounts.first
12
+ account.should be_instance_of FbGraph2::Page
13
+ account.name.should == 'Identity Conference #idcon'
14
+ account.access_token.should == 'page_token'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,16 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FbGraph2::Node do
4
- describe '.new' do
5
- it 'should support access_token option' do
6
- FbGraph2::Node.new(
7
- 'matake', :access_token => 'access_token'
8
- ).access_token.should == 'access_token'
4
+ let(:klass) { FbGraph2::Node }
5
+ let(:instance) { klass.new 'identifier' }
6
+
7
+ context 'class' do
8
+ subject { klass }
9
+ it { should_not respond_to :register_attributes }
10
+ it { should_not respond_to :registered_attributes }
11
+ it { should_not respond_to :registered_attributes= }
12
+ end
13
+
14
+ context 'instance' do
15
+ subject { instance }
16
+ it { should_not respond_to :assign }
17
+
18
+ describe '#initialize' do
19
+ its(:id) { should == 'identifier' }
20
+ its(:access_token) { should be_nil }
21
+ its(:raw_attributes) { should be_nil }
9
22
  end
10
23
 
11
- it 'should store raw attributes' do
12
- attributes = {:key => :value}
13
- FbGraph2::Node.new(12345, attributes).raw_attributes.should == attributes
24
+ describe '#authenticate' do
25
+ before { instance.authenticate 'access_token' }
26
+ its(:access_token) { should == 'access_token' }
14
27
  end
15
28
  end
16
29
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ module FbGraph2
4
+ class NodeSubClass < Node
5
+ end
6
+ end
7
+
8
+ describe FbGraph2::NodeSubClass do
9
+ let(:klass) { FbGraph2::NodeSubClass }
10
+ let(:instance) { klass.new 'identifier' }
11
+
12
+ context 'class' do
13
+ subject { klass }
14
+ it { should respond_to :register_attributes }
15
+ it { should respond_to :registered_attributes }
16
+ it { should respond_to :registered_attributes= }
17
+ end
18
+
19
+ context 'instance' do
20
+ subject { instance }
21
+ it { should respond_to :assign }
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph2::Page do
4
+ it :TODO
5
+ end
@@ -1,8 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe FbGraph2::User do
4
- it do
5
- p FbGraph2::User, FbGraph2::User.registered_attributes
6
- p FbGraph2::Page, FbGraph2::Page.registered_attributes
4
+ describe '.me' do
5
+ let(:klass) { FbGraph2::User }
6
+
7
+ it 'should not call API' do
8
+ expect do
9
+ me = klass.me 'token'
10
+ me.should be_instance_of klass
11
+ end.not_to request_to 'me'
12
+ end
13
+
14
+ context 'when fetched' do
15
+ it 'should call API' do
16
+ me = mock_graph :get, 'me', 'user/me' do
17
+ FbGraph2::User.me('token').fetch
18
+ end
19
+ me.should be_instance_of klass
20
+ end
21
+ end
7
22
  end
8
23
  end
@@ -4,12 +4,21 @@ describe FbGraph2 do
4
4
  subject { FbGraph2 }
5
5
  after { FbGraph2.debugging = false }
6
6
 
7
- its(:logger) { should be_a Logger }
8
- its(:debugging?) { should be_false }
7
+ context 'as default' do
8
+ its(:logger) { should be_a Logger }
9
+ its(:api_version) { should == 'v2.0' }
10
+ its(:root_url) { should == 'https://graph.facebook.com/v2.0' }
11
+ it { should_not be_debugging }
12
+ end
9
13
 
10
14
  describe '.debug!' do
11
15
  before { FbGraph2.debug! }
12
- its(:debugging?) { should be_true }
16
+ it { should be_debugging }
17
+ end
18
+
19
+ describe '.api_version' do
20
+ before { FbGraph2.api_version = 'v2.x' }
21
+ its(:root_url) { should == 'https://graph.facebook.com/v2.x' }
13
22
  end
14
23
 
15
24
  describe '.http_client' do
@@ -22,6 +31,7 @@ describe FbGraph2 do
22
31
  config.receive_timeout = 60
23
32
  end
24
33
  end
34
+
25
35
  it 'should configure Rack::OAuth2 and FbGraph2 http_client' do
26
36
  [Rack::OAuth2, FbGraph2].each do |klass|
27
37
  klass.http_client.ssl_config.verify_mode.should == OpenSSL::SSL::VERIFY_NONE
@@ -0,0 +1,24 @@
1
+ {
2
+ "data": [{
3
+ "category": "Community",
4
+ "name": "Identity Conference #idcon",
5
+ "access_token": "page_token",
6
+ "perms": ["ADMINISTER", "EDIT_PROFILE", "CREATE_CONTENT", "MODERATE_CONTENT", "CREATE_ADS", "BASIC_ADMIN"],
7
+ "id": "367989543259757"
8
+ }, {
9
+ "category": "Community organization",
10
+ "name": "OAuth.jp",
11
+ "access_token": "page_token",
12
+ "perms": ["ADMINISTER", "EDIT_PROFILE", "CREATE_CONTENT", "MODERATE_CONTENT", "CREATE_ADS", "BASIC_ADMIN"],
13
+ "id": "140478125968442"
14
+ }, {
15
+ "category": "Non-profit organization",
16
+ "name": "OpenID Foundation Japan",
17
+ "access_token": "access_token",
18
+ "perms": ["ADMINISTER", "EDIT_PROFILE", "CREATE_CONTENT", "MODERATE_CONTENT", "CREATE_ADS", "BASIC_ADMIN"],
19
+ "id": "157574337644417"
20
+ }],
21
+ "paging": {
22
+ "next": "https:\/\/graph.facebook.com\/v2.0\/579612276\/accounts?limit=5000&offset=5000&__after_id=enc_AeyErLVKPOCVAXiRThtd3kSkz__A4QR6eZWAQTTTWw-QCDtft_TmuaKhPOxK_I993BKoO1VIgoyXIAd72ZZNYvrw"
23
+ }
24
+ }
@@ -0,0 +1,421 @@
1
+ {
2
+ "id": "10152411392127277",
3
+ "bio": "Ruby/Rails developer, developing several gems like fb_graph, rack-oauth2, paypal-express, openid_connect, activitystreams etc.",
4
+ "birthday": "12/13/1981",
5
+ "education": [{
6
+ "classes": [{
7
+ "id": "114799961869204",
8
+ "name": "3rd year high school"
9
+ }, {
10
+ "id": "196267900399898",
11
+ "name": "2nd year",
12
+ "with": [{
13
+ "id": "10152979910439657",
14
+ "name": "Ikuko Kishida"
15
+ }]
16
+ }, {
17
+ "id": "128688833868666",
18
+ "name": "1st year",
19
+ "with": [{
20
+ "id": "10203579017097193",
21
+ "name": "Yuko Shimabata"
22
+ }]
23
+ }],
24
+ "school": {
25
+ "id": "168218936549964",
26
+ "name": "Doshisha High School"
27
+ },
28
+ "type": "High School",
29
+ "year": {
30
+ "id": "324576644221180",
31
+ "name": "2000"
32
+ }
33
+ }, {
34
+ "classes": [{
35
+ "id": "157989264254684",
36
+ "name": "Intelligent Systems Design Laboratory '04",
37
+ "with": [{
38
+ "id": "682734878458663",
39
+ "name": "Keiji Yamamoto"
40
+ }]
41
+ }],
42
+ "concentration": [{
43
+ "id": "109532545739630",
44
+ "name": "Engineering"
45
+ }],
46
+ "school": {
47
+ "id": "109239532428621",
48
+ "name": "Doshisha University"
49
+ },
50
+ "type": "College",
51
+ "year": {
52
+ "id": "113125125403208",
53
+ "name": "2004"
54
+ }
55
+ }, {
56
+ "classes": [{
57
+ "id": "137361399662343",
58
+ "name": "Intelligent Systems Design Laboratory '07"
59
+ }],
60
+ "concentration": [{
61
+ "id": "109532545739630",
62
+ "name": "Engineering"
63
+ }],
64
+ "degree": {
65
+ "id": "200416999973329",
66
+ "name": "Master of Engineering"
67
+ },
68
+ "school": {
69
+ "id": "109239532428621",
70
+ "name": "Doshisha University"
71
+ },
72
+ "type": "Graduate School",
73
+ "year": {
74
+ "id": "140617569303679",
75
+ "name": "2007"
76
+ }
77
+ }],
78
+ "email": "nov@matake.jp",
79
+ "favorite_teams": [{
80
+ "id": "112498808761105",
81
+ "name": "Bologna F.C. 1909"
82
+ }, {
83
+ "id": "103968596307357",
84
+ "name": "Gamba Osaka"
85
+ }],
86
+ "first_name": "Nov",
87
+ "gender": "male",
88
+ "hometown": {
89
+ "id": "112359252112966",
90
+ "name": "Hirakata, Osaka"
91
+ },
92
+ "interested_in": ["female"],
93
+ "languages": [{
94
+ "id": "109549852396760",
95
+ "name": "Japanese"
96
+ }, {
97
+ "id": "106059522759137",
98
+ "name": "English"
99
+ }],
100
+ "last_name": "Matake",
101
+ "link": "https://www.facebook.com/app_scoped_user_id/10152411392127277/",
102
+ "location": {
103
+ "id": "100563866688613",
104
+ "name": "Kawasaki-shi, Kanagawa, Japan"
105
+ },
106
+ "locale": "en_US",
107
+ "name": "Nov Matake",
108
+ "relationship_status": "Married",
109
+ "sports": [{
110
+ "id": "114967135183020",
111
+ "name": "Billiards"
112
+ }, {
113
+ "id": "104085636293671",
114
+ "name": "Darts"
115
+ }, {
116
+ "id": "111124835576428",
117
+ "name": "Rugby"
118
+ }],
119
+ "quotes": "求めなさい。そうすれば、与えられる。\r\n探しなさい。そうすれば、見つかる。\r\n門をたたきなさい。そうすれば、開かれる。\r\nだれでも、求める者は受け、探す者は見つけ、門をたたく者には開かれる。\r\n\r\nあなたがたのだれが、パンを欲しがる自分の子供に、石を与えるだろうか。魚を欲しがるのに、蛇を与えるだろうか。\r\n\r\nこのように、あなたがたは悪い者でありながらも、自分の子供に良い物を与えることを知っている。まして、あなたがたの天の父は、求める者に良い物をくださるにちがいない。\r\n\r\nだから、人にしてもらいたいと思うことは何でも、あなたがたも人にしなさい。\r\n\r\nこれこそ、律法と預言者である。",
120
+ "timezone": 9,
121
+ "updated_time": "2014-04-17T02:03:08+0000",
122
+ "verified": true,
123
+ "website": "http://matake.jp",
124
+ "work": [{
125
+ "employer": {
126
+ "id": "212867592069252",
127
+ "name": "GREE"
128
+ },
129
+ "position": {
130
+ "id": "137221592980321",
131
+ "name": "Developer"
132
+ },
133
+ "start_date": "2013-02-01"
134
+ }, {
135
+ "employer": {
136
+ "id": "157574337644417",
137
+ "name": "OpenID Foundation Japan"
138
+ },
139
+ "position": {
140
+ "id": "103770909661937",
141
+ "name": "Evangelist"
142
+ },
143
+ "start_date": "2011-09-01"
144
+ }, {
145
+ "employer": {
146
+ "id": "19124593579",
147
+ "name": "OpenID Foundation"
148
+ },
149
+ "position": {
150
+ "id": "139666082733546",
151
+ "name": "Member"
152
+ },
153
+ "start_date": "2011-08-01"
154
+ }, {
155
+ "description": "Translating OpenID & OAuth related documents into Japanese.",
156
+ "employer": {
157
+ "id": "157574337644417",
158
+ "name": "OpenID Foundation Japan"
159
+ },
160
+ "position": {
161
+ "id": "279848128693060",
162
+ "name": "Translation & Education Working Group Leader"
163
+ },
164
+ "projects": [{
165
+ "id": "223851157668338",
166
+ "description": "RFC 6749, 6750, 6819",
167
+ "end_date": "2013-01-01",
168
+ "name": "OAuth 2.0 Spec Translation",
169
+ "start_date": "2013-01-01",
170
+ "with": [{
171
+ "id": "10203856708878032",
172
+ "name": "Yusuke Kondo"
173
+ }, {
174
+ "id": "10203073519271473",
175
+ "name": "Ryo Ito"
176
+ }, {
177
+ "id": "672668269435107",
178
+ "name": "Naohiro Fujie"
179
+ }, {
180
+ "id": "634113926669120",
181
+ "name": "Masaru Kurahayashi"
182
+ }, {
183
+ "id": "10201113604960646",
184
+ "name": "Tatsuya Katsuhara"
185
+ }, {
186
+ "id": "652608194806969",
187
+ "name": "Boku Kihara"
188
+ }, {
189
+ "id": "648027665265419",
190
+ "name": "Kazuki Shimizu"
191
+ }, {
192
+ "id": "562632100518923",
193
+ "name": "Satoshi Yagi"
194
+ }, {
195
+ "id": "10203985460665265",
196
+ "name": "Noboru Kurumai"
197
+ }]
198
+ }, {
199
+ "id": "223851157668338",
200
+ "description": "draft 22",
201
+ "end_date": "2011-11-01",
202
+ "name": "OAuth 2.0 Spec Translation",
203
+ "start_date": "2011-10-01",
204
+ "with": [{
205
+ "id": "10201113604960646",
206
+ "name": "Tatsuya Katsuhara"
207
+ }, {
208
+ "id": "10203599839574972",
209
+ "name": "Taizo Matsuoka"
210
+ }, {
211
+ "id": "10203856708878032",
212
+ "name": "Yusuke Kondo"
213
+ }, {
214
+ "id": "10203073519271473",
215
+ "name": "Ryo Ito"
216
+ }, {
217
+ "id": "672668269435107",
218
+ "name": "Naohiro Fujie"
219
+ }, {
220
+ "id": "634113926669120",
221
+ "name": "Masaru Kurahayashi"
222
+ }, {
223
+ "id": "652608194806969",
224
+ "name": "Boku Kihara"
225
+ }]
226
+ }, {
227
+ "id": "223851157668338",
228
+ "description": "draft 10",
229
+ "end_date": "2010-11-01",
230
+ "name": "OAuth 2.0 Spec Translation",
231
+ "start_date": "2010-09-01",
232
+ "with": [{
233
+ "id": "10152392979304293",
234
+ "name": "Eiji Kitamura"
235
+ }, {
236
+ "id": "10202539573504945",
237
+ "name": "Takanori Ishikawa"
238
+ }, {
239
+ "id": "10203599839574972",
240
+ "name": "Taizo Matsuoka"
241
+ }, {
242
+ "id": "10203073519271473",
243
+ "name": "Ryo Ito"
244
+ }, {
245
+ "id": "10201113604960646",
246
+ "name": "Tatsuya Katsuhara"
247
+ }, {
248
+ "id": "10203856708878032",
249
+ "name": "Yusuke Kondo"
250
+ }, {
251
+ "id": "779688938729375",
252
+ "name": "Toyoaki Ohgochi"
253
+ }, {
254
+ "id": "10152359746567310",
255
+ "name": "Daichi Morifuji"
256
+ }]
257
+ }, {
258
+ "id": "295286707152335",
259
+ "end_date": "2010-03-01",
260
+ "name": "OAuth 1.0 Spec Translation",
261
+ "start_date": "2010-02-01",
262
+ "with": [{
263
+ "id": "10203073519271473",
264
+ "name": "Ryo Ito"
265
+ }, {
266
+ "id": "10201113604960646",
267
+ "name": "Tatsuya Katsuhara"
268
+ }, {
269
+ "id": "10152392979304293",
270
+ "name": "Eiji Kitamura"
271
+ }, {
272
+ "id": "10203599839574972",
273
+ "name": "Taizo Matsuoka"
274
+ }, {
275
+ "id": "10203856708878032",
276
+ "name": "Yusuke Kondo"
277
+ }]
278
+ }, {
279
+ "id": "275379439146839",
280
+ "end_date": "2010-01-01",
281
+ "name": "OpenID Authentication 2.0 Spec Translation",
282
+ "start_date": "2009-10-01",
283
+ "with": [{
284
+ "id": "10203073519271473",
285
+ "name": "Ryo Ito"
286
+ }, {
287
+ "id": "10201113604960646",
288
+ "name": "Tatsuya Katsuhara"
289
+ }, {
290
+ "id": "10203599839574972",
291
+ "name": "Taizo Matsuoka"
292
+ }]
293
+ }],
294
+ "start_date": "2009-12-01"
295
+ }, {
296
+ "end_date": "2013-01-01",
297
+ "employer": {
298
+ "id": "1414141888809913",
299
+ "name": "CyberAgent America"
300
+ },
301
+ "location": {
302
+ "id": "114600441890814",
303
+ "name": "Shibuya, Tokyo"
304
+ },
305
+ "position": {
306
+ "id": "137221592980321",
307
+ "name": "Developer"
308
+ },
309
+ "start_date": "2012-02-01"
310
+ }, {
311
+ "end_date": "2012-02-01",
312
+ "employer": {
313
+ "id": "216536155172635",
314
+ "name": "Cerego Japan"
315
+ },
316
+ "location": {
317
+ "id": "112261372122567",
318
+ "name": "Shibuya, Tokyo"
319
+ },
320
+ "position": {
321
+ "id": "116439701737440",
322
+ "name": "Rails Developer"
323
+ },
324
+ "projects": [{
325
+ "id": "147355305316648",
326
+ "end_date": "2012-02-01",
327
+ "name": "i know",
328
+ "start_date": "2011-02-01"
329
+ }, {
330
+ "id": "115003951868033",
331
+ "end_date": "2011-03-01",
332
+ "name": "Smart FM",
333
+ "start_date": "2009-03-01"
334
+ }, {
335
+ "id": "147355305316648",
336
+ "end_date": "2009-02-01",
337
+ "name": "i know",
338
+ "start_date": "2008-10-01"
339
+ }],
340
+ "start_date": "2008-10-01"
341
+ }, {
342
+ "end_date": "2008-09-01",
343
+ "employer": {
344
+ "id": "110398398982373",
345
+ "name": "ドリコム"
346
+ },
347
+ "position": {
348
+ "id": "108480125843293",
349
+ "name": "Web Developer"
350
+ },
351
+ "projects": [{
352
+ "id": "196036717085376",
353
+ "end_date": "2008-01-01",
354
+ "name": "Drecom Blog",
355
+ "start_date": "2008-01-01",
356
+ "with": [{
357
+ "id": "10202539573504945",
358
+ "name": "Takanori Ishikawa"
359
+ }]
360
+ }, {
361
+ "id": "186298551407738",
362
+ "end_date": "2008-05-01",
363
+ "name": "Resumy",
364
+ "start_date": "2008-01-01",
365
+ "with": [{
366
+ "id": "10202539573504945",
367
+ "name": "Takanori Ishikawa"
368
+ }]
369
+ }, {
370
+ "id": "133078480094168",
371
+ "end_date": "2007-12-01",
372
+ "name": "Drecom Wanted",
373
+ "start_date": "2006-04-01",
374
+ "with": [{
375
+ "id": "10152349447699566",
376
+ "name": "Hiroumi Mitani"
377
+ }]
378
+ }],
379
+ "start_date": "2006-01-01",
380
+ "with": [{
381
+ "id": "10202539573504945",
382
+ "name": "Takanori Ishikawa"
383
+ }, {
384
+ "id": "10202864487006831",
385
+ "name": "Shoichi Imamura"
386
+ }]
387
+ }, {
388
+ "description": "NPO for IT education",
389
+ "end_date": "2007-03-01",
390
+ "employer": {
391
+ "id": "200555370122204",
392
+ "name": "Kyoto CtoG.org"
393
+ },
394
+ "location": {
395
+ "id": "107601722603088",
396
+ "name": "Kyoto"
397
+ },
398
+ "position": {
399
+ "id": "107957955904825",
400
+ "name": "Founder"
401
+ },
402
+ "start_date": "2003-10-01",
403
+ "with": [{
404
+ "id": "10203411865798623",
405
+ "name": "Junya Wako"
406
+ }, {
407
+ "id": "667000650003141",
408
+ "name": "Ken-ichi Niimi"
409
+ }, {
410
+ "id": "10152381152939826",
411
+ "name": "Hiroyuki Makino"
412
+ }]
413
+ }, {
414
+ "end_date": "0000-00",
415
+ "employer": {
416
+ "id": "246222982173835",
417
+ "name": "Capy Inc."
418
+ },
419
+ "start_date": "0000-00"
420
+ }]
421
+ }
@@ -5,4 +5,8 @@ SimpleCov.start do
5
5
  end
6
6
 
7
7
  require 'rspec'
8
- require 'fb_graph2'
8
+ require 'fb_graph2'
9
+
10
+ Dir[File.join(__dir__, 'spec_helper/*.rb')].each do |file|
11
+ require file
12
+ end
@@ -0,0 +1,85 @@
1
+ require 'webmock/rspec'
2
+
3
+ module MockGraph
4
+ def mock_graph(method, path, response_path, options = {})
5
+ stub_request(
6
+ method,
7
+ endpoint_for(path)
8
+ ).with(
9
+ request_for(method, options)
10
+ ).to_return(
11
+ response_for(response_path, options)
12
+ )
13
+ if block_given?
14
+ response = yield
15
+ a_request(
16
+ method,
17
+ endpoint_for(path)
18
+ ).with(
19
+ request_for(method, options)
20
+ ).should have_been_made.once
21
+ response
22
+ end
23
+ end
24
+
25
+ def request_to(path, method = :get)
26
+ raise_error { |e|
27
+ e.should be_instance_of WebMock::NetConnectNotAllowedError
28
+ e.message.should include("Unregistered request: #{method.to_s.upcase}")
29
+ e.message.should include(endpoint_for path)
30
+ }
31
+ end
32
+
33
+ private
34
+
35
+ def endpoint_for(path)
36
+ File.join(FbGraph2.root_url, path)
37
+ end
38
+
39
+ def request_for(method, options = {})
40
+ request = {}
41
+ if options[:access_token]
42
+ options[:params] ||= {}
43
+ options[:params][:access_token] = options[:access_token].to_s
44
+ end
45
+ if options[:params]
46
+ case method
47
+ when :post, :put
48
+ request[:body] = options[:params]
49
+ else
50
+ request[:query] = options[:params]
51
+ end
52
+ end
53
+ request
54
+ end
55
+
56
+ def response_for(response_path, options = {})
57
+ response = {}
58
+ response[:body] = response_file_for response_path
59
+ if options[:status]
60
+ response[:status] = options[:status]
61
+ end
62
+ response
63
+ end
64
+
65
+ def response_file_for(response_path)
66
+ _response_file_path_ = if File.exist? response_path
67
+ response_path
68
+ else
69
+ File.join(
70
+ File.dirname(__FILE__), '../mock_json', "#{response_path}.json"
71
+ )
72
+ end
73
+ unless File.exist? _response_file_path_
74
+ response_file_required! _response_file_path_
75
+ end
76
+ File.new _response_file_path_, 'r', encoding: 'utf-8'
77
+ end
78
+
79
+ def response_file_required!(response_path)
80
+ warn 'No response file found.'
81
+ end
82
+ end
83
+
84
+ include MockGraph
85
+ WebMock.disable_net_connect!
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.0.0
4
+ version: 0.0.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: 2014-05-05 00:00:00.000000000 Z
11
+ date: 2014-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rspec
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -136,11 +150,17 @@ files:
136
150
  - lib/fb_graph2/request_filter/authenticator.rb
137
151
  - lib/fb_graph2/request_filter/debugger.rb
138
152
  - lib/fb_graph2/user.rb
153
+ - spec/fb_graph2/edge/accounts_spec.rb
139
154
  - spec/fb_graph2/node_spec.rb
155
+ - spec/fb_graph2/node_subclass_spec.rb
156
+ - spec/fb_graph2/page_spec.rb
140
157
  - spec/fb_graph2/user_spec.rb
141
158
  - spec/fb_graph2_spec.rb
159
+ - spec/mock_json/user/accounts.json
160
+ - spec/mock_json/user/me.json
142
161
  - spec/spec_helper.rb
143
- homepage: ''
162
+ - spec/spec_helper/mock_graph.rb
163
+ homepage: https://github.com/fb_graph2
144
164
  licenses:
145
165
  - MIT
146
166
  metadata: {}
@@ -160,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
180
  version: '0'
161
181
  requirements: []
162
182
  rubyforge_project:
163
- rubygems_version: 2.2.2
183
+ rubygems_version: 2.2.0
164
184
  signing_key:
165
185
  specification_version: 4
166
186
  summary: Facebook Graph API v2.0 Wrapper in Ruby