-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement tweet function #19
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
586635f
follow
Gaddict 75e49e0
Merge remote-tracking branch 'upstream/develop' into develop
Gaddict f1868d1
Merge remote-tracking branch 'upstream/develop' into develop
Gaddict 21884e3
Merge remote-tracking branch 'upstream/develop' into develop
Gaddict 9915f1b
teeeeet
Gaddict 7c4910b
Merge remote-tracking branch 'upstream/develop' into develop
Gaddict File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
require 'oauth' | ||
|
||
class Admin::BotController < ApplicationController | ||
|
||
NG = "ng".freeze | ||
|
@@ -7,9 +9,36 @@ def index | |
@bot = Bot.new | ||
end | ||
|
||
def update | ||
parameters = params.require(:tweet).permit :bot_id, :content | ||
bot = Bot.find_by_id(parameters[:bot_id]) | ||
|
||
puts "bot_id" + parameters[:bot_id] | ||
|
||
client = Twitter::REST::Client.new do |config| | ||
config.consumer_key = Settings.twitter.consumer_key | ||
config.consumer_secret = Settings.twitter.consumer_secret | ||
config.access_token = bot.access_token | ||
config.access_token_secret = bot.access_secret | ||
end | ||
|
||
puts "content" + parameters[:content] | ||
|
||
|
||
client.update(parameters[:content]) | ||
|
||
redirect_to "/admin/bot" | ||
end | ||
|
||
def create | ||
bots | ||
@bot = Bot.new(bot_params) | ||
|
||
paramerters = bot_params | ||
|
||
paramerters[:access_token] = session[:access_token] | ||
paramerters[:access_secret] = session[:access_secret] | ||
|
||
@bot = Bot.new(paramerters) | ||
render action: 'admin/bot/index', alert: "登録失敗!!" if @bot.nil? | ||
|
||
if @bot.save | ||
|
@@ -29,13 +58,23 @@ def destroy | |
end | ||
end | ||
|
||
def callback | ||
auth = request.env["omniauth.auth"] | ||
token = auth[:credentials] | ||
|
||
session[:access_token] = token[:token] | ||
session[:access_secret] = token[:secret] | ||
|
||
redirect_to "/admin/bot" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redirect_to "/admin/bot"は
で |
||
end | ||
|
||
private | ||
def bots | ||
@bots = Bot.find_by | ||
end | ||
|
||
def bot_params | ||
params.require(:bot).permit :twitter_name, :twitter_id, :access_token, :hash_tags | ||
params.require(:bot).permit :twitter_name, :twitter_id, :hash_tags | ||
end | ||
|
||
def find_destroy_bot | ||
|
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,16 @@ | ||
<h1>TwitterTestView</h1> | ||
|
||
<hr> | ||
|
||
<h2>❏ CreateTest</h2> | ||
|
||
<div style="padding-bottom: 10px;"> | ||
<%= form_tag "/twitter/update" do %> | ||
<p>Consumer Key<%= f.text_field :con_key %></p> | ||
<p>Consumer Secret<%= f.text_field :con_sec %></p> | ||
<%= button_tag('bot登録') %> | ||
<% end %> | ||
</div> | ||
|
||
|
||
</div> |
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,4 @@ | ||
class Settings < Settingslogic | ||
source "#{Rails.root}/config/settings.yml" | ||
namespace Rails.env | ||
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,3 @@ | ||
Rails.application.config.middleware.use OmniAuth::Builder do | ||
provider :twitter, Settings.twitter.consumer_key, Settings.twitter.consumer_secret | ||
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 |
---|---|---|
@@ -1,4 +1,9 @@ | ||
Rails.application.routes.draw do | ||
|
||
match '/auth/twitter/callback', to: 'admin/bot#callback', via: 'get' | ||
|
||
match '/bot/update', to: 'admin/bot#update', via: 'post' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. このパスないと動かない?? |
||
|
||
# 管理機能 | ||
namespace :admin do | ||
# ADMIN TOP | ||
|
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,13 @@ | ||
defaults: &defaults | ||
|
||
development: | ||
<<: *defaults | ||
twitter: | ||
consumer_key: CTGO18drqCEpTMbPhYucIV3Hc | ||
consumer_secret: 90EU6sv8Bw3PRgM8H0yLrAnXoo8jXZavVx1FsibiRe1DzQAlYw | ||
|
||
test: | ||
<<: *defaults | ||
|
||
production: | ||
<<: *defaults |
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 @@ | ||
class DeleteColumnPinFromBots < ActiveRecord::Migration | ||
def change | ||
remove_column :bots, :pin | ||
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 @@ | ||
class AddColumnPinToBots < ActiveRecord::Migration | ||
def change | ||
add_column :bots, :pin, :integer | ||
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,6 @@ | ||
class AddColumnAccToBots < ActiveRecord::Migration | ||
def change | ||
add_column :bots, :acc_key, :integer | ||
add_column :bots, :acc_sec, :integer | ||
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 @@ | ||
class AddColumnToBots < ActiveRecord::Migration | ||
def change | ||
add_column :bots, :pin, :integer | ||
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 @@ | ||
class AddAccessSecretToBot < ActiveRecord::Migration | ||
def change | ||
add_column :bots, :access_secret, :string | ||
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 @@ | ||
class RemovePinFromBot < ActiveRecord::Migration | ||
def change | ||
remove_column :bots, :pin, :integer | ||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.