omniauth-tradier 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ --markup markdown
2
+ -
3
+ LICENSE.md
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Tradier Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,46 @@
1
+ # OmniAuth Tradier
2
+
3
+ This is the official OmniAuth strategy for authenticating with Tradier's API. To
4
+ use it, you'll need a Client ID and Secret which can be obtained from [developer.tradier.com](https://developer.tradier.com/).
5
+
6
+ ## Usage
7
+
8
+ Add the strategy to your `Gemfile`:
9
+
10
+ ```ruby
11
+ gem 'omniauth-tradier'
12
+ ```
13
+
14
+ Then integrate the strategy into your middleware:
15
+
16
+ ```ruby
17
+ use OmniAuth::Builder do
18
+ provider :tradier, ENV['CLIENT_ID'], ENV['SECRET']
19
+ end
20
+ ```
21
+
22
+ In Rails, you'll want to add to the middleware stack:
23
+
24
+ ```ruby
25
+ Rails.application.config.middleware.use OmniAuth::Builder do
26
+ provider :tradier, ENV['CLIENT_ID'], ENV['SECRET']
27
+ end
28
+ ```
29
+
30
+ ### Scopes
31
+
32
+ Tradier's API lets you set scopes to provide granular access to different types of data:
33
+
34
+ ```ruby
35
+ use OmniAuth::Builder do
36
+ provider :tradier, ENV['CLIENT_ID'], ENV['SECRET'], :scope => "read,write,trade"
37
+ end
38
+ ```
39
+
40
+ For more information on available scopes, refer to Tradier's [API documentation][scope].
41
+
42
+ [scope]: http://developer.tradier.com/documentation/overview/registration
43
+
44
+ ## Copyright
45
+
46
+ Copyright (c) 2013 Tradier Inc. See [LICENSE](LICENSE.md) for detail.
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
4
+
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
9
+ task :test => :spec
10
+
11
+ require 'yard'
12
+ namespace :doc do
13
+ YARD::Rake::YardocTask.new do |task|
14
+ task.files = ['LICENSE.md', 'lib/**/*.rb']
15
+ task.options = ['--markup', 'markdown']
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ require 'omniauth/strategies/tradier'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Tradier
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,47 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Tradier < OmniAuth::Strategies::OAuth2
6
+
7
+ DEFAULT_SCOPE = 'read,write,market,trade,stream'
8
+
9
+ option :client_options, {
10
+ :site => 'https://api.tradier.com',
11
+ :authorize_url => 'https://api.tradier.com/v1/oauth/authorize',
12
+ :token_url => 'https://api.tradier.com/v1/oauth/accesstoken'
13
+ }
14
+
15
+ def authorize_params
16
+ super.tap do |params|
17
+ %w[scope].each do |v|
18
+ if request.params[v]
19
+ params[v.to_sym] = request.params[v]
20
+ end
21
+ end
22
+
23
+ params[:scope] ||= DEFAULT_SCOPE
24
+ end
25
+ end
26
+
27
+ uid { raw_info['profile']['id'] }
28
+
29
+ info do
30
+ {
31
+ 'name' => raw_info['profile']['name']
32
+ }
33
+ end
34
+
35
+ extra do
36
+ { :raw_info => raw_info }
37
+ end
38
+
39
+ def raw_info
40
+ @raw_info ||= access_token.get('/v1/user/profile', :headers => { 'Accept' => 'application/json' }).parsed
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+
47
+ OmniAuth.config.add_camelization 'tradier', 'Tradier'
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth-tradier/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "omniauth-tradier"
8
+ gem.version = OmniAuth::Tradier::VERSION
9
+
10
+ gem.authors = ["Jason Barry", "Steve Agalloco"]
11
+ gem.email = ["jbarry@tradier.com", "sagalloco@tradier.com"]
12
+
13
+ gem.description = %q{OmniAuth strategy for the Tradier API}
14
+ gem.summary = %q{OmniAuth strategy for the Tradier API}
15
+ gem.homepage = "https://githubm.com/tradier/omniauth-tradier"
16
+
17
+ gem.license = 'MIT'
18
+
19
+ gem.add_dependency 'omniauth-oauth2', '~> 1.1'
20
+
21
+ gem.files = %w(.yardopts LICENSE.md README.md Rakefile omniauth-tradier.gemspec)
22
+ gem.files += Dir.glob("lib/**/*.rb")
23
+ gem.files += Dir.glob("spec/**/*")
24
+
25
+ gem.test_files = Dir.glob("spec/**/*")
26
+
27
+ gem.require_paths = ["lib"]
28
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Tradier do
4
+ let(:access_token) { double('AccessToken', :options => {}) }
5
+ let(:parsed_response) { double('ParsedResponse') }
6
+ let(:response) { double('Response', :parsed => parsed_response) }
7
+
8
+ subject do
9
+ OmniAuth::Strategies::Tradier.new({})
10
+ end
11
+
12
+ before(:each) do
13
+ allow(subject).to receive(:access_token).and_return(access_token)
14
+ end
15
+
16
+ context "client options" do
17
+ it 'should have correct site' do
18
+ expect(subject.options.client_options.site).to eq("https://api.tradier.com")
19
+ end
20
+
21
+ it 'should have correct authorize url' do
22
+ expect(subject.options.client_options.authorize_url).to eq('https://api.tradier.com/v1/oauth/authorize')
23
+ end
24
+
25
+ it 'should have correct token url' do
26
+ expect(subject.options.client_options.token_url).to eq('https://api.tradier.com/v1/oauth/accesstoken')
27
+ end
28
+ end
29
+
30
+ context "#raw_info" do
31
+ it "should use relative paths" do
32
+ access_token.should_receive(:get).with('/v1/user/profile', kind_of(Hash)).and_return(response)
33
+ expect(subject.raw_info).to eq(parsed_response)
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ unless ENV['CI']
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_group 'GemTemplate', 'lib/gem_template'
6
+ add_group 'Specs', 'spec'
7
+ end
8
+ end
9
+
10
+ require 'rspec'
11
+ require 'rack/test'
12
+ require 'webmock/rspec'
13
+ require 'omniauth-tradier'
14
+
15
+ RSpec.configure do |config|
16
+ config.expect_with :rspec do |c|
17
+ c.syntax = :expect
18
+ end
19
+
20
+ config.include WebMock::API
21
+ config.include Rack::Test::Methods
22
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
23
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-tradier
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Barry
9
+ - Steve Agalloco
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-11-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: omniauth-oauth2
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: '1.1'
31
+ description: OmniAuth strategy for the Tradier API
32
+ email:
33
+ - jbarry@tradier.com
34
+ - sagalloco@tradier.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - .yardopts
40
+ - LICENSE.md
41
+ - README.md
42
+ - Rakefile
43
+ - omniauth-tradier.gemspec
44
+ - lib/omniauth/strategies/tradier.rb
45
+ - lib/omniauth-tradier/version.rb
46
+ - lib/omniauth-tradier.rb
47
+ - spec/omniauth/strategies/tradier_spec.rb
48
+ - spec/spec_helper.rb
49
+ homepage: https://githubm.com/tradier/omniauth-tradier
50
+ licenses:
51
+ - MIT
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ segments:
63
+ - 0
64
+ hash: -430562647277157515
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ segments:
72
+ - 0
73
+ hash: -430562647277157515
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 1.8.23
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: OmniAuth strategy for the Tradier API
80
+ test_files:
81
+ - spec/omniauth/strategies/tradier_spec.rb
82
+ - spec/spec_helper.rb
83
+ has_rdoc: