Skip to content

Commit

Permalink
Merge pull request #1 from hostari/chore/update-docs
Browse files Browse the repository at this point in the history
Update docs
  • Loading branch information
xaviablaza authored Feb 12, 2024
2 parents 460eb64 + 401bab4 commit 31afe9d
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 14 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# TODO: Uncomment when test suite is written
# name: Crystal CI
# on:
# pull_request:
# branches: [ "main" ]
# jobs:
# build:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/setup-node@v4
# with:
# node-version: 20.x
# - uses: crystal-lang/install-crystal@v1
# with:
# crystal: 1.6.2
# - name: Download source
# uses: actions/checkout@v4
# - name: Install dependencies
# run: shards install
# - name: Run tests
# run: crystal spec
51 changes: 51 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Crystal Docs Generation

on:
push:
branches: [ "main" ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/setup-node@v4
with:
node-version: 20.x
- uses: crystal-lang/install-crystal@v1
with:
crystal: 1.6.2
- uses: actions/checkout@v4
- name: Generate docs
run: crystal docs
- name: Move docs to _site
run: mv docs/ _site/
- name: Upload artifact
uses: actions/upload-pages-artifact@v3

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 paula4230 <paudepolonia000@yahoo.com>
Copyright (c) 2022-2024 Hostari Philippines, Inc. <eng@hostari.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
52 changes: 49 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bentonow_client

This is a crystal wrapper for the Bentonow API.
A crystal lang wrapper for the [Bentonow API](https://bentonow.com/).

## Installation

Expand All @@ -24,15 +24,60 @@ require "bentonow_client"

To build a new Bentonow client:
```crystal
publishable_key = ENV["BENTO_PUBLISHABLE_KEY"]
secret_key = ENV["BENTO_SECRET_KEY"]
client = Bentonow::Client.new(publishable_key, secret_key)
```

## Endpoints
Most useful available Bentonow API resources are implemented.

1. Creating an Event - for single or batch processing of events such as adding users and other user information, adding tags to already exisiting users, or adding fields to existing users.
1. [Creating an Event](https://docs.bentonow.com/reference-api/create-events) - for single or batch processing of events such as adding users and other user information, adding tags to already exisiting users, or adding fields to existing users.

```crystal
body = {
events: [
{
type: "$completed_onboarding",
email: "[email protected]"
},
{
type: "$completed_onboarding",
email: "[email protected]",
fields: {
first_name: "Jesse",
last_name: "Pinkman"
}
},
{
email: "[email protected]",
type: "$purchase",
fields: {
first_name: "Jesse"
},
details: {
unique: {
key: "test123"
},
value: {
currency: "USD",
amount: 8000
},
cart: {
items: [
{
product_sku: "SKU123",
product_name: "Test",
quantity: 100
}
],
abandoned_checkout_url: "https://test.com"
}
}
}
]
}.to_json
site_uuid = ENV["BENTO_SITE_UUID"]
event = Bentonow::Event.create_event(publishable_key, secret_key, site_uuid, body)
```

Expand All @@ -46,4 +91,5 @@ event = Bentonow::Event.create_event(publishable_key, secret_key, site_uuid, bod

## Contributors

- [Pauline De Polonia](https://github.com/your-github-user) - creator and maintainer
- [Pauline De Polonia](https://github.com/paula4230) - creator
- [Xavi Ablaza](https://github.com/xaviablaza) - maintainer
5 changes: 3 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: bentonow_client
version: 0.1.0
version: 1.0.0

authors:
- paula4230 <[email protected]>
- Xavi Ablaza <[email protected]>

crystal: 1.4.1
crystal: ~> 1.6.2

license: MIT
19 changes: 14 additions & 5 deletions src/bentonow/client.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
module Bentonow
class Client
private getter publishable_key : String
private getter secret_key : String

BASE_URI = "app.bentonow.com"

def initialize(@publishable_key, @secret_key)
Expand All @@ -11,10 +8,22 @@ module Bentonow
def reset_client
HTTP::Client.new(BASE_URI, port: 443, tls: true).tap do |client|
client.before_request do |request|
request.headers["Authorization"] = "Basic #{Base64.urlsafe_encode("#{publishable_key}:#{secret_key}")}"
request.headers["Content-Type"] = "application/json"
request.headers["Authorization"] = build_auth_header_value
request.headers["Content-Type"] = content_type
end
end
end

private def build_auth_header_value
"Basic #{Base64.urlsafe_encode(authorization_key)}"
end

private def authorization_key
"#{@publishable_key}:#{@secret_key}"
end

private def content_type
"application/json"
end
end
end
3 changes: 1 addition & 2 deletions src/bentonow/create_event.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This endpoint is used for single or batch processing of events such as adding tags or fields to one or more users (https://docs.bentonow.com/batch-api/events)

module Bentonow
class Event
# Use this for single or batch processing of events such as adding tags or fields to one or more users. See Bento API reference [here](https://docs.bentonow.com/batch-api/event).
def self.create_event(publishable_key : String, secret_key : String, site_uuid : String, body : String)
client = Bentonow::Client.new(publishable_key, secret_key).reset_client
client.post("/api/v1/batch/events?site_uuid=#{site_uuid}", body: body)
Expand Down
2 changes: 1 addition & 1 deletion src/bentonow_client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "json"
require "http/client"

module BentonowClient
VERSION = "0.1.0"
VERSION = "1.0.0"
end

require "./bentonow/**"

0 comments on commit 31afe9d

Please sign in to comment.