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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0"
".": "0.2.0"
}
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ Metrics/BlockLength:
Metrics/ClassLength:
Enabled: false

Metrics/CollectionLiteralLength:
Exclude:
- "test/**/*"

Metrics/CyclomaticComplexity:
Enabled: false

Expand Down
6 changes: 3 additions & 3 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 16
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/surge%2Fsurge-f593640d38b503dfa2f7018efe014d446c67a5b66e523155cb0643cc9079564b.yml
openapi_spec_hash: b567da489f6e30c4ad893e9c5a9b7399
config_hash: d9682af69d6ed28eac51eb95929790b6
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/surge%2Fsurge-6d6362cb88f011e556ebcc100851d12736654094d351bc5b402ea1cc05eeedbc.yml
openapi_spec_hash: 93e79d53e56fdf12b8287a5048f2c0aa
config_hash: 2005008b28252768774740897c65d562
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Changelog

## 0.2.0 (2025-10-09)

Full Changelog: [v0.1.0...v0.2.0](https://github.com/surgeapi/ruby-sdk/compare/v0.1.0...v0.2.0)

### Features

* **api:** api update ([8a7eeeb](https://github.com/surgeapi/ruby-sdk/commit/8a7eeeb4c5248d0f0aa4da399c45d2763b98ba3b))


### Bug Fixes

* always send `filename=...` for multipart requests where a file is expected ([28bdedf](https://github.com/surgeapi/ruby-sdk/commit/28bdedfba8e9bef43abf39e08169bc2bf2edb0e8))
* coroutine leaks from connection pool ([239043f](https://github.com/surgeapi/ruby-sdk/commit/239043f74e12856fb8e6b2a477ea9bf35945f2f2))


### Chores

* ignore linter error for tests having large collections ([4d89802](https://github.com/surgeapi/ruby-sdk/commit/4d898024ffae04e4f24591b1c54a922e1b6c51f4))

## 0.1.0 (2025-09-26)

Full Changelog: [v0.0.1...v0.1.0](https://github.com/surgeapi/ruby-sdk/compare/v0.0.1...v0.1.0)
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GIT
PATH
remote: .
specs:
surge_api (0.1.0)
surge_api (0.2.0)
connection_pool

GEM
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ To use this gem, install via Bundler by adding the following to your application
<!-- x-release-please-start-version -->

```ruby
gem "surge_api", "~> 0.1.0"
gem "surge_api", "~> 0.2.0"
```

<!-- x-release-please-end -->
Expand Down
2 changes: 2 additions & 0 deletions lib/surge_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
require_relative "surge_api/models/campaign_create_params"
require_relative "surge_api/models/contact"
require_relative "surge_api/models/contact_create_params"
require_relative "surge_api/models/contact_opted_in_webhook_event"
require_relative "surge_api/models/contact_opted_out_webhook_event"
require_relative "surge_api/models/contact_retrieve_params"
require_relative "surge_api/models/contact_update_params"
require_relative "surge_api/models/conversation_created_webhook_event"
Expand Down
17 changes: 10 additions & 7 deletions lib/surge_api/file_part.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,21 @@ def to_json(*a) = read.to_json(*a)
def to_yaml(*a) = read.to_yaml(*a)

# @param content [Pathname, StringIO, IO, String]
# @param filename [String, nil]
# @param filename [Pathname, String, nil]
# @param content_type [String, nil]
def initialize(content, filename: nil, content_type: nil)
@content = content
@content_type = content_type
@filename =
case content
in Pathname
filename.nil? ? content.basename.to_path : ::File.basename(filename)
case [filename, (@content = content)]
in [String | Pathname, _]
::File.basename(filename)
in [nil, Pathname]
content.basename.to_path
in [nil, IO]
content.to_path
else
filename.nil? ? nil : ::File.basename(filename)
filename
end
@content_type = content_type
end
end
end
17 changes: 7 additions & 10 deletions lib/surge_api/internal/transport/pooled_net_requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ def execute(request)

# rubocop:disable Metrics/BlockLength
enum = Enumerator.new do |y|
with_pool(url, deadline: deadline) do |conn|
next if finished
next if finished

with_pool(url, deadline: deadline) do |conn|
req, closing = self.class.build_request(request) do
self.class.calibrate_socket_timeout(conn, deadline)
end
Expand All @@ -149,7 +149,7 @@ def execute(request)

self.class.calibrate_socket_timeout(conn, deadline)
conn.request(req) do |rsp|
y << [conn, req, rsp]
y << [req, rsp]
break if finished

rsp.read_body do |bytes|
Expand All @@ -160,6 +160,8 @@ def execute(request)
end
eof = true
end
ensure
conn.finish if !eof && conn&.started?
end
rescue Timeout::Error
raise SurgeAPI::Errors::APITimeoutError.new(url: url, request: req)
Expand All @@ -168,16 +170,11 @@ def execute(request)
end
# rubocop:enable Metrics/BlockLength

conn, _, response = enum.next
_, response = enum.next
body = SurgeAPI::Internal::Util.fused_enum(enum, external: true) do
finished = true
tap do
enum.next
rescue StopIteration
nil
end
loop { enum.next }
ensure
conn.finish if !eof && conn&.started?
closing&.call
end
[Integer(response.code), response, body]
Expand Down
11 changes: 7 additions & 4 deletions lib/surge_api/internal/type/file_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,20 @@ def coerce(value, state:)
#
# @return [Pathname, StringIO, IO, String, Object]
def dump(value, state:)
# rubocop:disable Lint/DuplicateBranch
case value
in StringIO | String
# https://datatracker.ietf.org/doc/html/rfc7578#section-4.2
# while not required, a filename is recommended, and in practice many servers do expect this
SurgeAPI::FilePart.new(value, filename: "upload")
in IO
state[:can_retry] = false
value.to_path.nil? ? SurgeAPI::FilePart.new(value, filename: "upload") : value
in SurgeAPI::FilePart if value.content.is_a?(IO)
state[:can_retry] = false
value
else
value
end
# rubocop:enable Lint/DuplicateBranch

value
end

# @api private
Expand Down
2 changes: 1 addition & 1 deletion lib/surge_api/internal/type/union.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Type
# puts(unwrap_webhook_event.account_id)
# when SurgeAPI::CampaignApprovedWebhookEvent
# puts(unwrap_webhook_event.data)
# when SurgeAPI::ConversationCreatedWebhookEvent
# when SurgeAPI::ContactOptedInWebhookEvent
# puts(unwrap_webhook_event.timestamp)
# else
# puts(unwrap_webhook_event)
Expand Down
4 changes: 4 additions & 0 deletions lib/surge_api/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ module SurgeAPI

ContactCreateParams = SurgeAPI::Models::ContactCreateParams

ContactOptedInWebhookEvent = SurgeAPI::Models::ContactOptedInWebhookEvent

ContactOptedOutWebhookEvent = SurgeAPI::Models::ContactOptedOutWebhookEvent

ContactRetrieveParams = SurgeAPI::Models::ContactRetrieveParams

ContactUpdateParams = SurgeAPI::Models::ContactUpdateParams
Expand Down
54 changes: 54 additions & 0 deletions lib/surge_api/models/contact_opted_in_webhook_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

module SurgeAPI
module Models
class ContactOptedInWebhookEvent < SurgeAPI::Internal::Type::BaseModel
# @!attribute account_id
# The ID of the account in which this event occurred
#
# @return [String]
required :account_id, String

# @!attribute data
# The data associated with the event
#
# @return [SurgeAPI::Models::ContactOptedInWebhookEvent::Data]
required :data, -> { SurgeAPI::ContactOptedInWebhookEvent::Data }

# @!attribute timestamp
# The timestamp when this event occurred, in ISO8601 format
#
# @return [Time]
required :timestamp, Time

# @!attribute type
# The type of the event. Always `contact.opted_in` for this event.
#
# @return [Symbol, :"contact.opted_in"]
required :type, const: :"contact.opted_in"

# @!method initialize(account_id:, data:, timestamp:, type: :"contact.opted_in")
# @param account_id [String] The ID of the account in which this event occurred
#
# @param data [SurgeAPI::Models::ContactOptedInWebhookEvent::Data] The data associated with the event
#
# @param timestamp [Time] The timestamp when this event occurred, in ISO8601 format
#
# @param type [Symbol, :"contact.opted_in"] The type of the event. Always `contact.opted_in` for this event.

# @see SurgeAPI::Models::ContactOptedInWebhookEvent#data
class Data < SurgeAPI::Internal::Type::BaseModel
# @!attribute id
# The unique identifier for the contact
#
# @return [String]
required :id, String

# @!method initialize(id:)
# The data associated with the event
#
# @param id [String] The unique identifier for the contact
end
end
end
end
54 changes: 54 additions & 0 deletions lib/surge_api/models/contact_opted_out_webhook_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

module SurgeAPI
module Models
class ContactOptedOutWebhookEvent < SurgeAPI::Internal::Type::BaseModel
# @!attribute account_id
# The ID of the account in which this event occurred
#
# @return [String]
required :account_id, String

# @!attribute data
# The data associated with the event
#
# @return [SurgeAPI::Models::ContactOptedOutWebhookEvent::Data]
required :data, -> { SurgeAPI::ContactOptedOutWebhookEvent::Data }

# @!attribute timestamp
# The timestamp when this event occurred, in ISO8601 format
#
# @return [Time]
required :timestamp, Time

# @!attribute type
# The type of the event. Always `contact.opted_out` for this event.
#
# @return [Symbol, :"contact.opted_out"]
required :type, const: :"contact.opted_out"

# @!method initialize(account_id:, data:, timestamp:, type: :"contact.opted_out")
# @param account_id [String] The ID of the account in which this event occurred
#
# @param data [SurgeAPI::Models::ContactOptedOutWebhookEvent::Data] The data associated with the event
#
# @param timestamp [Time] The timestamp when this event occurred, in ISO8601 format
#
# @param type [Symbol, :"contact.opted_out"] The type of the event. Always `contact.opted_out` for this event.

# @see SurgeAPI::Models::ContactOptedOutWebhookEvent#data
class Data < SurgeAPI::Internal::Type::BaseModel
# @!attribute id
# The unique identifier for the contact
#
# @return [String]
required :id, String

# @!method initialize(id:)
# The data associated with the event
#
# @param id [String] The unique identifier for the contact
end
end
end
end
6 changes: 5 additions & 1 deletion lib/surge_api/models/unwrap_webhook_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ module UnwrapWebhookEvent

variant -> { SurgeAPI::CampaignApprovedWebhookEvent }

variant -> { SurgeAPI::ContactOptedInWebhookEvent }

variant -> { SurgeAPI::ContactOptedOutWebhookEvent }

variant -> { SurgeAPI::ConversationCreatedWebhookEvent }

variant -> { SurgeAPI::MessageDeliveredWebhookEvent }
Expand All @@ -20,7 +24,7 @@ module UnwrapWebhookEvent
variant -> { SurgeAPI::MessageSentWebhookEvent }

# @!method self.variants
# @return [Array(SurgeAPI::Models::CallEndedWebhookEvent, SurgeAPI::Models::CampaignApprovedWebhookEvent, SurgeAPI::Models::ConversationCreatedWebhookEvent, SurgeAPI::Models::MessageDeliveredWebhookEvent, SurgeAPI::Models::MessageFailedWebhookEvent, SurgeAPI::Models::MessageReceivedWebhookEvent, SurgeAPI::Models::MessageSentWebhookEvent)]
# @return [Array(SurgeAPI::Models::CallEndedWebhookEvent, SurgeAPI::Models::CampaignApprovedWebhookEvent, SurgeAPI::Models::ContactOptedInWebhookEvent, SurgeAPI::Models::ContactOptedOutWebhookEvent, SurgeAPI::Models::ConversationCreatedWebhookEvent, SurgeAPI::Models::MessageDeliveredWebhookEvent, SurgeAPI::Models::MessageFailedWebhookEvent, SurgeAPI::Models::MessageReceivedWebhookEvent, SurgeAPI::Models::MessageSentWebhookEvent)]
end
end
end
2 changes: 1 addition & 1 deletion lib/surge_api/resources/webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Resources
class Webhooks
# @param payload [String] The raw webhook payload as a string
#
# @return [SurgeAPI::Models::CallEndedWebhookEvent, SurgeAPI::Models::CampaignApprovedWebhookEvent, SurgeAPI::Models::ConversationCreatedWebhookEvent, SurgeAPI::Models::MessageDeliveredWebhookEvent, SurgeAPI::Models::MessageFailedWebhookEvent, SurgeAPI::Models::MessageReceivedWebhookEvent, SurgeAPI::Models::MessageSentWebhookEvent]
# @return [SurgeAPI::Models::CallEndedWebhookEvent, SurgeAPI::Models::CampaignApprovedWebhookEvent, SurgeAPI::Models::ContactOptedInWebhookEvent, SurgeAPI::Models::ContactOptedOutWebhookEvent, SurgeAPI::Models::ConversationCreatedWebhookEvent, SurgeAPI::Models::MessageDeliveredWebhookEvent, SurgeAPI::Models::MessageFailedWebhookEvent, SurgeAPI::Models::MessageReceivedWebhookEvent, SurgeAPI::Models::MessageSentWebhookEvent]
def unwrap(payload)
parsed = JSON.parse(payload, symbolize_names: true)
SurgeAPI::Internal::Type::Converter.coerce(SurgeAPI::Models::UnwrapWebhookEvent, parsed)
Expand Down
2 changes: 1 addition & 1 deletion lib/surge_api/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SurgeAPI
VERSION = "0.1.0"
VERSION = "0.2.0"
end
2 changes: 1 addition & 1 deletion rbi/surge_api/file_part.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module SurgeAPI
sig do
params(
content: T.any(Pathname, StringIO, IO, String),
filename: T.nilable(String),
filename: T.nilable(T.any(Pathname, String)),
content_type: T.nilable(String)
).returns(T.attached_class)
end
Expand Down
4 changes: 4 additions & 0 deletions rbi/surge_api/models.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ module SurgeAPI

ContactCreateParams = SurgeAPI::Models::ContactCreateParams

ContactOptedInWebhookEvent = SurgeAPI::Models::ContactOptedInWebhookEvent

ContactOptedOutWebhookEvent = SurgeAPI::Models::ContactOptedOutWebhookEvent

ContactRetrieveParams = SurgeAPI::Models::ContactRetrieveParams

ContactUpdateParams = SurgeAPI::Models::ContactUpdateParams
Expand Down
Loading