Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
It's a Rails Engine that makes easy your development of a web service based on twitter.
Ruby JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
app
config
db
lib
script
test
.gitignore
Gemfile
Gemfile.lock
MIT-LICENSE
README.rdoc
Rakefile
smart_twitter.gemspec

README.rdoc

smart_twitter

smart_twitter helps you produce your twitter-based rails 3.1 application. smart_twitter has the next two features.

  1. All functions of twitter-auth(github.com/mbleigh/twitter-auth.git) is supported.

  2. 'twitter'(rubydoc.info/gems/twitter/2.1.0/frames) is included as a client for twitter api.

This project rocks and uses MIT-LICENSE.

Install & Preperation

1.Include the next code in Your Rails Application's Gemfile.

gem 'smart_twitter', :git => 'git://github.com/y-uuki/smart-twitter.git'

2.Install smart_twitter by bundle.

$ bundle install

or

$ budnle install --path=vendor/bundle

3.create config/smart_twitter.yml

smart_twitter.yml

development:
    oauth_consumer_key: XXXXXXXXXXXXXX
    oauth_consumer_secret: XXXXXXXXXXXXX
    base_url: "http://api.twitter.com"
    authorize_path: "/oauth/authenticate"
    api_timeout: 10
    remember_for: 14 #days
    oauth_callback: "http://localhost:3000/oauth_callback"

test:
    oauth_consumer_key: XXXXXXXXXXX
    oauth_consumer_secret: XXXXXXXXX
    base_url: "http://api.twitter.com"
    authorize_path: "/oauth/authenticate"
    api_timeout: 10
    remember_for: 14 #days
    oauth_callback: "http://localhost:3000/oauth_callback"

production:
    oauth_consumer_key: XXXXXXXXXXX
    oauth_consumer_secret: XXXXXXXXX
    base_url: "http://api.twitter.com"
    authorize_path: "/oauth/authenticate"
    api_timeout: 10
    remember_for: 14 #days
    oauth_callback: "http://localhost:3000/oauth_callback"
  1. Add the follow code to the end of config/routes.rb in order to mount smart_twitter Engines.

mount SmartTwitter::Engine => "/", :as => "smart_twitter"
  1. Add the follow code to config/application.rb

require 'smart_twitter'

config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]
  1. Install smart_twitter_user table schema to your db directory.

rake smart_twitter:install:migrations
rake db:migrate

Usage

User Login

smart_twitter gives your application a twitter-login system.

Added /login and /logout to the URL routing. If your application is accessed to /login, a screen transitions to a twitter-login screen, then comes back to your application's root.

Custamize User DB Table

smart_twitter gives your application a twitter-logined user table.

You can custamize it by inheritting SmartTwitter::GenericUser For Example,

class User < SmartTwitter::GenericUser
  set_table_name :smart_twitter_users
  has_many :hash_tag, :include => 'hash_tag', :foreign_key => 'twitter_id'

end

Controller-Extended Method

  • login_required: a before filter that can be added to a controller to require that a user logs in before he/she can view the page.

  • current_user: returns the logged in user if one exists, otherwise returns nil.

  • logged_in?: true if logged in, false otherwise.

  • redirect_back_or_default(url): redirects to the location where store_location was last called or the specified default URL.

  • store_location: store the current URL for returning to when a redirect_back_or_default is called.

  • authorized?: override this to add fine-grained access control for when login_required is already called.

@y_uuki_: twitter.com/y_uuki_

Something went wrong with that request. Please try again.