Skip to content

Commit

Permalink
Merge pull request #1 from doomspork/implementation
Browse files Browse the repository at this point in the history
Implementation of PG&E strategy
  • Loading branch information
doomspork committed May 18, 2015
2 parents 2c8a45b + 234c5f2 commit 91f9213
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 17 deletions.
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
language: ruby
rvm:
- 2.2.2
- 2.1.1
- 2.0.0
- ruby-head
script: bundle exec rspec
matrix:
allow_failures:
- rvm: ruby-head
34 changes: 34 additions & 0 deletions lib/omniauth/strategies/pge.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'omniauth-oauth2'

module OmniAuth
module Strategies
class PGE < OmniAuth::Strategies::OAuth2
option :client_options, {
site: 'https://api.pge.com',
authorize_url: 'https://api.pge.com/datacustodian/test/oauth/v2/authorize',
token_url: 'https://api.pge.com/datacustodian/test/oauth/v2/token'
}

def request_phase
super
end

def authorize_params
super.tap do |params|
%w[scope client_options].each do |v|
if request.params[v]
params[v.to_sym] = request.params[v]
end
end
end
end

uid { raw_info['id'].to_s }

info do
end
end
end
end

OmniAuth.config.add_camelization 'pge', 'PGE'
12 changes: 7 additions & 5 deletions omniauth-pge.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ Gem::Specification.new do |spec|
spec.authors = ['Sean Callan']
spec.email = ['[email protected]']

spec.summary = %q{OmniAuth strategy for PG&E.}
spec.summary = 'OmniAuth strategy for PG&E.'
spec.homepage = 'https://github.com/doomspork/omniauth-pge'
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ['lib']

spec.add_runtime_dependency 'omniauth-oauth2', '~> 1.3'

spec.add_development_dependency 'bundler', '~> 1.9'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_dependency 'omniauth-oauth2', '~> 1.3'

spec.add_development_dependency 'bundler', '> 1.7'
spec.add_development_dependency 'coveralls', '~> 0.8'
spec.add_development_dependency 'rack-test', '~> 0.6.3'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.2'
spec.add_development_dependency 'simplecov', '~> 0.10'
spec.add_development_dependency 'webmock', '~> 1.21'
end
11 changes: 0 additions & 11 deletions spec/omniauth/pge_spec.rb

This file was deleted.

60 changes: 60 additions & 0 deletions spec/omniauth/strategies/pge_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require 'spec_helper'

module OmniAuth
module Strategies
describe PGE do
let(:access_token) { stub('AccessToken', options: {}) }
let(:parsed_response) { stub('ParsedResponse') }
let(:response) { stub('Response', parsed: parsed_response) }

let(:production_site) { 'https://some.other.site.com/api/v3' }
let(:production_authorize_url) { 'https://some.other.site.com/login/oauth/authorize' }
let(:production_token_url) { 'https://some.other.site.com/login/oauth/access_token' }
let(:production) do
OmniAuth::Strategies::PGE.new('PGE_KEY', 'PGE_SECRET', {
client_options: {
site: production_site,
authorize_url: production_authorize_url,
token_url: production_token_url
}
})
end

subject do
OmniAuth::Strategies::PGE.new({})
end

before(:each) do
allow(subject).to receive(:access_token) { access_token }
end

context 'client options' do
it 'should have correct site' do
expect(subject.options.client_options.site).to eq 'https://api.pge.com'
end

it 'should have correct authorize url' do
expect(subject.options.client_options.authorize_url).to eq 'https://api.pge.com/datacustodian/test/oauth/v2/authorize'
end

it 'should have correct token url' do
expect(subject.options.client_options.token_url).to eq 'https://api.pge.com/datacustodian/test/oauth/v2/token'
end

describe 'should be overrideable' do
it 'for site' do
expect(production.options.client_options.site).to eq production_site
end

it 'for authorize url' do
expect(production.options.client_options.authorize_url).to eq production_authorize_url
end

it 'for token url' do
expect(production.options.client_options.token_url).to eq production_token_url
end
end
end
end
end
end
8 changes: 7 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

require 'coveralls'
require 'simplecov'
require 'rack/test'
require 'webmock/rspec'

SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]

Expand All @@ -12,11 +14,15 @@
coverage_dir 'docs/coverage'
end

require 'omniauth/pge'
require 'omniauth'
require 'omniauth-pge'

Dir['spec/support/**/*.rb'].each { |f| require f }

RSpec.configure do |config|
config.pattern = '**/*_spec.rb'
config.mock_framework = :rspec
config.include WebMock::API
config.include Rack::Test::Methods
config.extend OmniAuth::Test::StrategyMacros, type: :strategy
end

0 comments on commit 91f9213

Please sign in to comment.