Skip to content

Commit

Permalink
Configuration using initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
candanedo committed Feb 8, 2024
1 parent 0dbbf03 commit 1e6dc80
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ If Bundler is not used to manage dependencies, install the gem with:

$ gem install use_paragon

## Configuration

To use the UseParagon gem, you need to configure it with your private key and project ID. Here's how to do it:

#### For Rails
Create a new initializer in your Rails project:

touch config/initializers/use_paragon.rb

Provide your private key and project ID in the initializer:

```ruby
# config/initializers/use_paragon.rb

UseParagon.configure do |config|
config.private_key = Rails.application.credentials.paragon.private_key
config.project_id = Rails.application.credentials.paragon.project_id
end
```

## Usage

To use UseParagon, add your project's ID along with your private key to your Rails credentials.
Expand Down
12 changes: 11 additions & 1 deletion lib/use_paragon.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
# frozen_string_literal: true

require "use_paragon/configuration"
require "use_paragon/base"
require "use_paragon/integration"
require "use_paragon/user"
require "use_paragon/version"
require "use_paragon/workflow"

module UseParagon
class Error < StandardError; end
class << self
def configuration
@configuration ||= Configuration.new
end

def configure(&block)
yield(configuration)
end
end

class Error < StandardError; end
class InvalidUserIdError < StandardError; end
end
9 changes: 3 additions & 6 deletions lib/use_paragon/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "jwt"
require "faraday"
require "use_paragon/configuration"

module UseParagon
# Basic logic for interacting with UseParagon platform
Expand Down Expand Up @@ -62,15 +63,11 @@ def path(endpoint)
end

def private_key
return nil unless defined?(Rails)

Rails.application.credentials.paragon.private_key
UseParagon.configuration.private_key
end

def project_id
return nil unless defined?(Rails)

Rails.application.credentials.paragon.project_id
UseParagon.configuration.project_id
end

def validate_user_id!
Expand Down
8 changes: 8 additions & 0 deletions lib/use_paragon/configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

module UseParagon
# Allows configuration using an initializer
class Configuration
attr_accessor :private_key, :project_id
end
end

0 comments on commit 1e6dc80

Please sign in to comment.