Stigg::Client
This Ruby gem provides a wrapper to Stigg's GraphQL API based on the operations that are in use by the Stigg's Node.js SDK.
It leverages the graphlient library under the hood, and utilizes the Graphlient::Client
class to execute the API requests.
Documentation
See https://docs.stigg.io/docs/ruby-sdk
Installation
Install the gem and add to the application's Gemfile by executing:
$ bundle add stigg-api-client
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install stigg-api-client
Usage
Initialize the client:
require("stigg")
api_key = ENV["STIGG_SERVER_API_KEY"]
client = Stigg.create_client(api_key)
Provision a customer
require("stigg")
api_key = ENV["STIGG_SERVER_API_KEY"]
client = Stigg.create_client(api_key)
resp = client.request(Stigg::Mutation::ProvisionCustomer, {
"input": {
"refId": "customer-id",
"name": "Acme",
"email": "hello@acme.com",
"couponRefId": "coupon-id",
"billingInformation": {
"language": "en",
"timezone": "America/New_York",
"billingAddress": {
"country": "US",
"city": "New York",
"state": "NY",
"addressLine1": "123 Main Street",
"addressLine2": "Apt. 1",
"phoneNumber": "+1 212-499-5321",
"postalCode": "10164"
},
"shippingAddress": {
"country": "US",
"city": "New York",
"state": "NY",
"addressLine1": "123 Main Street",
"addressLine2": "Apt. 1",
"phoneNumber": "+1 212-499-5321",
"postalCode": "10164"
}
},
"additionalMetaData": {
"key": "value"
},
"subscriptionParams": {
"planId": "plan-revvenu-basic"
}
}
})
p resp.data.provision_customer.customer.name
Get a customer by ID
require("stigg")
api_key = ENV["STIGG_SERVER_API_KEY"]
client = Stigg.create_client(api_key)
resp = client.request(Stigg::Query::GetCustomerById, { 'customerId': 'customer-id' })
customer_edge = resp.data.customers.edges[0]
if customer_edge
customer = customer_edge.node
p customer.name
else
p 'Customer not found'
end