flayyer 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +34 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/flayyer.gemspec +31 -0
- data/lib/flayyer.rb +71 -0
- data/lib/flayyer/version.rb +3 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e5822ca789be9267bee7ee619207c7e6fca6b0da10149d802c47ac794975d8bf
|
4
|
+
data.tar.gz: 1996d8b0432671c590e80299d8ed41fea657771489a9735589253cf9de1bb592
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 20d466ce769a0b1b1fd6c0e4d6f26a5b165796d68b13eb3dae64e4834539c7271c5efdd8aa5d9d1cc5e99c8376ea03b7aa650006f9bdc427a2ebfd444ed2e2c8
|
7
|
+
data.tar.gz: a0a6a27576c0ce834db173f1c97eb2f71a996a3af2e1efec455539b6d027751714946b7ba9ec2f3dcab56e9060d0664b8999ce3e1d7cca6c196df99dbffc6ebc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
flayyer (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.4.4)
|
10
|
+
rake (12.3.3)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.2)
|
16
|
+
rspec-support (~> 3.9.3)
|
17
|
+
rspec-expectations (3.9.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.3)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
flayyer!
|
30
|
+
rake (~> 12.0)
|
31
|
+
rspec (~> 3.0)
|
32
|
+
|
33
|
+
BUNDLED WITH
|
34
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Patricio López Juri
|
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,91 @@
|
|
1
|
+
# flayyer-ruby
|
2
|
+
|
3
|
+
This gem is agnostic to any Ruby framework.
|
4
|
+
|
5
|
+
To create a template please refer to: [flayyer.com](https://flayyer.com?ref=flayyer-ruby)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'flayyer'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install flayyer
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
After installing the gem you can format URL as:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'flayyer'
|
29
|
+
|
30
|
+
flayyer = Flayyer::FlayyerURL.create do |f|
|
31
|
+
f.tenant = 'flayyer'
|
32
|
+
f.deck = 'deck'
|
33
|
+
f.template = 'template'
|
34
|
+
f.variables = {
|
35
|
+
title: 'Hello world!'
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# Use this image in your <head/> tags
|
40
|
+
url = flayyer.href
|
41
|
+
# > https://flayyer.host/v2/flayyer/deck/template.jpeg?__v=1596906866&title=Hello+world%21
|
42
|
+
```
|
43
|
+
|
44
|
+
Variables can be complex arrays and hashes.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
flayyer = Flayyer::FlayyerURL.create do |f|
|
48
|
+
# ...
|
49
|
+
f.variables = {
|
50
|
+
items: [
|
51
|
+
{ text: 'Oranges', count: 12 },
|
52
|
+
{ text: 'Apples', count: 14 },
|
53
|
+
],
|
54
|
+
}
|
55
|
+
end
|
56
|
+
```
|
57
|
+
|
58
|
+
**IMPORTANT: variables should be serializable.**
|
59
|
+
|
60
|
+
To decode the URL for debugging purposes:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
print(CGI.unescape(url))
|
64
|
+
# > https://flayyer.host/v2/flayyer/deck/template.jpeg?title=Hello+world!&__v=123
|
65
|
+
```
|
66
|
+
|
67
|
+
## Ruby on Rails
|
68
|
+
|
69
|
+
Ruby on Rails will try to safely render strings into the HTML. Any FLAYYER string is already safe-serialized and should not be serialized again.
|
70
|
+
|
71
|
+
To prevent double serialization make sure to call `.html_safe` like this:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
url = flayyer.href.html_safe
|
75
|
+
```
|
76
|
+
|
77
|
+
> https://apidock.com/rails/String/html_safe
|
78
|
+
|
79
|
+
## Development
|
80
|
+
|
81
|
+
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.
|
82
|
+
|
83
|
+
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).
|
84
|
+
|
85
|
+
## Contributing
|
86
|
+
|
87
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/flayyer/flayyer-ruby.
|
88
|
+
|
89
|
+
## License
|
90
|
+
|
91
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "flayyer"
|
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/flayyer.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'lib/flayyer/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "flayyer"
|
5
|
+
spec.version = Flayyer::VERSION
|
6
|
+
spec.authors = ["Patricio López Juri"]
|
7
|
+
spec.email = ["patricio@flayyer.com"]
|
8
|
+
|
9
|
+
spec.summary = "FLAYYER.com helper classes and methods"
|
10
|
+
# spec.summary = %q{TODO: Write a short summary, because RubyGems requires one.}
|
11
|
+
spec.description = "FLAYYER.com helper classes and methods"
|
12
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
13
|
+
spec.homepage = "https://github.com/flayyer/flayyer-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/flayyer/flayyer-ruby"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/flayyer/flayyer-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/flayyer.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "flayyer/version"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
module Flayyer
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
class FlayyerURL
|
8
|
+
attr_accessor :version, :tenant, :deck, :template, :extension, :variables
|
9
|
+
|
10
|
+
def self.create(&block)
|
11
|
+
self.new(&block)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(tenant = nil, deck = nil, template = nil, version = nil, extension = 'jpeg', variables = {})
|
15
|
+
@tenant = tenant
|
16
|
+
@deck = deck
|
17
|
+
@template = template
|
18
|
+
@version = version
|
19
|
+
@extension = extension
|
20
|
+
@variables = variables
|
21
|
+
yield(self) if block_given?
|
22
|
+
end
|
23
|
+
|
24
|
+
def querystring
|
25
|
+
defaults = {
|
26
|
+
__v: Time.now.to_i, # This forces crawlers to refresh the image
|
27
|
+
}
|
28
|
+
result = FlayyerHash.new(@variables.nil? ? defaults : defaults.merge(@variables))
|
29
|
+
result.to_query
|
30
|
+
end
|
31
|
+
|
32
|
+
# Create a https://FLAYYER.com string.
|
33
|
+
# If you are on Ruby on Rails please use .html_safe when rendering this string into the HTML
|
34
|
+
def href
|
35
|
+
raise Error.new("Missing 'tenant' property") if @tenant.nil?
|
36
|
+
raise Error.new("Missing 'deck' property") if @deck.nil?
|
37
|
+
raise Error.new("Missing 'template' property") if @template.nil?
|
38
|
+
|
39
|
+
if @version.nil?
|
40
|
+
"https://flayyer.host/v2/#{@tenant}/#{@deck}/#{@template}.#{@extension}?#{self.querystring}"
|
41
|
+
else
|
42
|
+
"https://flayyer.host/v2/#{@tenant}/#{@deck}/#{@template}.#{@version}.#{@extension}?#{self.querystring}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# A compatible qs stringify/parse (https://github.com/ljharb/qs)
|
48
|
+
class FlayyerHash
|
49
|
+
@hash = {}
|
50
|
+
def initialize(hash)
|
51
|
+
@hash = hash
|
52
|
+
end
|
53
|
+
|
54
|
+
def to_query_hash(key)
|
55
|
+
@hash.reduce({}) do |h, (k, v)|
|
56
|
+
new_key = key.nil? ? k : "#{key}[#{k}]"
|
57
|
+
v = Hash[v.each_with_index.to_a.map(&:reverse)] if v.is_a?(Array)
|
58
|
+
if v.is_a?(Hash)
|
59
|
+
h.merge!(FlayyerHash.new(v).to_query_hash(new_key))
|
60
|
+
else
|
61
|
+
h[new_key] = v
|
62
|
+
end
|
63
|
+
h
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_query(key = nil)
|
68
|
+
URI.encode_www_form(self.to_query_hash(key))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flayyer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patricio López Juri
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: FLAYYER.com helper classes and methods
|
14
|
+
email:
|
15
|
+
- patricio@flayyer.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".travis.yml"
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/console
|
29
|
+
- bin/setup
|
30
|
+
- flayyer.gemspec
|
31
|
+
- lib/flayyer.rb
|
32
|
+
- lib/flayyer/version.rb
|
33
|
+
homepage: https://github.com/flayyer/flayyer-ruby
|
34
|
+
licenses:
|
35
|
+
- MIT
|
36
|
+
metadata:
|
37
|
+
homepage_uri: https://github.com/flayyer/flayyer-ruby
|
38
|
+
source_code_uri: https://github.com/flayyer/flayyer-ruby
|
39
|
+
changelog_uri: https://github.com/flayyer/flayyer-ruby
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.3.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.7.6.2
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: FLAYYER.com helper classes and methods
|
60
|
+
test_files: []
|