Skip to content

Commit

Permalink
Update readme and reorganize methods
Browse files Browse the repository at this point in the history
  • Loading branch information
candanedo committed Feb 28, 2024
1 parent 6ade8d0 commit 8a0b6d5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 64 deletions.
65 changes: 21 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# UseParagon

The UseParagon Ruby Gem simplifies the interaction with Paragon's service through RESTful API calls, enabling seamless integration of native features into your Ruby applications. With this gem, product and engineering teams can effortlessly incorporate Paragon's SDK and embedded Integration Platform as a Service (iPaaS) to accelerate the development of native integrations.
[![example workflow](https://github.com/candanedo/use_paragon/actions/workflows/main.yaml/badge.svg)](https://github.com/candanedo/use_paragon/actions?query=branch%3Amain)
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)

The UseParagon Ruby Gem simplifies the interaction with Paragon's service through RESTful API calls, enabling seamless integration of native features into your Ruby applications. With this gem, engineering teams can effortlessly incorporate Paragon's API to accelerate the development of native integrations.

| API Method | REST Method | Supported | Gem's Class | Method |
|--------------------------------|-------------|-----------|-------------------------|---------------------------------------------------------------------------------|
| Disable Workflow | DELETE | [x] | UseParagon::Workflow | disable(workflow_id) |
| Get Integrations Metadata | GET | [x] | UseParagon::Integration | metadata |
| Get User | GET | [x] | UseParagon::User | get |
| Workflow Event (App Events) | POST | [x] | UseParagon::Workflow | event(event_name, payload = {}) |
| Proxy Request | | [x] | UseParagon::Workflow | proxy_request(request_method, integration_type, integration_path, payload = {}) |
| Set User Metadata | PATCH | [x] | UseParagon::User | metadata=(metadata) |
| Uninstall Integration | DELETE | [x] | UseParagon::Integration | uninstall(integration_id) |
| Workflow Request (Trigger) | POST | [x] | UseParagon::Workflow | request(workflow_id, payload = {}) |
| Get Project's Integrations | GET | [x] | UseParagon::Integration | list |
| Get User's Connect Credentials | GET | [x] | UseParagon::User | credentials |

## Installation

Expand All @@ -22,56 +38,17 @@ If Bundler is not used to manage dependencies, install the gem with:

## Configuration

To use the UseParagon gem, you need to configure it with your private key and project ID. Here's how to do it:
To use the UseParagon gem, you need to configure it with your private key and project ID. Here's an example on 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:
Provide your private key and project ID:

```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
config.private_key = YOUR_PRIVATE_KEY
config.project_id = YOUR_PROJECT_ID
end
```

## Usage

To use UseParagon, add your project's ID along with your private key to your Rails credentials.

The private key is generated on the UseParagon Dashboard. Follow [these instructions](https://docs.useparagon.com/getting-started/installing-the-connect-sdk#setup-with-your-own-authentication-backend).

Rails.application.credentials.paragon.private_key

Find your project ID in the Overview tab of any Integration.

Rails.application.credentials.paragon.project_id

Once this information is configured in your Rails project, you can start using the gem as needed.

## Javascript assets (Paragon SDK)

The UseParagon gem includes the JavaScript assets necessary for you to utilize the Paragon SDK. To use window.paragon.authenticate(project, token) or window.connect(integration_name, options) in your JavaScript, you need to require the assets.

#### Using Importmaps
If you're using importmaps, add the following line to your config/importmap.rb file:

```ruby
pin "useparagon/connect" # 3.1.2
```
This will ensure that the necessary JavaScript asset is included in your application.

If you're using Stimulus controllers, you can require the asset in your desired controllers:

```js
import "useparagon/connect"
```

### Workflow triggers
#### Request trigger

Expand Down
24 changes: 20 additions & 4 deletions lib/use_paragon/integration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,34 @@
module UseParagon
# https://docs.useparagon.com/api/users#disconnecting-integrations
class Integration < Base
# Returns a list of the integrations enabled for the Paragon project by the ID in the URL.
def list
endpoint = path("sdk/integrations")

connection.get(endpoint)
end

# Get the name, brandColor, and icon, for any of your active integration providers.
def metadata
endpoint = path("sdk/metadata")

connection.get(endpoint)
end

# Returns a list of the integrations enabled for the Paragon project by the ID in the URL.
def list
endpoint = path("sdk/integrations")
# Call proxy_request to send an API request to a third-party integration on behalf of
# one of your users
# https://docs.useparagon.com/api/making-api-requests#server-side-usage
# This endpoint accepts any HTTP verb you want to use with the API:
# post, get, put, patch or delete.
# Body contents must be specified as application/json.
def proxy_request(request_method, integration_type, integration_path, payload = {})
formatted_method = request_method&.downcase

connection.get(endpoint)
validate_proxy_http_method(formatted_method)

endpoint = path("sdk/proxy/#{integration_type}/#{integration_path}")

connection.send(formatted_method, endpoint, payload)
end

# Integrations can be disconnected using uninstall via REST API.
Expand Down
16 changes: 0 additions & 16 deletions lib/use_paragon/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,6 @@ def request(workflow_id, payload = {})
connection.post(endpoint, payload)
end

# Call proxy_request to send an API request to a third-party integration on behalf of
# one of your users
# https://docs.useparagon.com/api/making-api-requests#server-side-usage
# This endpoint accepts any HTTP verb you want to use with the API:
# post, get, put, patch or delete.
# Body contents must be specified as application/json.
def proxy_request(request_method, integration_type, integration_path, payload = {})
formatted_method = request_method&.downcase

validate_proxy_http_method(formatted_method)

endpoint = path("sdk/proxy/#{integration_type}/#{integration_path}")

connection.send(formatted_method, endpoint, payload)
end

# App Events can be sent from your application using the Paragon REST API.
def event(event_name, payload = {})
endpoint = path("sdk/events/trigger")
Expand Down

0 comments on commit 8a0b6d5

Please sign in to comment.