google_mobile_friendly 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/google_mobile_friendly.gemspec +29 -0
- data/lib/google_mobile_friendly.rb +15 -0
- data/lib/google_mobile_friendly/request.rb +23 -0
- data/lib/google_mobile_friendly/response_data/mobile_friendly_issue.rb +19 -0
- data/lib/google_mobile_friendly/response_data/resource_issue.rb +11 -0
- data/lib/google_mobile_friendly/response_data/run_mobile_friendly_test_response.rb +13 -0
- data/lib/google_mobile_friendly/response_data/test_status.rb +18 -0
- data/lib/google_mobile_friendly/test_page.rb +23 -0
- data/lib/google_mobile_friendly/version.rb +3 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2b6336b135771aed6ff80ba94b710cc61b82430b
|
4
|
+
data.tar.gz: 2a9325d8cc1b681bae8edbd7c35bd4ea955d65b1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9e828030b269b26aa5b1ee1c4a8575bb5cb47c4b15735925f08631a22be8d14d7e1f8d307d43f83699f24affde31cf2c69ab8bc8fab0083582e5be764b2cca41
|
7
|
+
data.tar.gz: d8c2db05f769219cef60c7bcac0697a4aac6f4c634eaf25c57cc5b65c715ba6fd17f4313e3a50891313627f6986e4d150a6c8693acc3bd09e479aaa17c2a0f83
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Pavel Kozlov
|
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,49 @@
|
|
1
|
+
# GoogleMobileFriendly
|
2
|
+
|
3
|
+
[](https://travis-ci.org/loadkpi/google_mobile_friendly) [](https://codeclimate.com/github/loadkpi/google_mobile_friendly)
|
4
|
+
|
5
|
+
Ruby Wrapper for Mobile-Friendly Test from Google Search Console URL Testing Tools API
|
6
|
+
|
7
|
+
See Google documentation for more information - https://developers.google.com/webmaster-tools/search-console-api/reference/rest/
|
8
|
+
|
9
|
+
## Requirements
|
10
|
+
|
11
|
+
* Ruby >= 2.0.0
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'google_mobile_friendly'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install google_mobile_friendly
|
28
|
+
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
page_one = GoogleMobileFriendly.run_test 'http://google.com', 'YOUR_API_KEY'
|
33
|
+
page_one.is_mobile_friendly?
|
34
|
+
# => true
|
35
|
+
page_one.list_of_mobile_issues
|
36
|
+
# => nil
|
37
|
+
page_one.list_of_blocked_resources
|
38
|
+
# => ["https://www.gstatic.com/og/_/ss/k=og.mob.o3hu3mtmammu.L.W.O/m=md/excm=mih,mab,meb/d=1/ed=1/rs=AA2YrTsgcHY9rgal7Q_4KtT2B4QI4nDAcA", "https://www.gstatic.com/og/_/js/k=og.mob.en_US.09TQbv5ZB3k.O/rt=j/m=md/exm=mih,mab,meb/d=1/ed=1/rs=AA2YrTtYyrscNOyD60o4h8_Tc0H3-gaXUQ", "https://www.google.com/xjs/_/js/k=xjs.qs.en_US.JLMJY8f85DU.O/m=sx,c,sb_mob,bct,cdos,elog,hsm,jsa,mbsf,qim,r,qsm,d,csi/am=gCNop3GCBgwAWHU0S-wLCAEoBA/rt=j/d=1/t=zcms/rs=ACT90oHfJ0gcIaPuA4F8guH-oefRznVKvw"]
|
39
|
+
|
40
|
+
page_two = GoogleMobileFriendly.run_test 'http://edition.cnn.com/EVENTS/1996/year.in.review/', 'YOUR_API_KEY'
|
41
|
+
page_two.is_mobile_friendly?
|
42
|
+
# => false
|
43
|
+
page_two.list_of_mobile_issues
|
44
|
+
# => ["Touch elements are too close to each other. [Learn more]\n(https://support.google.com/webmasters/answer/6352293#touch_elements_too_close).", "Viewsport is not specified using the meta viewport tag. [Learn more]\n(https://support.google.com/webmasters/answer/6352293#viewport_not_configured).", "Font size is too small for easy reading on a small screen. [Learn More]\n(https://support.google.com/webmasters/answer/6352293#small_font_size)."]
|
45
|
+
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'google_mobile_friendly/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "google_mobile_friendly"
|
8
|
+
spec.version = GoogleMobileFriendly::VERSION
|
9
|
+
spec.authors = ["Pavel Kozlov"]
|
10
|
+
spec.email = ["loadkpi@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Google Mobile-Friendly Test API wrapper for Ruby"
|
13
|
+
spec.description = "Ruby Wrapper for Mobile-Friendly Test from Google Search Console URL Testing Tools API"
|
14
|
+
spec.homepage = "https://github.com/loadkpi/google_mobile_friendly"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", '~> 1.7'
|
25
|
+
spec.add_development_dependency "rake", '>= 10.0'
|
26
|
+
spec.add_development_dependency "rspec", '~> 3.1'
|
27
|
+
spec.add_development_dependency "webmock", '~> 2.0'
|
28
|
+
spec.add_development_dependency "simplecov", '~> 0.10'
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'google_mobile_friendly/request'
|
2
|
+
require 'google_mobile_friendly/test_page'
|
3
|
+
require 'google_mobile_friendly/response_data/mobile_friendly_issue'
|
4
|
+
require 'google_mobile_friendly/response_data/resource_issue'
|
5
|
+
require 'google_mobile_friendly/response_data/run_mobile_friendly_test_response'
|
6
|
+
require 'google_mobile_friendly/response_data/test_status'
|
7
|
+
require 'google_mobile_friendly/version'
|
8
|
+
|
9
|
+
|
10
|
+
module GoogleMobileFriendly
|
11
|
+
def self.run_test url, api_key
|
12
|
+
request = GoogleMobileFriendly::Request.new url, api_key
|
13
|
+
request.execute
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module GoogleMobileFriendly
|
5
|
+
class Request
|
6
|
+
#see https://searchconsole.googleapis.com/$discovery/rest?version=v1 for more info
|
7
|
+
GOOGLE_TEST_REQUEST_URI = 'https://searchconsole.googleapis.com/v1/urlTestingTools/mobileFriendlyTest:run'
|
8
|
+
|
9
|
+
def initialize url, api_key
|
10
|
+
@url = url
|
11
|
+
@api_key = api_key
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
uri = URI(GOOGLE_TEST_REQUEST_URI)
|
16
|
+
params = {:key => @api_key}
|
17
|
+
uri.query = URI.encode_www_form(params)
|
18
|
+
http_result = Net::HTTP.post_form(uri, 'url' => @url)
|
19
|
+
response = JSON.parse(http_result.body, symbolize_names: true)
|
20
|
+
GoogleMobileFriendly::TestPage.new response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module GoogleMobileFriendly
|
2
|
+
module ResponseData
|
3
|
+
class MobileFriendlyIssue
|
4
|
+
MOBILE_FRIENDLY_RULE_UNSPECIFIED = "Unknown rule. Sorry, we don't have any description for the rule that was\nbroken."
|
5
|
+
USES_INCOMPATIBLE_PLUGINS = "Plugins incompatible with mobile devices are being used. [Learn more]\n(https://support.google.com/webmasters/answer/6352293#flash_usage)."
|
6
|
+
CONFIGURE_VIEWPORT = "Viewsport is not specified using the meta viewport tag. [Learn more]\n(https://support.google.com/webmasters/answer/6352293#viewport_not_configured)."
|
7
|
+
FIXED_WIDTH_VIEWPORT = "Viewport defined to a fixed width. [Learn more]\n(https://support.google.com/webmasters/answer/6352293#fixed-width_viewport)."
|
8
|
+
SIZE_CONTENT_TO_VIEWPORT = "Content not sized to viewport. [Learn more]\n(https://support.google.com/webmasters/answer/6352293#content_not_sized_to_viewport)."
|
9
|
+
USE_LEGIBLE_FONT_SIZES = "Font size is too small for easy reading on a small screen. [Learn More]\n(https://support.google.com/webmasters/answer/6352293#small_font_size)."
|
10
|
+
TAP_TARGETS_TOO_CLOSE = "Touch elements are too close to each other. [Learn more]\n(https://support.google.com/webmasters/answer/6352293#touch_elements_too_close)."
|
11
|
+
|
12
|
+
def self.get_user_friendly_issues response
|
13
|
+
response[:mobileFriendlyIssues].map do |issue|
|
14
|
+
self.const_get issue[:rule]
|
15
|
+
end unless response[:mobileFriendlyIssues].nil?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module GoogleMobileFriendly
|
2
|
+
module ResponseData
|
3
|
+
class ResourceIssue
|
4
|
+
def self.get_blocked_resources_issues_urls response
|
5
|
+
response[:resourceIssues].map do |issue|
|
6
|
+
issue[:blockedResource][:url]
|
7
|
+
end unless response[:resourceIssues].nil?
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module GoogleMobileFriendly
|
2
|
+
module ResponseData
|
3
|
+
class RunMobileFriendlyTestResponse
|
4
|
+
MOBILE_FRIENDLY_TEST_RESULT_UNSPECIFIED = 'Internal error when running this test. Please try running the test again.'
|
5
|
+
MOBILE_FRIENDLY = 'The page is mobile friendly.'
|
6
|
+
NOT_MOBILE_FRIENDLY = 'The page is not mobile friendly.'
|
7
|
+
|
8
|
+
def self.mobile_friendly
|
9
|
+
'MOBILE_FRIENDLY'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module GoogleMobileFriendly
|
2
|
+
module ResponseData
|
3
|
+
class TestStatus
|
4
|
+
TEST_STATUS_UNSPECIFIED = "Internal error when running this test. Please try running the test again."
|
5
|
+
COMPLETE = "Inspection has completed without errors."
|
6
|
+
INTERNAL_ERROR = "Inspection terminated in an error state. This indicates a problem in\nGoogle's infrastructure, not a user error. Please try again later."
|
7
|
+
PAGE_UNREACHABLE = "Google can not access the URL because of a user error such as a robots.txt\nblockage, a 403 or 500 code etc. Please make sure that the URL provided is\naccessible by Googlebot and is not password protected."
|
8
|
+
|
9
|
+
def self.raise_if_response_is_bad response
|
10
|
+
return if response[:testStatus][:status] == "COMPLETE"
|
11
|
+
raise MobileFriendlyAPIError.new(self.const_get response[:testStatus][:status])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class MobileFriendlyAPIError < StandardError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module GoogleMobileFriendly
|
2
|
+
class TestPage
|
3
|
+
attr_reader :response
|
4
|
+
|
5
|
+
def initialize api_response
|
6
|
+
@response = api_response
|
7
|
+
raise @response[:error][:message] unless @response[:error].nil?
|
8
|
+
GoogleMobileFriendly::ResponseData::TestStatus.raise_if_response_is_bad @response
|
9
|
+
end
|
10
|
+
|
11
|
+
def is_mobile_friendly?
|
12
|
+
@response[:mobileFriendliness] == GoogleMobileFriendly::ResponseData::RunMobileFriendlyTestResponse.mobile_friendly
|
13
|
+
end
|
14
|
+
|
15
|
+
def list_of_mobile_issues
|
16
|
+
GoogleMobileFriendly::ResponseData::MobileFriendlyIssue.get_user_friendly_issues @response
|
17
|
+
end
|
18
|
+
|
19
|
+
def list_of_blocked_resources
|
20
|
+
GoogleMobileFriendly::ResponseData::ResourceIssue.get_blocked_resources_issues_urls @response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_mobile_friendly
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pavel Kozlov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
description: Ruby Wrapper for Mobile-Friendly Test from Google Search Console URL
|
84
|
+
Testing Tools API
|
85
|
+
email:
|
86
|
+
- loadkpi@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- google_mobile_friendly.gemspec
|
101
|
+
- lib/google_mobile_friendly.rb
|
102
|
+
- lib/google_mobile_friendly/request.rb
|
103
|
+
- lib/google_mobile_friendly/response_data/mobile_friendly_issue.rb
|
104
|
+
- lib/google_mobile_friendly/response_data/resource_issue.rb
|
105
|
+
- lib/google_mobile_friendly/response_data/run_mobile_friendly_test_response.rb
|
106
|
+
- lib/google_mobile_friendly/response_data/test_status.rb
|
107
|
+
- lib/google_mobile_friendly/test_page.rb
|
108
|
+
- lib/google_mobile_friendly/version.rb
|
109
|
+
homepage: https://github.com/loadkpi/google_mobile_friendly
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.4.5
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Google Mobile-Friendly Test API wrapper for Ruby
|
133
|
+
test_files: []
|