imageboss-rb 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b261b09c7de94415ab69c0c6a0cc4485231434f9
4
+ data.tar.gz: 56d13e6cfaeb4c999f6c1241d64a2945ebc7dc4e
5
+ SHA512:
6
+ metadata.gz: ae4c3eb20e937d0f665ee092e9018157bb578f4f924883bd0b74b3b7090cfff6ce9be14455ad7609457d59cdc00953fb17241a14f3d2c4002bccea4d15552754
7
+ data.tar.gz: 2552e3bf2bdbd03fa77497838811a7351012e4e4010872a57f0004af188ce2e4dd67dfb8ccb06896a08d6f1d7e52af5874608dc73b6199207ade177d00e87012
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ cache: bundler
3
+ bundler_args: "--binstubs --path ../bundle --retry=3 --jobs=3"
4
+ before_install:
5
+ - gem install bundler
6
+ - rvm get head
7
+ - bundle install
8
+ script:
9
+ - bundle exec rspec
10
+ rvm:
11
+ - 2.5.1
12
+ - 2.4.4
13
+ - 2.3.7
14
+ - 2.2.7
15
+ - 2.1.10
16
+ - jruby-9.0.5.0
17
+ - rbx-3.100
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ imageboss-rb (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ byebug (10.0.0)
10
+ diff-lcs (1.3)
11
+ rspec (3.7.0)
12
+ rspec-core (~> 3.7.0)
13
+ rspec-expectations (~> 3.7.0)
14
+ rspec-mocks (~> 3.7.0)
15
+ rspec-core (3.7.1)
16
+ rspec-support (~> 3.7.0)
17
+ rspec-expectations (3.7.0)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.7.0)
20
+ rspec-mocks (3.7.0)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.7.0)
23
+ rspec-support (3.7.1)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ byebug
30
+ imageboss-rb!
31
+ rspec
32
+
33
+ BUNDLED WITH
34
+ 1.16.0
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,60 @@
1
+ # ImageBoss Helper for Ruby [![Build Status](https://travis-ci.org/imageboss/imageboss-rb.svg?branch=master)](https://travis-ci.org/imageboss/imageboss-rb)
2
+
3
+ Official Gem for generating ImageBoss URLs.
4
+ [https://imageboss.me/](https://imageboss.me/)
5
+
6
+ ## Installation
7
+ Add this line to your application's Gemfile:
8
+ ```
9
+ bundle add imageboss-rb
10
+ ```
11
+
12
+ Or install it yourself as:
13
+
14
+ ```
15
+ gem install imageboss-rb
16
+ ```
17
+
18
+ ## Usage
19
+ ### Example `Image Resizing With Cover Operation`
20
+ ```ruby
21
+ client = ImageBoss::Client.new('https://mywebsite.com')
22
+
23
+ image_url = client.path('/images/img01.jpg')
24
+ .operation(:cover, width: 100, height: 100)
25
+ #=> https://service.imageboss.me/cover/100x100/https://mywebsite.com/images/img01.jpg
26
+ ```
27
+
28
+ ### Example `Image Resizing With Height Operation`
29
+ ```ruby
30
+ client = ImageBoss::Client.new('https://mywebsite.com')
31
+
32
+ image_url = client.path('/images/img01.jpg')
33
+ .operation(:height, height: 100)
34
+ #=> https://service.imageboss.me/height/100/https://mywebsite.com/images/img01.jpg
35
+ ```
36
+
37
+ ### Example `Image Resizing With Extra Options`
38
+ ```ruby
39
+ client = ImageBoss::Client.new('https://mywebsite.com')
40
+
41
+ image_url = client.path('/images/img01.jpg')
42
+ .operation(:width, width: 100, options: { grayscale: true })
43
+ #=> https://service.imageboss.me/width/100/grayscale:trye/https://mywebsite.com/images/img01.jpg
44
+ ```
45
+ ### All operations and options for Image Resizing
46
+ It's all available on our [Official Docs](https://imageboss.me/docs).
47
+
48
+ ## Tested on
49
+ Ruby
50
+ - 2.5.1
51
+ - 2.4.4
52
+ - 2.3.7
53
+ - 2.2.7
54
+ - 2.1.10
55
+
56
+ jRuby
57
+ - jruby-9.0.5.0
58
+
59
+ Rubinius
60
+ - rbx-3.100
@@ -0,0 +1,22 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'imageboss/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'imageboss-rb'
7
+ spec.version = ImageBoss::VERSION
8
+ spec.authors = ['Igor Escobar']
9
+ spec.email = ['igor@imageboss.me']
10
+ spec.description = 'Generate ImageBoss URLs with Ruby'
11
+ spec.summary = 'Official Ruby Gem for generating ImageBoss URLs.'
12
+ spec.homepage = 'https://github.com/imageboss/imageboss-rb'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.required_ruby_version = '>= 1.9.0'
21
+ spec.add_development_dependency "rspec"
22
+ end
@@ -0,0 +1,5 @@
1
+ require 'imageboss/path'
2
+ require 'imageboss/client'
3
+
4
+ module ImageBoss
5
+ end
@@ -0,0 +1,11 @@
1
+ module ImageBoss
2
+ class Client
3
+ def initialize(domain:)
4
+ @domain = domain
5
+ end
6
+
7
+ def path(asset_path)
8
+ Path.new(@domain, asset_path)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,59 @@
1
+ module ImageBoss
2
+ class Path
3
+ SERVICE_URL = 'https://service.imageboss.me'.freeze
4
+ OPERATIONS = {
5
+ cover: {
6
+ recipe: '/:operation::mode/:widthx:height/:options/', required: [:width, :height]
7
+ },
8
+ width: {
9
+ recipe: '/:operation/:width/:options/', required: [:width]
10
+ },
11
+ height: { recipe: '/:operation/:height/:options/', required: [:height]},
12
+ cdn: { recipe: '/:operation/:options/', required: [] }
13
+ }.freeze
14
+
15
+ def initialize(domain, asset_path)
16
+ @domain = domain.chomp('/')
17
+ @asset_path = asset_path
18
+ end
19
+
20
+ def operation(name, options = {})
21
+ @operation_name = name.to_sym
22
+ @options = options
23
+ @extra_options = parse_options(options[:options])
24
+ @operation = OPERATIONS[@operation_name]
25
+ @required = @operation[:required]
26
+
27
+ @required.each do |r|
28
+ @options.fetch(r)
29
+ end
30
+
31
+ recipe = [
32
+ SERVICE_URL,
33
+ @operation[:recipe].chomp('/'),
34
+ @domain,
35
+ @asset_path
36
+ ].join
37
+ parse(recipe)
38
+ end
39
+ private
40
+
41
+ def parse(recipe)
42
+ recipe
43
+ .sub(':operation', @operation_name.to_s)
44
+ .sub(':width', @options[:width].to_s)
45
+ .sub(':height', @options[:height].to_s)
46
+ .sub(':options', @extra_options.empty? ? "" : "#{@extra_options}/")
47
+ .sub('::mode', @options[:mode] ? ":#{@options[:mode]}" : '').to_s
48
+ end
49
+
50
+ def parse_options(options = {})
51
+ valid_options = [ :grayscale, :blur ]
52
+ opts = []
53
+ valid_options.each do |vo|
54
+ opts << [vo.to_s, options[vo] ].join(':') if options && options.has_key?(vo)
55
+ end
56
+ opts.join(',')
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module ImageBoss
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe ImageBoss::Client do
4
+ let(:service) { 'https://service.imageboss.me' }
5
+ let(:client_args) {{
6
+ domain: 'https://myassets.com'
7
+ }}
8
+
9
+ let(:operation_args) { [:cover, width: 100, height: 100] }
10
+
11
+ subject { described_class.new(**client_args) }
12
+
13
+ context 'initialize' do
14
+ it { expect(subject.instance_variable_get(:@domain)).to eq client_args[:domain] }
15
+ end
16
+
17
+ context 'path' do
18
+ let(:path) {
19
+ subject
20
+ .path('/assets/img01.jpg')
21
+ }
22
+
23
+ let(:image_url) { path.operation(*operation_args) }
24
+
25
+ context 'cover' do
26
+ it { expect(image_url).to eq "#{service}/cover/100x100/https://myassets.com/assets/img01.jpg" }
27
+
28
+ context 'with options' do
29
+ let(:operation_args) { [:cover, width: 100, height: 100, options: { grayscale: true, blur: 2.0 } ] }
30
+ it { expect(image_url).to eq "#{service}/cover/100x100/grayscale:true,blur:2.0/https://myassets.com/assets/img01.jpg" }
31
+ end
32
+
33
+ context 'mode' do
34
+ let(:operation_args) { [:cover, mode: :entropy, width: 100, height: 100 ] }
35
+ it { expect(image_url).to eq "#{service}/cover:entropy/100x100/https://myassets.com/assets/img01.jpg" }
36
+
37
+ context 'with options' do
38
+ let(:operation_args) { [:cover, mode: :entropy, width: 100, height: 100, options: { grayscale: true, blur: 2.0 } ] }
39
+ it { expect(image_url).to eq "#{service}/cover:entropy/100x100/grayscale:true,blur:2.0/https://myassets.com/assets/img01.jpg" }
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ context 'width' do
46
+ let(:operation_args) { [:width, width: 100 ] }
47
+ it { expect(image_url).to eq "#{service}/width/100/https://myassets.com/assets/img01.jpg" }
48
+ end
49
+
50
+ context 'height' do
51
+ let(:operation_args) { [:height, height: 200 ] }
52
+ it { expect(image_url).to eq "#{service}/height/200/https://myassets.com/assets/img01.jpg" }
53
+ end
54
+
55
+ context 'cdn' do
56
+ let(:operation_args) { [:cdn] }
57
+ it { expect(image_url).to eq "#{service}/cdn/https://myassets.com/assets/img01.jpg" }
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'imageboss'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imageboss-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Igor Escobar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Generate ImageBoss URLs with Ruby
28
+ email:
29
+ - igor@imageboss.me
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".travis.yml"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - LICENSE
40
+ - README.md
41
+ - imageboss-rb.gemspec
42
+ - lib/imageboss.rb
43
+ - lib/imageboss/client.rb
44
+ - lib/imageboss/path.rb
45
+ - lib/imageboss/version.rb
46
+ - spec/imageboss/client_spec.rb
47
+ - spec/spec_helper.rb
48
+ homepage: https://github.com/imageboss/imageboss-rb
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.9.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 2.5.1
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Official Ruby Gem for generating ImageBoss URLs.
72
+ test_files:
73
+ - spec/imageboss/client_spec.rb
74
+ - spec/spec_helper.rb