Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion .fern/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"cliVersion": "5.91.0",
"generatorName": "fernapi/fern-ruby-sdk",
"generatorVersion": "1.21.1",
"originGitCommit": "232d5e0240d5673a73c9ea7c7ae9e7b937fdd5b3",
"generatorConfig": {
"moduleName": "CloudPDF"
},
"originGitCommit": "a0adb9e77ef16feaef2358d71b247b4f5a98fd23",
"originGitCommitIsDirty": false,
"invokedBy": "ci",
"requestedVersion": "3.0.0.alpha.1",
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/sdk-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ jobs:
ruby-version: '3.3'
- run: ruby -e 'Dir["lib/**/*.rb"].each { |file| RubyVM::InstructionSequence.compile_file(file) }'
- run: gem build cloudpdf.gemspec --output /tmp/cloudpdf-ruby.gem
- name: Verify packaged require graph
run: |
ruby_gem_home="$(mktemp -d)"
gem install /tmp/cloudpdf-ruby.gem --local --no-document --install-dir "$ruby_gem_home"
GEM_HOME="$ruby_gem_home" GEM_PATH="$ruby_gem_home" ruby -e 'require "cloudpdf"; abort "CloudPDF::Client was not packaged" unless defined?(CloudPDF::Client)'
130 changes: 130 additions & 0 deletions .github/workflows/sdk-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: SDK Release

on:
push:
branches: [main]
paths-ignore:
- '.github/**'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: sdk-release
cancel-in-progress: false

jobs:
release:
name: Publish cloudpdf
if: github.event_name == 'workflow_dispatch' || vars.SDK_AUTO_PUBLISH_ENABLED == 'true'
runs-on: ubuntu-latest
environment: release
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'

- name: Verify generated release version
id: version
run: |
ruby <<'RUBY'
require "json"
require_relative "lib/CloudPDF/version"

generation = JSON.parse(File.read("cloudpdf-generation.json"))
raise "generation language is not ruby" unless generation.fetch("language") == "ruby"
version = CloudPDF::VERSION
unless version == generation.fetch("sdkVersion")
raise "package version #{version} does not match generated version #{generation.fetch('sdkVersion')}"
end
prerelease = generation.fetch("canonicalVersion").include?("-")
File.open(ENV.fetch("GITHUB_OUTPUT"), "a") do |output|
output.puts "version=#{version}"
output.puts "tag=v#{version}"
output.puts "prerelease=#{prerelease}"
end
RUBY

- name: Build and verify packaged require graph
run: |
mkdir -p dist
gem build cloudpdf.gemspec --output "dist/cloudpdf-${{ steps.version.outputs.version }}.gem"
ruby_gem_home="$(mktemp -d)"
gem install "dist/cloudpdf-${{ steps.version.outputs.version }}.gem" --local --no-document --install-dir "$ruby_gem_home"
GEM_HOME="$ruby_gem_home" GEM_PATH="$ruby_gem_home" ruby -e 'require "cloudpdf"; abort "CloudPDF::Client was not packaged" unless defined?(CloudPDF::Client)'

- name: Protect immutable release tag
id: release-tag
env:
RELEASE_TAG: ${{ steps.version.outputs.tag }}
run: |
git fetch --force --tags origin
if git rev-parse --quiet --verify "refs/tags/$RELEASE_TAG" >/dev/null; then
tagged_commit="$(git rev-list -n 1 "$RELEASE_TAG")"
if [ "$tagged_commit" != "$GITHUB_SHA" ]; then
if git diff --quiet "$RELEASE_TAG" "$GITHUB_SHA" -- . ':(exclude).github/**'; then
echo "::notice::Reusing $RELEASE_TAG after a workflow-only change."
else
echo "::error::Release tag $RELEASE_TAG already points to different package source at $tagged_commit; bump the SDK version."
exit 1
fi
fi
echo "existed=true" >> "$GITHUB_OUTPUT"
else
git config user.name cloudpdf-sdk-bot
git config user.email hello@cloudpdf.com
git tag -a "$RELEASE_TAG" -m "CloudPDF Ruby SDK $RELEASE_TAG"
git push origin "refs/tags/$RELEASE_TAG"
echo "existed=false" >> "$GITHUB_OUTPUT"
fi

- name: Check RubyGems publication state
id: registry
env:
VERSION: ${{ steps.version.outputs.version }}
TAG_EXISTED: ${{ steps.release-tag.outputs.existed }}
run: |
versions_file="$(mktemp)"
http_status="$(curl --silent --show-error --output "$versions_file" --write-out '%{http_code}' https://rubygems.org/api/v1/versions/cloudpdf.json)"
if [ "$http_status" != '200' ]; then
echo "::error::RubyGems returned HTTP $http_status while checking cloudpdf $VERSION."
exit 1
fi
if ruby -rjson -e 'version = ENV.fetch("VERSION"); exit(JSON.parse(File.read(ARGV.fetch(0))).any? { |item| item["number"] == version } ? 0 : 1)' "$versions_file"; then
if [ "$TAG_EXISTED" != 'true' ]; then
echo "::error::cloudpdf $VERSION already exists on RubyGems but its release tag did not exist."
exit 1
fi
echo "publish=false" >> "$GITHUB_OUTPUT"
else
echo "publish=true" >> "$GITHUB_OUTPUT"
fi

- name: Configure RubyGems trusted publishing
if: steps.registry.outputs.publish == 'true'
uses: rubygems/configure-rubygems-credentials@dc5a8d8553e6ee01fc26761a49e99e733d17954a

- name: Publish to RubyGems
if: steps.registry.outputs.publish == 'true'
run: gem push "dist/cloudpdf-${{ steps.version.outputs.version }}.gem"

- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
RELEASE_TAG: ${{ steps.version.outputs.tag }}
PRERELEASE: ${{ steps.version.outputs.prerelease }}
run: |
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
exit 0
fi
args=(--verify-tag --generate-notes --title "CloudPDF Ruby SDK $RELEASE_TAG")
if [ "$PRERELEASE" = 'true' ]; then args+=(--prerelease); fi
gh release create "$RELEASE_TAG" "${args[@]}"
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Cloudpdf Ruby Library
# CloudPDF Ruby SDK

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=Cloudpdf%2FRuby)

The Cloudpdf Ruby library provides convenient access to the Cloudpdf APIs from Ruby.
The official Ruby SDK for the CloudPDF API.

## Table of Contents

Expand All @@ -28,7 +28,7 @@ Instantiate and use the client with the following:
```ruby
require "cloudpdf"

client = Cloudpdf::Client.new(token: "<token>")
client = CloudPDF::Client.new(token: "<token>")

client.tenants.create(id: "id")
```
Expand All @@ -41,7 +41,7 @@ This SDK allows you to configure different custom URLs for API requests. You can
```ruby
require "cloudpdf"

client = Cloudpdf::Client.new(
client = CloudPDF::Client.new(
base_url: "https://example.com"
)
```
Expand All @@ -53,21 +53,21 @@ Failed API calls will raise errors that can be rescued from granularly.
```ruby
require "cloudpdf"

client = Cloudpdf::Client.new(
client = CloudPDF::Client.new(
base_url: "https://example.com"
)

begin
result = client.tenants.create
rescue Cloudpdf::Errors::TimeoutError
rescue CloudPDF::Errors::TimeoutError
puts "API didn't respond before our timeout elapsed"
rescue Cloudpdf::Errors::ServiceUnavailableError
rescue CloudPDF::Errors::ServiceUnavailableError
puts "API returned status 503, is probably overloaded, try again later"
rescue Cloudpdf::Errors::ServerError
rescue CloudPDF::Errors::ServerError
puts "API returned some other 5xx status, this is probably a bug"
rescue Cloudpdf::Errors::ResponseError => e
rescue CloudPDF::Errors::ResponseError => e
puts "API returned an unexpected status other than 5xx: #{e.code} #{e.message}"
rescue Cloudpdf::Errors::ApiError => e
rescue CloudPDF::Errors::ApiError => e
puts "Some other error occurred when calling the API: #{e.message}"
end
```
Expand Down Expand Up @@ -95,7 +95,7 @@ Use the `max_retries` option to configure this behavior.
```ruby
require "cloudpdf"

client = Cloudpdf::Client.new(
client = CloudPDF::Client.new(
base_url: "https://example.com",
max_retries: 3 # Configure max retries (default is 2)
)
Expand Down
2 changes: 1 addition & 1 deletion cloudpdf-generation.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"repository": "embedpdf/embed-pdf-viewer",
"openapi": "cloudpdf/contract/openapi.json",
"openapiSha256": "6858ce7912e9063d8fb171ade95fc473db01c5971a3af241a612dda79cc05100",
"gitCommit": "232d5e0240d5673a73c9ea7c7ae9e7b937fdd5b3",
"gitCommit": "a0adb9e77ef16feaef2358d71b247b4f5a98fd23",
"gitCommitIsDirty": false
},
"fern": {
Expand Down
10 changes: 5 additions & 5 deletions cloudpdf.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

require_relative "lib/cloudpdf/version"
require_relative "lib/CloudPDF/version"
require_relative "custom.gemspec"

# NOTE: A handful of these fields are required as part of the Ruby specification.
# You can change them here or overwrite them in the custom gemspec file.
Gem::Specification.new do |spec|
spec.name = "cloudpdf"
spec.authors = ["Cloudpdf"]
spec.version = Cloudpdf::VERSION
spec.summary = "Ruby client library for the Cloudpdf API"
spec.description = "The Cloudpdf Ruby library provides convenient access to the Cloudpdf API from Ruby."
spec.authors = ["CloudPDF"]
spec.version = CloudPDF::VERSION
spec.summary = "Ruby client library for the CloudPDF API"
spec.description = "The CloudPDF Ruby library provides convenient access to the CloudPDF API from Ruby."
spec.required_ruby_version = ">= 3.3.0"
spec.metadata["rubygems_mfa_required"] = "true"

Expand Down
7 changes: 7 additions & 0 deletions custom.gemspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ def add_custom_gemspec_data(spec)
spec.email = ["hello@cloudpdf.com"]
spec.homepage = "https://www.cloudpdf.com"
spec.license = "Apache-2.0"
spec.summary = "The official Ruby SDK for the CloudPDF API."
spec.description = "A typed Ruby client for deployment, tenant, and document operations in the CloudPDF API."
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/embedpdf/cloudpdf-sdk-ruby"
spec.files = spec.files.reject do |file|
file.start_with?(".github/") || file == "cloudpdf-generation.json"
end
end
46 changes: 46 additions & 0 deletions lib/CloudPDF/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# frozen_string_literal: true

module CloudPDF
class Client
# @param token [String]
# @param base_url [String, nil]
# @param max_retries [Integer]
#
# @return [void]
def initialize(token:, base_url: nil, max_retries: 2)
@raw_client = CloudPDF::Internal::Http::RawClient.new(
base_url: base_url,
headers: {
"X-Fern-Language" => "Ruby",
Authorization: "Bearer #{token}"
},
max_retries: max_retries
)
end

# @return [CloudPDF::Deployment::Client]
def deployment
@deployment ||= CloudPDF::Deployment::Client.new(client: @raw_client)
end

# @return [CloudPDF::Doc::Client]
def doc
@doc ||= CloudPDF::Doc::Client.new(client: @raw_client)
end

# @return [CloudPDF::Tenants::Client]
def tenants
@tenants ||= CloudPDF::Tenants::Client.new(client: @raw_client)
end

# @return [CloudPDF::Documents::Client]
def documents
@documents ||= CloudPDF::Documents::Client.new(client: @raw_client)
end

# @return [CloudPDF::Tokens::Client]
def tokens
@tokens ||= CloudPDF::Tokens::Client.new(client: @raw_client)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

module Cloudpdf
module CloudPDF
module Deployment
class Client
# @param client [Cloudpdf::Internal::Http::RawClient]
# @param client [CloudPDF::Internal::Http::RawClient]
#
# @return [void]
def initialize(client:)
Expand All @@ -21,9 +21,9 @@ def initialize(client:)
# @example
# client.deployment.license_status
#
# @return [Cloudpdf::Types::DeploymentLicenseStatusResponse]
# @return [CloudPDF::Types::DeploymentLicenseStatusResponse]
def license_status(request_options: {}, **_params)
request = Cloudpdf::Internal::JSON::Request.new(
request = CloudPDF::Internal::JSON::Request.new(
base_url: request_options[:base_url],
method: "GET",
path: "v1/deployment/license/status",
Expand All @@ -32,13 +32,13 @@ def license_status(request_options: {}, **_params)
begin
response = @client.send(request)
rescue Net::HTTPRequestTimeout
raise Cloudpdf::Errors::TimeoutError
raise CloudPDF::Errors::TimeoutError
end
code = response.code.to_i
if code.between?(200, 299)
Cloudpdf::Types::DeploymentLicenseStatusResponse.load(response.body)
CloudPDF::Types::DeploymentLicenseStatusResponse.load(response.body)
else
error_class = Cloudpdf::Errors::ResponseError.subclass_for_code(code)
error_class = CloudPDF::Errors::ResponseError.subclass_for_code(code)
raise error_class.new(response.body, code: code)
end
end
Expand Down
Loading
Loading