@planningcenter/url
v2.7.2
Published
url utilities for planning center apps
Downloads
9,797
Keywords
Readme
@planningcenter/url
A dumb url origin generator in JS.
Builds environment-considered url origins in JS-land, for Planning Center apps.
Examples
planningcenterurl("development")("api");
// => "http://api.pco.test"
planningcenterurl("staging")("people");
// => "https://accounts.planningcenteronline.com"
planningcenterurl("production")("accounts");
// => "https://people-staging.planningcenteronline.com"
Arguments are curried. You can make a generic env-considered function.
const envURL = planningcenterurl(window.railsEnv);
envURL("api");
In Planning Center Apps
Planning center apps expose the Rails env as the JS global railsEnv
. Use like so.
planningcenterurl(railsEnv)("api");
Fetching example
fetch(`${planningcenterurl(env)("api")}/people/v2/me`, {
credentials: "include"
})
.then(res => res.json())
.then(json => json.data)
.then(({ id, attributes }) =>
this.setState({
currentUser: {
id,
...attributes
}
})
)
.catch(err => console.log(err));
Installation
Script tag on Rails
<script type="javascript" src="https://unpkg.com/@planningcenter/url"></script>
<!-- exposed as global `planningcenterurl` -->
Webpacker on Rails
yarn add @planningcenter/url
/* global railsEnv */
import pcurl from "@planningcenter/url";
pcurl(railsEnv)("api");