g5_facebook_api_client 0.0.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.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +4 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +60 -0
  9. data/Rakefile +2 -0
  10. data/g5_facebook_api_client.gemspec +30 -0
  11. data/lib/g5_facebook_api_client/access_token.rb +16 -0
  12. data/lib/g5_facebook_api_client/base.rb +28 -0
  13. data/lib/g5_facebook_api_client/insights.rb +32 -0
  14. data/lib/g5_facebook_api_client/page.rb +28 -0
  15. data/lib/g5_facebook_api_client/user.rb +12 -0
  16. data/lib/g5_facebook_api_client/version.rb +3 -0
  17. data/lib/g5_facebook_api_client.rb +15 -0
  18. data/spec/fixtures/vcr_cassettes/access_token.yml +48 -0
  19. data/spec/fixtures/vcr_cassettes/access_token_invalid_client_id.yml +50 -0
  20. data/spec/fixtures/vcr_cassettes/access_token_invalid_client_secret.yml +50 -0
  21. data/spec/fixtures/vcr_cassettes/page_posts.yml +243 -0
  22. data/spec/fixtures/vcr_cassettes/page_posts_invalid_client_id.yml +98 -0
  23. data/spec/fixtures/vcr_cassettes/page_posts_invalid_client_secret.yml +98 -0
  24. data/spec/fixtures/vcr_cassettes/user.yml +189 -0
  25. data/spec/fixtures/vcr_cassettes/user_invalid_client_id.yml +50 -0
  26. data/spec/fixtures/vcr_cassettes/user_invalid_client_secret.yml +50 -0
  27. data/spec/lib/g5_facebook_api_client/access_token_spec.rb +41 -0
  28. data/spec/lib/g5_facebook_api_client/base_spec.rb +34 -0
  29. data/spec/lib/g5_facebook_api_client/insights_spec.rb +12 -0
  30. data/spec/lib/g5_facebook_api_client/page_spec.rb +65 -0
  31. data/spec/lib/g5_facebook_api_client/user_spec.rb +22 -0
  32. data/spec/spec_helper.rb +12 -0
  33. metadata +188 -0
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://graph.facebook.com/oauth/access_token?client_id=foo&client_secret=b0d3826624470f5f5c3e70ce70893ed4&grant_type=client_credentials
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 500
19
+ message: Internal Server Error
20
+ headers:
21
+ Www-Authenticate:
22
+ - OAuth "Facebook Platform" "unknown_error" "An unknown error has occurred."
23
+ Facebook-Api-Version:
24
+ - v1.0
25
+ Content-Type:
26
+ - application/json; charset=UTF-8
27
+ Pragma:
28
+ - no-cache
29
+ Access-Control-Allow-Origin:
30
+ - "*"
31
+ X-Fb-Rev:
32
+ - '1532927'
33
+ Cache-Control:
34
+ - no-store
35
+ Expires:
36
+ - Sat, 01 Jan 2000 00:00:00 GMT
37
+ X-Fb-Debug:
38
+ - ld274SrecbAMTr3yq5bKqwwL+mHajfDlL0UHif/3lsPwKFBn7NmDh9mcN6BXEJjSPRkKkCrJtpAiF5LWTYugIQ==
39
+ Date:
40
+ - Tue, 16 Dec 2014 01:47:00 GMT
41
+ Connection:
42
+ - keep-alive
43
+ Content-Length:
44
+ - '87'
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"error":{"message":"An unknown error has occurred.","type":"OAuthException","code":1}}'
48
+ http_version:
49
+ recorded_at: Tue, 16 Dec 2014 01:47:01 GMT
50
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://graph.facebook.com/oauth/access_token?client_id=121584141274833&client_secret=bar&grant_type=client_credentials
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 400
19
+ message: Bad Request
20
+ headers:
21
+ Www-Authenticate:
22
+ - OAuth "Facebook Platform" "invalid_request" "Error validating client secret."
23
+ Facebook-Api-Version:
24
+ - v1.0
25
+ Content-Type:
26
+ - application/json; charset=UTF-8
27
+ Pragma:
28
+ - no-cache
29
+ Access-Control-Allow-Origin:
30
+ - "*"
31
+ X-Fb-Rev:
32
+ - '1532927'
33
+ Cache-Control:
34
+ - no-store
35
+ Expires:
36
+ - Sat, 01 Jan 2000 00:00:00 GMT
37
+ X-Fb-Debug:
38
+ - FL4l/a533waILrxJtdjLcH2f9lUwo80KPEai754wXJVprpFOzsDvPm3rWvJPaNvKUM9jB5psrdKFOIr22zed1A==
39
+ Date:
40
+ - Tue, 16 Dec 2014 01:47:01 GMT
41
+ Connection:
42
+ - keep-alive
43
+ Content-Length:
44
+ - '88'
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"error":{"message":"Error validating client secret.","type":"OAuthException","code":1}}'
48
+ http_version:
49
+ recorded_at: Tue, 16 Dec 2014 01:47:01 GMT
50
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ describe G5FacebookApiClient::AccessToken do
4
+ let(:client_id) { "121584141274833" }
5
+ let(:client_secret) { "b0d3826624470f5f5c3e70ce70893ed4" }
6
+ let(:access_token_fetcher) { described_class.new(client_id, client_secret) }
7
+
8
+ describe "#fetch" do
9
+ subject { access_token_fetcher.fetch }
10
+
11
+ context "valid params" do
12
+ it "fetches an access token for a client" do
13
+ VCR.use_cassette("access_token") do
14
+ expect(subject).
15
+ to eq("access_token=121584141274833|EzolJusCGWQEJt_mnLvlo7Jiz_Q")
16
+ end
17
+ end
18
+ end
19
+
20
+ context "invalid client_id param" do
21
+ let(:client_id) { "foo" }
22
+
23
+ it "it explodes with an oauth error" do
24
+ VCR.use_cassette("access_token_invalid_client_id") do
25
+ expect(subject).to include("OAuthException")
26
+ end
27
+ end
28
+ end
29
+
30
+ context "invalid client_id param" do
31
+ let(:client_secret) { "bar" }
32
+
33
+ it "it explodes with an oauth error" do
34
+ VCR.use_cassette("access_token_invalid_client_secret") do
35
+ expect(subject).to include("OAuthException")
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,34 @@
1
+ require "spec_helper"
2
+
3
+ describe G5FacebookApiClient::Base do
4
+ let(:client_id) { "121584141274833" }
5
+ let(:client_secret) { "b0d3826624470f5f5c3e70ce70893ed4" }
6
+ let(:base) { described_class.new(client_id, client_secret) }
7
+ let(:response) { double(body: "bar") }
8
+
9
+ describe "#parse" do
10
+ subject { base.parse('{ "foo":"bar" }') }
11
+ specify { expect(subject).to eq({ "foo" => "bar" }) }
12
+ end
13
+
14
+ describe "#get" do
15
+ before { HTTParty.stub(get: response) }
16
+ subject { base.get("foo") }
17
+
18
+ specify { expect(subject).to eq("bar") }
19
+ end
20
+
21
+ describe "#post" do
22
+ before { HTTParty.stub(post: response) }
23
+ subject { base.post("http://foo.com") }
24
+
25
+ specify { expect(subject).to eq("bar") }
26
+ end
27
+
28
+ describe "#encode" do
29
+ subject { base.encode("foo|bar") }
30
+
31
+ specify { expect(subject).to eq("foo%7Cbar") }
32
+ end
33
+ end
34
+
@@ -0,0 +1,12 @@
1
+ require "spec_helper"
2
+
3
+ describe G5FacebookApiClient::Insights do
4
+ let(:insights) { described_class.new }
5
+
6
+ describe "#page_likes" do
7
+ end
8
+
9
+ describe "#page_views" do
10
+ end
11
+ end
12
+
@@ -0,0 +1,65 @@
1
+ require "spec_helper"
2
+
3
+ describe G5FacebookApiClient::Page do
4
+ let(:page_id) { "GetG5" }
5
+ let(:client_id) { "121584141274833" }
6
+ let(:client_secret) { "b0d3826624470f5f5c3e70ce70893ed4" }
7
+ let(:page) { described_class.new(page_id, client_id, client_secret) }
8
+
9
+ describe "#posts" do
10
+ subject { VCR.use_cassette("page_posts") { page.posts } }
11
+
12
+ it "fetches posts for a page" do
13
+ expect(subject["data"].size).to eq(20)
14
+ end
15
+
16
+ describe "individual post data" do
17
+ context "a post with no shares" do
18
+ let(:post) { subject["data"].first }
19
+
20
+ specify { expect(post["shares"]).to be_nil }
21
+ specify { expect(post["message"]).to include("Check out a few G5ers") }
22
+ specify { expect(post["id"]).to eq("15485466463_10152611792811464") }
23
+ specify { expect(post["created_time"]).to eq("2014-12-15T21:40:09+0000") }
24
+
25
+ it "has 'from' data" do
26
+ expect(post["from"]).to eq({
27
+ "category" => "Local business",
28
+ "category_list" => [{
29
+ "id" => "187133811318958",
30
+ "name" => "Business Services"
31
+ }],
32
+ "name" => "G5",
33
+ "id" => "15485466463"
34
+ })
35
+ end
36
+
37
+ it "has 'likes' data" do
38
+ expect(post["likes"]).to eq({
39
+ "data" => [{
40
+ "id" => "755437763",
41
+ "name" => "Sara Lamb Hobin"
42
+ }],
43
+ "paging" => {
44
+ "cursors" => {
45
+ "after" => "NzU1NDM3NzYz",
46
+ "before" => "NzU1NDM3NzYz"
47
+ },
48
+ "next" => "https://graph.facebook.com/v1.0/15485466463_10152611792811464/" \
49
+ "likes?limit=1&summary=true&access_token=121584141274833|" \
50
+ "EzolJusCGWQEJt_mnLvlo7Jiz_Q&after=NzU1NDM3NzYz"
51
+ },
52
+ "summary" => { "total_count" =>8 }
53
+ })
54
+ end
55
+ end
56
+
57
+ context "a post with no shares" do
58
+ let(:post) { subject["data"].last }
59
+
60
+ specify { expect(post["shares"]).to eq({ "count" => 1 }) }
61
+ end
62
+ end
63
+ end
64
+ end
65
+
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ describe G5FacebookApiClient::User do
4
+ let(:client_id) { "509257122550305" }
5
+ let(:client_secret) { "7fdaa62f5bdcbaeb7fd8b0f5ba137f7c" }
6
+ let(:user) { described_class.new(client_id, client_secret) }
7
+
8
+ describe "#permissions" do
9
+ subject { VCR.use_cassette("user") { user.permissions } }
10
+
11
+ it "returns an app's permissions" do
12
+ expect(subject).to eq({
13
+ "data" => [
14
+ { "permission" => "public_profile", "status" => "live" },
15
+ { "permission" => "user_friends", "status" => "live"},
16
+ { "permission" => "email", "status" => "live" }
17
+ ]
18
+ })
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,12 @@
1
+ require "g5_facebook_api_client"
2
+ require 'webmock/rspec'
3
+ require "vcr"
4
+
5
+ VCR.configure do |c|
6
+ c.cassette_library_dir = "spec/fixtures/vcr_cassettes"
7
+ c.hook_into :webmock
8
+ c.allow_http_connections_when_no_cassette = true
9
+ end
10
+
11
+ RSpec.configure do |c|
12
+ end
metadata ADDED
@@ -0,0 +1,188 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: g5_facebook_api_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - bbauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
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'
111
+ description: Facebook Graph Api Client
112
+ email:
113
+ - brian.bauer@g5platform.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".ruby-version"
121
+ - ".travis.yml"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - g5_facebook_api_client.gemspec
127
+ - lib/g5_facebook_api_client.rb
128
+ - lib/g5_facebook_api_client/access_token.rb
129
+ - lib/g5_facebook_api_client/base.rb
130
+ - lib/g5_facebook_api_client/insights.rb
131
+ - lib/g5_facebook_api_client/page.rb
132
+ - lib/g5_facebook_api_client/user.rb
133
+ - lib/g5_facebook_api_client/version.rb
134
+ - spec/fixtures/vcr_cassettes/access_token.yml
135
+ - spec/fixtures/vcr_cassettes/access_token_invalid_client_id.yml
136
+ - spec/fixtures/vcr_cassettes/access_token_invalid_client_secret.yml
137
+ - spec/fixtures/vcr_cassettes/page_posts.yml
138
+ - spec/fixtures/vcr_cassettes/page_posts_invalid_client_id.yml
139
+ - spec/fixtures/vcr_cassettes/page_posts_invalid_client_secret.yml
140
+ - spec/fixtures/vcr_cassettes/user.yml
141
+ - spec/fixtures/vcr_cassettes/user_invalid_client_id.yml
142
+ - spec/fixtures/vcr_cassettes/user_invalid_client_secret.yml
143
+ - spec/lib/g5_facebook_api_client/access_token_spec.rb
144
+ - spec/lib/g5_facebook_api_client/base_spec.rb
145
+ - spec/lib/g5_facebook_api_client/insights_spec.rb
146
+ - spec/lib/g5_facebook_api_client/page_spec.rb
147
+ - spec/lib/g5_facebook_api_client/user_spec.rb
148
+ - spec/spec_helper.rb
149
+ homepage: ''
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.4.3
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Facebook Graph Api Client
173
+ test_files:
174
+ - spec/fixtures/vcr_cassettes/access_token.yml
175
+ - spec/fixtures/vcr_cassettes/access_token_invalid_client_id.yml
176
+ - spec/fixtures/vcr_cassettes/access_token_invalid_client_secret.yml
177
+ - spec/fixtures/vcr_cassettes/page_posts.yml
178
+ - spec/fixtures/vcr_cassettes/page_posts_invalid_client_id.yml
179
+ - spec/fixtures/vcr_cassettes/page_posts_invalid_client_secret.yml
180
+ - spec/fixtures/vcr_cassettes/user.yml
181
+ - spec/fixtures/vcr_cassettes/user_invalid_client_id.yml
182
+ - spec/fixtures/vcr_cassettes/user_invalid_client_secret.yml
183
+ - spec/lib/g5_facebook_api_client/access_token_spec.rb
184
+ - spec/lib/g5_facebook_api_client/base_spec.rb
185
+ - spec/lib/g5_facebook_api_client/insights_spec.rb
186
+ - spec/lib/g5_facebook_api_client/page_spec.rb
187
+ - spec/lib/g5_facebook_api_client/user_spec.rb
188
+ - spec/spec_helper.rb