gastly 0.2.3 → 0.2.4

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: a44ef15ac998bc80a529ceb87f868e53c8ce61bf
4
- data.tar.gz: 75a64b654c9031160a85aff58f5ef47b2f1add23
3
+ metadata.gz: 72868583159f8e35a055086dbba4130ad364589e
4
+ data.tar.gz: 7f86570ddc94846083a66fddc3e20234ae7ecef6
5
5
  SHA512:
6
- metadata.gz: 8d110af0420f000a7851a1c21855ec111d4924ce34df3b5677fb8db1c57835fc541a96596e5f2c5fc1366955ba16b69a4df1c66db9ec5a40d25430cadc18ad78
7
- data.tar.gz: 83e1dd27eb9f8122bc86764c03a2c837f512742300d86e905b188fe3f934e2e60139e091b0d0ae43d4122f2b76c0c1966448efdf46c2eb435d33522dae397da0
6
+ metadata.gz: 3fe604a0a919d5d76a6be7358074e1348da096919c4db9217361d23fca30efc4d39a55d5e491772a692a87f521060a003be5c9a5820570bb9191a10b4a8bfa14
7
+ data.tar.gz: da9a98e0fe76658bb2a779623205e0628124c5138e0dd564c2bfe09b014e4ecf227913c7b4918f99b10991ba908d495735eef9741eadbdb313979a9feb6c4951
@@ -0,0 +1 @@
1
+ repo_token: Yl4eB6CrBH8Jq6D02bBV5MxCtrNfDGP4L
@@ -0,0 +1 @@
1
+ 2.2.3
@@ -1,6 +1,11 @@
1
+ dist: trusty
1
2
  language: ruby
2
3
  rvm:
3
- - 1.9.3
4
- - 2.0.0
5
4
  - 2.1.7
6
- - 2.2.3
5
+ - 2.2.3
6
+ - 2.3.0
7
+ before_install:
8
+ - mkdir travis-phantomjs
9
+ - wget https://s3.amazonaws.com/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2 -O $PWD/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2
10
+ - tar -xvf $PWD/travis-phantomjs/phantomjs-2.0.0-ubuntu-12.04.tar.bz2 -C $PWD/travis-phantomjs
11
+ - export PATH=$PWD/travis-phantomjs:$PATH
@@ -1,3 +1,9 @@
1
+ ## 0.2.4 (24/01/2016)
2
+
3
+ ### Enhancements
4
+
5
+ * Code optimization
6
+
1
7
  ## 0.2.3 (23/11/2015)
2
8
 
3
9
  ### Enhancements
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in gastly.gemspec
4
4
  gemspec
5
+
6
+ gem 'coveralls', require: false
data/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/gastly.svg)](http://badge.fury.io/rb/gastly)
4
4
  [![Dependency Status](https://gemnasium.com/mgrachev/gastly.svg)](https://gemnasium.com/mgrachev/gastly)
5
5
  [![Code Climate](https://codeclimate.com/github/mgrachev/gastly/badges/gpa.svg)](https://codeclimate.com/github/mgrachev/gastly)
6
+ [![Build Status](https://travis-ci.org/mgrachev/gastly.svg?branch=master)](https://travis-ci.org/mgrachev/gastly)
7
+ [![Coverage Status](https://coveralls.io/repos/github/mgrachev/gastly/badge.svg?branch=master)](https://coveralls.io/github/mgrachev/gastly?branch=master)
6
8
 
7
9
  Create screenshots or previews of web pages using Gastly. Under the hood [Phantom.js](https://github.com/ariya/phantomjs/) and [MiniMagick](https://github.com/minimagick/minimagick). Gastly, I choose you!
8
10
 
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
+ require 'bundler/setup'
1
2
  require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task default: :spec
@@ -18,9 +18,10 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency 'bundler', '~> 1.9'
21
+ spec.add_development_dependency 'bundler'
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
23
  spec.add_development_dependency 'rubocop'
24
+ spec.add_development_dependency 'rspec', '~> 3.4.0'
24
25
 
25
26
  spec.add_dependency 'phantomjs2', '~> 2.0'
26
27
  spec.add_dependency 'mini_magick', '~> 4.2'
@@ -1,3 +1,8 @@
1
+ require 'phantomjs'
2
+ require 'mini_magick'
3
+ require 'active_support/core_ext/hash/keys'
4
+ require 'active_support/core_ext/object/blank'
5
+
1
6
  require_relative 'gastly/image'
2
7
  require_relative 'gastly/screenshot'
3
8
  require_relative 'gastly/exceptions'
@@ -8,4 +8,5 @@ module Gastly
8
8
  end
9
9
 
10
10
  PhantomJSError = Class.new(RuntimeError)
11
+ UnknownError = Class.new(RuntimeError)
11
12
  end
@@ -1,25 +1,29 @@
1
- require 'mini_magick'
2
-
3
1
  module Gastly
4
2
  class Image
5
- attr_reader :file
3
+ attr_reader :image
6
4
 
7
- def initialize(tempfile)
8
- @file = MiniMagick::Image.open(tempfile.path)
9
- tempfile.unlink
5
+ # @param image [MiniMagick::Image] Instance of MiniMagick::Image
6
+ def initialize(image)
7
+ @image = image
10
8
  end
11
9
 
10
+ # @param width [Fixnum] Image width
11
+ # @param height [Fixnum] Image height
12
12
  def resize(width:, height:)
13
13
  dimensions = "#{width}x#{height}"
14
- @file.resize(dimensions)
14
+ image.resize(dimensions)
15
15
  end
16
16
 
17
+ # @param ext [String] Image extension
18
+ # @return [MiniMagick::Image] Instance
17
19
  def format(ext)
18
- @file.format(ext)
20
+ image.format(ext)
19
21
  end
20
22
 
23
+ # @param output [String] Full path to image
24
+ # @return [String] Full path to image
21
25
  def save(output)
22
- @file.write(output)
26
+ image.write(output)
23
27
  output
24
28
  end
25
29
  end
@@ -1,51 +1,46 @@
1
- require 'phantomjs'
2
- require 'active_support/core_ext/hash/keys'
3
- require 'active_support/core_ext/object/blank'
4
-
5
1
  module Gastly
6
2
  class Screenshot
7
3
  SCRIPT_PATH = File.expand_path('../script.js', __FILE__)
8
4
  DEFAULT_TIMEOUT = 0
9
5
  DEFAULT_BROWSER_WIDTH = 1440
10
6
  DEFAULT_BROWSER_HEIGHT = 900
11
- DEFAULT_FILE_NAME = 'output'.freeze
12
7
  DEFAULT_FILE_FORMAT = '.png'.freeze
13
8
 
9
+ attr_reader :image
14
10
  attr_writer :timeout, :browser_width, :browser_height
15
11
  attr_accessor :url, :selector, :cookies, :proxy_host, :proxy_port
16
- attr_reader :tempfile
17
12
 
13
+ # @param url [String] The full url to the site
18
14
  def initialize(url, **kwargs)
19
15
  kwargs.assert_valid_keys(:timeout, :browser_width, :browser_height, :selector, :cookies, :proxy_host, :proxy_port)
20
16
 
21
17
  @url = url
22
- @tempfile = Tempfile.new([DEFAULT_FILE_NAME, DEFAULT_FILE_FORMAT])
23
- self.cookies = kwargs.delete(:cookies)
24
-
25
- kwargs.each { |key, value| instance_variable_set(:"@#{key}", value) }
26
- end
27
-
28
- def timeout
29
- @timeout || DEFAULT_TIMEOUT
30
- end
18
+ @cookies = kwargs.delete(:cookies)
31
19
 
32
- def browser_width
33
- @browser_width || DEFAULT_BROWSER_WIDTH
34
- end
20
+ @image = MiniMagick::Image.create(DEFAULT_FILE_FORMAT, false) # Disable validation
35
21
 
36
- def browser_height
37
- @browser_height || DEFAULT_BROWSER_HEIGHT
22
+ kwargs.each { |key, value| instance_variable_set(:"@#{key}", value) }
38
23
  end
39
24
 
25
+ # Capture image via PhantomJS and save to output file
26
+ #
27
+ # @return [Gastly::Image] Instance of Gastly::Image
40
28
  def capture
29
+ # This necessary to install PhantomJS via proxy
41
30
  Phantomjs.proxy_host = proxy_host if proxy_host
42
31
  Phantomjs.proxy_port = proxy_port if proxy_port
43
32
 
44
33
  output = Phantomjs.run(proxy_options, SCRIPT_PATH.to_s, *prepared_params)
34
+ handle_output(output)
45
35
 
46
- handle_exception(output) if output.present?
36
+ Gastly::Image.new(image)
37
+ end
47
38
 
48
- Gastly::Image.new(tempfile)
39
+ %w(timeout browser_width browser_height).each do |name|
40
+ define_method name do # def timeout
41
+ instance_variable_get("@#{name}") || # @timeout ||
42
+ self.class.const_get("default_#{name}".upcase) # self.class.const_get('DEFAULT_TIMEOUT')
43
+ end # end
49
44
  end
50
45
 
51
46
  private
@@ -61,23 +56,28 @@ module Gastly
61
56
  timeout: timeout,
62
57
  width: browser_width,
63
58
  height: browser_height,
64
- output: tempfile.path
59
+ output: image.path
65
60
  }
66
61
 
67
62
  params[:selector] = selector if selector.present?
68
- params[:cookies] = hash_to_array(cookies).join(',') if cookies.present?
63
+ params[:cookies] = parameterize(cookies).join(',') if cookies.present?
69
64
 
70
- hash_to_array(params)
65
+ parameterize(params)
71
66
  end
72
67
 
73
- def hash_to_array(data)
74
- data.map { |key, value| "#{key}=#{value}" }
68
+ # @param hash [Hash]
69
+ # @return [Array] Array of parameterized strings
70
+ def parameterize(hash)
71
+ hash.map { |key, value| "#{key}=#{value}" }
75
72
  end
76
73
 
77
- def handle_exception(output)
74
+ def handle_output(output)
75
+ return unless output.present?
76
+
78
77
  error = case output
79
78
  when /^FetchError:(.+)/ then Gastly::FetchError
80
79
  when /^RuntimeError:(.+)/m then Gastly::PhantomJSError
80
+ else UnknownError
81
81
  end
82
82
 
83
83
  fail error, Regexp.last_match(1)
@@ -1,3 +1,3 @@
1
1
  module Gastly
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gastly
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikhail Grachev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-11-23 00:00:00.000000000 Z
11
+ date: 2016-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.9'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.9'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '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.4.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.4.0
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: phantomjs2
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -102,8 +116,10 @@ executables: []
102
116
  extensions: []
103
117
  extra_rdoc_files: []
104
118
  files:
119
+ - ".coveralls.yml"
105
120
  - ".gitignore"
106
121
  - ".rubocop.yml"
122
+ - ".ruby-version"
107
123
  - ".travis.yml"
108
124
  - CHANGELOG.md
109
125
  - Gemfile
@@ -138,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
154
  version: '0'
139
155
  requirements: []
140
156
  rubyforge_project:
141
- rubygems_version: 2.4.5
157
+ rubygems_version: 2.4.5.1
142
158
  signing_key:
143
159
  specification_version: 4
144
160
  summary: Create screenshots or previews of web pages using Gastly. Gastly, I choose