Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

なぜ作ったか

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

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

https://github.com/addyosmani/psi

使い方

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
mi-bear
かなりの老熊がボケ防止のために自分自身の健忘録に使うクマ。https://github.com/mi-bear に何かを上げたりするかもしれません。
https://note.mu/micchiebear
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした