Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@mi-bear

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

なぜ作ったか

  • 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
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
1
Help us understand the problem. What are the problem?