fb_graph2 0.4.1 → 0.4.3

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: 6036910e798a2dc8d32f03de1fec4d99bcd197eb
4
- data.tar.gz: 3cc301a00712616e7165541d2fd5fecd9b27fa7c
3
+ metadata.gz: 27eba51717bb5b667d0e6c6f4919c4d896c7c444
4
+ data.tar.gz: 51dc48b5d3239da4c9573c217d95e85c4825e13f
5
5
  SHA512:
6
- metadata.gz: ed9daa2f3139f01b5611797a49fe172609c9981431409e5f95567597bdf4f4bfd877df9a55d1e765ff27ea462cfe07787e180260d12f4e372075fa7a53cc3c24
7
- data.tar.gz: 6fe6cdf6b25d1b88c0efcf20fdceed25ba59c52a5592bb644948f04c0c91e0ad4cb26914cde97d665cf5bf72bb47bc09d81a724a000c5a7dac11922d2601f0f5
6
+ metadata.gz: 322128ddffe2d900508098b9098b1d71a1c492d755cea87c3be3d9d6ccfa0de945433f51fe4532234b4d1d3b5d39615b1b3404284ee21a661bd46387efe6d368
7
+ data.tar.gz: 9c2eaae75431949e4b659ded3a719483df74cb0d5000449050acac8519bd32e9f580b5d68b70114c567d911a5c8240ae888bba885293f4a4b930f618cdd0d424
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.4.3
@@ -9,6 +9,7 @@ module FbGraph2
9
9
  include Edge::Picture
10
10
  include Edge::Photos
11
11
  include Edge::Videos
12
+ extend Searchable
12
13
 
13
14
  register_attributes(
14
15
  raw: [:description, :is_date_only, :location, :name, :privacy, :ticket_uri, :timezone],
@@ -5,6 +5,7 @@ module FbGraph2
5
5
  include Edge::Feed
6
6
  include Edge::Files
7
7
  include Edge::Members
8
+ extend Searchable
8
9
 
9
10
  register_attributes(
10
11
  raw: [
@@ -20,6 +20,7 @@ module FbGraph2
20
20
  include Edge::Statuses
21
21
  include Edge::Tagged
22
22
  include Edge::Videos
23
+ extend Searchable
23
24
 
24
25
  register_attributes(
25
26
  raw: [
@@ -0,0 +1,4 @@
1
+ module FbGraph2
2
+ class Place < Page
3
+ end
4
+ end
@@ -0,0 +1,32 @@
1
+ module FbGraph2
2
+ module Searchable
3
+ class Result < Collection
4
+ attr_accessor :query, :access_token, :klass, :collection, :options
5
+
6
+ def initialize(query, access_token, klass, options = {})
7
+ @klass = klass
8
+ @access_token = access_token
9
+ @query = query
10
+ @options = options
11
+ @collection = options.delete(:collection) || Collection.new
12
+ replace @collection
13
+ end
14
+
15
+ def next(_options_ = {})
16
+ if collection.next.present?
17
+ klass.search query, access_token, options.merge(_options_).merge(collection.next)
18
+ else
19
+ self.class.new query, access_token, klass
20
+ end
21
+ end
22
+
23
+ def previous(_options_ = {})
24
+ if collection.previous.present?
25
+ klass.search query, access_token, options.merge(_options_).merge(collection.previous)
26
+ else
27
+ self.class.new query, access_token, klass
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,27 @@
1
+ module FbGraph2
2
+ module Searchable
3
+ def self.search(query, access_token, options = {})
4
+ klass = options.delete(:class) || Searchable
5
+ collection = Collection.new(
6
+ Node.new(:search).authenticate(
7
+ access_token
8
+ ).send(:get, options.merge(q: query))
9
+ )
10
+ yield collection if block_given?
11
+ Searchable::Result.new(query, access_token, klass, options.merge(:collection => collection))
12
+ end
13
+
14
+ def search(query, access_token, options = {})
15
+ type = self.to_s.split('::').last.underscore
16
+ Searchable.search(query, access_token, options.merge(:type => type, :class => self)) do |collection|
17
+ collection.map! do |obj|
18
+ self.new(obj[:id], obj.merge(
19
+ :access_token => options[:access_token]
20
+ ))
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ require 'fb_graph2/searchable/result'
@@ -3,9 +3,9 @@ module FbGraph2
3
3
  class Education < Struct
4
4
  register_attributes(
5
5
  raw: [:type],
6
- page: [:school, :year],
6
+ page: [:school, :year, :degree],
7
7
  pages: [:classes, :concentration]
8
8
  )
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -37,6 +37,7 @@ module FbGraph2
37
37
  include Edge::TaggedPlaces
38
38
  include Edge::Television
39
39
  include Edge::Videos
40
+ extend Searchable
40
41
 
41
42
  register_attributes(
42
43
  raw: [
data/lib/fb_graph2.rb CHANGED
@@ -43,6 +43,7 @@ end
43
43
  require 'fb_graph2/attribute_assigner'
44
44
  require 'fb_graph2/node'
45
45
  require 'fb_graph2/collection'
46
+ require 'fb_graph2/searchable'
46
47
  require 'fb_graph2/edge'
47
48
  [
48
49
  '.',
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe FbGraph2::Searchable do
4
+ describe 'search' do
5
+ context 'User' do
6
+ it 'should return users' do
7
+ users = mock_graph :get, 'search', 'search/user', access_token: 'token', params: {
8
+ q: 'nov.matake',
9
+ type: 'user'
10
+ } do
11
+ FbGraph2::User.search 'nov.matake', 'token'
12
+ end
13
+ users.should be_instance_of FbGraph2::Searchable::Result
14
+ users.should_not be_empty
15
+ users.each do |user|
16
+ user.should be_instance_of FbGraph2::User
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ describe 'pagination' do
23
+ context 'when first page' do
24
+ let :page1 do
25
+ mock_graph :get, 'search', 'search/user', access_token: 'token', params: {
26
+ q: 'nov.matake',
27
+ type: 'user'
28
+ } do
29
+ FbGraph2::User.search 'nov.matake', 'token'
30
+ end
31
+ end
32
+
33
+ it 'should have next' do
34
+ mock_graph :get, 'search', 'blank_collection', access_token: 'token', params: {
35
+ q: 'nov.matake',
36
+ type: 'user',
37
+ __after_id: 'enc_AeyyBJc7uo9gY-nHN9-LM0yG_IKBN5nCmqdkG8b4Ql-COLTnpQ-2NUc-xSDK6VwPhsq2W9Ktnr0zf7dD25Bc9eKT',
38
+ limit: 5000,
39
+ offset: 5000
40
+ } do
41
+ page1.next
42
+ end
43
+ end
44
+
45
+ it 'should have no previous' do
46
+ page1.previous.should be_blank
47
+ end
48
+ end
49
+ end
50
+ end
@@ -8,7 +8,7 @@ describe FbGraph2 do
8
8
  its(:logger) { should be_a Logger }
9
9
  its(:api_version) { should == 'v2.0' }
10
10
  its(:root_url) { should == 'https://graph.facebook.com' }
11
- its(:object_classes) { should contain_exactly *FbGraph2::Node.subclasses }
11
+ its(:object_classes) { should contain_exactly *FbGraph2::Node.subclasses + [FbGraph2::Place] }
12
12
  it { should_not be_debugging }
13
13
  end
14
14
 
@@ -0,0 +1,9 @@
1
+ {
2
+ "data": [{
3
+ "name": "Nov Matake",
4
+ "id": "426118390869327"
5
+ }],
6
+ "paging": {
7
+ "next": "https:\/\/graph.facebook.com\/v2.0\/search?type=user&q=nov.matake&limit=5000&offset=5000&__after_id=enc_AeyyBJc7uo9gY-nHN9-LM0yG_IKBN5nCmqdkG8b4Ql-COLTnpQ-2NUc-xSDK6VwPhsq2W9Ktnr0zf7dD25Bc9eKT"
8
+ }
9
+ }
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.4.1
4
+ version: 0.4.3
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-12-22 00:00:00.000000000 Z
11
+ date: 2015-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -247,12 +247,15 @@ files:
247
247
  - lib/fb_graph2/page_category.rb
248
248
  - lib/fb_graph2/payment.rb
249
249
  - lib/fb_graph2/photo.rb
250
+ - lib/fb_graph2/place.rb
250
251
  - lib/fb_graph2/place_tag.rb
251
252
  - lib/fb_graph2/post.rb
252
253
  - lib/fb_graph2/request.rb
253
254
  - lib/fb_graph2/request_filter/authenticator.rb
254
255
  - lib/fb_graph2/request_filter/debugger.rb
255
256
  - lib/fb_graph2/review.rb
257
+ - lib/fb_graph2/searchable.rb
258
+ - lib/fb_graph2/searchable/result.rb
256
259
  - lib/fb_graph2/struct.rb
257
260
  - lib/fb_graph2/struct/action.rb
258
261
  - lib/fb_graph2/struct/age_range.rb
@@ -346,6 +349,7 @@ files:
346
349
  - spec/fb_graph2/page_spec.rb
347
350
  - spec/fb_graph2/request_filter/authenticator_spec.rb
348
351
  - spec/fb_graph2/request_filter/debugger_spec.rb
352
+ - spec/fb_graph2/searchable_spec.rb
349
353
  - spec/fb_graph2/token_metadata_spec.rb
350
354
  - spec/fb_graph2/user_spec.rb
351
355
  - spec/fb_graph2/util_spec.rb
@@ -380,6 +384,7 @@ files:
380
384
  - spec/mock_json/post/liked_and_commented.json
381
385
  - spec/mock_json/post/likes.json
382
386
  - spec/mock_json/post/shared_posts.json
387
+ - spec/mock_json/search/user.json
383
388
  - spec/mock_json/success_true.json
384
389
  - spec/mock_json/success_with_id.json
385
390
  - spec/mock_json/token_metadata/app_token.json
@@ -443,7 +448,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
443
448
  version: '0'
444
449
  requirements: []
445
450
  rubyforge_project:
446
- rubygems_version: 2.2.2
451
+ rubygems_version: 2.4.5
447
452
  signing_key:
448
453
  specification_version: 4
449
454
  summary: Facebook Graph API v2.0 Wrapper in Ruby