cloudimage 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +10 -0
- data/LICENSE +21 -0
- data/README.md +134 -0
- data/bin/console +8 -0
- data/bin/setup +7 -0
- data/lib/cloudimage.rb +6 -0
- data/lib/cloudimage/client.rb +35 -0
- data/lib/cloudimage/custom_helpers.rb +9 -0
- data/lib/cloudimage/params.rb +36 -0
- data/lib/cloudimage/uri.rb +47 -0
- data/lib/cloudimage/version.rb +5 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 38b6b4cf631917e41ac56722f43b942e77714815d52ac15a7080e56173d776e5
|
4
|
+
data.tar.gz: 8b5d8d15e125b076908c6d9a9e36cffe13dce4c89b2b7586235ccbc0c4e8dd71
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4405e0f5eacfd9417fc300b801cafac50a1a9e352c64bf7e611e401e66d6ac6cde6743c9a00db116118f2ae8eb2433cc5dba99fe695bc3705b0dd96911db4589
|
7
|
+
data.tar.gz: 28126cfc5f7c63153a6ef57b0b1bad2bd93cd22d14b093f68fa340ab2a65d730d3d25f84b3d3bedf676cca92547f0bd6bf579f5d3b55807755f899e9e273f9aa
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
## master
|
2
|
+
|
3
|
+
## 0.1.0 (2020-08-09)
|
4
|
+
|
5
|
+
- Introduce base models: `Cloudimage::Client`, and `Cloudimage::URI`. Generate
|
6
|
+
URLs via `to_url` method. Add support for image resizing params.
|
7
|
+
[#2](https://github.com/scaleflex/cloudimage-rb/pull/2) (@janklimo)
|
8
|
+
|
9
|
+
- Set up Github actions for CI.
|
10
|
+
[#1](https://github.com/scaleflex/cloudimage-rb/pull/1) (@janklimo)
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Scaleflex
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# cloudimage
|
2
|
+
|
3
|
+
![](https://github.com/scaleflex/cloudimage-rb/workflows/Build/badge.svg)
|
4
|
+
|
5
|
+
`cloudimage` is the official Ruby API wrapper for
|
6
|
+
[Cloudimage's API](https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/introduction).
|
7
|
+
|
8
|
+
Supports Ruby `2.4` and above, `JRuby`, and `TruffleRuby`.
|
9
|
+
|
10
|
+
- [cloudimage](#cloudimage)
|
11
|
+
- [Installation](#installation)
|
12
|
+
- [Usage](#usage)
|
13
|
+
- [Hash of params](#hash-of-params)
|
14
|
+
- [Chainable helpers](#chainable-helpers)
|
15
|
+
- [Aliases](#aliases)
|
16
|
+
- [Custom helpers](#custom-helpers)
|
17
|
+
- [Development](#development)
|
18
|
+
- [Contributing](#contributing)
|
19
|
+
- [License](#license)
|
20
|
+
- [Code of Conduct](#code-of-conduct)
|
21
|
+
|
22
|
+
## Installation
|
23
|
+
|
24
|
+
Add this line to your application's Gemfile:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
gem 'cloudimage'
|
28
|
+
```
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle install
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install cloudimage
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
The only requirement to get started is your customer token. You can
|
41
|
+
find it within your Admin interface:
|
42
|
+
|
43
|
+
![token](docs/token.png)
|
44
|
+
|
45
|
+
In order to interact with Cloudimage, we'll first initialize a client service
|
46
|
+
object:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
client = Cloudimage::Client.new(token: 'mysecrettoken')
|
50
|
+
```
|
51
|
+
|
52
|
+
Calling `path` on the client object returns an instance of `Cloudimage::URI`.
|
53
|
+
It accepts path to the image as a string and we we will use it to build
|
54
|
+
Cloudimage URLs.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
uri = client.path('/assets/image.png')
|
58
|
+
```
|
59
|
+
|
60
|
+
Here are some common approaches for constructing Cloudimage URLs using this gem:
|
61
|
+
|
62
|
+
### Hash of params
|
63
|
+
|
64
|
+
Pass a hash to `to_url`. Every key becomes a param in the final Cloudimage
|
65
|
+
URL so this gives you the freedom to pass arbitrary params if need be.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
uri.to_url(w: 200, h: 400, sharp: 1, gravity: 'west', ci_info: 1)
|
69
|
+
# => "https://mysecrettoken.cloudimg.io/v7/assets/image.png?ci_info=1&gravity=west&h=400&sharp=1&w=200"
|
70
|
+
```
|
71
|
+
|
72
|
+
### Chainable helpers
|
73
|
+
|
74
|
+
Every param supported by Cloudimage can be used as a helper method.
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
uri.w(200).h(400).gravity('west').to_url
|
78
|
+
# => "https://mysecrettoken.cloudimg.io/v7/assets/image.png?gravity=west&h=400&w=200"
|
79
|
+
```
|
80
|
+
|
81
|
+
While every key passed into `to_url` method gets appended to the URL,
|
82
|
+
chainable helper methods will throw a `NoMethodError` when using an
|
83
|
+
unsupported method.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
uri.heigth(200).to_url
|
87
|
+
# NoMethodError (undefined method `heigth' for #<Cloudimage::URI:0x00007fae461c42a0>)
|
88
|
+
```
|
89
|
+
|
90
|
+
This is useful for catching typos and identifying deprecated methods in
|
91
|
+
case Cloudimage's API changes.
|
92
|
+
|
93
|
+
### Aliases
|
94
|
+
|
95
|
+
The gem comes with a handful of useful aliases. Consult
|
96
|
+
[`Cloudimage::Params`](lib/cloudimage/params.rb) module for their full list.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
uri.debug.prevent_enlargement.to_url
|
100
|
+
# => "https://mysecrettoken.cloudimg.io/v7/assets/image.png?ci_info=1&org_if_sml=1"
|
101
|
+
```
|
102
|
+
|
103
|
+
From the example above you can see that params that only serve as a flag don't
|
104
|
+
need to accept arguments and will be translated into `param=1` in the final URL.
|
105
|
+
|
106
|
+
### Custom helpers
|
107
|
+
|
108
|
+
For a list of custom helpers available to you, please consult
|
109
|
+
[`Cloudimage::CustomHelpers`](lib/cloudimage/custom_helpers.rb) module.
|
110
|
+
|
111
|
+
## Development
|
112
|
+
|
113
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
114
|
+
Then, run `bundle exec rake` to run the tests. You can also run
|
115
|
+
`bin/console` for an interactive prompt that will allow you to
|
116
|
+
experiment.
|
117
|
+
|
118
|
+
## Contributing
|
119
|
+
|
120
|
+
Bug reports and pull requests are welcome. This project is intended
|
121
|
+
to be a safe, welcoming space for collaboration, and contributors
|
122
|
+
are expected to adhere to the
|
123
|
+
[code of conduct](https://github.com/scaleflex/cloudimage-rb/blob/master/CODE_OF_CONDUCT.md).
|
124
|
+
|
125
|
+
## License
|
126
|
+
|
127
|
+
The gem is available as open source under the terms of the
|
128
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
129
|
+
|
130
|
+
## Code of Conduct
|
131
|
+
|
132
|
+
Everyone interacting with the project's codebase, issues, and pull
|
133
|
+
requests is expected to follow the
|
134
|
+
[code of conduct](https://github.com/scaleflex/cloudimage-rb/blob/master/CODE_OF_CONDUCT.md).
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/cloudimage.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'uri'
|
4
|
+
|
5
|
+
module Cloudimage
|
6
|
+
class InvalidConfig < StandardError; end
|
7
|
+
|
8
|
+
class Client
|
9
|
+
attr_reader :token
|
10
|
+
|
11
|
+
API_VERSION = 'v7'
|
12
|
+
|
13
|
+
def initialize(token: nil)
|
14
|
+
@token = token
|
15
|
+
|
16
|
+
ensure_valid_config
|
17
|
+
end
|
18
|
+
|
19
|
+
def path(path)
|
20
|
+
URI.new(base_url_for(token), path)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def base_url_for(token)
|
26
|
+
"https://#{token}.cloudimg.io/#{API_VERSION}"
|
27
|
+
end
|
28
|
+
|
29
|
+
def ensure_valid_config
|
30
|
+
return unless token.to_s.strip.empty?
|
31
|
+
|
32
|
+
raise InvalidConfig, 'Please specify your Cloudimage customer token.'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Cloudimage
|
4
|
+
module Params
|
5
|
+
ALIASES = {
|
6
|
+
debug: :ci_info,
|
7
|
+
prevent_enlargement: :org_if_sml,
|
8
|
+
rotate: :r,
|
9
|
+
sharper_resizing: :sharp,
|
10
|
+
resize_mode: :func,
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
PARAMS = %i[
|
14
|
+
bg_blur
|
15
|
+
bg_color
|
16
|
+
bg_colorize
|
17
|
+
bg_colour
|
18
|
+
bg_colourise
|
19
|
+
bg_img_fit
|
20
|
+
bg_opacity
|
21
|
+
br_px
|
22
|
+
ci_info
|
23
|
+
func
|
24
|
+
gravity
|
25
|
+
h
|
26
|
+
height
|
27
|
+
org_if_sml
|
28
|
+
r
|
29
|
+
sharp
|
30
|
+
tl_px
|
31
|
+
trim
|
32
|
+
w
|
33
|
+
width
|
34
|
+
].freeze
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'params'
|
4
|
+
require_relative 'custom_helpers'
|
5
|
+
|
6
|
+
module Cloudimage
|
7
|
+
class URI
|
8
|
+
include Params
|
9
|
+
include CustomHelpers
|
10
|
+
|
11
|
+
attr_reader :uri, :params
|
12
|
+
|
13
|
+
def initialize(base_url, path)
|
14
|
+
path = ensure_path_format(path)
|
15
|
+
@uri = Addressable::URI.parse(base_url + path)
|
16
|
+
@params = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
PARAMS.each do |param|
|
20
|
+
define_method param do |*args|
|
21
|
+
@params[param] = if args.any?
|
22
|
+
args.join(',')
|
23
|
+
else
|
24
|
+
# Flag params don't need to pass in arguments.
|
25
|
+
@params[param] = 1
|
26
|
+
end
|
27
|
+
self
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
ALIASES.each do |from, to|
|
32
|
+
alias_method from, to
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_url(extra_params = {})
|
36
|
+
url_params = params.merge(extra_params)
|
37
|
+
uri.query_values = url_params if url_params.any?
|
38
|
+
uri.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def ensure_path_format(path)
|
44
|
+
path.start_with?('/') ? path : "/#{path}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloudimage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jan Klimo
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
description: Fast and easy image resizing, transformation, and acceleration in the
|
28
|
+
Cloud.
|
29
|
+
email:
|
30
|
+
- jan.klimo@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- CHANGELOG.md
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- bin/console
|
39
|
+
- bin/setup
|
40
|
+
- lib/cloudimage.rb
|
41
|
+
- lib/cloudimage/client.rb
|
42
|
+
- lib/cloudimage/custom_helpers.rb
|
43
|
+
- lib/cloudimage/params.rb
|
44
|
+
- lib/cloudimage/uri.rb
|
45
|
+
- lib/cloudimage/version.rb
|
46
|
+
homepage: https://github.com/scaleflex/cloudimage-rb
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata:
|
50
|
+
bug_tracker_uri: https://github.com/scaleflex/cloudimage-rb/issues
|
51
|
+
changelog_uri: https://github.com/scaleflex/cloudimage-rb/blob/master/CHANGELOG.md
|
52
|
+
source_code_uri: https://github.com/scaleflex/cloudimage-rb
|
53
|
+
documentation_uri: https://docs.cloudimage.io/go/cloudimage-documentation-v7/en/introduction
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.4.0
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubygems_version: 3.1.2
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Official API wrapper for Cloudimage's API.
|
73
|
+
test_files: []
|