fb_graph 2.7.0 → 2.7.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: 6bb0cff0747ba82525632c181554093904607ba0
4
- data.tar.gz: c9edf38574b3bb297f2fa4c3e4f23c8a306f0af6
3
+ metadata.gz: 7655ead97fca704002f5dac9ef943dbd61e8dde6
4
+ data.tar.gz: 3166cea76ebd6bc8f439f0ecfe1080f294aa8f14
5
5
  SHA512:
6
- metadata.gz: e112a82bc1b7dfb771be8b3b1df73d33a69832e54dd5511ae9b0ed21493cca937b75018b01847c25945629d73c03f9055e2837af6c7ecded01fce56618706764
7
- data.tar.gz: 846321308f913f609d4a6702d9f56e01610e771f5858033639580fba99b89c1cca2d5b7d87338cead6949f1a1b4423ab2f217adf8a4b49c17b28b7f271187a00
6
+ metadata.gz: e42d8137dd19236c601b4a6cd1c85d185228b5c6cb90712c8dce246da36968410359e357f752aa8702de546197a65f0636e10b6bf059ba730a9834abf5fed926
7
+ data.tar.gz: 600d5eab48fae82d012047d911374ac8928a343b65777b8f22cabcd09d6749e1131672b6be4c59f9d4e632b39c92151f1af68d38781c08a1da5109ca39f54497
@@ -1,3 +1,4 @@
1
1
  rvm:
2
2
  - 1.9.2
3
3
  - 1.9.3
4
+ - 2.0.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.7.0
1
+ 2.7.1
@@ -1,6 +1,6 @@
1
1
  module FbGraph
2
2
  class Collection < Array
3
- attr_reader :previous, :next, :total_count, :unread_count, :updated_time
3
+ attr_reader :previous, :next, :total_count, :unread_count, :updated_time, :cursors
4
4
 
5
5
  def initialize(collection = nil)
6
6
  collection = case collection
@@ -27,7 +27,7 @@ module FbGraph
27
27
  else
28
28
  @total_count = collection[:count]
29
29
  end
30
- @previous, @next = {}, {}
30
+ @previous, @next, @cursors = {}, {}, {}
31
31
  if (paging = collection[:paging])
32
32
  if paging[:previous]
33
33
  @previous = fetch_params(paging[:previous])
@@ -35,21 +35,24 @@ module FbGraph
35
35
  if paging[:next]
36
36
  @next = fetch_params(paging[:next])
37
37
  end
38
+ if paging[:cursors]
39
+ @cursors[:after] = paging[:cursors].try(:[], :after)
40
+ @cursors[:before] = paging[:cursors].try(:[], :before)
41
+ end
38
42
  end
39
43
  end
40
44
 
41
45
  private
42
46
 
43
47
  def fetch_params(url)
44
- query = URI.parse(URI.encode(url)).query
48
+ query = Rack::Utils.parse_nested_query(
49
+ URI.unescape(URI.parse(URI.encode(url)).query)
50
+ )
45
51
  params = {}
46
- query.split('&').each do |q|
47
- key, value = q.split('=')
48
- if ['limit', 'offset', 'until', 'since', '__after_id', '__before_id'].include?(key)
49
- params[key.to_sym] = URI.unescape(value)
50
- end
52
+ query.each do |key, value|
53
+ params[key.to_sym] = value
51
54
  end
52
55
  params
53
56
  end
54
57
  end
55
- end
58
+ end
@@ -20,7 +20,14 @@ module FbGraph
20
20
  method.to_s.gsub('_', '') == self.connection.to_s
21
21
  end
22
22
  end
23
- self.owner.send(connection_method, self.options.merge(_options_).merge(self.collection.next))
23
+ self.owner.send(
24
+ connection_method,
25
+ self.options.merge(
26
+ self.collection.next.merge(
27
+ _options_
28
+ )
29
+ )
30
+ )
24
31
  else
25
32
  self.class.new(self.owner, self.connection)
26
33
  end
@@ -3,6 +3,7 @@ module FbGraph
3
3
  attr_accessor :code, :type
4
4
 
5
5
  ERROR_HEADER_MATCHERS = {
6
+ /not_found/ => "NotFound",
6
7
  /invalid_token/ => "InvalidToken",
7
8
  /invalid_request/ => "InvalidRequest"
8
9
  }
@@ -54,7 +54,35 @@ describe FbGraph::Collection, '.new' do
54
54
  comments.should be_a FbGraph::Collection
55
55
  comments.collection.next.should include :limit, :offset, :__after_id
56
56
  comments.collection.previous.should include :limit, :offset, :__before_id
57
+ comments.collection.cursors.should be_empty
57
58
  end
58
59
  end
59
60
 
60
- end
61
+ it 'should handle paging params when array of ids is passed' do
62
+ params = {:campaign_ids => "[6001111111467]", :include_deleted => "true"}
63
+ mock_graph :get, '100111111111121/adgroups', 'ad_groups/test_ad_group_with_paging', :params => params do
64
+ ad_groups = FbGraph::AdAccount.new(100111111111121).ad_groups(params)
65
+ ad_groups.should be_instance_of FbGraph::Connection
66
+ ad_groups.should be_a FbGraph::Collection
67
+
68
+ ad_groups.collection.next.should include :offset, :campaign_ids
69
+ ad_groups.collection.next[:offset].should == "100"
70
+ ad_groups.collection.next[:campaign_ids].should == '["6001111111467"]'
71
+
72
+ ad_groups.collection.previous.should include :offset, :campaign_ids
73
+ ad_groups.collection.previous[:offset].should == "0"
74
+ ad_groups.collection.previous[:campaign_ids].should == '["6001111111467"]'
75
+ end
76
+ end
77
+
78
+ it 'should handle cursor paging params' do
79
+ mock_graph :get, 'post_id/comments', 'posts/comments/with_cursor_paging_params' do
80
+ comments = FbGraph::Post.new('post_id').comments
81
+ comments.should be_instance_of FbGraph::Connection
82
+ comments.should be_a FbGraph::Collection
83
+ comments.collection.next.should include :limit, :after
84
+ comments.collection.previous.should include :limit, :before
85
+ comments.collection.cursors.should include :before, :after
86
+ end
87
+ end
88
+ end
@@ -22,7 +22,7 @@ describe FbGraph::Connection do
22
22
  posts.first.created_time.should == Time.parse('2010-04-27T13:06:14+0000')
23
23
  posts.last.created_time.should == Time.parse('2010-04-27T11:07:48+0000')
24
24
  end
25
- mock_graph :get, 'me/home', 'users/home/me_private_previous', :access_token => 'access_token', :params => {
25
+ mock_graph :get, 'me/home', 'users/home/me_private_previous', :access_token => '2227470867|2.WUnvvW0Q_ksjjVOCIEkEiQ__.3600.1272380400-579612276|Skfo-M8-vpId32OYv6xLZFlsToY.', :params => {
26
26
  :limit => '25',
27
27
  :since => '123456789'
28
28
  } do
@@ -30,7 +30,7 @@ describe FbGraph::Connection do
30
30
  previous_posts.first.created_time.should == Time.parse('2010-04-27T13:23:08+0000')
31
31
  previous_posts.last.created_time.should == Time.parse('2010-04-27T13:10:56+0000')
32
32
  end
33
- mock_graph :get, 'me/home', 'users/home/me_private_next', :access_token => 'access_token', :params => {
33
+ mock_graph :get, 'me/home', 'users/home/me_private_next', :access_token => '2227470867|2.WUnvvW0Q_ksjjVOCIEkEiQ__.3600.1272380400-579612276|Skfo-M8-vpId32OYv6xLZFlsToY.', :params => {
34
34
  :limit => '25',
35
35
  :until => '123456789'
36
36
  } do
@@ -38,5 +38,13 @@ describe FbGraph::Connection do
38
38
  next_posts.first.created_time.should == Time.parse('2010-04-27T11:06:29+0000')
39
39
  next_posts.last.created_time.should == Time.parse('2010-04-27T09:44:28+0000')
40
40
  end
41
+ mock_graph :get, 'me/home', 'users/home/me_private_next', :access_token => 'access_token', :params => {
42
+ :limit => '25',
43
+ :until => '123456789'
44
+ } do
45
+ next_posts = posts.next(:access_token => 'access_token')
46
+ next_posts.first.created_time.should == Time.parse('2010-04-27T11:06:29+0000')
47
+ next_posts.last.created_time.should == Time.parse('2010-04-27T09:44:28+0000')
48
+ end
41
49
  end
42
50
  end
@@ -94,8 +94,8 @@ describe FbGraph::Connections::Insights do
94
94
  it 'should used for pagination' do
95
95
  mock_graph :get, 'FbGraph/insights/page_like_adds/day', 'pages/insights/page_like_adds/day/FbGraph_private', :access_token => 'access_token' do
96
96
  insights = FbGraph::Page.new('FbGraph').insights(:access_token => 'access_token', :metrics => :page_like_adds, :period => :day)
97
- expect { insights.next }.to request_to 'FbGraph/insights/page_like_adds/day?access_token=access_token&since=1292065709&until=1292324909'
98
- expect { insights.previous }.to request_to 'FbGraph/insights/page_like_adds/day?access_token=access_token&since=1291547309&until=1291806509'
97
+ expect { insights.next }.to request_to 'FbGraph/insights/page_like_adds/day?access_token=134145643294322%7C9b95ab3141be69aff9766c90-579612276%7C9UA_-V98QdZDfoX4MSS-DdwTFFk&since=1292065709&until=1292324909'
98
+ expect { insights.previous }.to request_to 'FbGraph/insights/page_like_adds/day?access_token=134145643294322%7C9b95ab3141be69aff9766c90-579612276%7C9UA_-V98QdZDfoX4MSS-DdwTFFk&since=1291547309&until=1291806509'
99
99
  end
100
100
  end
101
101
  end
@@ -124,6 +124,26 @@ describe FbGraph::Exception, ".handle_httpclient_error" do
124
124
  lambda {FbGraph::Exception.handle_httpclient_error(parsed_response, headers)}.should raise_exception(FbGraph::InvalidRequest)
125
125
  end
126
126
  end
127
+
128
+ context "to an an alias that does not exist" do
129
+ let(:parsed_response) do
130
+ {
131
+ :error => {
132
+ :message => '(#803) Some of the aliases you requested do not exist: test',
133
+ :type => "OAuthException"
134
+ }
135
+ }
136
+ end
137
+ let(:headers) do
138
+ {
139
+ "WWW-Authenticate" =>'OAuth "Facebook Platform" "not_found" "(#803) Some of the aliases you requested do not exist: test"'
140
+ }
141
+ end
142
+
143
+ it "should raise a NotFound exception" do
144
+ lambda {FbGraph::Exception.handle_httpclient_error(parsed_response, headers)}.should raise_exception(FbGraph::NotFound)
145
+ end
146
+ end
127
147
  end
128
148
 
129
149
  context "without the WWW-Authenticate header" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fb_graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.7.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: 2013-05-04 00:00:00.000000000 Z
11
+ date: 2013-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient