Skip to content

Instantly share code, notes, and snippets.

@laurentpellegrino
Created December 24, 2025 11:12
Show Gist options
  • Select an option

  • Save laurentpellegrino/8c9ad39a92909c5759a66fd5b196e6a9 to your computer and use it in GitHub Desktop.

Select an option

Save laurentpellegrino/8c9ad39a92909c5759a66fd5b196e6a9 to your computer and use it in GitHub Desktop.
Example to create a Noticeable Publication with segments using Ruby
#!/usr/bin/env ruby
require "json"
require "net/http"
require "uri"
endpoint = ENV.fetch("NOTICEABLE_GRAPHQL_ENDPOINT", "https://api.noticeable.io/graphql")
api_key = ENV.fetch("NOTICEABLE_API_KEY")
project_id = ENV.fetch("NOTICEABLE_PROJECT_ID")
mutation = <<~GRAPHQL
mutation {
createPublication(
input: {
projectId: "#{project_id}"
author: { fullName: "John Doe" }
title: "Publication from Docker Ruby"
content: "Hello **Markdown**"
isDraft: false
publishedAt: "#{Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')}"
segments: ["User:X"]
labels: [{ slug: "new" }]
isArchived: true
}
) {
publication {
id
permalink
}
}
}
GRAPHQL
uri = URI.parse(endpoint)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == "https")
req = Net::HTTP::Post.new(uri.request_uri)
req["Content-Type"] = "application/json"
req["Authorization"] = "Apikey #{api_key}"
req.body = { query: mutation }.to_json
res = http.request(req)
puts JSON.pretty_generate((JSON.parse(res.body) rescue { raw: res.body }))
@laurentpellegrino
Copy link
Author

laurentpellegrino commented Dec 24, 2025

docker run --rm -v "$PWD:/app:z" -w /app \
  -e NOTICEABLE_API_KEY="X" \
  -e NOTICEABLE_PROJECT_ID="Y" \
  ruby:3.3 ruby create-publication.rb

@laurentpellegrino
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment