unisender-ruby 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +89 -0
  3. data/CONTRIBUTING.md +10 -1
  4. data/README.md +55 -112
  5. data/docs/api.md +395 -210
  6. data/docs/execution.md +89 -0
  7. data/docs/import-recovery.md +41 -0
  8. data/docs/live-contracts.md +34 -0
  9. data/docs/migration-0.2.md +129 -0
  10. data/docs/rails.md +248 -0
  11. data/docs/releases.md +4 -4
  12. data/docs/testing.md +83 -0
  13. data/docs/usage.md +144 -0
  14. data/docs/webhooks.md +41 -0
  15. data/examples/campaign.rb +5 -6
  16. data/examples/campaign_lifecycle.rb +28 -0
  17. data/examples/check_connection.rb +1 -1
  18. data/examples/events.rb +1 -1
  19. data/examples/export.rb +20 -6
  20. data/examples/import.rb +3 -2
  21. data/examples/import_recovery.rb +70 -0
  22. data/examples/quickstart.rb +1 -1
  23. data/examples/subscribe.rb +2 -2
  24. data/lib/unisender/acceptance.rb +104 -0
  25. data/lib/unisender/attachment.rb +47 -0
  26. data/lib/unisender/batch_report.rb +115 -0
  27. data/lib/unisender/batch_summary.rb +87 -0
  28. data/lib/unisender/batches.rb +41 -12
  29. data/lib/unisender/campaign_workflow.rb +72 -0
  30. data/lib/unisender/client.rb +65 -33
  31. data/lib/unisender/client_configuration.rb +50 -0
  32. data/lib/unisender/client_execution.rb +43 -0
  33. data/lib/unisender/client_state.rb +31 -0
  34. data/lib/unisender/client_validation.rb +97 -0
  35. data/lib/unisender/configuration.rb +151 -0
  36. data/lib/unisender/contact_records.rb +251 -0
  37. data/lib/unisender/diagnostic_urls.rb +68 -0
  38. data/lib/unisender/diagnostics.rb +83 -0
  39. data/lib/unisender/download_target.rb +61 -0
  40. data/lib/unisender/download_transfer.rb +43 -0
  41. data/lib/unisender/downloader.rb +99 -0
  42. data/lib/unisender/error_diagnostics.rb +83 -0
  43. data/lib/unisender/errors.rb +125 -8
  44. data/lib/unisender/event_batches.rb +40 -0
  45. data/lib/unisender/event_payload.rb +50 -22
  46. data/lib/unisender/events.rb +21 -5
  47. data/lib/unisender/execution_context.rb +114 -0
  48. data/lib/unisender/form.rb +20 -12
  49. data/lib/unisender/helpers.rb +70 -10
  50. data/lib/unisender/hooks.rb +79 -0
  51. data/lib/unisender/import_cells.rb +62 -0
  52. data/lib/unisender/input_types.rb +30 -0
  53. data/lib/unisender/inputs.rb +262 -0
  54. data/lib/unisender/iteration.rb +15 -0
  55. data/lib/unisender/iterators.rb +60 -0
  56. data/lib/unisender/mail_inputs.rb +37 -0
  57. data/lib/unisender/named_inputs.rb +52 -0
  58. data/lib/unisender/observation.rb +30 -0
  59. data/lib/unisender/operation_contracts.rb +106 -0
  60. data/lib/unisender/operations/contacts_1.rb +4 -3
  61. data/lib/unisender/operations/contacts_2.rb +23 -4
  62. data/lib/unisender/operations/messages_1.rb +7 -4
  63. data/lib/unisender/operations/messages_2.rb +8 -3
  64. data/lib/unisender/operations/messages_3.rb +1 -1
  65. data/lib/unisender/operations/notes_1.rb +1 -1
  66. data/lib/unisender/operations/statistics_1.rb +3 -3
  67. data/lib/unisender/operations/templates_1.rb +2 -2
  68. data/lib/unisender/outcomes.rb +320 -0
  69. data/lib/unisender/page_response.rb +48 -0
  70. data/lib/unisender/paginated_operations.rb +43 -2
  71. data/lib/unisender/pagination.rb +53 -20
  72. data/lib/unisender/persistent_transport.rb +104 -0
  73. data/lib/unisender/rate_limiter.rb +72 -0
  74. data/lib/unisender/record.rb +210 -0
  75. data/lib/unisender/record_rows.rb +69 -0
  76. data/lib/unisender/records.rb +614 -0
  77. data/lib/unisender/request_execution.rb +108 -0
  78. data/lib/unisender/response.rb +13 -10
  79. data/lib/unisender/result_registry.rb +72 -0
  80. data/lib/unisender/results.rb +105 -0
  81. data/lib/unisender/retry_policy.rb +10 -16
  82. data/lib/unisender/serialization.rb +54 -0
  83. data/lib/unisender/statistic_records.rb +129 -0
  84. data/lib/unisender/task_response.rb +85 -0
  85. data/lib/unisender/task_waiter.rb +25 -11
  86. data/lib/unisender/testing/assertions.rb +48 -0
  87. data/lib/unisender/testing/fixtures.rb +24 -0
  88. data/lib/unisender/testing.rb +91 -0
  89. data/lib/unisender/transport.rb +17 -9
  90. data/lib/unisender/validation.rb +11 -9
  91. data/lib/unisender/version.rb +1 -1
  92. data/lib/unisender/webhooks/tokens.rb +38 -0
  93. data/lib/unisender/webhooks.rb +230 -0
  94. data/lib/unisender.rb +42 -0
  95. data/sig/acceptance.rbs +30 -0
  96. data/sig/attachment.rbs +15 -0
  97. data/sig/batch_summary.rbs +38 -0
  98. data/sig/campaign_workflow.rbs +20 -0
  99. data/sig/configuration.rbs +62 -0
  100. data/sig/connection_controls.rbs +55 -0
  101. data/sig/diagnostics.rbs +37 -0
  102. data/sig/domain_records.rbs +96 -0
  103. data/sig/downloads.rbs +53 -0
  104. data/sig/execution.rbs +52 -0
  105. data/sig/execution_context.rbs +46 -0
  106. data/sig/hooks.rbs +18 -0
  107. data/sig/inputs.rbs +84 -0
  108. data/sig/iterators.rbs +11 -0
  109. data/sig/mail_inputs.rbs +8 -0
  110. data/sig/manifest.yaml +11 -0
  111. data/sig/operation_contracts.rbs +28 -0
  112. data/sig/operations.rbs +73 -69
  113. data/sig/outcomes.rbs +90 -0
  114. data/sig/record.rbs +77 -0
  115. data/sig/records.rbs +182 -0
  116. data/sig/serialization.rbs +13 -0
  117. data/sig/tasks.rbs +26 -0
  118. data/sig/testing.rbs +54 -0
  119. data/sig/unisender.rbs +128 -39
  120. data/sig/webhooks.rbs +55 -0
  121. metadata +84 -3
@@ -0,0 +1,62 @@
1
+ module Unisender
2
+ class Client
3
+ USER_AGENT: String
4
+ end
5
+ type config_value = bool | RateLimiter | String | Symbol | duration | _Transport | RetryPolicy | Hash[String | Symbol, String?] | Hash[Symbol, String] | (^(RequestEvent) -> void) | (^(AcceptanceEvent) -> void) | nil
6
+
7
+ interface _Environment
8
+ def []: (String) -> String?
9
+ end
10
+
11
+ class RequestEvent < Data
12
+ attr_reader operation: String
13
+ attr_reader attempt: Integer
14
+ attr_reader duration: Float
15
+ attr_reader http_status: Integer?
16
+ attr_reader outcome: Symbol
17
+ attr_reader error_category: Symbol?
18
+ attr_reader request_id: String?
19
+ def self.new: (operation: String, attempt: Integer, duration: Float, http_status: Integer?, outcome: Symbol, error_category: Symbol?, request_id: String?) -> RequestEvent
20
+ end
21
+
22
+ module Observation
23
+ def self.emit: ((^(RequestEvent) -> void)?, RequestEvent) -> void
24
+ def self.event: (String, Integer, Float, HTTPResponse?, Exception?) -> RequestEvent
25
+ def self.category: (Exception?) -> Symbol?
26
+ end
27
+ class Configuration
28
+ DEFAULT_KEYS: Array[Symbol]
29
+ TIMEOUT_KEYS: Array[Symbol]
30
+ RETRY_KEYS: Array[Symbol]
31
+ @state: ClientState
32
+ @owns_transport: bool
33
+ attr_reader rate_limiter: RateLimiter?
34
+ attr_reader event_rate_limiter: RateLimiter?
35
+ attr_reader acceptance_instrumentation: (^(AcceptanceEvent) -> void)?
36
+ def close: () -> void
37
+ def check_open!: () -> void
38
+ @options: Hash[Symbol, config_value]
39
+ attr_reader api_key: String
40
+ attr_reader language: String
41
+ attr_reader transport: _Transport
42
+ attr_reader retry_policy: RetryPolicy
43
+ attr_reader message_defaults: Hash[Symbol, String]
44
+ attr_reader instrumentation: (^(RequestEvent) -> void)?
45
+ def initialize: (api_key: String, ?language: String | Symbol, ?transport: _Transport?, ?retry_policy: RetryPolicy?, ?open_timeout: duration?, ?read_timeout: duration?, ?write_timeout: duration?, ?max_retries: Integer?, ?max_elapsed: duration?, ?message_defaults: Hash[String | Symbol, String?], ?instrumentation: (^(RequestEvent) -> void)?, ?persistent: bool, ?rate_limiter: RateLimiter?, ?event_rate_limiter: RateLimiter?, ?acceptance_instrumentation: (^(AcceptanceEvent) -> void)?) -> void
46
+ def merge_defaults: (Hash[Symbol, config_value], Hash[Symbol, config_value]) -> void
47
+ def options_for: (Hash[Symbol, config_value]) -> Hash[Symbol, config_value]
48
+ def inspect: () -> String
49
+ private
50
+ def initialize_resources: (RateLimiter?, _Transport?, RateLimiter?, (^(AcceptanceEvent) -> void)?) -> void
51
+ def validate_default_keys: (Hash[String | Symbol, String?]) -> void
52
+ def timeout_options: (duration?, duration?, duration?) -> Hash[Symbol, duration]
53
+ def clear_alternative: (Hash[Symbol, config_value], Hash[Symbol, config_value], Symbol, Array[Symbol]) -> void
54
+ def credentials: (String, String | Symbol) -> [String, String]
55
+ def build_transport: (_Transport?, duration?, duration?, duration?, bool) -> _Transport
56
+ def build_retry: (RetryPolicy?, Integer?, duration?) -> RetryPolicy
57
+ def default_value: (String?) -> String?
58
+ def validate_conflicts: (_Transport | RetryPolicy | nil, Array[duration?]) -> void
59
+ def defaults: (Hash[String | Symbol, String?]) -> Hash[Symbol, String]
60
+ def normalize_defaults: (Hash[String | Symbol, String?]) -> Hash[Symbol, String?]
61
+ end
62
+ end
@@ -0,0 +1,55 @@
1
+ module Unisender
2
+ class ClientClosedError < Error
3
+ end
4
+ class ClientState
5
+ @closed: bool
6
+ @mutex: Mutex
7
+ def initialize: () -> void
8
+ def check_open!: () -> void
9
+ def close: () { () -> void } -> void
10
+ end
11
+
12
+ class RateLimiter
13
+ DEFAULT_METHODS: Hash[String, [Integer, duration]]
14
+ @limits: Hash[String, [Integer, Float]]
15
+ @history: Hash[String, Array[Float]]
16
+ @clock: ^() -> Float
17
+ @sleeper: ^(Float) -> void
18
+ @mutex: Mutex
19
+ def self.unisender: (?clock: ( ^() -> Float)?, ?sleeper: ( ^(Float) -> void)?) -> RateLimiter
20
+ def initialize: (global: [Integer, duration], ?methods: Hash[String, [Integer, duration]], ?clock: ( ^() -> Float)?, ?sleeper: ( ^(Float) -> void)?) -> void
21
+ def acquire: (String, ?execution: ExecutionContext?) -> void
22
+ def inspect: () -> String
23
+ private
24
+ def validate: ([Integer, duration]) -> [Integer, Float]
25
+ def reserve: (String) -> Float
26
+ def delay_for: (String, Float) -> Float
27
+ end
28
+
29
+ class PersistentTransport < Transport
30
+ class Connection < Data
31
+ attr_reader http: Net::HTTP
32
+ attr_reader used_at: Float
33
+ def self.new: (http: Net::HTTP, used_at: Float) -> Connection
34
+ end
35
+ HOSTS: Array[String]
36
+ @idle_timeout: duration
37
+ @clock: ^() -> Float
38
+ @pid_source: ^() -> Integer
39
+ @pid: Integer
40
+ @connections: Hash[String, Connection]
41
+ @mutex: Mutex
42
+ @closed: bool
43
+ def initialize: (?idle_timeout: duration, ?clock: ( ^() -> Float)?, ?pid: ( ^() -> Integer)?, ?open_timeout: duration, ?read_timeout: duration, ?write_timeout: duration, ?http_factory: (^(URI::Generic) -> Net::HTTP)?) -> void
44
+ def close: () -> void
45
+ def initialize_pool: (( ^() -> Float)?, ( ^() -> Integer)?) -> void
46
+ def inspect: () -> String
47
+ private
48
+ def send_request: (String, URI::Generic, Net::HTTPRequest, ExecutionContext?) -> Net::HTTPResponse
49
+ def perform: (URI::Generic, Net::HTTPRequest, execution: ExecutionContext?) -> Net::HTTPResponse
50
+ def origin: (URI::Generic) -> String
51
+ def connection: (String, URI::Generic, ExecutionContext?) -> Net::HTTP
52
+ def discard: (String) -> void
53
+ def reset_after_fork: () -> void
54
+ end
55
+ end
@@ -0,0 +1,37 @@
1
+ module Unisender
2
+ module Diagnostics
3
+ TYPES: Hash[Module, String]
4
+ FIELDS: Array[String]
5
+ URLS: Hash[String, String]
6
+ def self.type_name: (parameter | value) -> String
7
+ def self.input_path: (String) -> String
8
+ def self.path_segment: (String) -> String
9
+ def self.for_error: (Error | ValidationError) -> Hash[Symbol, json]
10
+ def self.error_fields: (Error) -> Hash[Symbol, json]
11
+ def self.common_fields: (Error | ValidationError) -> Hash[Symbol, json]
12
+ def self.validation_fields: (ValidationError) -> Hash[Symbol, json]
13
+ def self.context_fields: (Error) -> Hash[Symbol, json]
14
+ def self.batch_fields: (BatchError) -> Hash[Symbol, json]
15
+ def self.underlying: (Error) -> (Error | ValidationError)?
16
+ end
17
+ class Error
18
+ @context_http_status: Integer?
19
+ @context_request_id: String?
20
+ def diagnostics: () -> Hash[Symbol, json]
21
+ def documentation_url: () -> String?
22
+ def with_http: (status: Integer?, request_id: String?) -> self
23
+ def http_status: () -> Integer?
24
+ def diagnostic_response: () -> Response?
25
+ end
26
+ class APIError
27
+ def safe_code: () -> String?
28
+ end
29
+ class InvalidResponseError
30
+ attr_reader path: String?
31
+ attr_reader expected_type: String?
32
+ attr_reader actual_type: String?
33
+ def initialize: (?String, ?path: String?, ?expected_type: String?, ?actual_type: String?) -> void
34
+ def prepend_path: (String) -> self
35
+ def to_s: () -> String
36
+ end
37
+ end
@@ -0,0 +1,96 @@
1
+ module Unisender
2
+ class EmailContact < Record
3
+ def email: () -> String
4
+ def status: () -> String?
5
+ def availability: () -> String?
6
+ def added_at: () -> String?
7
+ def last_send_datetime: () -> String?
8
+ def last_delivery_datetime: () -> String?
9
+ def last_read_datetime: () -> String?
10
+ def last_click_datetime: () -> String?
11
+ def rating: () -> (Integer | Float)?
12
+ def normalize: () -> void
13
+ end
14
+ class PhoneContact < Record
15
+ def phone: () -> String
16
+ def status: () -> String?
17
+ def availability: () -> String?
18
+ def added_at: () -> String?
19
+ def normalize: () -> void
20
+ end
21
+ class ContactList < IdentifierRecord
22
+ def status: () -> String?
23
+ def added_at: () -> String?
24
+ def normalize: () -> void
25
+ end
26
+ class Contact < Record
27
+ def email: () -> (EmailContact | String)?
28
+ def email_address: () -> String?
29
+ def phone: () -> (PhoneContact | String)?
30
+ def phone_number: () -> String?
31
+ def lists: () -> Array[ContactList]?
32
+ def fields: () -> Record?
33
+ def normalize: () -> void
34
+ end
35
+ class ContactResponse < ObjectResponse[Contact]
36
+ def email: () -> (EmailContact | String)?
37
+ def email_address: () -> String?
38
+ def phone: () -> (PhoneContact | String)?
39
+ def phone_number: () -> String?
40
+ def lists: () -> Array[ContactList]?
41
+ def fields: () -> Record?
42
+ end
43
+ class SenderDomain < Record
44
+ def domain: () -> String
45
+ def status: () -> String?
46
+ def key: () -> String?
47
+ def normalize: () -> void
48
+ end
49
+ class SenderDomainGroup < Record
50
+ def status: () -> String?
51
+ def domains: () -> Array[SenderDomain]
52
+ def normalize: () -> void
53
+ end
54
+ class ContactFields < Record
55
+ def field_values: () -> Record
56
+ def normalize: () -> void
57
+ end
58
+ class ContactFieldsResponse < ObjectResponse[ContactFields]
59
+ def field_values: () -> Record
60
+ end
61
+ class CampaignStats < Record
62
+ COUNTERS: Array[String]
63
+ def total: () -> Integer?
64
+ def sent: () -> Integer?
65
+ def delivered: () -> Integer?
66
+ def read_unique: () -> Integer?
67
+ def read_all: () -> Integer?
68
+ def clicked_unique: () -> Integer?
69
+ def clicked_all: () -> Integer?
70
+ def unsubscribed: () -> Integer?
71
+ def spam: () -> Integer?
72
+ def normalize: () -> void
73
+ end
74
+ class CampaignStatsResponse < ObjectResponse[CampaignStats]
75
+ def total: () -> Integer?
76
+ def sent: () -> Integer?
77
+ def delivered: () -> Integer?
78
+ def read_unique: () -> Integer?
79
+ def read_all: () -> Integer?
80
+ def clicked_unique: () -> Integer?
81
+ def clicked_all: () -> Integer?
82
+ def unsubscribed: () -> Integer?
83
+ def spam: () -> Integer?
84
+ end
85
+ class SmsReceipt < Record
86
+ def sms_id: () -> id
87
+ def price: () -> (Integer | Float)?
88
+ def currency: () -> String?
89
+ def normalize: () -> void
90
+ end
91
+ class EmailDelivery < Record
92
+ def id: () -> id?
93
+ def status: () -> String?
94
+ def normalize: () -> void
95
+ end
96
+ end
data/sig/downloads.rbs ADDED
@@ -0,0 +1,53 @@
1
+ module Unisender
2
+ interface _Writable
3
+ def write: (String) -> Integer
4
+ end
5
+ class DownloadReceipt < Data
6
+ attr_reader bytes_written: Integer
7
+ attr_reader http_status: Integer
8
+ def self.new: (bytes_written: Integer, http_status: Integer) -> DownloadReceipt
9
+ end
10
+ class DownloadError < Error
11
+ attr_reader reason: Symbol
12
+ attr_reader bytes_written: Integer
13
+ attr_reader http_status: Integer?
14
+ def initialize: (reason: Symbol, ?bytes_written: Integer, ?http_status: Integer?) -> void
15
+ end
16
+ class DownloadTarget
17
+ GLOBAL_V6: IPAddr
18
+ BLOCKED: Array[IPAddr]
19
+ @timeout: duration
20
+ @resolver: ^(String) -> Array[String]
21
+ def initialize: (timeout: duration, ?resolver: (^(String) -> Array[String])?) -> void
22
+ def resolve: (String) -> [URI::Generic, String]
23
+ private
24
+ def validated_uri: (String) -> URI::Generic
25
+ def resolved_addresses: (String) -> Array[String]
26
+ def blocked?: (String) -> bool
27
+ end
28
+ class DownloadTransfer
29
+ @execution: ExecutionContext?
30
+ @io: _Writable
31
+ @max_bytes: Integer
32
+ attr_reader bytes_written: Integer
33
+ def initialize: (_Writable, Integer, ?execution: ExecutionContext?) -> void
34
+ def write: (String) -> void
35
+ private
36
+ def copy_chunk: (String) -> void
37
+ end
38
+ class Downloader
39
+ @open_timeout: duration
40
+ @read_timeout: duration
41
+ @write_timeout: duration
42
+ @target: DownloadTarget
43
+ @http_factory: ^(URI::Generic, String) -> Net::HTTP
44
+ def initialize: (?open_timeout: duration, ?read_timeout: duration, ?write_timeout: duration, ?resolver: (^(String) -> Array[String])?, ?http_factory: (^(URI::Generic, String) -> Net::HTTP)?) -> void
45
+ def download: (String, _Writable, max_bytes: Integer, ?execution: ExecutionContext?) -> DownloadReceipt
46
+ private
47
+ def execute: (String, DownloadTransfer, ExecutionContext?) -> DownloadReceipt
48
+ def download_response: (String, DownloadTransfer, ExecutionContext?) -> Net::HTTPResponse
49
+ def build_http: (URI::Generic, String) -> Net::HTTP
50
+ def configured_http: (URI::Generic, String, ?ExecutionContext?) -> Net::HTTP
51
+ def stream: (Net::HTTPResponse, DownloadTransfer) -> void
52
+ end
53
+ end
data/sig/execution.rbs ADDED
@@ -0,0 +1,52 @@
1
+ module Unisender
2
+ module Iteration
3
+ def self.items: [Item < Record] (Enumerator[PageResponse[Item], void]) -> Enumerator[Item, void]
4
+ def self.call: [Item] (Enumerator[Item, void]) ?{ (Item) -> void } -> Enumerator[Item, void]
5
+ end
6
+ class BatchReport
7
+ include Enumerable[Response]
8
+ attr_reader responses: Array[Response]
9
+ @error: StandardError?
10
+ @failed_range: Range[Integer]?
11
+ @offsets: Array[Integer]?
12
+ def initialize: (Array[Response], ?error: StandardError?, ?failed_range: Range[Integer]?, ?offsets: Array[Integer]?) -> void
13
+ def each: () -> Enumerator[Response, Array[Response]]
14
+ | () { (Response) -> void } -> Array[Response]
15
+ def complete?: () -> bool
16
+ def completed_batches: () -> Integer
17
+ def partial?: () -> bool
18
+ def uncertain?: () -> bool
19
+ def failures: () -> Array[Failure]
20
+ def row_warnings: () -> Array[Failure]
21
+ def total: () -> Integer?
22
+ def invalid: () -> Integer?
23
+ private
24
+ def failed_warnings: () -> Array[Failure]
25
+ def warning_rows: (ImportResponse, Integer?) -> Array[Failure]
26
+ def failed_response: () -> OutcomeResponse[Record & _Outcome]?
27
+ def import_results: () -> Array[ImportResult]?
28
+ end
29
+
30
+ module EventBatches
31
+ def self.each: (Enumerable[params], Integer) -> Enumerator[Array[params], void]
32
+ def self.validate: (params, Integer) -> void
33
+ def self.build: (Enumerable[params], Integer, _EventBatchSink) -> void
34
+ def self.append: (Array[params], params, Integer, _EventBatchSink) -> Array[params]
35
+ end
36
+
37
+ interface _EventBatchSink
38
+ def <<: (Array[params]) -> void
39
+ end
40
+
41
+ class PageResponse[out Item < Record = Record] < CollectionResponse[Item]
42
+ @client: Client
43
+ @method: String
44
+ @params: params
45
+ def initialize: (CollectionResponse[Item], client: Client, method: String, params: params) -> void
46
+ def each_page: (?max_pages: Integer) ?{ (PageResponse[Item]) -> void } -> Enumerator[PageResponse[Item], void]
47
+ def auto_each: (?max_pages: Integer) ?{ (Item) -> void } -> Enumerator[Item, void]
48
+ def offset: () -> Integer
49
+ def limit: () -> Integer
50
+ def next_offset: () -> Integer
51
+ end
52
+ end
@@ -0,0 +1,46 @@
1
+ module Unisender
2
+ class CancellationToken
3
+ @cancelled: bool
4
+ @mutex: Mutex
5
+ def initialize: () -> void
6
+ def cancel: () -> bool
7
+ def cancelled?: () -> bool
8
+ end
9
+ class CancelledError < Error
10
+ end
11
+ class DeadlineExceededError < Error
12
+ end
13
+ class ExecutionEvent < Data
14
+ attr_reader kind: Symbol
15
+ attr_reader operation: String
16
+ attr_reader duration: Float
17
+ attr_reader outcome: Symbol
18
+ def self.new: (kind: Symbol, operation: String, duration: Float, outcome: Symbol) -> ExecutionEvent
19
+ end
20
+ class ExecutionContext
21
+ @clock: ^() -> Float
22
+ @deadline: Float?
23
+ @cancellation: CancellationToken?
24
+ @parent: ExecutionContext?
25
+ @instrumentation: (^(ExecutionEvent) -> void)?
26
+ @closed: bool
27
+ @owned_clients: Array[Client]
28
+ def initialize: (?timeout: duration?, ?cancellation: CancellationToken?, ?parent: ExecutionContext?, ?instrumentation: (^(ExecutionEvent) -> void)?, ?clock: (^() -> Float)?) -> void
29
+ def check!: () -> void
30
+ def close: () -> Array[Client]
31
+ def own: (Client) -> Array[Client]
32
+ def remaining: () -> Float?
33
+ def wait: (duration, Symbol, String, ^(Float) -> void) -> void
34
+ def measure: [Result] (Symbol, String) { () -> Result } -> Result
35
+ private
36
+ def emit: (ExecutionEvent) -> void
37
+ end
38
+ class Client
39
+ @execution: ExecutionContext?
40
+ def with_execution: [Result] (?timeout: duration?, ?cancellation: CancellationToken?, ?instrumentation: (^(ExecutionEvent) -> void)?) { (Client) -> Result } -> Result
41
+ def execution_wait: (duration, Symbol, String, ^(duration) -> void) -> void
42
+ def check_execution!: () -> void
43
+ def execution_context: () -> ExecutionContext?
44
+ def execution_client: (ExecutionContext) -> Client
45
+ end
46
+ end
data/sig/hooks.rbs ADDED
@@ -0,0 +1,18 @@
1
+ module Unisender
2
+ class Hook < IdentifierRecord
3
+ def url: () -> String
4
+ def event_format: () -> String
5
+ def max_parallel: () -> Integer
6
+ def single_event: () -> Integer
7
+ def status: () -> String
8
+ def events: () -> Record
9
+ def normalize: () -> void
10
+ end
11
+ class Client
12
+ def set_hook: (hook_url: String, events: Hash[String | Symbol, String | Array[String | Integer]], ?event_format: :json_post | :json_post_gzip | :http_get | String, ?max_parallel: Integer?, ?single_event: flag, ?status: :active | :disabled | String) -> Response[json]
13
+ def list_hooks: () -> CollectionResponse[Hook]
14
+ def remove_hook: (hook_url: String) -> Response[json]
15
+ private
16
+ def hook_events: (parameter, parameter) -> params
17
+ end
18
+ end
data/sig/inputs.rbs ADDED
@@ -0,0 +1,84 @@
1
+ module Unisender
2
+ module NamedInputs
3
+ EMPTY_ENUMS: Hash[Symbol, Array[String]]
4
+ FLAGS: Hash[String, Array[Symbol]]
5
+ ENUMS: Hash[String, Hash[Symbol, Array[String]]]
6
+ def self.normalize: (String, params) -> params
7
+ def self.flag!: (Symbol, parameter, String) -> void
8
+ def self.choice: (parameter, Symbol, Array[String], String) -> String
9
+ end
10
+ class ValidationError < ArgumentError
11
+ attr_reader field: String
12
+ attr_reader code: Symbol
13
+ attr_reader operation: String?
14
+ attr_reader index: Integer?
15
+ attr_reader expected_type: String?
16
+ attr_reader actual_type: String?
17
+ alias path field
18
+ def diagnostics: () -> Hash[Symbol, json]
19
+ def documentation_url: () -> String?
20
+ def initialize: (field: String, code: Symbol, ?operation: String?, ?index: Integer?, ?expected_type: String?, ?actual_type: String?) -> void
21
+ def with_operation: (String) -> self
22
+ def category: () -> Symbol
23
+ def recovery_hint: () -> String
24
+ def transient?: () -> bool
25
+ def safe_to_retry?: () -> bool
26
+ end
27
+
28
+ module Inputs
29
+ def self.operation_values: (String, params) -> params
30
+ def self.schedule_timezone!: (params) -> void
31
+ MODES: Hash[Symbol, Hash[Symbol, Integer]]
32
+ MINUTES: Array[String]
33
+ SECONDS: Array[String]
34
+ DATES: Array[Symbol]
35
+ def self.attachments: (parameter) -> parameter
36
+ def self.attachment_parameters: (params) -> params
37
+ def self.attachment_items: (parameter) -> Array[Attachment]
38
+ def self.normalize: (String, params) -> params
39
+ def self.timestamp_format: (String) -> String?
40
+ def self.mode: (parameter, Hash[Symbol, Integer], Symbol) -> Integer?
41
+ def self.timestamp: (parameter, String, Symbol) -> String?
42
+ def self.contact_fields: (parameter, parameter) -> params
43
+ def self.validate_email_alias: (parameter) -> void
44
+ def self.merge_email: (params, parameter) -> parameter
45
+ def self.validate_email: (params) -> void
46
+ end
47
+
48
+ module ContactInputs
49
+ def self.filter_container: (parameter) -> params?
50
+ def self.contact_selector: (params, String) -> params
51
+ def self.validate_selector: (params, params, String) -> void
52
+ def self.count_filters: (parameter, parameter, parameter, parameter) -> params
53
+ def self.count_contact_type: (parameter) -> String?
54
+ def self.validate_filters: (parameter, parameter) -> void
55
+ end
56
+
57
+ module SmsInputs
58
+ def self.phone: (parameter) -> String
59
+ end
60
+
61
+ class RecordRows
62
+ def self.bounded: (Enumerable[params]) -> RecordRows
63
+ include Enumerable[Array[parameter]]
64
+ @records: Enumerable[params]
65
+ @rows: Array[Array[parameter]]?
66
+ attr_reader field_names: Array[String]
67
+ def initialize: (Enumerable[params]) -> void
68
+ def each: () { (Array[parameter]) -> void } -> void
69
+ private
70
+ def row: (parameter, Integer) -> Array[parameter]
71
+ def record_object: (parameter, Integer) -> params
72
+ def validate_columns: (Array[String], Integer) -> void
73
+ end
74
+ module ImportCells
75
+ LISTS: Array[String]
76
+ TIMES: Array[String]
77
+ def self.convert: (String, parameter, Integer) -> parameter
78
+ def self.array: (String, Array[parameter], Integer) -> String
79
+ def self.list: (Array[parameter], Integer) -> String
80
+ def self.times: (Array[parameter] | Time, Integer) -> String
81
+ def self.validate_times: (Hash[String, parameter], Integer) -> void
82
+ def self.invalid!: (Integer) -> bot
83
+ end
84
+ end
data/sig/iterators.rbs ADDED
@@ -0,0 +1,11 @@
1
+ module Unisender
2
+ class Client
3
+ def each_campaign: (from: String | Time, ?to: String | Time | nil, ?page_size: Integer, ?max_pages: Integer, ?offset: Integer) ?{ (Campaign) -> void } -> Enumerator[Campaign, void]
4
+ def each_message: (date_from: String | Time, date_to: String | Time, ?page_size: Integer, ?max_pages: Integer, ?offset: Integer) ?{ (Message) -> void } -> Enumerator[Message, void]
5
+ def each_message_summary: (date_from: String | Time, date_to: String | Time, ?page_size: Integer, ?max_pages: Integer, ?offset: Integer) ?{ (Message) -> void } -> Enumerator[Message, void]
6
+ def each_template: (?type: template_type | nil, ?date_from: String | Time | nil, ?date_to: String | Time | nil, ?page_size: Integer, ?max_pages: Integer, ?offset: Integer) ?{ (Template) -> void } -> Enumerator[Template, void]
7
+ def each_template_summary: (?type: template_type | nil, ?date_from: String | Time | nil, ?date_to: String | Time | nil, ?page_size: Integer, ?max_pages: Integer, ?offset: Integer) ?{ (Template) -> void } -> Enumerator[Template, void]
8
+ def each_sender_domain_group: (username: String, ?domain: String | nil, ?page_size: Integer, ?max_pages: Integer, ?offset: Integer) ?{ (SenderDomainGroup) -> void } -> Enumerator[SenderDomainGroup, void]
9
+ def each_subscriber_note: (subscriber_id: id, ?order_type: note_order | nil, ?order_by: note_field | nil, ?is_pinned: flag | nil, ?page_size: Integer, ?max_pages: Integer, ?offset: Integer) ?{ (Note) -> void } -> Enumerator[Note, void]
10
+ end
11
+ end
@@ -0,0 +1,8 @@
1
+ module Unisender
2
+ module MailInputs
3
+ def self.normalize: (params) -> params
4
+ def self.headers: (params) -> Hash[String, String]
5
+ def self.header: (parameter) -> String?
6
+ def self.merge: (parameter, Hash[String, String]) -> params
7
+ end
8
+ end
data/sig/manifest.yaml ADDED
@@ -0,0 +1,11 @@
1
+ dependencies:
2
+ - name: net-http
3
+ - name: json
4
+ - name: uri
5
+ - name: openssl
6
+ - name: time
7
+ - name: ipaddr
8
+ - name: socket
9
+ - name: timeout
10
+ - name: zlib
11
+ - name: stringio
@@ -0,0 +1,28 @@
1
+ module Unisender
2
+ module OperationContracts
3
+ DEFINITIONS: Hash[String, [String, Array[String], Hash[String, Array[String]]]]
4
+ def self.wire_name: (Symbol) -> String
5
+ def self.validate!: (String, params) -> void
6
+ def self.validate_keys!: (String, params) -> void
7
+ def self.comma_fields: (String) -> Array[String]
8
+ end
9
+ module InputTypes
10
+ KINDS: Hash[String, Module]
11
+ def self.validate!: (parameter, Array[String], String) -> void
12
+ def self.accepts?: (parameter, String) -> bool
13
+ end
14
+ class Client
15
+ def validate!: (Symbol, ?records: Enumerable[params]?, **parameter) -> true
16
+ private
17
+ def validation_dispatch: (Symbol, params) -> true
18
+ def validate_named: (Symbol, params) -> true
19
+ def validation_page: (Symbol, params) -> params
20
+ def validate_campaign: (params) -> true
21
+ def validation_keywords: (parameter, String) -> Hash[Symbol, parameter]
22
+ def validate_events: (params) -> true
23
+ def validation_import: (params, Enumerable[params]) -> params
24
+ def validation_parameters: (String, params) -> params
25
+ def validation_count: (params) -> params
26
+ def preparation_defaults: (String) -> params
27
+ end
28
+ end