Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseyoungmann committed Aug 30, 2012
0 parents commit 713eae2
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source "http://rubygems.org"

# Specify your gem's dependencies in omniauth-stocktwits.gemspec
gemspec

group :development, :test do
gem "rspec"
end
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# OmniAuth StockTwits

This gem contains an unofficial StockTwits strategy for OmniAuth 2.0 .

Read more at the [StockTwits Authentication Documentation](http://stocktwits.com/developers/docs/authentication).

## How To Use It

Add the following to your `config/initializers/omniauth.rb`:

use OmniAuth::Builder do
provider :stocktwits, ENV['STOCKTWITS_KEY'], ENV['STOCKTWITS_SECRET']
end

Or, if you're authenticating with devise, put this in your `config/initializers/devise.rb`

require "omniauth-stocktwits"
config.omniauth :stocktwits, ENV['STOCKTWITS_KEY'], ENV['STOCKTWITS_SECRET']

### Scopes

This gem defaults to the `read` scope, but you can pass in scope options on initialization as a comma separated string:

use OmniAuth::Builder do
provider :stocktwits, ENV['STOCKTWITS_KEY'], ENV['STOCKTWITS_SECRET'], scope: => "read,watch_lists,publish_messages"
end

## Contribute

1. Fork it
2. Create your feature branch (`git checkout -b some-feature`)
3. Commit your changes (`git commit -am 'Added some feature'`)
4. Push to the branch (`git push origin some-feature`)
5. Create new Pull Request

## License

Copyright (c) 2012 by Jesse Youngmann

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
2 changes: 2 additions & 0 deletions lib/omniauth-stocktwits.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require 'omniauth-stocktwits/version'
require 'omniauth/strategies/stocktwits'
5 changes: 5 additions & 0 deletions lib/omniauth-stocktwits/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module OmniAuth
module StockTwits
VERSION = "0.0.1"
end
end
48 changes: 48 additions & 0 deletions lib/omniauth/strategies/stocktwits.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require 'omniauth-oauth2'

module OmniAuth
module Strategies
class StockTwits < OmniAuth::Strategies::OAuth2
option :name, "stocktwits"

option :client_options, {
:site => "https://api.stocktwits.com",
:token_url => 'https://api.stocktwits.com/api/2/oauth/token',
:authorize_url => 'https://api.stocktwits.com/api/2/oauth/authorize'
}

option :scope, 'read'

def authorize_params
super.tap do |params|
params[:response_type] = "code"
end
end

uid{ access_token.params['user_id'] }

info do
{
:name => raw_info['user']['name'],
:avatar_url => raw_info['user']['avatar_url'],
:nickname => raw_info['user']['username']
}
end

extra do
{
'raw_info' => raw_info
}
end

def raw_info
access_token.options[:mode] = :query
access_token.options[:param_name] = 'access_token'
@raw_info ||= access_token.get("/api/2/account/verify.json").parsed
end

end
end
end

OmniAuth.config.add_camelization 'stocktwits', 'StockTwits'
22 changes: 22 additions & 0 deletions omniauth-stocktwits.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- encoding: utf-8 -*-
require File.expand_path('../lib/omniauth-stocktwits/version', __FILE__)

Gem::Specification.new do |gem|
gem.name = "omniauth-stocktwits"
gem.version = OmniAuth::StockTwits::VERSION
gem.description = "Unofficial StockTwits strategy for OmniAuth"
gem.summary = "Unofficial StockTwits strategy for OmniAuth"
gem.homepage = "https://github.com/jesseyoungmann/omniauth-stocktwits"

gem.authors = ["Jesse Youngmann"]
gem.email = ["jesse.youngmann@gmail.com"]

gem.files = `git ls-files`.split("\n")
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
gem.require_paths = ["lib"]


gem.add_dependency 'omniauth-oauth2'

end
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$LOAD_PATH.unshift File.expand_path('..', __FILE__)
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)

require 'rspec'
require 'omniauth-stocktwits'

RSpec.configure do |config|

end

0 comments on commit 713eae2

Please sign in to comment.