Skip to content

Commit

Permalink
oauth + cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
Adeel Ahmad committed Oct 3, 2015
1 parent 7e9b7e8 commit bee39b2
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 5 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ client.get_user('<username>')

```

## Authentication

You can generate access tokens through the link above, or you can use OAuth
Authentication

In your app, make sure you have the omniauth gem installed. Add the following
to your ```intializers/omniauth.rb``` file

```ruby

Rails.application.config.middleware.use OmniAuth::Builder do
provider :pinterest, ENV['PINTEREST_APP_ID'], ENV['PINTEREST_APP_SECRET']
end

```

Direct your users to ```/auth/pinterest```

Once they approve your app, they'll be redirect to your callback URL, which
should be something like ```auth/pinterest/callback``` with a hash of
OAuth values from Pinterest in ```request.env['omniauth.auth']```

For more details, check out "Integrating OmniAuth Into Your Application"
https://github.com/intridea/omniauth

## Known Issues

The gem is currently under active development.
Expand Down
1 change: 1 addition & 0 deletions lib/pinterest-api.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "pinterest/version"
require "pinterest/client"
require "pinterest/omniauth"

module Pinterest

Expand Down
28 changes: 28 additions & 0 deletions lib/pinterest/omniauth.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'omniauth-oauth2'

module OmniAuth
module Strategies
class Pinterest < OmniAuth::Strategies::OAuth2
option :client_options, {
:site => 'https://api.pinterest.com/',
:authorize_url => 'https://api.pinterest.com/oauth/',
:token_url => 'https://api.pinterest.com/v1/oauth/token'
}

def request_phase
options[:scope] ||= 'read_public,write_public'
options[:response_type] ||= 'token'
#options[:state] ||= '22'
super
end

uid { raw_info['id'] }

info { raw_info }

def raw_info
@raw_info ||= access_token.get('/v1/me/').parsed['data']
end
end
end
end
2 changes: 1 addition & 1 deletion lib/pinterest/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Pinterest
VERSION = "0.1.1"
VERSION = "0.2.0"
end
Binary file added pinterest-api-0.2.0.gem
Binary file not shown.
7 changes: 5 additions & 2 deletions pinterest.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Gem::Specification.new do |spec|

spec.summary = %q{Ruby gem to interact with the Pinterest REST API}
spec.description = %q{This gem makes it simple to interact with the official Pinterest REST API}
spec.homepage = "http://github.com/realadeel"
spec.homepage = "http://github.com/realadeel/pinterest-api"
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
Expand All @@ -24,8 +24,11 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rspec", "~> 3.3"
spec.add_development_dependency "vcr", "~> 2.9"
spec.add_development_dependency "dotenv", "~> 2.0"
spec.add_development_dependency "webmock", "~> 1.0"

spec.add_dependency 'faraday', "~> 0.9"
spec.add_dependency 'faraday_middleware', ">= 0.9.0"
spec.add_dependency 'faraday_middleware', "~> 0.9"
spec.add_dependency 'hashie', "~> 3.0"
spec.add_dependency 'omniauth', '~> 1.0'
spec.add_dependency 'omniauth-oauth2', '~> 1.0'
end
21 changes: 21 additions & 0 deletions spec/omniauth_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'spec_helper'

describe "Omniauth::Strategies::Pinterest" do
context 'client options' do
before :each do
@auth = OmniAuth::Strategies::Pinterest.new({})
end

it 'should call correct base url' do
expect(@auth.options.client_options.site).to eq('https://api.pinterest.com/')
end

it 'should call correct authorization url' do
expect(@auth.options.client_options.authorize_url).to eq('https://api.pinterest.com/oauth/')
end

it 'should call correct token url' do
expect(@auth.options.client_options.token_url).to eq('https://api.pinterest.com/v1/oauth/token')
end
end
end
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'pinterest'
require 'pinterest-api'

require 'vcr'
require 'webmock/rspec'
Expand All @@ -14,7 +14,7 @@
VCR.configure do |c|
c.cassette_library_dir = "spec/fixtures/cassettes"
c.hook_into :webmock
c.default_cassette_options = { record: :once }
c.default_cassette_options = { record: :none }
c.filter_sensitive_data('<HIDDEN>') do |interaction|
ENV['ACCESS_TOKEN']
end
Expand Down

0 comments on commit bee39b2

Please sign in to comment.