Skip to content

[client] add new methods#30

Merged
capcom6 merged 1 commit intomasterfrom
client/add-new-methods
Jul 10, 2025
Merged

[client] add new methods#30
capcom6 merged 1 commit intomasterfrom
client/add-new-methods

Conversation

@capcom6
Copy link
Copy Markdown
Member

@capcom6 capcom6 commented Jul 9, 2025

Summary by CodeRabbit

  • New Features
    • Added support for device management, health checks, inbox export, log retrieval, and device settings management.
    • Introduced flexible SMS sending options to customize phone validation and device activity filtering.
  • Bug Fixes
    • Updated message and state retrieval endpoints for improved accuracy.
  • Tests
    • Introduced comprehensive tests for new device, health, export, log, and settings features.
    • Added tests for SMS sending options and their URL parameter conversion.
    • Updated existing tests to align with revised API endpoints.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
smsgateway/client.go 97.45% <100.00%> (+14.76%) ⬆️
smsgateway/requests_3rdparty.go 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jul 9, 2025

Warning

Rate limit exceeded

@capcom6 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 20 minutes and 32 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 99e16e3 and cce3fa0.

📒 Files selected for processing (4)
  • smsgateway/client.go (6 hunks)
  • smsgateway/client_test.go (7 hunks)
  • smsgateway/requests_3rdparty.go (1 hunks)
  • smsgateway/requests_3rdparty_test.go (1 hunks)

Walkthrough

The changes introduce new client methods for device management, health checks, inbox export, logs retrieval, and settings management in the SMS gateway client. Existing message and webhook operations are refined, including endpoint path corrections. Corresponding tests are added for all new methods and updated for existing ones to match the revised API paths. Additionally, a flexible options pattern for sending SMS is implemented and tested.

Changes

File(s) Change Summary
smsgateway/client.go Added client methods: ListDevices, DeleteDevice, CheckHealth, ExportInbox, GetLogs, Get/Update/ReplaceSettings. Updated Send and GetState methods to use "/messages" endpoints with query parameters. Updated webhook method comments for clarity. Introduced settingsPath constant.
smsgateway/requests_3rdparty.go Added SendOptions struct and SendOption functional options for configuring SMS send requests with URL query parameter conversion.
smsgateway/client_test.go Added comprehensive tests for all new client methods and webhook methods. Refactored existing tests for Send and GetState to use updated endpoints and a reusable mock HTTP server helper. Improved validation of requests and responses, including error cases.
smsgateway/requests_3rdparty_test.go Added tests for SendOptions and related option functions verifying correct application and URL query parameter serialization.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API

    Client->>API: GET /devices
    API-->>Client: List of devices

    Client->>API: DELETE /devices/{id}
    API-->>Client: Deletion confirmation

    Client->>API: GET /health
    API-->>Client: Health status

    Client->>API: POST /inbox/export
    API-->>Client: Export confirmation

    Client->>API: GET /logs?from=&to=
    API-->>Client: Logs data

    Client->>API: GET /settings
    API-->>Client: Current settings

    Client->>API: PATCH /settings
    API-->>Client: Updated settings

    Client->>API: PUT /settings
    API-->>Client: Replaced settings

    Client->>API: POST /messages?options...
    API-->>Client: Message state

    Client->>API: GET /messages/{id}
    API-->>Client: Message state
Loading

Possibly related PRs

  • [webhooks] add client methods #9: Adds webhook client methods and tests; the current PR extends these webhook methods and adds device and settings management features, building directly on that work.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch client/add-new-methods

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (1)
smsgateway/client.go (1)

101-115: Consider using url.Values for cleaner query string construction.

While the current implementation is correct, using url.Values would be more idiomatic and maintainable.

 func (c *Client) GetLogs(ctx context.Context, from, to time.Time) ([]LogEntry, error) {
-	path := fmt.Sprintf(
-		"/logs?from=%s&to=%s",
-		url.QueryEscape(from.Format(time.RFC3339)),
-		url.QueryEscape(to.Format(time.RFC3339)),
-	)
+	query := url.Values{}
+	query.Set("from", from.Format(time.RFC3339))
+	query.Set("to", to.Format(time.RFC3339))
+	path := fmt.Sprintf("/logs?%s", query.Encode())
 	var logs []LogEntry
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d60747c and 9922525.

📒 Files selected for processing (2)
  • smsgateway/client.go (6 hunks)
  • smsgateway/client_test.go (8 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
smsgateway/client.go (5)
smsgateway/domain_messages.go (2)
  • Message (54-85)
  • MessageState (139-154)
smsgateway/domain_devices.go (1)
  • Device (6-14)
smsgateway/requests.go (1)
  • MessagesExportRequest (9-16)
smsgateway/domain_logs.go (1)
  • LogEntry (15-28)
smsgateway/domain_settings.go (1)
  • DeviceSettings (33-48)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (8)
smsgateway/client.go (6)

9-9: Good additions for the new functionality.

The time import is properly utilized by the new methods, and defining settingsPath as a constant follows the DRY principle.

Also applies to: 16-16


31-53: Excellent security improvement and API consistency.

The updated paths follow RESTful conventions with plural resource names, and the use of url.PathEscape for the messageID prevents path injection vulnerabilities.


55-76: Well-implemented device management methods.

Both methods follow REST conventions and properly handle path parameters with URL escaping for security.


78-99: LGTM!

Standard implementations for health check and inbox export functionality.


117-151: Excellent implementation of settings management.

The methods correctly distinguish between partial updates (PATCH) and full replacement (PUT), following REST best practices.


153-154: Improved documentation clarity.

The updated comments better describe the webhook methods' behavior and return values.

Also applies to: 166-167, 179-180

smsgateway/client_test.go (2)

15-80: Excellent test infrastructure setup.

The mock server implementation provides comprehensive request validation, and the helper functions improve test maintainability.


82-785: Comprehensive test coverage.

The test suite thoroughly covers all client methods with both success and error scenarios using table-driven tests.

Comment thread smsgateway/client_test.go
Comment thread smsgateway/client_test.go Outdated
Comment thread smsgateway/client_test.go Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
smsgateway/client_test.go (1)

818-818: Fix copy-paste error in error message.

The error message incorrectly references Client.UpdateSettings() instead of Client.ReplaceSettings().

-				t.Errorf("Client.UpdateSettings() error = %v, wantErr %v", err, tt.wantErr)
+				t.Errorf("Client.ReplaceSettings() error = %v, wantErr %v", err, tt.wantErr)
🧹 Nitpick comments (2)
smsgateway/requests_3rdparty_test.go (1)

87-150: Consider consolidating duplicate test functions.

The TestSendOptionFunctions test appears to duplicate the functionality already covered by TestSendOptions_ToURLValues. Both tests verify the same behavior: applying options and converting to URL values.

Consider consolidating these into a single comprehensive test function to reduce duplication and improve maintainability.

-func TestSendOptionFunctions(t *testing.T) {
-	tests := []struct {
-		name     string
-		options  []smsgateway.SendOption
-		expected url.Values
-	}{
-		// ... duplicate test cases ...
-	}
-	// ... duplicate test logic ...
-}
smsgateway/client_test.go (1)

82-82: Remove unnecessary leading newline.

Static analysis and pipeline failures indicate an unnecessary leading newline that should be removed.

-func TestClient_Send(t *testing.T) {
-
+func TestClient_Send(t *testing.T) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9922525 and bef21ca.

📒 Files selected for processing (4)
  • smsgateway/client.go (6 hunks)
  • smsgateway/client_test.go (7 hunks)
  • smsgateway/requests_3rdparty.go (1 hunks)
  • smsgateway/requests_3rdparty_test.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
smsgateway/requests_3rdparty_test.go (1)
smsgateway/requests_3rdparty.go (4)
  • SendOption (8-8)
  • WithSkipPhoneValidation (38-42)
  • WithDeviceActiveWithin (46-50)
  • SendOptions (10-13)
🪛 GitHub Check: Lint
smsgateway/client_test.go

[failure] 82-82:
unnecessary leading newline (whitespace)

🪛 GitHub Actions: Go
smsgateway/client_test.go

[error] 82-82: golangci-lint: unnecessary leading newline (whitespace)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (7)
smsgateway/requests_3rdparty.go (1)

1-51: Excellent implementation of functional options pattern.

This is a clean, idiomatic Go implementation of the functional options pattern that follows best practices:

  • Uses pointer fields to distinguish between unset and zero values
  • Provides fluent API with the Apply method
  • Only includes set options in URL query parameters
  • Constructor functions create appropriate closures

The code is well-structured and will provide flexibility for SMS sending options.

smsgateway/client.go (3)

31-42: Well-implemented options pattern integration.

The Send method correctly integrates the functional options pattern by:

  • Accepting variadic SendOption parameters
  • Applying options using the Apply method
  • Converting options to URL query parameters
  • Maintaining backwards compatibility

The implementation is clean and follows Go best practices.


44-54: Correct endpoint path fix.

The path correction from "/message/{id}" to "/messages/{id}" aligns with REST conventions and the endpoint documented in the AI summary. The URL path escaping prevents potential injection issues.


56-151: Comprehensive API expansion with consistent patterns.

The new client methods follow excellent patterns:

  • Consistent error handling with wrapped errors
  • Proper URL path escaping for dynamic segments
  • Appropriate HTTP methods for each operation
  • Clear method documentation
  • Logical parameter handling (e.g., time formatting in GetLogs)

The API surface is now much more comprehensive while maintaining consistency.

smsgateway/client_test.go (3)

21-80: Excellent test infrastructure improvements.

The introduction of newMockServer and newClient helper functions significantly improves the test suite by:

  • Providing reusable mock server setup with comprehensive validation
  • Standardizing request validation (method, path, query, headers, body)
  • Reducing code duplication across tests
  • Making tests more maintainable and readable

This is a substantial improvement to the test infrastructure.


82-221: Comprehensive Send method testing with options support.

The TestClient_Send test now properly validates:

  • Various send options combinations
  • Correct query parameter generation
  • Request body JSON structure
  • Error handling scenarios

The test cases cover all the new functionality introduced by the options pattern.


434-826: Thorough test coverage for all new client methods.

The test suite now provides comprehensive coverage for all new client methods:

  • Device management (ListDevices, DeleteDevice)
  • Health checks (CheckHealth)
  • Inbox operations (ExportInbox)
  • Logging (GetLogs)
  • Settings management (GetSettings, UpdateSettings, ReplaceSettings)

Each test appropriately validates request parameters, response parsing, and error handling.

@capcom6 capcom6 force-pushed the client/add-new-methods branch from 99e16e3 to cce3fa0 Compare July 9, 2025 23:18
@capcom6 capcom6 merged commit d2923fb into master Jul 10, 2025
7 checks passed
@capcom6 capcom6 deleted the client/add-new-methods branch July 10, 2025 03:21
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