前提・実現したいこと
railsで、app_review を取得して、slackに流すシステムを作っています。
ratingで評価を星で表したいのですが上手くいきません。
発生している問題・エラーメッセージ
@star=,
case の使い方、
attachments を使って、星を出す方法
この三つをどう繋げていいか分かりません。
該当のソースコード
rails
1 2class Tasks::RunnerTest 3 4#インスタンスメソッドの定義 5 def self.execute 6#reviewを取ってくる 7 url = 'https://itunes.apple.com/jp/rss/customerreviews/page=1/id=414706506/sortBy=mostRecent/xml' 8 xml = Nokogiri::XML(open(url).read) 9 xml.remove_namespaces! 10 item_nodes = xml.xpath('/feed/entry') 11#スラックに通知する 12 slack = Slack::Incoming::Webhooks.new "https://hooks.slack.com/services/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" 13=begin 14 15 item_nodes.each do |item| 16 17 @app_name= "Google 翻訳" 18 @author_name = item.xpath('author/name').text 19 @author_uri = item.xpath('author/uri').text 20 @star= item.xpath('rating').text 21 @app_icon = 'https://is2-ssl.mzstatic.com/image/thumb/Purple125/v4/e9/99/c4/e999c4b4-60be-9e4b-1f7a-d5945c898d47/logo_translate_color-1x_U007emarketing-0-0-GLES2_U002c0-512MB-sRGB-0-0-0-85-220-0-0-0-5.png/100x100bb-85.png' 22 @title=item.xpath('title').text 23 @content=item.xpath("content[@type='text']").text 24 @updated=item.xpath('updated').text 25 26 27 case 'rating' 28 when 1 then 29 @star = ':star:☆☆☆☆' 30 when 2 then 31 @star = ':star::star:☆☆☆' 32 when 3 then 33 @star = ':star::star::star:☆☆' 34 when 4 then 35 @star = ':star::star::star::star:☆' 36 when 5 then 37 @star = ':star::star::star::star::star:' 38 end 39 40 41 attachments = [{ 42 43 color: "#7CD197", 44 pretext: @app_name, 45 author_name: @star, 46 author_icon: @app_icon, 47 title: @title, 48 title_link: @author_uri, 49 text: @content, 50 footer: DateTime.parse(@updated).strftime("%Y-%m-%d %H:%M:%S"), 51 footer_icon: "https://platform.slack-edge.com/img/default_application_icon.png" 52 53 }] 54 slack.post "", attachments: attachments 55 end 56 57 58 end 59 60end 61
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。