flyyer 2.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.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +36 -0
- data/.gitignore +147 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +36 -0
- data/LICENSE.txt +21 -0
- data/README.md +204 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/flyyer.gemspec +31 -0
- data/lib/flyyer.rb +171 -0
- data/lib/flyyer/version.rb +3 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ef1404087856253e14da6d226113d736d21cd5abb60cd8f52dfeb11f483bc8e1
|
4
|
+
data.tar.gz: 830b066c275d67436ef02dc16ea5f4deb75cefa2ce1a710d18963918947dcdc9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5a9a5f581151cf0f7c5dde17a7bec9c24be0efe260bcf4632583aec215857a019a39fd4e245406e8490cb7709fa3630171bd44062ea98af9be7120dccc1ce2b
|
7
|
+
data.tar.gz: 8d258f240f0a74a37d7a0c06f2eeeda1fe165c4fb2b71b4d6f908f7c65e4aedb77c6b77b8ba8ca24b49183d244ade6482a76f91b0026360cd6719e11b29371ec
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ master ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ master ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
strategy:
|
20
|
+
fail-fast: false
|
21
|
+
matrix:
|
22
|
+
os: [ubuntu-18.04, macos-latest]
|
23
|
+
ruby: [2.5, 2.6, 2.7]
|
24
|
+
runs-on: ${{ matrix.os }}
|
25
|
+
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- name: Set up Ruby
|
29
|
+
uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby }}
|
32
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
33
|
+
- name: Install dependencies
|
34
|
+
run: bundle install
|
35
|
+
- name: Run tests
|
36
|
+
run: bundle exec rake spec
|
data/.gitignore
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# Custom
|
2
|
+
/.bundle/
|
3
|
+
/.yardoc
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
|
11
|
+
# rspec failure tracking
|
12
|
+
.rspec_status
|
13
|
+
|
14
|
+
# Created by https://www.toptal.com/developers/gitignore/api/ruby,osx,windows,linux
|
15
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=ruby,osx,windows,linux
|
16
|
+
|
17
|
+
### Linux ###
|
18
|
+
*~
|
19
|
+
|
20
|
+
# temporary files which can be created if a process still has a handle open of a deleted file
|
21
|
+
.fuse_hidden*
|
22
|
+
|
23
|
+
# KDE directory preferences
|
24
|
+
.directory
|
25
|
+
|
26
|
+
# Linux trash folder which might appear on any partition or disk
|
27
|
+
.Trash-*
|
28
|
+
|
29
|
+
# .nfs files are created when an open file is removed but is still being accessed
|
30
|
+
.nfs*
|
31
|
+
|
32
|
+
### OSX ###
|
33
|
+
# General
|
34
|
+
.DS_Store
|
35
|
+
.AppleDouble
|
36
|
+
.LSOverride
|
37
|
+
|
38
|
+
# Icon must end with two \r
|
39
|
+
Icon
|
40
|
+
|
41
|
+
# Thumbnails
|
42
|
+
._*
|
43
|
+
|
44
|
+
# Files that might appear in the root of a volume
|
45
|
+
.DocumentRevisions-V100
|
46
|
+
.fseventsd
|
47
|
+
.Spotlight-V100
|
48
|
+
.TemporaryItems
|
49
|
+
.Trashes
|
50
|
+
.VolumeIcon.icns
|
51
|
+
.com.apple.timemachine.donotpresent
|
52
|
+
|
53
|
+
# Directories potentially created on remote AFP share
|
54
|
+
.AppleDB
|
55
|
+
.AppleDesktop
|
56
|
+
Network Trash Folder
|
57
|
+
Temporary Items
|
58
|
+
.apdisk
|
59
|
+
|
60
|
+
### Ruby ###
|
61
|
+
*.gem
|
62
|
+
*.rbc
|
63
|
+
/.config
|
64
|
+
/coverage/
|
65
|
+
/InstalledFiles
|
66
|
+
/pkg/
|
67
|
+
/spec/reports/
|
68
|
+
/spec/examples.txt
|
69
|
+
/test/tmp/
|
70
|
+
/test/version_tmp/
|
71
|
+
/tmp/
|
72
|
+
|
73
|
+
# Used by dotenv library to load environment variables.
|
74
|
+
# .env
|
75
|
+
|
76
|
+
# Ignore Byebug command history file.
|
77
|
+
.byebug_history
|
78
|
+
|
79
|
+
## Specific to RubyMotion:
|
80
|
+
.dat*
|
81
|
+
.repl_history
|
82
|
+
build/
|
83
|
+
*.bridgesupport
|
84
|
+
build-iPhoneOS/
|
85
|
+
build-iPhoneSimulator/
|
86
|
+
|
87
|
+
## Specific to RubyMotion (use of CocoaPods):
|
88
|
+
#
|
89
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
90
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
91
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
92
|
+
# vendor/Pods/
|
93
|
+
|
94
|
+
## Documentation cache and generated files:
|
95
|
+
/.yardoc/
|
96
|
+
/_yardoc/
|
97
|
+
/doc/
|
98
|
+
/rdoc/
|
99
|
+
|
100
|
+
## Environment normalization:
|
101
|
+
/.bundle/
|
102
|
+
/vendor/bundle
|
103
|
+
/lib/bundler/man/
|
104
|
+
|
105
|
+
# for a library or gem, you might want to ignore these files since the code is
|
106
|
+
# intended to run in multiple environments; otherwise, check them in:
|
107
|
+
# Gemfile.lock
|
108
|
+
# .ruby-version
|
109
|
+
# .ruby-gemset
|
110
|
+
|
111
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
112
|
+
.rvmrc
|
113
|
+
|
114
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
115
|
+
# .rubocop-https?--*
|
116
|
+
|
117
|
+
### Ruby Patch ###
|
118
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
119
|
+
# .rubocop-https?--*
|
120
|
+
|
121
|
+
### Windows ###
|
122
|
+
# Windows thumbnail cache files
|
123
|
+
Thumbs.db
|
124
|
+
Thumbs.db:encryptable
|
125
|
+
ehthumbs.db
|
126
|
+
ehthumbs_vista.db
|
127
|
+
|
128
|
+
# Dump file
|
129
|
+
*.stackdump
|
130
|
+
|
131
|
+
# Folder config file
|
132
|
+
[Dd]esktop.ini
|
133
|
+
|
134
|
+
# Recycle Bin used on file shares
|
135
|
+
$RECYCLE.BIN/
|
136
|
+
|
137
|
+
# Windows Installer files
|
138
|
+
*.cab
|
139
|
+
*.msi
|
140
|
+
*.msix
|
141
|
+
*.msm
|
142
|
+
*.msp
|
143
|
+
|
144
|
+
# Windows shortcuts
|
145
|
+
*.lnk
|
146
|
+
|
147
|
+
# End of https://www.toptal.com/developers/gitignore/api/ruby,osx,windows,linux
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
flyyer (2.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
jwt (2.2.2)
|
11
|
+
rake (12.3.3)
|
12
|
+
rspec (3.10.0)
|
13
|
+
rspec-core (~> 3.10.0)
|
14
|
+
rspec-expectations (~> 3.10.0)
|
15
|
+
rspec-mocks (~> 3.10.0)
|
16
|
+
rspec-core (3.10.0)
|
17
|
+
rspec-support (~> 3.10.0)
|
18
|
+
rspec-expectations (3.10.0)
|
19
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
20
|
+
rspec-support (~> 3.10.0)
|
21
|
+
rspec-mocks (3.10.0)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-support (3.10.0)
|
25
|
+
|
26
|
+
PLATFORMS
|
27
|
+
ruby
|
28
|
+
|
29
|
+
DEPENDENCIES
|
30
|
+
flyyer!
|
31
|
+
jwt
|
32
|
+
rake (~> 12.0)
|
33
|
+
rspec (~> 3.0)
|
34
|
+
|
35
|
+
BUNDLED WITH
|
36
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Flyyer
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
# flyyer-ruby
|
2
|
+
|
3
|
+
The AI-powered preview system built from your website (no effort required).
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
**This gem is agnostic to any Ruby framework.**
|
8
|
+
|
9
|
+
## Index
|
10
|
+
|
11
|
+
- [Get started (5 minutes)](#get-started-5-minutes)
|
12
|
+
- [Advanced usage](#advanced-usage)
|
13
|
+
- [Flyyer Render](#flyyer-render)
|
14
|
+
- [Development](#development)
|
15
|
+
- [Test](#test)
|
16
|
+
|
17
|
+
## Get started (5 minutes)
|
18
|
+
|
19
|
+
Haven't registered your website yet? Go to [Flyyer.io](https://flyyer.io?ref=flyyer-ruby) and create a project (e.g. `website-com`).
|
20
|
+
|
21
|
+
### 1. Install the library
|
22
|
+
|
23
|
+
Add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'flyyer'
|
27
|
+
```
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
```sh
|
32
|
+
bundle install
|
33
|
+
```
|
34
|
+
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
```sh
|
38
|
+
gem install flyyer
|
39
|
+
```
|
40
|
+
|
41
|
+
### 2. Get your Flyyer.io smart image link
|
42
|
+
|
43
|
+
In your website code (e.g. your landing or product/post view file), set the following:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
flyyer = Flyyer::Flyyer.create do |f|
|
47
|
+
# Your project slug
|
48
|
+
f.project = 'website-com'
|
49
|
+
# The current path of your website
|
50
|
+
f.path = '/path/to/product' # In Ruby on Rails you can use `request.env['PATH_INFO']`
|
51
|
+
end
|
52
|
+
|
53
|
+
# Check:
|
54
|
+
puts flyyer.href
|
55
|
+
# > https://cdn.flyyer.io/v2/website-com/_/__v=1618281823/path/to/product
|
56
|
+
```
|
57
|
+
|
58
|
+
### 3. Put your smart image link in your `<head>` tags
|
59
|
+
|
60
|
+
You'll get the best results like this:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
# .haml
|
64
|
+
%meta{ property: 'og:image', content: flyyer.href }
|
65
|
+
%meta{ name: 'twitter:image', content: flyyer.href }
|
66
|
+
%meta{ name: 'twitter:card', content: 'summary_large_image' }
|
67
|
+
|
68
|
+
# .erb
|
69
|
+
<meta property="og:image" content='<%= flyyer.href %>'>
|
70
|
+
<meta name="twitter:image" content='<%= flyyer.href %>'>
|
71
|
+
<meta name="twitter:card" content="summary_large_image">
|
72
|
+
|
73
|
+
# IMPORTANT: if you're using Ruby on Rails, please use `flyyer.href.html_safe` to prevent double serialization
|
74
|
+
```
|
75
|
+
|
76
|
+
### 4. Create a `rule` for your project
|
77
|
+
|
78
|
+
Login at [Flyyer.io](https://flyyer.io?ref=flyyer-ruby) > Go to your Dashboard > Manage rules and create a rule like the following:
|
79
|
+
|
80
|
+
[](https://flyyer.io/dashboard)
|
81
|
+
|
82
|
+
Voilà!
|
83
|
+
|
84
|
+
## Advanced usage
|
85
|
+
|
86
|
+
Advanced features include:
|
87
|
+
|
88
|
+
- Custom variables: additional information for your preview that is not present in your website. [Note: if you need customization you should take a look at [Flyyer Render](#flyyer-render)]
|
89
|
+
- Custom metadata: set custom width, height, resolution, and more (see example).
|
90
|
+
- Signed URLs.
|
91
|
+
|
92
|
+
Here you have a detailed full example for project `website-com` and path `/path/to/product`.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
flyyer = Flyyer::Flyyer.create do |f|
|
96
|
+
# [Required] Your project slug, find it in your dashboard https://flyyer.io/dashboard/.
|
97
|
+
f.project = 'website-com'
|
98
|
+
# [Recommended] The current path of your website (by default it's `/`).
|
99
|
+
f.path = '/path/to/product'
|
100
|
+
# [Optional] In case you want to provide information that is not present in your page set it here.
|
101
|
+
f.variables = {
|
102
|
+
'title': 'Product name',
|
103
|
+
'img': 'https://flyyer.io/img/marketplace/flyyer-banner.png',
|
104
|
+
}
|
105
|
+
# [Optional] Custom metadata for rendering the image. ID is recommended so we provide you with better statistics.
|
106
|
+
f.meta = {
|
107
|
+
'id': 'jeans-123', # recommended for better stats
|
108
|
+
'v': '12369420123', # specific handler version, by default it's a random number to circumvent platforms' cache,
|
109
|
+
'width': 1200,
|
110
|
+
'height': 600,
|
111
|
+
'resolution': 0.9, # from 0.0 to 1.0
|
112
|
+
'agent': 'whatsapp', # force dimensions for specific platform
|
113
|
+
}
|
114
|
+
end
|
115
|
+
|
116
|
+
# Use this image in your <head/> tags (og:image & twitter:image)
|
117
|
+
puts flyyer.href
|
118
|
+
# > https://cdn.flyyer.io/v2/website-com/_/__id=jeans-123&__v=1618281823&img=https%3A%2F%2Fflyyer.io%2Fimg%2Fmarketplace%2Fflyyer-banner.png&title=Product+name/path/to/product
|
119
|
+
|
120
|
+
# IMPORTANT: if you're using Ruby on Rails, please use `flyyer.href.html_safe` to prevent double serialization
|
121
|
+
```
|
122
|
+
|
123
|
+
For signed URLs, just provide your secret (find it in Dashboard > Project > Advanced settings) and choose a strategy (`HMAC` or `JWT`).
|
124
|
+
|
125
|
+
```ruby
|
126
|
+
flyyer = Flyyer::Flyyer.create do |f|
|
127
|
+
f.project = 'website-com'
|
128
|
+
f.path = '/path/to/product'
|
129
|
+
f.secret = 'your-secret-key'
|
130
|
+
f.strategy = 'JWT' # or 'HMAC'
|
131
|
+
end
|
132
|
+
|
133
|
+
url = flyyer.href
|
134
|
+
# > https://cdn.flyyer.io/v2/website-com/jwt-eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJwYXJhbXMiOnsiX19pZCI6ImplYW5zLTEyMyJ9LCJwYXRoIjoiXC9wYXRoXC90b1wvcHJvZHVjdCJ9.X8Vs5SGEA1-3M6bH-h24jhQnbwH95V_G0f-gPhTBTzE?__v=1618283086
|
135
|
+
|
136
|
+
# IMPORTANT: if you're using Ruby on Rails, please prevent double serialization like the following:
|
137
|
+
url = flyyer.href.html_safe
|
138
|
+
```
|
139
|
+
|
140
|
+
## Flyyer Render
|
141
|
+
|
142
|
+
As you probably realized, **Flyyer** uses the [rules defined on your dashboard](https://flyyer.io/dashboard/_/projects) to decide how to handle every image based on path patterns. It analyses your website to obtain information and then render a content-rich image with no effort. Let's say _"Flyyer delivers images based on the content of this route"_.
|
143
|
+
|
144
|
+
**Flyyer Render** instead requires you to explicitly declare template and variables for the images to render, **giving you more control for customization**. Let's say _"FlyyerRender delivers an image using this template and these explicit variables"_.
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
require 'flyyer'
|
148
|
+
|
149
|
+
flyyer = Flyyer::FlyyerRender.create do |f|
|
150
|
+
f.tenant = 'tenant'
|
151
|
+
f.deck = 'deck'
|
152
|
+
f.template = 'template'
|
153
|
+
f.variables = {
|
154
|
+
title: 'Hello world!'
|
155
|
+
}
|
156
|
+
end
|
157
|
+
|
158
|
+
# Use this image in your <head/> tags
|
159
|
+
url = flyyer.href
|
160
|
+
# > https://cdn.flyyer.io/render/v2/tenant/deck/template.jpeg?__v=1596906866&title=Hello+world%21
|
161
|
+
|
162
|
+
# IMPORTANT: if you're using Ruby on Rails, please prevent double serialization like the following:
|
163
|
+
url = flyyer.href.html_safe
|
164
|
+
```
|
165
|
+
|
166
|
+
Variables can be complex arrays and hashes.
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
flyyer = Flyyer::FlyyerRender.create do |f|
|
170
|
+
# ...
|
171
|
+
f.variables = {
|
172
|
+
items: [
|
173
|
+
{ text: 'Oranges', count: 12 },
|
174
|
+
{ text: 'Apples', count: 14 },
|
175
|
+
],
|
176
|
+
}
|
177
|
+
f.meta = {
|
178
|
+
id: 'slug-or-id', # To identify the resource in our analytics report
|
179
|
+
}
|
180
|
+
end
|
181
|
+
```
|
182
|
+
|
183
|
+
**IMPORTANT: variables must be serializable.**
|
184
|
+
|
185
|
+
To decode the URL for debugging purposes:
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
print(CGI.unescape(url))
|
189
|
+
# > https://cdn.flyyer.io/render/v2/tenant/deck/template.jpeg?title=Hello+world!&__v=123
|
190
|
+
```
|
191
|
+
|
192
|
+
## Development
|
193
|
+
|
194
|
+
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.
|
195
|
+
|
196
|
+
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).
|
197
|
+
|
198
|
+
## Test
|
199
|
+
|
200
|
+
Run Rake tests with:
|
201
|
+
|
202
|
+
```sh
|
203
|
+
rake spec
|
204
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "flyyer"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/flyyer.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/flyyer/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'flyyer'
|
5
|
+
spec.version = Flyyer::VERSION
|
6
|
+
spec.authors = ['Patricio López Juri', 'Franco Méndez Z']
|
7
|
+
spec.email = ['patricio@flyyer.io', 'franco@flyyer.io']
|
8
|
+
|
9
|
+
spec.summary = 'FLYYER.io helper classes and methods'
|
10
|
+
# spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
|
11
|
+
spec.description = 'FLYYER.io helper classes and methods'
|
12
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
13
|
+
spec.homepage = 'https://github.com/useflyyer/flyyer-ruby'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
|
+
|
17
|
+
# spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com''
|
18
|
+
|
19
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/useflyyer/flyyer-ruby'
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/useflyyer/flyyer-ruby'
|
22
|
+
|
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)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
end
|
data/lib/flyyer.rb
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
require 'flyyer/version'
|
2
|
+
require 'uri'
|
3
|
+
require 'openssl'
|
4
|
+
require 'jwt'
|
5
|
+
|
6
|
+
module Flyyer
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
class Flyyer
|
10
|
+
attr_accessor :project, :path, :variables, :meta, :secret, :strategy
|
11
|
+
|
12
|
+
def self.create(&block)
|
13
|
+
self.new(&block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(project = nil, path = nil, variables = {}, meta = {}, secret = nil, strategy = nil)
|
17
|
+
@project = project
|
18
|
+
@path = path || "/"
|
19
|
+
@variables = variables
|
20
|
+
@meta = meta
|
21
|
+
@secret = secret
|
22
|
+
@strategy = strategy
|
23
|
+
yield(self) if block_given?
|
24
|
+
end
|
25
|
+
|
26
|
+
def path_safe
|
27
|
+
@path.start_with?("/") ? @path : "/#{@path}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def params_hash(ignoreV)
|
31
|
+
defaults = {
|
32
|
+
__v: @meta[:v] || Time.now.to_i, # This forces crawlers to refresh the image
|
33
|
+
__id: @meta[:id] || nil,
|
34
|
+
_w: @meta[:width] || nil,
|
35
|
+
_h: @meta[:height] || nil,
|
36
|
+
_res: @meta[:resolution] || nil,
|
37
|
+
_ua: @meta[:agent] || nil
|
38
|
+
}
|
39
|
+
defaults.delete(:__v) if ignoreV
|
40
|
+
@variables.nil? ? defaults : defaults.merge(@variables)
|
41
|
+
end
|
42
|
+
|
43
|
+
def querystring(ignoreV = false)
|
44
|
+
# Allow accesing the keys of @meta with symbols and strings
|
45
|
+
# https://stackoverflow.com/a/10786575
|
46
|
+
@meta.default_proc = proc do |h, k|
|
47
|
+
case k
|
48
|
+
when String then sym = k.to_sym; h[sym] if h.key?(sym)
|
49
|
+
when Symbol then str = k.to_s; h[str] if h.key?(str)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
defaults = self.params_hash(ignoreV)
|
54
|
+
result = FlyyerHash.new(defaults)
|
55
|
+
result.to_query.split("&").sort().join("&")
|
56
|
+
end
|
57
|
+
|
58
|
+
def sign
|
59
|
+
return '_' if @strategy.nil? and @secret.nil?
|
60
|
+
raise Error.new('Got `strategy` but missing `secret`. You can find it in your project in Advanced settings.') if @secret.nil?
|
61
|
+
raise Error.new('Got `secret` but missing `strategy`. Valid options are `HMAC` or `JWT`.') if @strategy.nil?
|
62
|
+
key = @secret
|
63
|
+
data = "#{@project}#{self.path_safe}#{self.querystring(true)}"
|
64
|
+
if strategy.downcase == "hmac" then
|
65
|
+
mac = OpenSSL::HMAC.hexdigest('SHA256', key, data)
|
66
|
+
mac[0..15]
|
67
|
+
elsif strategy.downcase == "jwt"
|
68
|
+
payload = { "params": self.params_hash(true).compact, "path": self.path_safe}
|
69
|
+
JWT.encode(payload, key, 'HS256')
|
70
|
+
else
|
71
|
+
raise Error.new('Invalid `strategy`. Valid options are `HMAC` or `JWT`.')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Create a https://FLAYYER.com string.
|
76
|
+
# If you are on Ruby on Rails please use .html_safe when rendering this string into the HTML
|
77
|
+
def href
|
78
|
+
raise Error.new('Missing "project" property') if @project.nil?
|
79
|
+
|
80
|
+
signature = self.sign
|
81
|
+
params = self.querystring
|
82
|
+
if strategy.nil? || strategy != "JWT" then
|
83
|
+
"https://cdn.flyyer.io/v2/#{@project}/#{signature}/#{params}#{self.path_safe}"
|
84
|
+
else
|
85
|
+
"https://cdn.flyyer.io/v2/#{@project}/jwt-#{signature}?__v=#{@meta[:v] || Time.now.to_i}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
class FlyyerRender
|
91
|
+
attr_accessor :version, :tenant, :deck, :template, :extension, :variables, :meta
|
92
|
+
|
93
|
+
def self.create(&block)
|
94
|
+
self.new(&block)
|
95
|
+
end
|
96
|
+
|
97
|
+
def initialize(tenant = nil, deck = nil, template = nil, version = nil, extension = 'jpeg', variables = {}, meta = {})
|
98
|
+
@tenant = tenant
|
99
|
+
@deck = deck
|
100
|
+
@template = template
|
101
|
+
@version = version
|
102
|
+
@extension = extension
|
103
|
+
@variables = variables
|
104
|
+
@meta = meta
|
105
|
+
yield(self) if block_given?
|
106
|
+
end
|
107
|
+
|
108
|
+
def querystring
|
109
|
+
# Allow accesing the keys of @meta with symbols and strings
|
110
|
+
# https://stackoverflow.com/a/10786575
|
111
|
+
@meta.default_proc = proc do |h, k|
|
112
|
+
case k
|
113
|
+
when String then sym = k.to_sym; h[sym] if h.key?(sym)
|
114
|
+
when Symbol then str = k.to_s; h[str] if h.key?(str)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
defaults = {
|
119
|
+
__v: @meta[:v].nil? ? Time.now.to_i : @meta[:v], # This forces crawlers to refresh the image
|
120
|
+
__id: @meta[:id] || nil,
|
121
|
+
_w: @meta[:width] || nil,
|
122
|
+
_h: @meta[:height] || nil,
|
123
|
+
_res: @meta[:resolution] || nil,
|
124
|
+
_ua: @meta[:agent] || nil
|
125
|
+
}
|
126
|
+
result = FlyyerHash.new(@variables.nil? ? defaults : defaults.merge(@variables))
|
127
|
+
result.to_query
|
128
|
+
end
|
129
|
+
|
130
|
+
# Create a https://flyyer.io string.
|
131
|
+
# If you are on Ruby on Rails please use .html_safe when rendering this string into the HTML
|
132
|
+
def href
|
133
|
+
raise Error.new('Missing "tenant" property') if @tenant.nil?
|
134
|
+
raise Error.new('Missing "deck" property') if @deck.nil?
|
135
|
+
raise Error.new('Missing "template" property') if @template.nil?
|
136
|
+
|
137
|
+
if @version.nil?
|
138
|
+
"https://cdn.flyyer.io/render/v2/#{@tenant}/#{@deck}/#{@template}.#{@extension}?#{self.querystring}"
|
139
|
+
else
|
140
|
+
"https://cdn.flyyer.io/render/v2/#{@tenant}/#{@deck}/#{@template}.#{@version}.#{@extension}?#{self.querystring}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# A compatible qs stringify/parse (https://github.com/ljharb/qs)
|
146
|
+
class FlyyerHash
|
147
|
+
@hash = {}
|
148
|
+
def initialize(hash)
|
149
|
+
@hash = hash
|
150
|
+
end
|
151
|
+
|
152
|
+
def to_query_hash(key)
|
153
|
+
@hash.reduce({}) do |h, (k, v)|
|
154
|
+
new_key = key.nil? ? k : "#{key}[#{k}]"
|
155
|
+
v = Hash[v.each_with_index.to_a.map(&:reverse)] if v.is_a?(Array)
|
156
|
+
if v.is_a?(Hash)
|
157
|
+
h.merge!(FlyyerHash.new(v).to_query_hash(new_key))
|
158
|
+
elsif v.nil?
|
159
|
+
# skip null values
|
160
|
+
else
|
161
|
+
h[new_key] = v
|
162
|
+
end
|
163
|
+
h
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def to_query(key = nil)
|
168
|
+
URI.encode_www_form(self.to_query_hash(key))
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flyyer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patricio López Juri
|
8
|
+
- Franco Méndez Z
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2021-07-11 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: FLYYER.io helper classes and methods
|
15
|
+
email:
|
16
|
+
- patricio@flyyer.io
|
17
|
+
- franco@flyyer.io
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ".github/workflows/ruby.yml"
|
23
|
+
- ".gitignore"
|
24
|
+
- ".rspec"
|
25
|
+
- ".travis.yml"
|
26
|
+
- Gemfile
|
27
|
+
- Gemfile.lock
|
28
|
+
- LICENSE.txt
|
29
|
+
- README.md
|
30
|
+
- Rakefile
|
31
|
+
- bin/console
|
32
|
+
- bin/setup
|
33
|
+
- flyyer.gemspec
|
34
|
+
- lib/flyyer.rb
|
35
|
+
- lib/flyyer/version.rb
|
36
|
+
homepage: https://github.com/useflyyer/flyyer-ruby
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata:
|
40
|
+
homepage_uri: https://github.com/useflyyer/flyyer-ruby
|
41
|
+
source_code_uri: https://github.com/useflyyer/flyyer-ruby
|
42
|
+
changelog_uri: https://github.com/useflyyer/flyyer-ruby
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: 2.3.0
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.0.6
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: FLYYER.io helper classes and methods
|
62
|
+
test_files: []
|