-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from true-runes/development
v2.0.0
- Loading branch information
Showing
11 changed files
with
195 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class CheckVotesAndBonusesController < ApplicationController | ||
def index | ||
screen_name = Presenter::Common.normalized_screen_name(params[:screen_name]) | ||
user = User.find_by(screen_name: screen_name) | ||
|
||
# TODO: エラーハンドリング | ||
return render json: {} if user.blank? | ||
|
||
gss2022_tweets = user.tweets.gensosenkyo_2022_votes_for_api | ||
unite_attacks_tweets = user.tweets.unite_attacks_votes_for_api | ||
short_stories = user.tweets.short_stories | ||
fav_quotes = user.tweets.fav_quotes | ||
sosenkyo_campaigns = user.tweets.sosenkyo_campaigns | ||
|
||
@gss2022_tweets = gss2022_tweets.map(&:id_number) | ||
@unite_attacks_tweets = unite_attacks_tweets.map(&:id_number) | ||
@short_stories = short_stories.map(&:id_number) | ||
@fav_quotes = fav_quotes.map(&:id_number) | ||
@sosenkyo_campaigns = sosenkyo_campaigns.map(&:id_number) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class CheckVisibleAndInvisibleTweetIdNumbers | ||
INTERVAL_SECONDS = 5 | ||
|
||
def self.exec(tweet_id_numbers, client_account_key: :ayy) | ||
client = TwitterRestApi.client(account_key: client_account_key) | ||
|
||
all_invisible_tweet_id_numbers = [] | ||
|
||
# 不可視の場合には client.statuses([tweet_id_number, ...]) の戻り値に返ってこない仕様を利用する | ||
tweet_id_numbers.each_slice(100) do |this_tweet_id_numbers| | ||
visible_tweet_objects = client.statuses(this_tweet_id_numbers) # API が消費される | ||
visible_tweet_id_numbers = visible_tweet_objects.map(&:id) # #id により id_number を取得できる | ||
|
||
# 配列 から 配列 を引き算して、不可視のツイートの id_number を取り出す | ||
invisible_tweet_id_numbers = this_tweet_id_numbers - visible_tweet_id_numbers | ||
|
||
all_invisible_tweet_id_numbers << invisible_tweet_id_numbers | ||
all_invisible_tweet_id_numbers.flatten! | ||
|
||
sleep INTERVAL_SECONDS | ||
end | ||
|
||
all_visible_tweet_id_numbers = Tweet.all.map(&:id_number) - all_invisible_tweet_id_numbers | ||
|
||
{ visible: all_visible_tweet_id_numbers, invisible: all_invisible_tweet_id_numbers} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module NaturalLanguage | ||
class SuggestCharacterNames | ||
def self.exec(tweet_or_dm) | ||
analyze_syntax = tweet_or_dm.analyze_syntax | ||
|
||
PickupCharacterNames.exec(analyze_syntax) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
json.set! 'gss2022', @gss2022_tweets | ||
json.set! 'unite_attacks', @unite_attacks_tweets | ||
json.set! 'short_stories', @short_stories | ||
json.set! 'fav_quotes', @fav_quotes | ||
json.set! 'sosenkyo_campaigns', @sosenkyo_campaigns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace :change_is_public_attributes do | ||
desc 'ツイートが非公開または削除になっていないかを調べ、変更があれば UPDATE を実行する' | ||
task all: :environment do | ||
tweets = Tweet.all | ||
tweet_id_numbers = tweets.map(&:id_number) | ||
|
||
# app/lib/check_visible_and_invisible_tweet_id_numbers.rb を参照のこと | ||
visible_and_invisible_tweet_id_numbers = CheckVisibleAndInvisibleTweetIdNumbers.exec(tweet_id_numbers) | ||
|
||
visible_tweet_id_numbers = visible_and_invisible_tweet_id_numbers[:visible] | ||
invisible_tweet_id_numbers = visible_and_invisible_tweet_id_numbers[:invisible] | ||
|
||
ActiveRecord::Base.transaction do | ||
# 鍵ツイート => 公開ツイート の場合 | ||
Tweet.where(id_number: visible_tweet_id_numbers).each do |tweet| | ||
tweet.update!(is_public: true) unless tweet.public? | ||
end | ||
|
||
# 公開ツイート => 鍵ツイート or 削除ツイート の場合 | ||
Tweet.where(id_number: invisible_tweet_id_numbers).each do |tweet| | ||
tweet.update!(is_public: false) if tweet.public? | ||
end | ||
end | ||
|
||
puts '[DONE] check_tweet_is_invisible:exec' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe CheckVotesAndBonusesController, type: :request do | ||
describe '#index' do | ||
context 'パラメータ screen_name が' do | ||
it 'データベースに存在しないとき、期待通りのレスポンスが返ってくること' do | ||
get check_votes_and_bonuses_path(screen_name: '@test_user') | ||
|
||
expect(response).to have_http_status :ok | ||
expect(response.body).to eq '{}' | ||
end | ||
|
||
it 'データベースに存在するとき、期待通りのレスポンスが返ってくること' do | ||
create(:user) | ||
|
||
get check_votes_and_bonuses_path(screen_name: '@test_screen_name') | ||
|
||
expect(response).to have_http_status :ok | ||
expect(JSON.parse(response.body)).to eq( | ||
{ | ||
"gss2022" => [], | ||
"unite_attacks" => [], | ||
"short_stories" => [], | ||
"fav_quotes" => [], | ||
"sosenkyo_campaigns" => [] | ||
} | ||
) | ||
end | ||
end | ||
end | ||
end |