Module: Clerk
- Defined in:
- lib/clerk/helpers.rb,
lib/clerk/id.rb,
lib/clerk/api.rb,
lib/clerk-rails.rb,
lib/clerk/engine.rb,
lib/clerk/tunnel.rb,
lib/clerk/version.rb,
app/models/clerk/plan.rb,
app/models/clerk/role.rb,
app/models/clerk/email.rb,
app/models/clerk/charge.rb,
app/models/clerk/client.rb,
app/models/clerk/account.rb,
app/models/clerk/subscription.rb,
app/jobs/clerk/application_job.rb,
app/models/clerk/session_token.rb,
app/models/clerk/payment_method.rb,
app/models/concerns/clerk/errors.rb,
app/models/concerns/clerk/clerked.rb,
app/models/clerk/application_record.rb,
app/mailers/clerk/application_mailer.rb,
app/controllers/clerk/application_controller.rb
Overview
Defined Under Namespace
Modules: Api, Clerked, Errors, Helpers, ID, Tunnel
Classes: Account, ApplicationController, ApplicationJob, ApplicationMailer, ApplicationRecord, Charge, Client, Configuration, Email, Engine, PaymentMethod, Plan, Role, SessionToken, Subscription
Constant Summary
collapse
- VERSION =
'0.1.15'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
10
11
12
|
# File 'lib/clerk-rails.rb', line 10
def config
@config
end
|
Class Method Details
.accounts_url ⇒ Object
36
37
38
|
# File 'lib/clerk-rails.rb', line 36
def accounts_url
@accounts_url ||= "https://#{Clerk.config.accounts_host}"
end
|
.api ⇒ Object
21
22
23
24
25
26
|
# File 'lib/clerk-rails.rb', line 21
def api
@conn ||= Clerk::Api::Connection.new(
(ENV["CLERK_API_PATH"] || "https://api.clerk.dev"),
key_secret
)
end
|
.app_url ⇒ Object
40
41
42
|
# File 'lib/clerk-rails.rb', line 40
def app_url
@app_url ||= "https://#{Clerk.config.app_host}"
end
|
.cipher_key ⇒ Object
44
45
46
|
# File 'lib/clerk-rails.rb', line 44
def cipher_key
@cipher_key ||= ::Base64.strict_decode64(Clerk.config.cipher_key)
end
|
12
13
14
15
|
# File 'lib/clerk-rails.rb', line 12
def configure
@config = Configuration.new
yield config
end
|
.database_connection_url ⇒ Object
17
18
19
|
# File 'lib/clerk-rails.rb', line 17
def database_connection_url
@database_connection_url ||= "#{Clerk.config.database_url}?prepared_statements=false"
end
|
.decrypt(encrypted_message) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/clerk-rails.rb', line 48
def decrypt(encrypted_message)
cipher = OpenSSL::Cipher.new("aes-256-gcm")
encrypted_data, iv, auth_tag = encrypted_message.split("--".freeze).map { |v| ::Base64.strict_decode64(v) }
raise InvalidMessage if (auth_tag.nil? || auth_tag.bytes.length != 16)
cipher.decrypt
cipher.key = cipher_key
cipher.iv = iv
cipher.auth_tag = auth_tag
cipher.auth_data = ""
message = cipher.update(encrypted_data)
message << cipher.final
message
end
|
.email(account: nil, to_email_address: nil, from_email_name: nil, email_template_token: nil, replacements: nil, subject: nil, body: nil) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/clerk-rails.rb', line 69
def email(
account: nil,
to_email_address: nil,
from_email_name: nil,
email_template_token: nil,
replacements: nil,
subject: nil,
body: nil
)
email = Clerk::Email.create(
account_id: account&.id,
to_email_address: to_email_address,
from_email_name: from_email_name,
email_template_token: email_template_token,
replacements: replacements.nil? ? nil : replacements.to_json,
subject: subject,
body: body
)
end
|
.key ⇒ Object
28
29
30
|
# File 'lib/clerk-rails.rb', line 28
def key
ENV['CLERK_KEY']
end
|
.key_secret ⇒ Object
32
33
34
|
# File 'lib/clerk-rails.rb', line 32
def key_secret
ENV['CLERK_KEY']&.slice(5..-1)
end
|