Skip to content

Commit

Permalink
twitter integration done and documentation added
Browse files Browse the repository at this point in the history
  • Loading branch information
ElvinEfendi committed Apr 20, 2012
1 parent d3c43dc commit 6ca2ae2
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 10 deletions.
1 change: 1 addition & 0 deletions .tmp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
== Josh Open Source Friday's

This is the place to be on Friday's.

To enable the Twitter integration you should do following once during the initial setup through rails console:
Setting.consumer_key = 'your twitter consumer key'
Setting.consumer_secret = 'your twitter consumer secret'
Setting.oauth_token = 'your twitter access token'
Setting.oauth_token_secret = 'your twitter access token secret'

5 changes: 0 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ class ApplicationController < ActionController::Base
helper_method :current_user
helper_method :user_signed_in?

def tweet(msg)
user = Twitter::Client.new(oauth_token: OAUTH_TOKEN, oauth_token_secret: OAUTH_TOKEN_SECRET)
user.update(msgmsg)
end

private
def current_user
@current_user ||= User.find_by_id(session[:user_id]) if session[:user_id]
Expand Down
17 changes: 17 additions & 0 deletions app/models/setting.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Setting < ActiveRecord::Base
attr_accessible :name, :value

def self.method_missing(identifier, args = nil)
identifier = identifier.to_s.gsub '=', ''
set = Setting.where(name: identifier).first
if args.nil? and !set.nil?
return set.value
elsif !args.nil?
set ||= Setting.new(name: identifier)
set.value = args
set.save!
else
super identifier, args
end
end
end
5 changes: 5 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
class User < ActiveRecord::Base
attr_accessible :name, :email
has_many :services, :dependent => :destroy

def tweet(msg)
twitter_user = Twitter::Client.new(oauth_token: Setting.oauth_token, oauth_token_secret: Setting.oauth_token_secret)
twitter_user.update(msg)
end

end
6 changes: 2 additions & 4 deletions config/initializers/omniauth.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
TWITTER_KEY= 'lBzoa7p7BDWR98IOsmcQQ'
TWITTER_SECRET= 'ur4TjBbwGOPJ1ieY9oFHK5z6w6bhiUMVgrEQxsVf4hY'
OAUTH_TOKEN = 'asfasf'
OAUTH_TOKEN_SECRET = ''
TWITTER_KEY= Setting.consumer_key
TWITTER_SECRET= Setting.consumer_secret

Rails.application.config.middleware.use OmniAuth::Builder do
#provider :developer unless Rails.env.production?
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20120420134408_create_settings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateSettings < ActiveRecord::Migration
def change
create_table :settings do |t|
t.string :name
t.string :value

t.timestamps
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120413132703) do
ActiveRecord::Schema.define(:version => 20120420134408) do

create_table "categories", :force => true do |t|
t.string "name"
Expand Down Expand Up @@ -67,6 +67,13 @@
t.datetime "updated_at", :null => false
end

create_table "settings", :force => true do |t|
t.string "name"
t.string "value"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "users", :force => true do |t|
t.string "name"
t.string "auth_hash"
Expand Down

0 comments on commit 6ca2ae2

Please sign in to comment.