Skip to content

Fix API compatibility issues and update response structures #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Fank
Copy link
Member

@Fank Fank commented Jul 15, 2025

Summary

This PR fixes several API compatibility issues discovered while testing against the actual Printix API endpoints.

Changes

1. User Identifier Configuration

  • Added userIdentifier field to Client struct
  • Created WithUserIdentifier() option to configure it (defaults to "API Client")
  • Replaced hardcoded "MTS API" strings with configurable identifier

2. Queue ID Support

  • Added QueueID field to PrintJob struct
  • Updated Submit endpoint to use correct format: /printers/{printerId}/queues/{queueId}/submit
  • Updated PrintFile and PrintData to accept separate queueID parameter
  • Breaking change: QueueID is now required (no backward compatibility)

3. v1.1 API Compatibility

  • Fixed v1.1 API request format to match documentation:
    • title, user, PDL parameters stay in query string (not body)
    • Added version: 1.1 header for v1.1 features
    • Request body only contains v1.1 specific fields
  • Added support for new v1.1 fields:
    • userMapping for user assignment
    • releaseImmediately parameter (defaults to true)
    • MediaSize and Scaling in PrintOptions

4. Response Structure Fixes

  • Fixed SubmitResponse to match actual API response:
    • Changed timestamps from int64 to string (ISO format)
    • Added nested _links section within job object
    • Updated root _links structure
  • Fixed Printer response structures:
    • Fixed Copies.Default field (API returns "defaultz")
    • Added proper HAL link structures instead of generic maps

Test plan

  • All existing tests pass
  • Linter passes with no issues
  • Tested against actual Printix API endpoints
  • Manual testing of print job submission
  • Verify backward compatibility impact is acceptable

Breaking Changes

  1. PrintFile signature changed: PrintFile(ctx, printerID, queueID, title, filePath, options)
  2. PrintData signature changed: PrintData(ctx, printerID, queueID, title, data, pdl, options)
  3. Submit now requires QueueID to be set (returns error if empty)

🤖 Generated with Claude Code

- Add configurable userIdentifier field to Client (replaces hardcoded "MTS API")
- Add QueueID support for Submit endpoint (printer ID and queue ID are separate)
- Fix Submit endpoint to properly handle v1.1 API requirements:
  - Send version: 1.1 header for v1.1 features
  - Keep title, user, PDL in query params (not body) for v1.1
  - Add userMapping and releaseImmediately parameter support
- Update PrintOptions with v1.1 fields (MediaSize, Scaling)
- Fix SubmitResponse structure to match actual API:
  - Change timestamps from int64 to ISO format strings
  - Add nested _links section within job object
  - Update root _links structure
- Update Printer response structures for proper HAL+JSON parsing:
  - Fix Copies.Default field name (defaultz)
  - Add proper HAL link structures instead of generic maps
- Update PrintFile and PrintData to accept separate queueID parameter

Breaking changes:
- PrintFile and PrintData now require queueID parameter
- Submit requires QueueID to be set (no backward compatibility)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @Fank, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on enhancing the Printix API client's compatibility and functionality by addressing discrepancies with the actual API endpoints. It introduces support for the v1.1 API, refines the print job submission process with mandatory queue IDs, and standardizes response structures for improved reliability.

Highlights

  • API Compatibility & V1.1 Support: The client has been updated for full compatibility with the actual Printix API endpoints, including comprehensive support for the v1.1 API. This involves adjusting request formats, adding new parameters like userMapping, releaseImmediately, MediaSize, and Scaling, and ensuring title, user, PDL are correctly sent as query parameters for v1.1 requests.
  • Queue ID Integration (Breaking Change): A QueueID field has been introduced to the PrintJob struct, and the submitEndpoint now explicitly includes it. This is a breaking change as QueueID is now a required parameter for job submission, and the PrintFile and PrintData function signatures have been updated to accept this new parameter.
  • User Identifier Configuration: A configurable userIdentifier has been added to the Client struct, allowing the client to specify its identity (defaulting to 'API Client') instead of using hardcoded strings like 'MTS API' in print job submissions.
  • Response Structure Harmonization: The SubmitResponse structure has been corrected to align with the actual API, changing job timestamps from int64 to ISO string format and properly structuring nested _links sections. Additionally, Printer response structures were refined to use explicit HAL link types and fix a specific field name (Copies.Default to defaultz).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses API compatibility issues and improves the client library. The changes include adding queueID support, correcting the v1.1 API request format, and using strongly-typed structs for API responses. The tests have also been updated.

Comment on lines +123 to +127
if job.ReleaseImmediately != nil && !*job.ReleaseImmediately {
params.Set("releaseImmediately", "false")
} else if job.ReleaseImmediately == nil {
params.Set("releaseImmediately", "true")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The logic for handling the releaseImmediately query parameter is incomplete. It misses the case where job.ReleaseImmediately is explicitly set to true. In that scenario, the parameter is not added to the query string at all, which is a bug.

Suggested change
if job.ReleaseImmediately != nil && !*job.ReleaseImmediately {
params.Set("releaseImmediately", "false")
} else if job.ReleaseImmediately == nil {
params.Set("releaseImmediately", "true")
}
if job.ReleaseImmediately != nil && !*job.ReleaseImmediately {
params.Set("releaseImmediately", "false")
} else {
params.Set("releaseImmediately", "true")
}

Comment on lines +161 to 165
if job.UserMapping != nil {
v11Body["userMapping"] = job.UserMapping
} else {
v11Body["userMapping"] = nil
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This if/else block for setting userMapping in the v1.1 request body is more verbose than necessary. Since job.UserMapping is a pointer, it can be assigned directly to the map.

v11Body["userMapping"] = job.UserMapping

- Remove separate HTTP client creation in UploadDocument
- Use the same httpClient configured when creating the client
- This respects custom timeouts, transports, and other configurations
- Enables better testing and consistency

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant