envato_optimiser 0.1.0
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 +10 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +45 -0
- data/Rakefile +6 -0
- data/envato_optimiser.gemspec +28 -0
- data/lib/envato_optimiser.rb +8 -0
- data/lib/envato_optimiser/checks.rb +5 -0
- data/lib/envato_optimiser/checks/image_response_status_code_check.rb +65 -0
- data/lib/envato_optimiser/checks/total_image_weight_check.rb +32 -0
- data/lib/envato_optimiser/item.rb +54 -0
- data/lib/envato_optimiser/version.rb +6 -0
- metadata +115 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 3b98db63d51545e95d458fc4be5a835969cf9749
|
|
4
|
+
data.tar.gz: d6e8428c2ba4928f0792139bd1ecd98d2bae006b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 3803fe936c19dafb457839fd41ece441516f4b99ef4dafb5b2d56e45e79b526a1ccfc40f7688cc3fb7fe036277fb3de5533d3a21645facc2895aa92027c8678e
|
|
7
|
+
data.tar.gz: a39ddc008d4262fb7cd1d5424d7d73aa0c8203b4ae90a4401d42c61e54878742adf2310caec97f419fea581fafa18ef8ce2aa4aa79cda95a352c7aa8f29765a5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2016 Jacob Bednarz
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
|
4
|
+
copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included
|
|
12
|
+
in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Envato Optimiser
|
|
2
|
+
|
|
3
|
+
A gem to make it easier to identify potential issues on your Envato item pages.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'envato_optimiser'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
$ bundle
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
$ gem install envato_optimiser
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
To use this you need to first instantiate a new instance of
|
|
28
|
+
`EnvatoOptimiser::Item` and pass in the full URI of the item page. For
|
|
29
|
+
example:
|
|
30
|
+
|
|
31
|
+
```rb
|
|
32
|
+
item = EnvatoOptimiser::Item.new('https://themeforest.net/item/avada-responsive-multipurpose-theme/2833226')
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Once you have this setup, you can run the `check!` method to perform
|
|
36
|
+
the tests.
|
|
37
|
+
|
|
38
|
+
```rb
|
|
39
|
+
item.check!
|
|
40
|
+
#=> {:image_count=>73, :image_403_count=>0, :image_404_count=>0, :image_redirect_count=>2, :total_image_weight=>3895262}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
This will return a hash with the results of the check. Depending on the
|
|
44
|
+
number of images found in the item page (and the speed the origin server
|
|
45
|
+
can process requests) this can take a minute or so to complete.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'envato_optimiser/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = 'envato_optimiser'
|
|
8
|
+
spec.version = EnvatoOptimiser::VERSION
|
|
9
|
+
spec.authors = ['Jacob Bednarz']
|
|
10
|
+
spec.email = ['jacob.bednarz@gmail.com']
|
|
11
|
+
spec.licenses = ['MIT']
|
|
12
|
+
spec.summary = %q{A gem to make it easier to identify potential issues on your Envato item pages.}
|
|
13
|
+
spec.homepage = 'https://github.com/jacobbednarz/envato_optimiser'
|
|
14
|
+
|
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
spec.bindir = 'bin'
|
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
|
+
spec.require_paths = ['lib']
|
|
22
|
+
|
|
23
|
+
spec.add_dependency 'nokogiri', '>= 1.6.7'
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
|
28
|
+
end
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
require 'envato_optimiser/version'
|
|
2
|
+
require 'envato_optimiser/item'
|
|
3
|
+
require 'envato_optimiser/checks'
|
|
4
|
+
require 'envato_optimiser/checks/image_response_status_code_check'
|
|
5
|
+
require 'envato_optimiser/checks/total_image_weight_check'
|
|
6
|
+
|
|
7
|
+
module EnvatoOptimiser
|
|
8
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
module EnvatoOptimiser
|
|
2
|
+
class ImageResponseStatusCodeCheck < Checks
|
|
3
|
+
# Initialize an image response status code check.
|
|
4
|
+
#
|
|
5
|
+
# @param image_urls [Array] Image URLs that you would like to check the HTTP
|
|
6
|
+
# response status codes for.
|
|
7
|
+
#
|
|
8
|
+
# @return [Nothing].
|
|
9
|
+
def initialize(image_urls)
|
|
10
|
+
@redirects = []
|
|
11
|
+
@not_found = []
|
|
12
|
+
@forbidden = []
|
|
13
|
+
@server_error = []
|
|
14
|
+
|
|
15
|
+
fetch_image_responses(image_urls)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Format the image response status code results into a usable Hash.
|
|
19
|
+
#
|
|
20
|
+
# @return [Hash]
|
|
21
|
+
def to_h
|
|
22
|
+
{
|
|
23
|
+
:image_redirect_count => redirect_count,
|
|
24
|
+
:image_not_found_count => not_found_count,
|
|
25
|
+
:image_forbidden_count => forbidden_count,
|
|
26
|
+
:image_server_error_count => server_error_count,
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
def redirect_count
|
|
33
|
+
@redirects.size
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def not_found_count
|
|
37
|
+
@not_found.size
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def forbidden_count
|
|
41
|
+
@forbidden.size
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def server_error_count
|
|
45
|
+
@server_error.size
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def fetch_image_responses(image_urls)
|
|
49
|
+
image_urls.each do |image|
|
|
50
|
+
response = Net::HTTP.get_response(URI.parse(image))
|
|
51
|
+
|
|
52
|
+
case response.code.to_i
|
|
53
|
+
when 300..399
|
|
54
|
+
@redirects << image
|
|
55
|
+
when 404
|
|
56
|
+
@not_found << image
|
|
57
|
+
when 403
|
|
58
|
+
@forbidden << image
|
|
59
|
+
when 500..599
|
|
60
|
+
@server_error << image
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module EnvatoOptimiser
|
|
2
|
+
class TotalImageWeightCheck < Checks
|
|
3
|
+
# Initialize a total image weight check.
|
|
4
|
+
#
|
|
5
|
+
# @param image_urls [Array] Image URLs that you would like to fetch the
|
|
6
|
+
# total image weight for.
|
|
7
|
+
#
|
|
8
|
+
# @return [Nothing].
|
|
9
|
+
def initialize(image_urls)
|
|
10
|
+
@total_image_weight = 0
|
|
11
|
+
get_total_image_weight(image_urls)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Format the results into a usable Hash.
|
|
15
|
+
#
|
|
16
|
+
# @return [Hash] `:total_image_weight` is the total image size in bytes.
|
|
17
|
+
def to_h
|
|
18
|
+
{
|
|
19
|
+
:total_image_weight => @total_image_weight
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def get_total_image_weight(image_urls)
|
|
26
|
+
image_urls.each do |image|
|
|
27
|
+
response = Net::HTTP.get_response(URI.parse(image))
|
|
28
|
+
@total_image_weight += response.content_length
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'net/http'
|
|
2
|
+
require 'uri'
|
|
3
|
+
require 'nokogiri'
|
|
4
|
+
|
|
5
|
+
module EnvatoOptimiser
|
|
6
|
+
class Item
|
|
7
|
+
# Initialize a new item page.
|
|
8
|
+
#
|
|
9
|
+
# @return [Nothing]
|
|
10
|
+
def initialize(item_url)
|
|
11
|
+
uri = URI.parse(item_url)
|
|
12
|
+
response = Net::HTTP.get_response(uri)
|
|
13
|
+
@document = Nokogiri::HTML(response.body)
|
|
14
|
+
@image_urls = image_urls
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Run checks against a specific item page.
|
|
18
|
+
#
|
|
19
|
+
# @param skip_image_status_check [Boolean] Used for determining whether or
|
|
20
|
+
# not the image HTTP response status checks should be run.
|
|
21
|
+
# @param skip_total_image_weight_check [Boolean] Determine whether or not
|
|
22
|
+
# you would like to calculate the total image weight generated by the item
|
|
23
|
+
# page.
|
|
24
|
+
#
|
|
25
|
+
# @return [Hash] Consolidated list of the checks output.
|
|
26
|
+
def check!(skip_image_status_check: false, skip_total_image_weight_check: false)
|
|
27
|
+
reports = []
|
|
28
|
+
|
|
29
|
+
reports << EnvatoOptimiser::ImageResponseStatusCodeCheck.new(@image_urls).to_h unless skip_image_status_check
|
|
30
|
+
reports << EnvatoOptimiser::TotalImageWeightCheck.new(@image_urls).to_h unless skip_total_image_weight_check
|
|
31
|
+
|
|
32
|
+
reports.inject(&:merge)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
# Gather all the image URLs.
|
|
38
|
+
#
|
|
39
|
+
# Loops over the document output and collects all of the image source values
|
|
40
|
+
# within the defined CSS div where user input is declared.
|
|
41
|
+
#
|
|
42
|
+
# @return [Array] All the images found in the requested document.
|
|
43
|
+
def image_urls
|
|
44
|
+
images = []
|
|
45
|
+
|
|
46
|
+
@document.css('.user-html img').map do |image|
|
|
47
|
+
images << image.attributes['src'].value
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Don't choke on protocol relative URL's.
|
|
51
|
+
images.collect { |image| image.gsub(%r{^//}, 'https://') }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: envato_optimiser
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jacob Bednarz
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-01-26 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: nokogiri
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 1.6.7
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 1.6.7
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1.13'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1.13'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.0'
|
|
69
|
+
description:
|
|
70
|
+
email:
|
|
71
|
+
- jacob.bednarz@gmail.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- ".gitignore"
|
|
77
|
+
- ".rspec"
|
|
78
|
+
- ".travis.yml"
|
|
79
|
+
- Gemfile
|
|
80
|
+
- LICENSE
|
|
81
|
+
- README.md
|
|
82
|
+
- Rakefile
|
|
83
|
+
- envato_optimiser.gemspec
|
|
84
|
+
- lib/envato_optimiser.rb
|
|
85
|
+
- lib/envato_optimiser/checks.rb
|
|
86
|
+
- lib/envato_optimiser/checks/image_response_status_code_check.rb
|
|
87
|
+
- lib/envato_optimiser/checks/total_image_weight_check.rb
|
|
88
|
+
- lib/envato_optimiser/item.rb
|
|
89
|
+
- lib/envato_optimiser/version.rb
|
|
90
|
+
homepage: https://github.com/jacobbednarz/envato_optimiser
|
|
91
|
+
licenses:
|
|
92
|
+
- MIT
|
|
93
|
+
metadata: {}
|
|
94
|
+
post_install_message:
|
|
95
|
+
rdoc_options: []
|
|
96
|
+
require_paths:
|
|
97
|
+
- lib
|
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
|
+
requirements:
|
|
105
|
+
- - ">="
|
|
106
|
+
- !ruby/object:Gem::Version
|
|
107
|
+
version: '0'
|
|
108
|
+
requirements: []
|
|
109
|
+
rubyforge_project:
|
|
110
|
+
rubygems_version: 2.5.1
|
|
111
|
+
signing_key:
|
|
112
|
+
specification_version: 4
|
|
113
|
+
summary: A gem to make it easier to identify potential issues on your Envato item
|
|
114
|
+
pages.
|
|
115
|
+
test_files: []
|