diff options
author | Rhenium <rhenium@rhe.jp> | 2013-12-16 12:44:15 +0900 |
---|---|---|
committer | Rhenium <rhenium@rhe.jp> | 2013-12-16 12:45:50 +0900 |
commit | 3b6b25ad0551f6f8bc2dcc8a3e3a2e9db3356fe4 (patch) | |
tree | 7c4abbdf4c3df33bacb295dcae45586403827b63 | |
parent | a83895a7f2b5e8ccdb9eb216b3c3e2af1ef45835 (diff) | |
download | aclog-3b6b25ad0551f6f8bc2dcc8a3e3a2e9db3356fe4.tar.gz |
refactor settings
-rw-r--r-- | app/controllers/sessions_controller.rb | 3 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 4 | ||||
-rw-r--r-- | app/helpers/tweets_helper.rb | 2 | ||||
-rw-r--r-- | app/models/account.rb | 5 | ||||
-rw-r--r-- | app/models/notification.rb | 7 | ||||
-rw-r--r-- | app/models/tweet.rb | 2 | ||||
-rw-r--r-- | config/initializers/omniauth.rb | 4 | ||||
-rw-r--r-- | config/settings.yml.example | 37 | ||||
-rw-r--r-- | db/migrate/20130805001722_create_accounts.rb | 1 | ||||
-rw-r--r-- | db/schema.rb | 1 | ||||
-rw-r--r-- | lib/aclog/receiver/collector_connection.rb | 3 |
11 files changed, 31 insertions, 38 deletions
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 06cbbee..20cead0 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -4,8 +4,7 @@ class SessionsController < ApplicationController account = Account.create_or_update(user_id: auth["uid"], oauth_token: auth["credentials"]["token"], - oauth_token_secret: auth["credentials"]["secret"], - consumer_version: Settings.collector.consumer_version) + oauth_token_secret: auth["credentials"]["secret"]) account.update_connection User.from_receiver("id" => account.user_id, diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8b45a5b..580e075 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,7 +9,7 @@ class UsersController < ApplicationController def discovered_by user_required authorize_to_show_best!(@user) - @result = @user.count_discovered_by.take(Settings.user_ranking.count) + @result = @user.count_discovered_by.take(Settings.users.count) @caption = "Discovered By" render "_user_ranking" end @@ -17,7 +17,7 @@ class UsersController < ApplicationController def discovered_users user_required authorize_to_show_best!(@user) - @result = @user.count_discovered_users.take(Settings.user_ranking.count) + @result = @user.count_discovered_users.take(Settings.users.count) @caption = "Discovered Users" render "_user_ranking" end diff --git a/app/helpers/tweets_helper.rb b/app/helpers/tweets_helper.rb index e8a2b41..96013d4 100644 --- a/app/helpers/tweets_helper.rb +++ b/app/helpers/tweets_helper.rb @@ -1,6 +1,6 @@ module TweetsHelper def favorites_truncate_count - params[:full] == "true" ? nil : Settings.tweets.favorites.truncate + params[:full] == "true" ? Settings.tweets.favorites.max : Settings.tweets.favorites.count end def favorites_truncated?(tweet) diff --git a/app/models/account.rb b/app/models/account.rb index 5348368..7b777ec 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -11,7 +11,6 @@ class Account < ActiveRecord::Base account = where(user_id: hash[:user_id]).first_or_initialize account.oauth_token = hash[:oauth_token] account.oauth_token_secret = hash[:oauth_token_secret] - account.consumer_version = hash[:consumer_version] account.status = Account::ACTIVE account.save if account.changed? account @@ -48,8 +47,8 @@ class Account < ActiveRecord::Base end def client - Twitter::REST::Client.new(consumer_key: Settings.collector.consumer[consumer_version].key, - consumer_secret: Settings.collector.consumer[consumer_version].secret, + Twitter::REST::Client.new(consumer_key: Settings.consumer.key, + consumer_secret: Settings.consumer.secret, oauth_token: oauth_token, oauth_token_secret: oauth_token_secret) end diff --git a/app/models/notification.rb b/app/models/notification.rb index ae6d01b..995e0cd 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -17,13 +17,12 @@ class Notification private def self.tweet(text, reply_to = 0) cur = Rails.cache.read("notification_account") || 0 - if Settings.notification.token[cur] + if Settings.notification.accounts[cur] begin client = Twitter::REST::Client.new(consumer_key: Settings.notification.consumer.key, consumer_secret: Settings.notification.consumer.secret, - oauth_token: Settings.notification.token[cur].token, - oauth_token_secret: Settings.notification.token[cur].secret) - + oauth_token: Settings.notification.accounts[cur].token, + oauth_token_secret: Settings.notification.accounts[cur].secret) client.update(text, in_reply_to_status_id: reply_to) rescue Exception diff --git a/app/models/tweet.rb b/app/models/tweet.rb index cc710e8..9952d74 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -40,7 +40,7 @@ class Tweet < ActiveRecord::Base def self.list(params, options = {}) count = params[:count].to_i - count = Settings.tweets.count_default unless (1..Settings.tweets.count_max) === count + count = Settings.tweets.count.default unless (1..Settings.tweets.count.max) === count if params[:page] || options[:force_page] page = [params[:page].to_i, 1].max diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index f61214a..a044813 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -11,8 +11,8 @@ end Rails.application.config.middleware.use OmniAuth::Builder do provider :twitter, - Settings.collector.consumer[Settings.collector.consumer_version].key, - Settings.collector.consumer[Settings.collector.consumer_version].secret, + Settings.consumer.key, + Settings.consumer.secret, request_path: "/i/login", callback_path: "/i/callback" end diff --git a/config/settings.yml.example b/config/settings.yml.example index 39a9eda..1d29ee4 100644 --- a/config/settings.yml.example +++ b/config/settings.yml.example @@ -1,37 +1,36 @@ default: &default base_url: "http://example.com/" # base url - + consumer: + key: "consumer key of collector (register)" + secret: "consumer secret" + collector: server_port: 42106 secret_key: "secret key to authorize workers" count: 1 # workers count - consumer_version: 0 # which consumer (0..) - consumer: - - key: "consumer key of collector (register)" - secret: "consumer secret" - - key: "if change consumer key" - secret: - + notification: enabled: false consumer: key: "consumer key of notification account" secret: "consumer secret" - token: + accounts: - token: "access token of notification account" secret: "access token secret" favorites: - 50 - 100 - 250 - + tweets: - count_default: 10 - count_max: 100 + count: + default: 10 + max: 100 favorites: - truncate: 20 - - user_ranking: + count: 20 + max: null + + users: count: 50 development: @@ -39,14 +38,14 @@ development: test: <<: *default + consumer: + key: "JVkX2Uy0Qtigsh0GiG5Lw" + secret: "vfkPvOkzKUGuZ4xKtFAVvlAKoL3u2grxchuQEBvE" + collector: server_port: 42106 secret_key: "secret" count: 1 - consumer_version: 0 - consumer: - - key: "JVkX2Uy0Qtigsh0GiG5Lw" - secret: "vfkPvOkzKUGuZ4xKtFAVvlAKoL3u2grxchuQEBvE" production: <<: *default diff --git a/db/migrate/20130805001722_create_accounts.rb b/db/migrate/20130805001722_create_accounts.rb index 16f9673..a91c78a 100644 --- a/db/migrate/20130805001722_create_accounts.rb +++ b/db/migrate/20130805001722_create_accounts.rb @@ -5,7 +5,6 @@ class CreateAccounts < ActiveRecord::Migration t.string :oauth_token, null: false t.string :oauth_token_secret, null: false t.timestamps - t.integer :consumer_version, null: false t.boolean :notification, null: false, default: true t.boolean :private, null: false, default: false t.integer :status, limit: 2, null: false, default: 0 diff --git a/db/schema.rb b/db/schema.rb index 3ece16d..e43806a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -19,7 +19,6 @@ ActiveRecord::Schema.define(version: 20131117024504) do t.string "oauth_token_secret", null: false t.datetime "created_at" t.datetime "updated_at" - t.integer "consumer_version", null: false t.boolean "notification", default: true, null: false t.boolean "private", default: false, null: false t.integer "status", limit: 2, default: 0, null: false diff --git a/lib/aclog/receiver/collector_connection.rb b/lib/aclog/receiver/collector_connection.rb index b45afc3..36f652f 100644 --- a/lib/aclog/receiver/collector_connection.rb +++ b/lib/aclog/receiver/collector_connection.rb @@ -23,8 +23,7 @@ module Aclog id: account.id, oauth_token: account.oauth_token, oauth_token_secret: account.oauth_token_secret, - user_id: account.user_id, - consumer_version: account.consumer_version) + user_id: account.user_id) Rails.logger.debug("Sent #{account.id}/#{account.user_id}") end |