LoginSignup
1
1

More than 5 years have passed since last update.

PageSpeed Insightsの情報をhubotに教えてもらう

Last updated at Posted at 2016-02-25

なぜ作ったか

  • CoffeeScriptに慣れたかった。
  • Hubotにやってもらうことを増やしたかった。

利用させていただいたもの

使い方

PCサイトの情報を知りたいときは

hubot psi google.co.jp desktop

スマートフォンサイトの情報を知りたいときは

hubot psi google.co.jp mobile

ソースコード

psi.coffee
psi = require('psi')

module.exports = (robot) ->
  message = (id, title, score, numberResources, numberHosts, totalRequestBytes
  , numberStaticResources, htmlResponseBytes, cssResponseBytes, imageResponseBytes
  , javascriptResponseBytes, otherResponseBytes, numberJsResources, numberCssResources)-> """


ʕ•ᴥ•ʔが教えるPageSpeed Insights!

domain: #{id}
name: #{title}
score: #{score}
numberResources: #{numberResources}
numberHosts: #{numberHosts}
totalRequestBytes: #{totalRequestBytes}
numberStaticResources: #{numberStaticResources}
htmlResponseBytes: #{htmlResponseBytes}
cssResponseBytes: #{cssResponseBytes}
imageResponseBytes: #{imageResponseBytes}
javascriptResponseBytes: #{javascriptResponseBytes}
otherResponseBytes: #{otherResponseBytes}
numberJsResources: #{numberJsResources}
numberCssResources: #{numberCssResources}

"""

  robot.respond /psi (.*)/i, (msg) ->
    matches = msg.match[1].split(' ')
    url = matches[0]

    if matches[1] == 'desktop' || matches[1] == 'mobile'
      strategy = matches[1]
    else
      strategy = 'desktop'

    locale = 'ja_JP'

    psi(url,
      nokey: 'true'
      strategy: strategy
      locale: locale).then (data) ->
      msg.send message(data.id, data.title, data.ruleGroups.SPEED.score, data.pageStats.numberResources, data.pageStats.numberHosts, data.pageStats.totalRequestBytes
      , data.pageStats.numberStaticResources, data.pageStats.htmlResponseBytes, data.pageStats.cssResponseBytes, data.pageStats.imageResponseBytes
      , data.pageStats.javascriptResponseBytes, data.pageStats.otherResponseBytes, data.pageStats.numberJsResources, data.pageStats.numberCssResources)
      return
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1