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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +60 -0
- data/Rakefile +2 -0
- data/g5_facebook_api_client.gemspec +30 -0
- data/lib/g5_facebook_api_client/access_token.rb +16 -0
- data/lib/g5_facebook_api_client/base.rb +28 -0
- data/lib/g5_facebook_api_client/insights.rb +32 -0
- data/lib/g5_facebook_api_client/page.rb +28 -0
- data/lib/g5_facebook_api_client/user.rb +12 -0
- data/lib/g5_facebook_api_client/version.rb +3 -0
- data/lib/g5_facebook_api_client.rb +15 -0
- data/spec/fixtures/vcr_cassettes/access_token.yml +48 -0
- data/spec/fixtures/vcr_cassettes/access_token_invalid_client_id.yml +50 -0
- data/spec/fixtures/vcr_cassettes/access_token_invalid_client_secret.yml +50 -0
- data/spec/fixtures/vcr_cassettes/page_posts.yml +243 -0
- data/spec/fixtures/vcr_cassettes/page_posts_invalid_client_id.yml +98 -0
- data/spec/fixtures/vcr_cassettes/page_posts_invalid_client_secret.yml +98 -0
- data/spec/fixtures/vcr_cassettes/user.yml +189 -0
- data/spec/fixtures/vcr_cassettes/user_invalid_client_id.yml +50 -0
- data/spec/fixtures/vcr_cassettes/user_invalid_client_secret.yml +50 -0
- data/spec/lib/g5_facebook_api_client/access_token_spec.rb +41 -0
- data/spec/lib/g5_facebook_api_client/base_spec.rb +34 -0
- data/spec/lib/g5_facebook_api_client/insights_spec.rb +12 -0
- data/spec/lib/g5_facebook_api_client/page_spec.rb +65 -0
- data/spec/lib/g5_facebook_api_client/user_spec.rb +22 -0
- data/spec/spec_helper.rb +12 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9d30689b1584cbb10798078becb15afb9c1005ee
|
4
|
+
data.tar.gz: 7f7e47bc55b70cfaf581154a8ca5feefe9e4d36e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea1e7513f3f374d29291fb14f60aa3987c4324682dbdf16d2830f6b22f3afcd9aa3d86c198959debf068361c4c90734e0322f53ba8de2b9b5eaec56b1da1a5af
|
7
|
+
data.tar.gz: 26825321c5c3b740d9fd9b168256c238da68fca48fc775242614ce58b6c42e8365273b8050414c1c892a921409f4b183827cff72091127cab5eaa213bb180d31
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.5
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 bbauer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# G5 Facebook Api Client
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/g5_facebook_api_client)
|
4
|
+
[](https://travis-ci.org/G5/g5_facebook_api_client.svg?branch=master)
|
5
|
+
|
6
|
+
Facebook Graph API Ruby client for G5 apps
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'g5_facebook_api_client'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install g5_facebook_api_client
|
23
|
+
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```client_id``` and ```client_secret``` parameters can either be passed to
|
28
|
+
the class on instantiation, or set as ```ENV["FACEBOOK_ID"]``` and ```ENV["FACEBOOK_SECRET"]```.
|
29
|
+
|
30
|
+
##### User Permissions
|
31
|
+
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
user = G5FacebookApiClient::User.new("client_id", "client_secret")
|
35
|
+
user.permissions
|
36
|
+
```
|
37
|
+
|
38
|
+
##### Page Feed
|
39
|
+
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
page = G5FacebookApiClient::Page.new("page_id", "client_id", "client_secret")
|
43
|
+
page.posts
|
44
|
+
```
|
45
|
+
|
46
|
+
##### Page Insights
|
47
|
+
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
# Coming Soon
|
51
|
+
```
|
52
|
+
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
1. Fork it ( https://github.com/[my-github-username]/g5_facebook_api_client/fork )
|
57
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
58
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
59
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
60
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'g5_facebook_api_client/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "g5_facebook_api_client"
|
9
|
+
spec.version = G5FacebookApiClient::VERSION
|
10
|
+
spec.authors = ["bbauer"]
|
11
|
+
spec.email = ["brian.bauer@g5platform.com"]
|
12
|
+
spec.summary = %q{Facebook Graph Api Client}
|
13
|
+
spec.description = %q{Facebook Graph Api Client}
|
14
|
+
spec.homepage = ""
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "httparty"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "webmock"
|
28
|
+
spec.add_development_dependency "vcr"
|
29
|
+
spec.add_development_dependency "pry"
|
30
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class G5FacebookApiClient::AccessToken < G5FacebookApiClient::Base
|
2
|
+
RESOURCE = "oauth/access_token"
|
3
|
+
|
4
|
+
def fetch
|
5
|
+
get(access_token_uri)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def access_token_uri
|
11
|
+
"#{G5FacebookApiClient::ENDPOINT}/#{RESOURCE}" \
|
12
|
+
"?client_id=#{@client_id}&client_secret=#{@client_secret}" \
|
13
|
+
"&grant_type=client_credentials"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class G5FacebookApiClient::Base
|
2
|
+
def initialize(client_id=nil, client_secret=nil)
|
3
|
+
@client_id = client_id || ENV["FACEBOOK_ID"]
|
4
|
+
@client_secret = client_secret || ENV["FACEBOOK_SECRET"]
|
5
|
+
end
|
6
|
+
|
7
|
+
def access_token
|
8
|
+
@access_token ||=
|
9
|
+
G5FacebookApiClient::AccessToken.new(@client_id, @client_secret).fetch
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse(body)
|
13
|
+
JSON.parse(body)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(url)
|
17
|
+
HTTParty.get(encode(url)).body
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(url)
|
21
|
+
HTTParty.post(encode(url)).body
|
22
|
+
end
|
23
|
+
|
24
|
+
def encode(string)
|
25
|
+
URI::encode(string)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class G5FacebookApiClient::Insights < G5FacebookApiClient::Base
|
2
|
+
RESOURCE = "insights"
|
3
|
+
|
4
|
+
def initialize(page, client_id=nil, client_secret=nil)
|
5
|
+
@page = page
|
6
|
+
@client_id = client_id || ENV["FACEBOOK_ID"]
|
7
|
+
@client_secret = client_secret || ENV["FACEBOOK_SECRET"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def page_likes
|
11
|
+
parse(request(resource("page_fans_locale/lifetime")))
|
12
|
+
end
|
13
|
+
|
14
|
+
def page_views
|
15
|
+
parse(request(resource("page_views")))
|
16
|
+
end
|
17
|
+
|
18
|
+
def page_impressions
|
19
|
+
parse(request(resource("page_impressions")))
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def resource(metric)
|
25
|
+
"#{@page}/#{RESOURCE}/#{metric}?#{access_token}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def request(resource)
|
29
|
+
get("#{G5FacebookApiClient::BASE_URI}/#{resource}")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class G5FacebookApiClient::Page < G5FacebookApiClient::Base
|
2
|
+
LIMIT = 20
|
3
|
+
|
4
|
+
def initialize(page, client_id=nil, client_secret=nil)
|
5
|
+
@page = page
|
6
|
+
@client_id = client_id || ENV["FACEBOOK_ID"]
|
7
|
+
@client_secret = client_secret || ENV["FACEBOOK_SECRET"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def posts
|
11
|
+
parse(get(posts_uri))
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def posts_uri
|
17
|
+
"#{G5FacebookApiClient::ENDPOINT}/#{@page}/#{feed_parameters}&#{default_parameters}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_parameters
|
21
|
+
"limit=#{LIMIT}&#{access_token}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def feed_parameters
|
25
|
+
"posts?fields=likes.limit(1).summary(true),shares,message,id,created_time,from"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "pry"
|
3
|
+
require "g5_facebook_api_client/base"
|
4
|
+
require "g5_facebook_api_client/version"
|
5
|
+
require "g5_facebook_api_client/page"
|
6
|
+
require "g5_facebook_api_client/insights"
|
7
|
+
require "g5_facebook_api_client/user"
|
8
|
+
require "g5_facebook_api_client/access_token"
|
9
|
+
|
10
|
+
module G5FacebookApiClient
|
11
|
+
ENDPOINT = "https://graph.facebook.com"
|
12
|
+
API_VERSION = "v2.2"
|
13
|
+
BASE_URI = "#{ENDPOINT}/#{API_VERSION}"
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://graph.facebook.com/oauth/access_token?client_id=121584141274833&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: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Facebook-Api-Version:
|
22
|
+
- v1.0
|
23
|
+
Content-Type:
|
24
|
+
- text/plain; charset=UTF-8
|
25
|
+
Pragma:
|
26
|
+
- no-cache
|
27
|
+
Access-Control-Allow-Origin:
|
28
|
+
- "*"
|
29
|
+
X-Fb-Rev:
|
30
|
+
- '1528169'
|
31
|
+
Cache-Control:
|
32
|
+
- private, no-cache, no-store, must-revalidate
|
33
|
+
Expires:
|
34
|
+
- Sat, 01 Jan 2000 00:00:00 GMT
|
35
|
+
X-Fb-Debug:
|
36
|
+
- tB3Fleg4WIvUptu40ZoA1j9SBXJIzxgwDNSJNcWwNWF/VSDTEbakK+ySXdKdB19AMziXPTQOxkej7kg4qvmCwQ==
|
37
|
+
Date:
|
38
|
+
- Thu, 11 Dec 2014 17:19:21 GMT
|
39
|
+
Connection:
|
40
|
+
- keep-alive
|
41
|
+
Content-Length:
|
42
|
+
- '56'
|
43
|
+
body:
|
44
|
+
encoding: UTF-8
|
45
|
+
string: access_token=121584141274833|EzolJusCGWQEJt_mnLvlo7Jiz_Q
|
46
|
+
http_version:
|
47
|
+
recorded_at: Thu, 11 Dec 2014 17:19:22 GMT
|
48
|
+
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=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
|
+
- '1527549'
|
33
|
+
Cache-Control:
|
34
|
+
- no-store
|
35
|
+
Expires:
|
36
|
+
- Sat, 01 Jan 2000 00:00:00 GMT
|
37
|
+
X-Fb-Debug:
|
38
|
+
- G/zykKfupeCmp1VhZfdqYo59PH2+uRAf/q0xSFimU6E94ULP5J/DjKs8zV0W6XrtKpz/DtldekHmkZyNZJ0Sew==
|
39
|
+
Date:
|
40
|
+
- Thu, 11 Dec 2014 17:20:49 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: Thu, 11 Dec 2014 17:20:50 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
|
+
- '1528169'
|
33
|
+
Cache-Control:
|
34
|
+
- no-store
|
35
|
+
Expires:
|
36
|
+
- Sat, 01 Jan 2000 00:00:00 GMT
|
37
|
+
X-Fb-Debug:
|
38
|
+
- Y+WGNa7VKxKQKg+ex4ifCRysyyKXexUJmjdz6TCrn6JpSvSv7S+UZxEJKTLVb9U0lLPDdVw3bOKC1FxpWQz3gQ==
|
39
|
+
Date:
|
40
|
+
- Thu, 11 Dec 2014 17:21:56 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: Thu, 11 Dec 2014 17:21:58 GMT
|
50
|
+
recorded_with: VCR 2.9.3
|