タカシカンパニーのiPhone鳴らせる。
今までcurlで叩いてたけど、めんどくさくなってきた。
#!/bin/bash MESSAGE=$1 curl "http://takashicompany.com/api/im/?message=$MESSAGE"
$ takashi 飲みに行くぞ!
なんかいい感じするgemとかありそうだけど、めんどくさいのでコードをピピッといじってピピッと見る。
actionpack
にaction_dispatch
っていうそれっぽいのがあったので中身をざっと見る。
lib/action_dispatch/routing/route_set.rb
とか怪しいんじゃなーい?と適当に見たら、dispatch
メソッドがあった。
def dispatch(controller, action, env) controller.action(action).call(env) end
もう完全にこれでしょって思ったので、こんな感じでp
追加してサーバ再起動して見た。
def dispatch(controller, action, env) p controller.new.method(action.to_sym).source_location controller.action(action).call(env) end
けど、他のページではちゃんとコードの場所が出るのに、目当てのページでは出ませんでした!なんやねんマジで
omniauthのバージョンは、1.1.4
https://github.com/intridea/omniauth/blob/master/lib/omniauth/strategy.rb#L298
# The setup phase looks for the `:setup` option to exist and, # if it is, will call either the Rack endpoint supplied to the # `:setup` option or it will call out to the setup path of the # underlying application. This will default to `/auth/:provider/setup`. def setup_phase if options[:setup].respond_to?(:call) log :info, "Setup endpoint detected, running now." options[:setup].call(env) elsif options.setup? log :info, "Calling through to underlying application for setup." setup_env = env.merge('PATH_INFO' => setup_path, 'REQUEST_METHOD' => 'GET') call_app!(setup_env) end end
setup_phaseというのがあるのでそれを使う。
# config/なんちゃらに追加 module OmniAuth module Strategies class Facebook configure do |c| # deviseを使っていると /resource_name/auth/facebook/setup が実行される c.setup = true end end end end
あとはよしなにルーティングとアクションとビューを追加する。ただcallbackの時もこのアクションが実行されると思うので注意
もっといい方法あるなら知りたい。