prtscr 0.2.0 → 0.3.0

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
- SHA1:
3
- metadata.gz: 8c5c49d2442534e189e5907a9edd239479ec9b6d
4
- data.tar.gz: 7d66cde279445b94f5c084e8f381b58031a84603
2
+ SHA256:
3
+ metadata.gz: fd71d32117b01be234eeefb0c6b9b431cbcc27d9fd018653d53e29f32a2b24cb
4
+ data.tar.gz: e5562258a66c4b6b3f306acb98f6c1d24da45654965436b867aae80511686a99
5
5
  SHA512:
6
- metadata.gz: b280d624379f28c8fdec5241c26517444ab994ba5c17c7eb783729d12ef5b9b9d2febb49744c1e124ca33e8860e5f66cad5470d5229d8282c846025d244e3ea3
7
- data.tar.gz: 7530dcf63710dedb263c1644bc7a2458fba3e4582fd825025960fcf6066fc88e450195e862b7992f25543769024de348bdc15379bdabf7c345fd91f60f85f471
6
+ metadata.gz: 0b963b49b70cd584acb469af715f5b084a4d4b04a2d03b3c10d3385a1be112a3076533d2767b5e881c6a6d5e458b465bf6e77a564b199cb97005a256ed5c2425
7
+ data.tar.gz: abd3af24c81ed508b58a9a3830d9e9121c7dbefeb9e7daa6ae4188a34a0c6242f0f61d69b9b629c1177678a6449d970012247db1b7394c8e06bdbe9ec1808385
data/.gitignore CHANGED
@@ -1,9 +1,11 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
7
6
  /pkg/
8
7
  /spec/reports/
9
8
  /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --require spec_helper
@@ -0,0 +1,3 @@
1
+ require: rubocop-rspec
2
+ Metrics/BlockLength:
3
+ IgnoredMethods: ['describe', 'context']
@@ -1,5 +1,6 @@
1
- sudo: false
1
+ ---
2
2
  language: ruby
3
+ cache: bundler
3
4
  rvm:
4
- - 2.4.0
5
- before_install: gem install bundler -v 1.13.7
5
+ - 2.7.2
6
+ before_install: gem install bundler -v 2.1.4
@@ -68,7 +68,7 @@ members of the project's leadership.
68
68
  ## Attribution
69
69
 
70
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]
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
72
 
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile CHANGED
@@ -1,4 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in prtscr.gemspec
4
6
  gemspec
7
+
8
+ gem 'rake', '~> 12.0', require: false
9
+
10
+ group :development, :test do
11
+ gem 'rspec', '~> 3.0'
12
+ gem 'rubocop'
13
+ end
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ prtscr (0.3.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ diff-lcs (1.4.4)
11
+ parallel (1.20.1)
12
+ parser (3.0.0.0)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
15
+ rake (12.3.3)
16
+ regexp_parser (2.0.3)
17
+ rexml (3.2.4)
18
+ rspec (3.10.0)
19
+ rspec-core (~> 3.10.0)
20
+ rspec-expectations (~> 3.10.0)
21
+ rspec-mocks (~> 3.10.0)
22
+ rspec-core (3.10.1)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-expectations (3.10.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-mocks (3.10.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-support (3.10.1)
31
+ rubocop (1.8.0)
32
+ parallel (~> 1.10)
33
+ parser (>= 3.0.0.0)
34
+ rainbow (>= 2.2.2, < 4.0)
35
+ regexp_parser (>= 1.8, < 3.0)
36
+ rexml
37
+ rubocop-ast (>= 1.2.0, < 2.0)
38
+ ruby-progressbar (~> 1.7)
39
+ unicode-display_width (>= 1.4.0, < 3.0)
40
+ rubocop-ast (1.4.0)
41
+ parser (>= 2.7.1.5)
42
+ ruby-progressbar (1.11.0)
43
+ unicode-display_width (2.0.0)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ prtscr!
50
+ rake (~> 12.0)
51
+ rspec (~> 3.0)
52
+ rubocop
53
+
54
+ BUNDLED WITH
55
+ 2.1.4
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2017 vickodin
3
+ Copyright (c) 2021 vickodin
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # Prtscr.ru API gem
1
+ # Prtscr
2
2
 
3
- This gem is a lib for [PrtScr.ru](https://prtscr.ru/) API (website screenshot).
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/prtscr`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
4
6
 
5
7
  ## Installation
6
8
 
@@ -12,7 +14,7 @@ gem 'prtscr'
12
14
 
13
15
  And then execute:
14
16
 
15
- $ bundle
17
+ $ bundle install
16
18
 
17
19
  Or install it yourself as:
18
20
 
@@ -20,31 +22,23 @@ Or install it yourself as:
20
22
 
21
23
  ## Usage
22
24
 
23
- run the next line of code:
24
-
25
- ```ruby
26
- Prtscr.get(url: 'https://google.com',width: 1280, height: 1024, scale: 250, key: 'YOUR_KEY_HERE', secret: 'YOUR_SECRET_HERE')
27
- ```
28
-
29
- And get something like:
30
-
31
- ```
32
- https://prtscr.ru/v1/1280x1024/250/jpg/1484087718/AIQACodQ/25dcf97122650b5c5282e5e7ab3539a1/https%3A%2F%2Fgoogle.com
33
- ```
34
-
35
- Having previous line, you can use html img tag:
36
-
37
- ![Google website screenshot](https://prtscr.ru/v1/1280x1024/250/jpg/1484087718/AIQACodQ/25dcf97122650b5c5282e5e7ab3539a1/https%3A%2F%2Fgoogle.com)
25
+ TODO: Write usage instructions here
38
26
 
39
27
  ## Development
40
28
 
41
29
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
30
 
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
43
33
  ## Contributing
44
34
 
45
- Bug reports and pull requests are welcome on GitHub at https://github.com/vickodin/prtscr.
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/prtscr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/prtscr/blob/master/CODE_OF_CONDUCT.md).
46
36
 
47
37
 
48
38
  ## License
49
39
 
50
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the Prtscr project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/prtscr/blob/master/CODE_OF_CONDUCT.md).
@@ -11,4 +11,4 @@ require "prtscr"
11
11
  # Pry.start
12
12
 
13
13
  require "irb"
14
- IRB.start
14
+ IRB.start(__FILE__)
@@ -1,32 +1,32 @@
1
- require "prtscr/version"
2
- require "base64"
1
+ # frozen_string_literal: true
3
2
 
3
+ require 'prtscr/version'
4
+ require 'digest'
5
+ require 'base64'
6
+
7
+ require 'prtscr/v1'
8
+ require 'prtscr/v2'
9
+ require 'prtscr/v3'
10
+
11
+ # Main module
4
12
  module Prtscr
13
+ extend Prtscr::V1
14
+ extend Prtscr::V2
15
+ extend Prtscr::V3
5
16
 
6
- def self.get(data)
7
- d = {
8
- version: 'v2',
9
- width: '1280',
10
- height: '1024',
11
- scale: '500',
12
- format: 'jpg',
13
- timestamp: Time.now.to_i,
14
- scheme: 'https:/',
15
- host: 'prtscr.ru'
16
- }.merge(data)
17
+ class Error < StandardError; end
17
18
 
18
- if d[:version] == 'v1'
19
- d[:url] = URI.encode_www_form_component(d[:url])
20
- d[:sign] = Digest::MD5.hexdigest([d[:width], d[:height], d[:scale], d[:format], d[:timestamp], d[:key], d[:url], d[:secret]].join(''))
21
- d[:size] = [d[:width], d[:height]].join('x')
22
- return [d[:scheme], d[:host], d[:version], d[:size], d[:scale], d[:format], d[:timestamp], d[:key], d[:sign], d[:url]].join('/')
23
- elsif d[:version] == 'v2'
24
- d[:url] = Base64.urlsafe_encode64(d[:url])
25
- d[:sign] = Digest::MD5.hexdigest([d[:width], d[:height], d[:scale], d[:timestamp], d[:key], d[:url], d[:format], d[:secret]].join(''))
26
- d[:size] = [d[:width], d[:height]].join('x')
19
+ def self.get(params)
20
+ # TODO: Move default values to initializer
21
+ data = {
22
+ version: 'v3', width: '1280', height: '1024', scale: '500',
23
+ format: 'jpg', timestamp: Time.now.to_i, scheme: 'https:/', host: 'prtscr.ru'
24
+ }.merge(params)
27
25
 
28
- return [[d[:scheme], d[:host], d[:version], d[:size], d[:scale], d[:timestamp], d[:key], d[:sign], d[:url]].join('/'), d[:format]].join('.')
26
+ case data[:version]
27
+ when 'v1' then v1(data)
28
+ when 'v2' then v2(data)
29
+ when 'v3' then v3(data)
29
30
  end
30
31
  end
31
-
32
32
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Prtscr
4
+ # Version 1:
5
+ module V1
6
+ def v1(data)
7
+ [
8
+ data[:scheme], data[:host],
9
+ data[:version], v1_size(data), data[:scale], data[:format], data[:timestamp], data[:key],
10
+ v1_sign(data), v1_url(data[:url])
11
+ ].join('/')
12
+ end
13
+
14
+ def v1_sign(data)
15
+ ::Digest::MD5.hexdigest(
16
+ [
17
+ data[:width], data[:height], data[:scale], data[:format], data[:timestamp],
18
+ data[:key], v1_url(data[:url]), data[:secret]
19
+ ].join('')
20
+ )
21
+ end
22
+
23
+ def v1_size(data)
24
+ [data[:width], data[:height]].join('x')
25
+ end
26
+
27
+ def v1_url(url)
28
+ ::URI.encode_www_form_component(url)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Prtscr
4
+ # Version 2:
5
+ module V2
6
+ def v2(data)
7
+ [
8
+ [
9
+ data[:scheme], data[:host], data[:version], v2_size(data), data[:scale],
10
+ data[:timestamp], data[:key], v2_sign(data), v2_url(data[:url])
11
+ ].join('/'), data[:format]
12
+ ].join('.')
13
+ end
14
+
15
+ def v2_sign(data)
16
+ ::Digest::MD5.hexdigest(
17
+ [
18
+ data[:width], data[:height], data[:scale], data[:timestamp], data[:key],
19
+ v2_url(data[:url]), data[:format], data[:secret]
20
+ ].join('')
21
+ )
22
+ end
23
+
24
+ def v2_size(data)
25
+ [data[:width], data[:height]].join('x')
26
+ end
27
+
28
+ def v2_url(url)
29
+ Base64.urlsafe_encode64(url)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Prtscr
4
+ # Version 2:
5
+ module V3
6
+ def v3(data)
7
+ "https://prtscr.ru/v3/screenshot.#{data[:format]}?#{v3_query(data)}"
8
+ end
9
+
10
+ def v3_sign(data)
11
+ ::Digest::MD5.hexdigest(
12
+ [
13
+ data[:url], data[:format], data[:key], data[:width],
14
+ data[:height], data[:scale], data[:secret]
15
+ ].map(&:to_s).join
16
+ )
17
+ end
18
+
19
+ def v3_query(data)
20
+ ::URI.encode_www_form(
21
+ {
22
+ url: data[:url],
23
+ key: data[:key],
24
+ sign: v3_sign(data),
25
+ width: data[:width],
26
+ height: data[:height],
27
+ scale: data[:scale]
28
+ }.compact
29
+ )
30
+ end
31
+ end
32
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Prtscr
2
- VERSION = "0.2.0"
4
+ VERSION = '0.3.0'
3
5
  end
@@ -1,36 +1,31 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'prtscr/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/prtscr/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "prtscr"
6
+ spec.name = 'prtscr'
8
7
  spec.version = Prtscr::VERSION
9
- spec.authors = ["vickodin"]
10
- spec.email = ["vick.orel@gmail.com"]
8
+ spec.authors = ['vickodin']
9
+ spec.email = ['vick.orel@gmail.com']
10
+
11
+ spec.summary = 'PrtScr.ru API gem'
12
+ spec.description = 'Website screenshot API gem for https://prtscr.ru'
13
+ spec.homepage = 'https://github.com/vickodin/prtscr'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
11
16
 
12
- spec.summary = "PrtScr.ru API gem"
13
- spec.description = "Website screenshot API gem for http://prtscr.ru"
14
- spec.homepage = "https://github.com/vickodin/prtscr"
15
- spec.license = "MIT"
17
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
16
18
 
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- #if spec.respond_to?(:metadata)
20
- # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
- #else
22
- # raise "RubyGems 2.0 or newer is required to protect against " \
23
- # "public gem pushes."
24
- #end
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/vickodin/prtscr'
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
25
22
 
26
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
- f.match(%r{^(test|spec|features)/})
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
28
27
  end
29
- spec.bindir = "exe"
28
+ spec.bindir = 'exe'
30
29
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
- spec.require_paths = ["lib"]
32
-
33
- spec.add_development_dependency "bundler", "~> 1.13"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.require_paths = ['lib']
36
31
  end
metadata CHANGED
@@ -1,58 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prtscr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - vickodin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-13 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.13'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.13'
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.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
55
- description: Website screenshot API gem for http://prtscr.ru
11
+ date: 2021-01-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Website screenshot API gem for https://prtscr.ru
56
14
  email:
57
15
  - vick.orel@gmail.com
58
16
  executables: []
@@ -61,21 +19,28 @@ extra_rdoc_files: []
61
19
  files:
62
20
  - ".gitignore"
63
21
  - ".rspec"
22
+ - ".rubocop.yml"
64
23
  - ".travis.yml"
65
24
  - CODE_OF_CONDUCT.md
66
25
  - Gemfile
26
+ - Gemfile.lock
67
27
  - LICENSE.txt
68
28
  - README.md
69
29
  - Rakefile
70
30
  - bin/console
71
31
  - bin/setup
72
32
  - lib/prtscr.rb
33
+ - lib/prtscr/v1.rb
34
+ - lib/prtscr/v2.rb
35
+ - lib/prtscr/v3.rb
73
36
  - lib/prtscr/version.rb
74
37
  - prtscr.gemspec
75
38
  homepage: https://github.com/vickodin/prtscr
76
39
  licenses:
77
40
  - MIT
78
- metadata: {}
41
+ metadata:
42
+ homepage_uri: https://github.com/vickodin/prtscr
43
+ source_code_uri: https://github.com/vickodin/prtscr
79
44
  post_install_message:
80
45
  rdoc_options: []
81
46
  require_paths:
@@ -84,15 +49,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
49
  requirements:
85
50
  - - ">="
86
51
  - !ruby/object:Gem::Version
87
- version: '0'
52
+ version: 2.3.0
88
53
  required_rubygems_version: !ruby/object:Gem::Requirement
89
54
  requirements:
90
55
  - - ">="
91
56
  - !ruby/object:Gem::Version
92
57
  version: '0'
93
58
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.6.8
59
+ rubygems_version: 3.1.4
96
60
  signing_key:
97
61
  specification_version: 4
98
62
  summary: PrtScr.ru API gem