aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/account.rb
diff options
context:
space:
mode:
authorrhenium <rhenium@rhe.jp>2014-07-18 06:42:38 +0900
committerrhenium <rhenium@rhe.jp>2014-07-18 06:42:38 +0900
commit9bab6f690fd77bd8e9ebdd0bf2c0653aa2e04f16 (patch)
tree4c1b7c6c72503419f2f6a3b5fe21acdf9b3a50ae /app/models/account.rb
parentd0077f8c7ff993d91821a5250632ae13a09868ec (diff)
downloadaclog-9bab6f690fd77bd8e9ebdd0bf2c0653aa2e04f16.tar.gz
doc: add YARD doc for Account model
Diffstat (limited to 'app/models/account.rb')
-rw-r--r--app/models/account.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index d3c23ab..17a5296 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -6,10 +6,16 @@ class Account < ActiveRecord::Base
belongs_to :user
scope :for_node, ->(block_number) { active.where("id % ? = ?", Settings.collector.nodes_count, block_number) }
+ # Returns whether tweet notification is enabled for this user.
def notification_enabled?; notification_enabled end
+
+ # Changes the `status` value to :inactive.
def deactivate!; self.inactive! end
class << self
+ # Registers a new account or updates an existing account.
+ # @param [Hash] hash data
+ # @return [Account] The target account object.
def register(hash)
account = where(user_id: hash[:user_id]).first_or_initialize
account.oauth_token = hash[:oauth_token]
@@ -18,17 +24,23 @@ class Account < ActiveRecord::Base
account.save! if account.changed?
end
+ # Returns a random active account.
+ # @return [Account] A random active account.
def random
active.order("RAND()").first
end
end
+ # Verifies the OAuth token pair with calling /1.1/account/verify_credentials.json.
+ # If the token was revoked, changes the `status` to :revoked.
def verify_token!
client.user
rescue
self.revoked!
end
+ # Returns Twitter Gem's Client instance.
+ # @return [Twitter::REST::Client] An instance of Twitter::REST::Client.
def client
@_client ||= Twitter::REST::Client.new(consumer_key: Settings.consumer.key,
consumer_secret: Settings.consumer.secret,
@@ -36,11 +48,16 @@ class Account < ActiveRecord::Base
access_token_secret: oauth_token_secret)
end
+ # Returns whether following the target user or not.
+ # @param [User, Integer] target_id Target user.
+ # @return [Boolean] whether following the target or not.
def following?(target_id)
target_id = target_id.id if target_id.is_a?(User)
friends.member? target_id
end
+ # Returns the array of friends.
+ # @return [Array<Integer>]
def friends
@_friends ||=
Rails.cache.fetch("accounts/#{self.id}/friends", expires_in: Settings.cache.friends) do