Skip to content

Commit

Permalink
Support of the official API
Browse files Browse the repository at this point in the history
  • Loading branch information
Niels Richter committed Oct 1, 2015
1 parent cca9d61 commit 4735de0
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 54 deletions.
35 changes: 21 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
omniauth-pinterest (1.0.0)
omniauth-pinterest (1.0.1)
omniauth (~> 1.0)
omniauth-oauth2 (~> 1.0)

Expand All @@ -11,10 +11,8 @@ GEM
addressable (2.2.7)
crack (0.3.1)
diff-lcs (1.1.3)
faraday (0.7.6)
addressable (~> 2.2)
multipart-post (~> 1.1)
rack (~> 1.1)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
ffi (1.0.11)
growl (1.0.3)
guard (1.0.1)
Expand All @@ -25,17 +23,23 @@ GEM
guard (>= 0.2.2)
guard-rspec (0.7.0)
guard (>= 0.10.0)
hashie (1.2.0)
hashie (3.4.2)
httpauth (0.2.1)
jwt (0.1.6)
multi_json (>= 1.0)
multi_json (1.2.0)
multipart-post (1.1.5)
oauth2 (0.5.2)
faraday (~> 0.7)
multipart-post (2.0.0)
oauth2 (0.8.1)
faraday (~> 0.8)
httpauth (~> 0.1)
jwt (~> 0.1.4)
multi_json (~> 1.0)
omniauth (1.0.3)
hashie (~> 1.2)
rack
omniauth-oauth2 (1.0.0)
oauth2 (~> 0.5.0)
rack (~> 1.2)
omniauth (1.2.2)
hashie (>= 1.2, < 4)
rack (~> 1.0)
omniauth-oauth2 (1.1.1)
oauth2 (~> 0.8.0)
omniauth (~> 1.0)
rack (1.4.1)
rack-test (0.6.1)
Expand Down Expand Up @@ -72,3 +76,6 @@ DEPENDENCIES
rspec (~> 2.7)
simplecov
webmock

BUNDLED WITH
1.10.6
11 changes: 0 additions & 11 deletions Guardfile

This file was deleted.

55 changes: 45 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,55 @@
NOTE: Unfortunately the API this library was created for never really existed. It was built against some API documentation that I think they accidentally released for about a week.

# OmniAuth Pinterest

This is the unofficial OmniAuth strategy for authenticating to Pinterest. To
use it, you'll need to sign up for an OAuth2 Application ID and Secret
on the [Pinterest Developer website](http://pinterest.com/developers/api).
This gem contains the [OmniAuth](https://github.com/intridea/omniauth/) strategy for authenticating to [Pinterest](https://www.pinterest.com/).

## Preparation

1. Register and sign into the [Pinterest developer center](https://developers.pinterest.com/)
2. Create an [application](https://developers.pinterest.com/apps/) and note the **App ID** and the **App secret**
3. Make sure that you have already installed [OmniAuth](https://github.com/intridea/omniauth/wiki) into your application. Otherwise check out the [installation details](https://github.com/intridea/omniauth) and the [documentation](https://github.com/intridea/omniauth/wiki).

## Installation

Add this gem to your application's ```Gemfile```:

```ruby
gem 'omniauth-pinterest'
```

## Basic Usage
Execute the ```bundle``` command to install the gem.

use OmniAuth::Builder do
provider :pinterest, ENV['PINTEREST_ID'], ENV['PINTEREST_SECRET']
end
Next, tell OmniAuth about the Pinterest provider. For a Ruby on Rails application, your ```config/initializers/omniauth.rb``` file should look like:

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

After restarting your application, point the authenticating user to ```/auth/pinterest```, the rest will be handled by OmniAuth.

## Authentication hash

Here's an example authentication hash available in ```request.env['omniauth.auth']```:

```ruby
{
:provider => 'pinterest',
:uid => '1234',
:info => {
:id => "1234",
:url => "https://www.pinterest.com/jane_doe/",
:first_name: "Jane"
:last_name => "Doe"
}
}
```

## License

Copyright (c) 2012 Jonathan Markwell and Intridea, Inc.
(The MIT License)

Copyright (c) 2015 Jonathan Markwell, endil GmbH and Intridea, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env rake
require "bundler/gem_tasks"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

desc 'Default: run specs.'
task :default => :spec

desc "Run specs"
desc 'Run specs'
RSpec::Core::RakeTask.new
2 changes: 1 addition & 1 deletion lib/omniauth-pinterest.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require "omniauth-pinterest/version"
require 'omniauth-pinterest/version'
require 'omniauth/strategies/pinterest'
2 changes: 1 addition & 1 deletion lib/omniauth-pinterest/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module OmniAuth
module Pinterest
VERSION = "1.0.0"
VERSION = '1.0.1'
end
end
17 changes: 6 additions & 11 deletions lib/omniauth/strategies/pinterest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module OmniAuth
module Strategies
class Pinterest < OmniAuth::Strategies::OAuth2
option :client_options, {
:site => 'https://pinterest.com',
:authorize_url => 'https://pinterest.com/oauth/authorize',
:token_url => 'https://api.pinterest.com/v2/oauth/access_token'
:site => 'https://api.pinterest.com/',
:authorize_url => 'https://api.pinterest.com/oauth/',
:token_url => 'https://api.pinterest.com/v1/oauth/token'
}

def request_phase
Expand All @@ -17,17 +17,12 @@ def request_phase

uid { raw_info['id'] }

info do
{
'nickname' => raw_info['username'],
'name' => raw_info['full_name'],
'image' => raw_info['image_url'],
}
end
info { raw_info }

def raw_info
@data ||= access_token.params["user"]
@raw_info ||= access_token.get('/v1/me/').parsed['data']
end

end
end
end
8 changes: 4 additions & 4 deletions spec/omniauth/strategies/pinterest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

describe OmniAuth::Strategies::Pinterest do

context "client options" do
context 'client options' do
subject do
OmniAuth::Strategies::Pinterest.new({})
end

it 'should have correct site' do
subject.options.client_options.site.should eq('https://pinterest.com')
subject.options.client_options.site.should eq('https://api.pinterest.com/')
end

it 'should have correct authorize url' do
subject.options.client_options.authorize_url.should eq('https://pinterest.com/oauth/authorize')
subject.options.client_options.authorize_url.should eq('https://api.pinterest.com/oauth/')
end

it 'should have correct token url' do
subject.options.client_options.token_url.should eq('https://api.pinterest.com/v2/oauth/access_token')
subject.options.client_options.token_url.should eq('https://api.pinterest.com/v1/oauth/token')
end
end
end

0 comments on commit 4735de0

Please sign in to comment.