omniauth-tradeking 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,40 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sw[a-p]
4
+ *.tmproj
5
+ *.tmproject
6
+ *.un~
7
+ *~
8
+ .DS_Store
9
+ .Spotlight-V100
10
+ .Trashes
11
+ ._*
12
+ .bundle
13
+ .config
14
+ .directory
15
+ .elc
16
+ .emacs.desktop
17
+ .emacs.desktop.lock
18
+ .redcar
19
+ .yardoc
20
+ Desktop.ini
21
+ Gemfile.lock
22
+ Icon?
23
+ InstalledFiles
24
+ Session.vim
25
+ Thumbs.db
26
+ \#*\#
27
+ _yardoc
28
+ auto-save-list
29
+ coverage
30
+ doc
31
+ lib/bundler/man
32
+ pkg
33
+ pkg/*
34
+ rdoc
35
+ spec/reports
36
+ test/tmp
37
+ test/version_tmp
38
+ tmp
39
+ tmtags
40
+ tramp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
@@ -0,0 +1 @@
1
+ SimpleCov.start
@@ -0,0 +1,3 @@
1
+ --markup markdown
2
+ -
3
+ LICENSE.md
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Steve Agalloco, Jason Barry
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 TradeKing
2
+
3
+ This gem is an OmniAuth 1.0 Strategy for the [TradeKing API](https://developers.tradeking.com)
4
+
5
+ ## Usage
6
+
7
+ Add the strategy to your `Gemfile` alongside OmniAuth:
8
+
9
+ ```ruby
10
+ gem 'omniauth'
11
+ gem 'omniauth-tradeking'
12
+ ```
13
+
14
+ Then integrate the strategy into your middleware:
15
+
16
+ ```ruby
17
+ use OmniAuth::Builder do
18
+ provider :tradeking, ENV['TRADEKING_CONSUMER_KEY_'], ENV['TRADEKING_CONSUMER_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 :tradeking, ENV['TRADEKING_CONSUMER_KEY_'], ENV['TRADEKING_CONSUMER_SECRET']
27
+ end
28
+ ```
29
+
30
+ You will have to put in your consumer key and secret.
31
+
32
+ For additional information, refer to the [OmniAuth wiki](https://github.com/intridea/omniauth/wiki).
33
+
34
+ ## Note on Patches/Pull Requests
35
+
36
+ * Fork the project.
37
+ * Make your feature addition or bug fix.
38
+ * Add tests for it. This is important so I don't break it in a
39
+ future version unintentionally.
40
+ * Commit, do not mess with rakefile, version, or history.
41
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
42
+ * Send me a pull request. Bonus points for topic branches.
43
+
44
+ ## Copyright
45
+
46
+ Copyright (c) 2012 Steve Agalloco, Jason Barry. See [LICENSE](https://github.com/jcbarry/omniauth-tradeking/blob/master/LICENSE.md) for details.
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task :default => :spec
10
+ task :test => :spec
11
+
12
+ require 'yard'
13
+ namespace :doc do
14
+ YARD::Rake::YardocTask.new do |task|
15
+ task.files = ['LICENSE.md', 'lib/**/*.rb']
16
+ task.options = ['--markup', 'markdown']
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'sinatra'
4
+ gem 'multi_json'
5
+ gem 'omniauth-tradeking', :path => '../'
@@ -0,0 +1,30 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'omniauth-tradeking'
4
+
5
+ ENV['CONSUMER_KEY'] = 'p8c1ZAnEBSdOcEL3ut5oJeOKPIixp4TlLf7uyHIy'
6
+ ENV['CONSUMER_SECRET'] = 'QIFWJuKYmXV8yW7hvfyZALpTIPSk8vrA3aKbAqcZ'
7
+
8
+ class App < Sinatra::Base
9
+ get '/' do
10
+ redirect '/auth/tradeking'
11
+ end
12
+
13
+ get '/auth/:provider/callback' do
14
+ content_type 'application/json'
15
+ MultiJson.encode(request.env)
16
+ end
17
+
18
+ get '/auth/failure' do
19
+ content_type 'application/json'
20
+ MultiJson.encode(request.env)
21
+ end
22
+ end
23
+
24
+ use Rack::Session::Cookie
25
+
26
+ use OmniAuth::Builder do
27
+ provider :tradeking, ENV['CONSUMER_KEY'], ENV['CONSUMER_SECRET']
28
+ end
29
+
30
+ run App.new
@@ -0,0 +1 @@
1
+ require 'omniauth/tradeking'
@@ -0,0 +1,51 @@
1
+ require 'omniauth-oauth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class TradeKing < OmniAuth::Strategies::OAuth
6
+ option :client_options, {
7
+ :site => 'https://api.tradeking.com',
8
+ :authorize_url => 'https://developers.tradeking.com/oauth/authorize',
9
+ :request_token_url => 'https://developers.tradeking.com/oauth/request_token',
10
+ :access_token_url => 'https://developers.tradeking.com/oauth/access_token'
11
+ }
12
+
13
+ uid { login_id }
14
+
15
+ info do
16
+ {
17
+ 'uid' => login_id,
18
+ 'name' => "#{first_name} #{last_name}",
19
+ 'email' => email
20
+ }
21
+ end
22
+
23
+ extra do
24
+ { 'raw_info' => raw_info }
25
+ end
26
+
27
+ def raw_info
28
+ @raw_info ||= MultiJson.decode(access_token.get('https://api.tradeking.com/v1/member/profile.json').body)['response']
29
+ end
30
+
31
+ def first_name
32
+ raw_info['userdata']['userprofile']['entry'].select { |r| r['name'] == 'primaryFirstName' }.first['value']
33
+ end
34
+
35
+ def last_name
36
+ raw_info['userdata']['userprofile']['entry'].select { |r| r['name'] == 'primaryLastName' }.first['value']
37
+ end
38
+
39
+ def email
40
+ raw_info['userdata']['userprofile']['entry'].select { |r| r['name'] == 'emailAddress1' }.first['value']
41
+ end
42
+
43
+ def login_id
44
+ raw_info['userdata']['userprofile']['entry'].select { |r| r['name'] == 'login_id' }.first['value']
45
+ end
46
+
47
+ end
48
+ end
49
+ end
50
+
51
+ OmniAuth.config.add_camelization 'tradeking', 'TradeKing'
@@ -0,0 +1 @@
1
+ require 'omniauth/strategies/tradeking'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module TradeKing
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/omniauth/tradeking/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = 'omniauth-tradeking'
6
+ gem.version = OmniAuth::TradeKing::VERSION
7
+ gem.homepage = 'https://github.com/jcbarry/omniauth-tradeking'
8
+
9
+ gem.author = ["Steve Agalloco", "Jason Barry"]
10
+ gem.email = ['steve.agalloco@gmail.com', 'jay@jcbarry.com']
11
+ gem.description = 'TradeKing strategy for OmniAuth 1.0'
12
+ gem.summary = gem.description
13
+
14
+ gem.add_dependency "omniauth-oauth", "~> 1.0"
15
+
16
+ gem.add_development_dependency 'rake', '~> 0.9'
17
+ gem.add_development_dependency 'rdiscount', '~> 1.6'
18
+ gem.add_development_dependency 'rspec', '~> 2.7'
19
+ gem.add_development_dependency 'simplecov', '~> 0.5'
20
+ gem.add_development_dependency 'yard', '~> 0.7'
21
+ gem.add_development_dependency 'webmock', '~> 1.7'
22
+
23
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
24
+ gem.files = `git ls-files`.split("\n")
25
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+
27
+ gem.require_paths = ['lib']
28
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'OmniAuth::Strategies::TradeKing Integration' do
4
+ pending 'write some tests yo'
5
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::TradeKing do
4
+ before :each do
5
+ @request = double('Request')
6
+ @request.stub(:params) { {} }
7
+ end
8
+
9
+ subject do
10
+ OmniAuth::Strategies::TradeKing.new(nil, @options || {}).tap do |strategy|
11
+ strategy.stub(:request) { @request }
12
+ end
13
+ end
14
+
15
+ describe '#client_options' do
16
+ it 'has correct TradeKing site' do
17
+ subject.options.client_options.site.should eq('https://api.tradeking.com')
18
+ end
19
+
20
+ it 'has correct authorize url' do
21
+ subject.options.client_options.authorize_url.should eq('https://developers.tradeking.com/oauth/authorize')
22
+ end
23
+
24
+ it 'has correct request token url' do
25
+ subject.options.client_options.request_token_url.should eq('https://developers.tradeking.com/oauth/request_token')
26
+ end
27
+
28
+ it 'has correct access token url' do
29
+ subject.options.client_options.access_token_url.should eq('https://developers.tradeking.com/oauth/access_token')
30
+ end
31
+ end
32
+
33
+ describe '#uid' do
34
+ it 'returns the uid from raw_info' do
35
+ subject.stub(:login_id) { 'omgbbqlol' }
36
+ subject.uid.should eq('omgbbqlol')
37
+ end
38
+ end
39
+
40
+ describe '#info' do
41
+ before :each do
42
+ subject.stub(:first_name) { 'James' }
43
+ subject.stub(:last_name) { 'Brown' }
44
+ subject.stub(:email) { 'jbrown@gmail.com' }
45
+ subject.stub(:login_id) { '12345' }
46
+ end
47
+
48
+ context 'when data is present in raw info' do
49
+ it 'returns the name' do
50
+ subject.info['name'].should eq('James Brown')
51
+ end
52
+
53
+ it 'returns the email' do
54
+ subject.info['email'].should eq('jbrown@gmail.com')
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '#extra' do
60
+ before :each do
61
+ @raw_info_hash = { "accounts" => [] }
62
+ subject.stub(:raw_info) { @raw_info_hash }
63
+ end
64
+
65
+ it 'returns a Hash' do
66
+ subject.extra.should be_a(Hash)
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ require 'omniauth-tradeking'
5
+ require 'rspec'
6
+ require 'webmock/rspec'
metadata ADDED
@@ -0,0 +1,146 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-tradeking
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steve Agalloco
9
+ - Jason Barry
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-02-22 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: omniauth-oauth
17
+ requirement: &70138196238720 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: '1.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70138196238720
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: &70138196238220 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70138196238220
37
+ - !ruby/object:Gem::Dependency
38
+ name: rdiscount
39
+ requirement: &70138196270760 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: '1.6'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70138196270760
48
+ - !ruby/object:Gem::Dependency
49
+ name: rspec
50
+ requirement: &70138196270300 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '2.7'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *70138196270300
59
+ - !ruby/object:Gem::Dependency
60
+ name: simplecov
61
+ requirement: &70138196269840 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: '0.5'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *70138196269840
70
+ - !ruby/object:Gem::Dependency
71
+ name: yard
72
+ requirement: &70138196269380 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '0.7'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *70138196269380
81
+ - !ruby/object:Gem::Dependency
82
+ name: webmock
83
+ requirement: &70138196268920 !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '1.7'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: *70138196268920
92
+ description: TradeKing strategy for OmniAuth 1.0
93
+ email:
94
+ - steve.agalloco@gmail.com
95
+ - jay@jcbarry.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - .gemtest
101
+ - .gitignore
102
+ - .rspec
103
+ - .simplecov
104
+ - .yardopts
105
+ - Gemfile
106
+ - LICENSE.md
107
+ - README.md
108
+ - Rakefile
109
+ - example/Gemfile
110
+ - example/config.ru
111
+ - lib/omniauth-tradeking.rb
112
+ - lib/omniauth/strategies/tradeking.rb
113
+ - lib/omniauth/tradeking.rb
114
+ - lib/omniauth/tradeking/version.rb
115
+ - omniauth-tradeking.gemspec
116
+ - spec/integration_spec.rb
117
+ - spec/omniauth/strategies/tradeking_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/jcbarry/omniauth-tradeking
120
+ licenses: []
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ none: false
133
+ requirements:
134
+ - - ! '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 1.8.10
140
+ signing_key:
141
+ specification_version: 3
142
+ summary: TradeKing strategy for OmniAuth 1.0
143
+ test_files:
144
+ - spec/integration_spec.rb
145
+ - spec/omniauth/strategies/tradeking_spec.rb
146
+ - spec/spec_helper.rb