-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add cook command #133
Add cook command #133
Conversation
c541840
to
a7caa30
Compare
変更点
コードレビューで頂いたアドバイスを基に,コードを修正しました |
a7caa30
to
5f96bbb
Compare
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.
レビューコメントを付けました.
lib/swimmy/command/cook.rb
Outdated
class Cook < Swimmy::Command::Base | ||
|
||
command "cook" do|client,data,match| | ||
food = match[:expression]||"" |
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.
food = match[:expression] || ""
のようにスペースを入れてください.
lib/swimmy/command/cook.rb
Outdated
rakuten_app_id = ENV['RAKUTEN_COOK_ID'] | ||
recipe_info = Service::RecipeInfomation.new.get_recipeinfo(rakuten_app_id, food) | ||
|
||
if recipe_info == nil then message = "レシピが見つかりませんでした.別のキーワードで再検索してください." |
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.
message = if recipe_info then recipe_info.make_mesage else "レシピが…" end
と書くか,
message = recipe_info&.make_message || "レシピ…"
と書けます.
lib/swimmy/resource/cook_resource.rb
Outdated
@name, @description, @url = name, description, url | ||
end | ||
|
||
def make_message() |
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.
Ruby では,引数がない場合の () は不要です.
引数のコンマに空白が必要です
lib/swimmy/resource/cook_resource.rb
Outdated
#{@url} | ||
EOS | ||
|
||
return message |
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.
Ruby では,途中から抜ける必要のない return は,そのまま message と書くだけでよいです
|
||
class HttpException < StandardError; end | ||
|
||
def get_recipeinfo(api_id, food) |
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.
api_id は,new の引数 (つまり initialize 関数の引数) で与えて,オブジェクト中にインスタンス変数として保持します.
# API仕様 : https://webservice.rakuten.co.jp/documentation/recipe-category-list | ||
result = JSON.parse(URI.open(category_url, &:read)) | ||
rescue | ||
puts "HttpException\n" |
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.
これでは,情報量がありません.もともと rescue した例外の詳細を puts して log に吐くべきです.
# API仕様 : https://webservice.rakuten.co.jp/documentation/recipe-category-ranking | ||
recipe_ranking = JSON.parse(URI.open(ranking_url, &:read)) | ||
rescue | ||
puts "HttpException\n" |
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.
これでは,情報量がありません.もともと rescue した例外の詳細を puts して log に吐くべきです.
lib/swimmy/command/cook.rb
Outdated
module Command | ||
class Cook < Swimmy::Command::Base | ||
|
||
command "cook" do|client,data,match| |
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.
以降同様ですが,コンマや演算子の前後にスペースを入れてください.
lib/swimmy/command/cook.rb
Outdated
|
||
if recipe_info == nil then message = "レシピが見つかりませんでした.別のキーワードで再検索してください." | ||
else | ||
message = recipe_info.make_message() |
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.
() は不要です
result["result"]["large"].each do |list| | ||
category_id_list[list["categoryName"]] = list["categoryId"].to_s | ||
end | ||
result["result"]["medium"].each do |list| | ||
category_id_list[list["categoryName"]] = list["parentCategoryId"].to_s + "-" + list["categoryId"].to_s | ||
parent_id_list[list["categoryId"]] = list["parentCategoryId"] | ||
end | ||
result["result"]["small"].each do |list| | ||
parent_id = parent_id_list[list["parentCategoryId"].to_i] | ||
category_id_list[list["categoryName"]] = parent_id + "-" + list["parentCategoryId"].to_s + "-" + list["categoryId"].to_s | ||
end |
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.
これらが何をやっているのかコメントを付けてください.
5f96bbb
to
62cd6c2
Compare
頂いたレビューコメントを基に,コードを修正しました. 共通の修正点
cook.rb の修正点
cook_resource.rb の修正点
recipe_information の修正点
|
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.
レビューしました.
end | ||
|
||
private | ||
def get_reciperanking(food, category_id_hash) |
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.
get_receiperanking → get_receipe_ranking がいいと思います.
p e | ||
raise HttpException.new | ||
end | ||
|
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.
以下が何をやっているのかの説明が必要です.
client.say(channel: data.channel, text: "レシピ情報を取得しています……") | ||
|
||
begin | ||
rakuten_app_id = ENV['RAKUTEN_COOK_ID'] |
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.
環境変数 RAKUTEN_COOK_ID が設定されていなかった場合の分岐を考えてください.
また,food の設定と RAKUTEN_COOK_ID の設定が離れているので,順序やタイミングを調整したほうがいいです.begin ... rescue に入れるべきかどうかの検討も含めて.
|
||
private | ||
def get_reciperanking(food, category_id_hash) | ||
recipe_candidates = category_id_hash.find_all{|key,value| key.include?(food)} |
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.
key,value → key, value
62cd6c2
to
26f4261
Compare
頂いたレビューコメントを基に,コードを修正しました. cook.rb の修正点
recipe_information の修正点
|
26f4261
to
c5781be
Compare
検討打合せでいただいたレビューを基にPRを更新しました.
|
c5781be
to
c5aac15
Compare
談話会でいただいたレビューを基にPRを更新しました.
|
f423062
to
fdee2d1
Compare
fdee2d1
to
649d548
Compare
概要
cook コマンドの追加
コマンドの概要
機能
指定された食材や料理に適したレシピの情報を表示する.
使用方法
swimmy cook <キーワード>
と入力するとキーワードに適したレシピを表示する.swimmy cook
と入力するとランダムにレシピを表示する.特徴
楽天レシピカテゴリ一覧APIと楽天レシピカテゴリ別ランキングAPIを使用している.