-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from Fullscreen/focus-on-auth
Extract non-auth methods into separate libraries
- Loading branch information
Showing
18 changed files
with
77 additions
and
431 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ By default, Fb::Auth will look for the environment variables called `FB_CLIENT_I | |
## Usage | ||
|
||
Fb::Auth#url | ||
--------------------- | ||
------------ | ||
|
||
The `url` method helps you obtain a URL where to redirect users who need to | ||
authenticate with their Facebook account in order to use your application: | ||
|
@@ -40,6 +40,9 @@ Fb::Auth.new(redirect_uri: redirect_uri).url | |
# => https://www.facebook.com/dialog/oauth?client_id=...&scope=manage_pages&redirect_uri=https%3A%2F%2Fexample.com%2Fauth | ||
``` | ||
|
||
Note that access is always requested with permission to access email, | ||
manage pages and read insights. | ||
|
||
Fb::Auth#access_token | ||
--------------------- | ||
|
||
|
@@ -56,69 +59,6 @@ Fb::Auth.new(redirect_uri: redirect_uri, code: code).access_token | |
# => "kefjej49s82hFS@2333233222FDh66" | ||
``` | ||
|
||
Fb::User#pages | ||
--------------------- | ||
|
||
Once you have successfully obtain an access token, you can fetch the pages managed | ||
by that access token. Calling `Fb::User.new(access_token).pages` will return an | ||
array of type Fb::Page, each with an id and name. | ||
|
||
```ruby | ||
access_token = Fb::Auth.new(redirect_uri: redirect_uri, code: code).access_token | ||
Fb::User.new(access_token).pages | ||
# => [#<Fb::Page: id="1234", name="sample1">, #<Fb::Page: id="5678", name="sample2">] | ||
``` | ||
|
||
Fb::User#email | ||
--------------------- | ||
|
||
Similarly, you can get the email of the user by calling `Fb::User.new(access_token).email`. | ||
|
||
```ruby | ||
access_token = Fb::Auth.new(redirect_uri: redirect_uri, code: code).access_token | ||
Fb::User.new(access_token).email | ||
# => "[email protected]" | ||
``` | ||
|
||
Fb::Page#insights | ||
--------------------- | ||
|
||
For each page object, you can fetch page insights for these [available metrics](https://developers.facebook.com/docs/graph-api/reference/v2.9/insights#availmetrics). The insights method takes a hash of three options: | ||
|
||
[String] :since The lower bound of the time range to consider. | ||
[String] :period The aggregation period (must be available to all | ||
given metrics). | ||
[Array] :metric A list of metrics. | ||
|
||
Insights will return a hash with the name of each metric as the key and the metric object as the value. | ||
|
||
```ruby | ||
options = { | ||
metric: %i(page_fan_adds_unique page_engaged_users page_views_total), | ||
period: :week, | ||
since: '2017-06-09' # sample date format | ||
} | ||
page = Fb::User.new('token').pages.first | ||
page.insights(options) | ||
# => {"page_fan_adds_unique"=>#<Fb::Metric:0x123abc | ||
# @name="page_fan_adds_unique", @description="Weekly: The | ||
# number of new people who have liked your Page (Unique Users)", | ||
# @value=123>,..} | ||
``` | ||
|
||
Fb::Error | ||
------------- | ||
|
||
`Fb::Error` will be raised when an issue occurs during the Facebook authentication process. | ||
The message of the error will include the details: | ||
|
||
```ruby | ||
redirect_uri = 'https://example.com/auth' # REPLACE WITH REAL ONE | ||
code = 'invalid-code' | ||
Fb::Auth.new(redirect_uri: redirect_uri, code: code).access_token | ||
# => Fb::Error: Invalid verification code format. | ||
``` | ||
|
||
## Development | ||
|
||
After checking out the repo, run `bin/setup` to install dependencies. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path("../lib", __FILE__) | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require "fb/auth/version" | ||
require 'fb/auth/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "fb-auth" | ||
spec.name = 'fb-auth' | ||
spec.version = Fb::Auth::VERSION | ||
spec.authors = ['Aaron Dao', 'Claudio Baccigalupo'] | ||
spec.email = ['[email protected]', '[email protected]'] | ||
|
||
spec.summary = %q{Ruby client to authenticate a Facebook user.} | ||
spec.description = %q{Fb::Auth provides methods to obtain an access token to | ||
manage pages of a Facebook user.} | ||
spec.homepage = "https://github.com/Fullscreen/fb-auth" | ||
spec.license = "MIT" | ||
spec.homepage = 'https://github.com/Fullscreen/fb-auth' | ||
spec.license = 'MIT' | ||
|
||
spec.files = `git ls-files -z`.split("\x0").reject do |f| | ||
f.match(%r{^(test|spec|features)/}) | ||
end | ||
spec.bindir = "exe" | ||
spec.bindir = 'exe' | ||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } | ||
spec.require_paths = ["lib"] | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_development_dependency "bundler", "~> 1.15" | ||
spec.add_development_dependency "rake", "~> 10.0" | ||
spec.add_development_dependency "rspec", "~> 3.0" | ||
spec.add_development_dependency "yard", "~> 0.9.9" | ||
spec.add_dependency 'fb-support', '~> 1.0.0.alpha1' | ||
|
||
spec.add_development_dependency 'bundler', '~> 1.15' | ||
spec.add_development_dependency 'rake', '~> 10.0' | ||
spec.add_development_dependency 'rspec', '~> 3.0' | ||
spec.add_development_dependency 'yard', '~> 0.9.9' | ||
spec.add_development_dependency 'coveralls' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.