flyyer 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef1404087856253e14da6d226113d736d21cd5abb60cd8f52dfeb11f483bc8e1
4
- data.tar.gz: 830b066c275d67436ef02dc16ea5f4deb75cefa2ce1a710d18963918947dcdc9
3
+ metadata.gz: c1e464a893bc3a20b7889928cd9ab42e630219f9a0b6949d7cc932c277fe10d9
4
+ data.tar.gz: d285616617397391d3f4c424980e39a014d662b3de85850ea50d8be8b931cb80
5
5
  SHA512:
6
- metadata.gz: e5a9a5f581151cf0f7c5dde17a7bec9c24be0efe260bcf4632583aec215857a019a39fd4e245406e8490cb7709fa3630171bd44062ea98af9be7120dccc1ce2b
7
- data.tar.gz: 8d258f240f0a74a37d7a0c06f2eeeda1fe165c4fb2b71b4d6f908f7c65e4aedb77c6b77b8ba8ca24b49183d244ade6482a76f91b0026360cd6719e11b29371ec
6
+ metadata.gz: 9068e285b85d5c3fd9d06c23e65eead115f629d99a82bd416441d190ea940a4902478381db17ebe2ee07338bb630b6882d9d9fee1f97e41a6dff5a4785a70528
7
+ data.tar.gz: 7846e196cbd31432133259794763300f21f332d4a9294f35582b7512f69933d0c228b666ce04b35d125f5797ed24502fc5b067c9ed0aa0fa81140f9a32bf8525
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flyyer (2.0.0)
4
+ flyyer (2.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -75,7 +75,7 @@ You'll get the best results like this:
75
75
 
76
76
  ### 4. Create a `rule` for your project
77
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:
78
+ Go to your dashboard [here](https://flyyer.io/dashboard/_/projects/_/manage) and create a rule like the following:
79
79
 
80
80
  [![Flyyer basic rule example](https://github.com/useflyyer/create-flyyer-app/blob/master/.github/assets/rule-example.png?raw=true&v=1)](https://flyyer.io/dashboard)
81
81
 
@@ -93,7 +93,7 @@ Here you have a detailed full example for project `website-com` and path `/path/
93
93
 
94
94
  ```ruby
95
95
  flyyer = Flyyer::Flyyer.create do |f|
96
- # [Required] Your project slug, find it in your dashboard https://flyyer.io/dashboard/.
96
+ # [Required] Your project slug, find it in your dashboard https://www.flyyer.io/dashboard/_/projects/_/integrate.
97
97
  f.project = 'website-com'
98
98
  # [Recommended] The current path of your website (by default it's `/`).
99
99
  f.path = '/path/to/product'
data/Rakefile CHANGED
@@ -3,4 +3,4 @@ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "flyyer"
3
+ require 'bundler/setup'
4
+ require 'flyyer'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "flyyer"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
data/flyyer.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  # Specify which files should be added to the gem when it is released.
24
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
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
26
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
27
  end
28
28
  spec.bindir = 'exe'
data/lib/flyyer.rb CHANGED
@@ -72,7 +72,7 @@ module Flyyer
72
72
  end
73
73
  end
74
74
 
75
- # Create a https://FLAYYER.com string.
75
+ # Create a https://FLYYER.io string.
76
76
  # If you are on Ruby on Rails please use .html_safe when rendering this string into the HTML
77
77
  def href
78
78
  raise Error.new('Missing "project" property') if @project.nil?
@@ -88,20 +88,22 @@ module Flyyer
88
88
  end
89
89
 
90
90
  class FlyyerRender
91
- attr_accessor :version, :tenant, :deck, :template, :extension, :variables, :meta
91
+ attr_accessor :version, :tenant, :deck, :template, :extension, :variables, :meta, :secret, :strategy
92
92
 
93
93
  def self.create(&block)
94
94
  self.new(&block)
95
95
  end
96
96
 
97
- def initialize(tenant = nil, deck = nil, template = nil, version = nil, extension = 'jpeg', variables = {}, meta = {})
97
+ def initialize(tenant = nil, deck = nil, template = nil, version = nil, extension = nil, variables = {}, meta = {}, secret = nil, strategy = nil)
98
98
  @tenant = tenant
99
99
  @deck = deck
100
100
  @template = template
101
101
  @version = version
102
102
  @extension = extension
103
- @variables = variables
103
+ @variables = variables || {}
104
104
  @meta = meta
105
+ @secret = secret
106
+ @strategy = strategy
105
107
  yield(self) if block_given?
106
108
  end
107
109
 
@@ -115,16 +117,38 @@ module Flyyer
115
117
  end
116
118
  end
117
119
 
120
+ default_v = {__v: @meta[:v].nil? ? Time.now.to_i : @meta[:v]} # This forces crawlers to refresh the image
118
121
  defaults = {
119
- __v: @meta[:v].nil? ? Time.now.to_i : @meta[:v], # This forces crawlers to refresh the image
120
122
  __id: @meta[:id] || nil,
121
123
  _w: @meta[:width] || nil,
122
124
  _h: @meta[:height] || nil,
123
125
  _res: @meta[:resolution] || nil,
124
- _ua: @meta[:agent] || nil
126
+ _ua: @meta[:agent] || nil,
127
+ }
128
+ jwt_defaults = {
129
+ i: @meta[:id] || nil,
130
+ w: @meta[:width] || nil,
131
+ h: @meta[:height] || nil,
132
+ r: @meta[:resolution] || nil,
133
+ u: @meta[:agent] || nil,
134
+ var: @variables,
125
135
  }
126
- result = FlyyerHash.new(@variables.nil? ? defaults : defaults.merge(@variables))
127
- result.to_query
136
+ if @strategy && @secret
137
+ key = @secret
138
+ if @strategy.downcase == "hmac"
139
+ default_query = FlyyerHash.new(defaults).to_query
140
+ data = [@deck, @template, @version || "", @extension || "", default_query].join("#")
141
+ __hmac = OpenSSL::HMAC.hexdigest('SHA256', key, data)[0..15]
142
+ return FlyyerHash.new([defaults, default_v, @variables, {__hmac: __hmac}].inject(&:merge)).to_query
143
+ end
144
+ if @strategy.downcase == "jwt"
145
+ payload = [{ d: @deck, t: @template, v: @version, e: @extension }, jwt_defaults].inject(&:merge)
146
+ __jwt = JWT.encode(payload, key, 'HS256')
147
+ return FlyyerHash.new({ __jwt: __jwt }.merge(default_v)).to_query
148
+ end
149
+ else
150
+ return FlyyerHash.new([default_v, defaults, @variables].inject(&:merge)).to_query
151
+ end
128
152
  end
129
153
 
130
154
  # Create a https://flyyer.io string.
@@ -133,12 +157,20 @@ module Flyyer
133
157
  raise Error.new('Missing "tenant" property') if @tenant.nil?
134
158
  raise Error.new('Missing "deck" property') if @deck.nil?
135
159
  raise Error.new('Missing "template" property') if @template.nil?
160
+ raise Error.new('Got `secret` but missing `strategy`. Valid options are `HMAC` or `JWT`.') if @secret && @strategy.nil?
161
+ raise Error.new('Got `strategy` but missing `secret`. You can find it in your project in Advanced settings.') if @strategy && @secret.nil?
162
+ raise Error.new('Invalid signing `strategy`. Valid options are `HMAC` or `JWT`.') if @strategy && @strategy.downcase != "jwt" && @strategy.downcase != "hmac"
136
163
 
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}"
164
+ base_href = "https://cdn.flyyer.io/render/v2/#{@tenant}"
165
+
166
+ if @strategy and @strategy.downcase == "jwt"
167
+ return "#{base_href}?#{self.querystring}"
141
168
  end
169
+
170
+ final_href = "#{base_href}/#{@deck}/#{@template}"
171
+ final_href << ".#{@version}" if @version
172
+ final_href << ".#{@extension}" if @extension
173
+ final_href << "?#{self.querystring}"
142
174
  end
143
175
  end
144
176
 
@@ -1,3 +1,3 @@
1
1
  module Flyyer
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flyyer
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patricio López Juri
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-07-11 00:00:00.000000000 Z
12
+ date: 2021-08-18 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: FLYYER.io helper classes and methods
15
15
  email: