ruboty-page_speed_insights 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 66eed41a6ffffcf277a77fd0bd3604454bd800ad
4
- data.tar.gz: 8b38c58ec306db7c997141bcc28c5c0fee8b305b
3
+ metadata.gz: 4c01d77aace52907183535d8ce208d9c039af38e
4
+ data.tar.gz: 1183c6a42edcdfc9f142abeedb3fb6472489df36
5
5
  SHA512:
6
- metadata.gz: '0091f423c1fbbdfd586fe9a6f0d79555ccc4a5dfac554a456b6da2ff58e359fc100125685a9e4a5fec6aeb0965d5a4754569c7eaddb00e87e8a662d6571bc847'
7
- data.tar.gz: 11cf7b32a04fe5f481013f1caa01024ff1a8864392cdc98520ce507c64023de3e6d00632f2eb817dcd809fd406d7146488797a41ed09e5ed0a5331001bfdda20
6
+ metadata.gz: b5d490cbe529050a8d153ea8d50cf15cdf5b7bfd67bd27cf120007efc86a6d01d9854e647ada2cd388957a05763f6a93a68328c613e95c0d81eab8d78bb43c84
7
+ data.tar.gz: 6084a40cf6d4768e6688d5ea08410c684a06bd2abc13c76965f3fcb7e20b9df33f964ee1cf148480e74ca1ae160950a8f900fcb073d8115648dbb5f7135d30d1
data/.env.sample ADDED
@@ -0,0 +1 @@
1
+ GOOGLE_TOKEN=<your-google-token>
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ .env
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hiromikimura@pepabo.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 kimromi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Ruboty::PageSpeedInsights
2
+
3
+ [PageSpeed Insights](https://developers.google.com/speed/pagespeed/insights) handler for Ruboty.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ruboty-page_speed_insights'
11
+ ```
12
+
13
+ ## Environment
14
+
15
+ #### `GOOGLE_TOKEN`
16
+
17
+ For use the PageSpeed Insights API(Google API). You can make a token with [this URL](https://console.developers.google.com/projectselector/apis/credentials).
18
+
19
+ ## Usage
20
+
21
+ ```
22
+ @ruboty psi <URL>
23
+ ```
24
+
25
+ ## Screenshots
26
+
27
+ ![](https://raw.githubusercontent.com/kimromi/ruboty-page_speed_insights/master/screenshots/result.png)
28
+
29
+ ### for ruboty-slack_rtm
30
+
31
+ ![](https://github.com/kimromi/ruboty-page_speed_insights/blob/master/screenshots/result-for-ruboty-slack_rtm.png?raw=true)
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
36
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/page_speed_insights"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require "dotenv"
10
+ Dotenv.load
11
+
12
+ require "ruboty"
13
+ Ruboty::CommandBuilder.new(ARGV).build.call
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ require "ruboty/page_speed_insights/actions/page_speed_insights"
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ class PageSpeedInsights < Base
6
+ on(
7
+ /psi (?<url>.*?)\z/,
8
+ name: 'page_speed_insights',
9
+ description: 'output PageSpeed Insights result'
10
+ )
11
+
12
+ def page_speed_insights(message)
13
+ Ruboty::PageSpeedInsights::Actions::PageSpeedInsights.new(message).call
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ require "ruboty"
2
+ require "ruboty/page_speed_insights/version"
3
+ require "ruboty/handlers/page_speed_insights"
4
+ require "ruboty/page_speed_insights/actions/page_speed_insights"
5
+
6
+ module Ruboty
7
+ module PageSpeedInsights
8
+ end
9
+ end
@@ -0,0 +1,48 @@
1
+ require 'json'
2
+ require 'open-uri'
3
+
4
+ module Ruboty
5
+ module PageSpeedInsights
6
+ module Actions
7
+ class PageSpeedInsights < Ruboty::Actions::Base
8
+ def call
9
+ unless ENV.key?('GOOGLE_TOKEN')
10
+ message.reply('Please set environment. see https://github.com/kimromi/ruboty-page_speed_insights#environment')
11
+ return
12
+ end
13
+
14
+ url = message.match_data[:url].strip
15
+ unless url =~ %r(https?://[\w/:%#\$&\?\(\)~\.=\+\-]+)
16
+ message.reply("Invalid URL #{url}")
17
+ return
18
+ end
19
+
20
+ message.reply('Fetching PageSpeed Insights Result...')
21
+
22
+ results = %i(
23
+ desktop
24
+ mobile
25
+ ).each_with_object({}) do |strategy, hash|
26
+ google_url = "https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url=#{url}&strategy=#{strategy}&key=#{ENV['GOOGLE_TOKEN']}"
27
+ data = ::JSON.parse(open(google_url, &:read))
28
+
29
+ hash[strategy] = { score: data['ruleGroups']['SPEED']['score'] }.merge(data['pageStats'])
30
+ end
31
+
32
+ # for slack_rtm
33
+ attachments = results.map do |strategy, scores|
34
+ {
35
+ color: strategy == :desktop ? '#64b639' : '#1bbee7',
36
+ author_name: strategy.to_s.upcase,
37
+ author_link: "https://developers.google.com/speed/pagespeed/insights/?hl=en&url=#{url}&tab=#{strategy}",
38
+ fields: scores.map {|stats, score| { title: stats, value: score, short: true } },
39
+ ts: Time.now.to_i
40
+ }
41
+ end
42
+
43
+ message.reply("PageSpeed Insights Result #{results.map{|k, v| "#{k.capitalize}: #{v[:score]}"}.join(', ')}", attachments: attachments)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module PageSpeedInsights
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'ruboty/page_speed_insights/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "ruboty-page_speed_insights"
7
+ spec.version = Ruboty::PageSpeedInsights::VERSION
8
+ spec.authors = ["kimromi"]
9
+ spec.email = ["kimromi4@gmail.com"]
10
+
11
+ spec.summary = %q{Get PageSpeed Insights result via Ruboty.}
12
+ spec.description = %q{Get PageSpeed Insights result via Ruboty.}
13
+ spec.homepage = "https://github.com/kimromi/ruboty-page_speed_insights"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "ruboty"
21
+ spec.add_development_dependency "bundler", "~> 1.14"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "dotenv"
24
+ end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-page_speed_insights
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kimromi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-16 00:00:00.000000000 Z
11
+ date: 2017-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty
@@ -52,13 +52,43 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Get PageSpeed Insights result via Ruboty.
56
70
  email:
57
71
  - kimromi4@gmail.com
58
72
  executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
- files: []
75
+ files:
76
+ - ".env.sample"
77
+ - ".gitignore"
78
+ - CODE_OF_CONDUCT.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/ruboty/handlers/page_speed_insights.rb
86
+ - lib/ruboty/page_speed_insights.rb
87
+ - lib/ruboty/page_speed_insights/actions/page_speed_insights.rb
88
+ - lib/ruboty/page_speed_insights/version.rb
89
+ - ruboty-page_speed_insights.gemspec
90
+ - screenshots/result-for-ruboty-slack_rtm.png
91
+ - screenshots/result.png
62
92
  homepage: https://github.com/kimromi/ruboty-page_speed_insights
63
93
  licenses:
64
94
  - MIT