celitech 2.0.7

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 (63) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +225 -0
  3. data/lib/celitech/client.rb +81 -0
  4. data/lib/celitech/config.rb +48 -0
  5. data/lib/celitech/environment.rb +7 -0
  6. data/lib/celitech/error.rb +50 -0
  7. data/lib/celitech/http/connection.rb +321 -0
  8. data/lib/celitech/http/hooks.rb +17 -0
  9. data/lib/celitech/http/oauth_token_manager.rb +76 -0
  10. data/lib/celitech/http/response.rb +35 -0
  11. data/lib/celitech/models/bad_request.rb +47 -0
  12. data/lib/celitech/models/create_purchase_ok_response.rb +63 -0
  13. data/lib/celitech/models/create_purchase_ok_response_profile.rb +75 -0
  14. data/lib/celitech/models/create_purchase_ok_response_purchase.rb +111 -0
  15. data/lib/celitech/models/create_purchase_request.rb +155 -0
  16. data/lib/celitech/models/create_purchase_request_language.rb +14 -0
  17. data/lib/celitech/models/create_purchase_v2_ok_response.rb +63 -0
  18. data/lib/celitech/models/create_purchase_v2_ok_response_profile.rb +96 -0
  19. data/lib/celitech/models/create_purchase_v2_ok_response_purchase.rb +70 -0
  20. data/lib/celitech/models/create_purchase_v2_request.rb +156 -0
  21. data/lib/celitech/models/create_purchase_v2_request_language.rb +14 -0
  22. data/lib/celitech/models/destinations.rb +80 -0
  23. data/lib/celitech/models/device.rb +80 -0
  24. data/lib/celitech/models/edit_purchase_ok_response.rb +90 -0
  25. data/lib/celitech/models/edit_purchase_request.rb +90 -0
  26. data/lib/celitech/models/get_esim_device_ok_response.rb +52 -0
  27. data/lib/celitech/models/get_esim_history_ok_response.rb +52 -0
  28. data/lib/celitech/models/get_esim_history_ok_response_esim.rb +61 -0
  29. data/lib/celitech/models/get_esim_ok_response.rb +52 -0
  30. data/lib/celitech/models/get_esim_ok_response_esim.rb +116 -0
  31. data/lib/celitech/models/get_purchase_consumption_ok_response.rb +70 -0
  32. data/lib/celitech/models/grant_type.rb +10 -0
  33. data/lib/celitech/models/history.rb +70 -0
  34. data/lib/celitech/models/list_destinations_ok_response.rb +51 -0
  35. data/lib/celitech/models/list_packages_ok_response.rb +64 -0
  36. data/lib/celitech/models/list_purchases_ok_response.rb +64 -0
  37. data/lib/celitech/models/o_auth_token_request.rb +84 -0
  38. data/lib/celitech/models/o_auth_token_response.rb +60 -0
  39. data/lib/celitech/models/open_model.rb +30 -0
  40. data/lib/celitech/models/package.rb +111 -0
  41. data/lib/celitech/models/packages.rb +121 -0
  42. data/lib/celitech/models/purchases.rb +178 -0
  43. data/lib/celitech/models/purchases_esim.rb +51 -0
  44. data/lib/celitech/models/serializable.rb +63 -0
  45. data/lib/celitech/models/token_ok_response.rb +47 -0
  46. data/lib/celitech/models/top_up_esim_ok_response.rb +63 -0
  47. data/lib/celitech/models/top_up_esim_ok_response_profile.rb +51 -0
  48. data/lib/celitech/models/top_up_esim_ok_response_purchase.rb +111 -0
  49. data/lib/celitech/models/top_up_esim_request.rb +145 -0
  50. data/lib/celitech/models/unauthorized.rb +47 -0
  51. data/lib/celitech/models/union_type.rb +12 -0
  52. data/lib/celitech/serializers/form_serializer.rb +41 -0
  53. data/lib/celitech/serializers/json_serializer.rb +41 -0
  54. data/lib/celitech/services/destinations.rb +59 -0
  55. data/lib/celitech/services/e_sim.rb +108 -0
  56. data/lib/celitech/services/i_frame.rb +59 -0
  57. data/lib/celitech/services/o_auth.rb +49 -0
  58. data/lib/celitech/services/packages.rb +82 -0
  59. data/lib/celitech/services/purchases.rb +195 -0
  60. data/lib/celitech/validator.rb +42 -0
  61. data/lib/celitech/version.rb +5 -0
  62. data/lib/celitech.rb +64 -0
  63. metadata +162 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d3424f5a55970a683d65659cdd00e6b6ed76433367af2804584ed8d0ae00e531
4
+ data.tar.gz: e13a30c0f6382ac209e773d18040150bec5cc57b6b19cd349dc34bd7ff4aba48
5
+ SHA512:
6
+ metadata.gz: 147b03dcc340c791f2117103fef9939fcf0ab1de63db3b60e30a69b545cc7050648d59ef30f05f49af017a00f61ab8dda8d562addd7b04cdfe152b183c31aa31
7
+ data.tar.gz: 5a3213b42f42925ee348d79a0f72c20b9ae56bb528a8df67c3edf1080e07a9489b5ec356776c28574fb3fc354438866eedbac56270080755bfea682ee5dcc25d
data/README.md ADDED
@@ -0,0 +1,225 @@
1
+ # Celitech Ruby SDK 2.0.7
2
+
3
+ Welcome to the Celitech SDK documentation. This guide will help you get started with integrating and using the Celitech SDK in your project.
4
+
5
+ ## Versions
6
+
7
+ - API version: `2.0.7`
8
+ - SDK version: `2.0.7`
9
+
10
+ ## About the API
11
+
12
+ Welcome to the CELITECH API documentation!
13
+
14
+ Useful links: [Homepage](https://www.celitech.com) | [Support email](mailto:support@celitech.com) | [Blog](https://www.celitech.com/blog/)
15
+
16
+ ## Table of Contents
17
+
18
+ - [Setup & Configuration](#setup--configuration)
19
+ - [Supported Language Versions](#supported-language-versions)
20
+ - [Installation](#installation)
21
+ - [Authentication](#authentication)
22
+ - [OAuth Authentication](#oauth-authentication)
23
+ - [Environment Variables](#environment-variables)
24
+ - [Sample Usage](#sample-usage)
25
+ - [Services](#services)
26
+ - [Models](#models)
27
+ - [License](#license)
28
+
29
+ # Setup & Configuration
30
+
31
+ ## Supported Language Versions
32
+
33
+ This SDK is compatible with the following versions: `Ruby >= 3.3`
34
+
35
+ ## Installation
36
+
37
+ ### Using RubyGems
38
+
39
+ If the gem is published to RubyGems or a private gem server, install it directly:
40
+
41
+ ```bash
42
+ gem install celitech
43
+ ```
44
+
45
+ ### Using Bundler (recommended)
46
+
47
+ Add the gem to your application's `Gemfile`:
48
+
49
+ ```ruby
50
+ gem 'celitech'
51
+ ```
52
+
53
+ Then run:
54
+
55
+ ```bash
56
+ bundle install
57
+ ```
58
+
59
+ ## Verifying the SDK setup
60
+
61
+ To verify the SDK works correctly, you can run the included example:
62
+
63
+ 1. Install dependencies:
64
+
65
+ ```bash
66
+ bundle install
67
+ ```
68
+
69
+ 2. Run the example:
70
+
71
+ ```bash
72
+ bundle exec ruby example/example.rb
73
+ ```
74
+
75
+ ## Configuration Scopes
76
+
77
+ The SDK supports three nested configuration scopes. The most-specific scope always wins; changes made at a narrower scope do not persist beyond that scope.
78
+
79
+ ### SDK-level (default)
80
+
81
+ Set once at initialization and applied to every request unless overridden.
82
+
83
+ ```ruby
84
+ require 'celitech'
85
+
86
+ sdk = Celitech::Client.new(
87
+ base_url: 'https://api.example.com',
88
+ timeout: 30,
89
+ )
90
+ ```
91
+
92
+ ### Service-level
93
+
94
+ Override config for all requests made through a particular service instance. The original client and other services are not affected.
95
+
96
+ ```ruby
97
+ override = Celitech::Config.new(base_url: 'https://api.example.com')
98
+ service = sdk.destinations(config: override)
99
+ response = service.some_method
100
+ ```
101
+
102
+ ### Per-request
103
+
104
+ Override config for a single call only. The next call automatically reverts to the enclosing scope.
105
+
106
+ ```ruby
107
+ response = sdk.destinations.some_method(
108
+ config: Celitech::Config.new(base_url: 'https://api.example.com'),
109
+ )
110
+
111
+ # The next call uses the original SDK-level config automatically
112
+ response = sdk.destinations.some_method
113
+ ```
114
+
115
+ Passing `config: nil` explicitly bypasses any service-level override for that single call, falling back directly to the SDK-level (connection) defaults.
116
+
117
+ ## Authentication
118
+
119
+ ### OAuth Authentication
120
+
121
+ The Celitech API uses OAuth 2.0 for authentication.
122
+
123
+ You need to provide your OAuth credentials when initializing the SDK. Tokens are automatically fetched, cached, and refreshed — you do not need to manage them yourself.
124
+
125
+ ```ruby
126
+ require 'celitech'
127
+
128
+ sdk = Celitech::Client.new(client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET')
129
+ ```
130
+
131
+ If you need to set or update the OAuth credentials after the SDK initialization, you can use:
132
+
133
+ ```ruby
134
+ require 'celitech'
135
+
136
+ sdk = Celitech::Client.new
137
+
138
+ sdk.client_id = 'YOUR_CLIENT_ID'
139
+ sdk.client_secret = 'YOUR_CLIENT_SECRET'
140
+ ```
141
+
142
+ ## Environment Variables
143
+
144
+ These are the environment variables for the SDK:
145
+
146
+ | Name | Description |
147
+ | :------------ | :---------------------- |
148
+ | CLIENT_ID | Client ID parameter |
149
+ | CLIENT_SECRET | Client Secret parameter |
150
+
151
+ Environment variables are a way to configure your application outside the code. You can set these environment variables on the command line or use your project's existing tooling for managing environment variables.
152
+
153
+ If you are using a `.env` file, a template with the variable names is provided in the `.env.example` file located in the same directory as this README.
154
+
155
+ # Sample Usage
156
+
157
+ Below is a comprehensive example demonstrating how to authenticate and call a simple endpoint:
158
+
159
+ ```ruby
160
+ require 'celitech'
161
+
162
+ sdk = Celitech::Client.new(client_id: 'YOUR_CLIENT_ID', client_secret: 'YOUR_CLIENT_SECRET')
163
+
164
+ response = sdk.destinations.list_destinations
165
+
166
+ puts response
167
+
168
+ ```
169
+
170
+ ## Services
171
+
172
+ The SDK provides various services to interact with the API.
173
+
174
+ <details>
175
+ <summary>Below is a list of all available services with links to their detailed documentation:</summary>
176
+
177
+ | Name |
178
+ | :----------------------------------------------------- |
179
+ | [Destinations](documentation/services/destinations.md) |
180
+ | [Packages](documentation/services/packages.md) |
181
+ | [Purchases](documentation/services/purchases.md) |
182
+ | [ESim](documentation/services/e_sim.md) |
183
+ | [IFrame](documentation/services/i_frame.md) |
184
+ | [OAuth](documentation/services/o_auth.md) |
185
+
186
+ </details>
187
+
188
+ ## Models
189
+
190
+ The SDK includes several models that represent the data structures used in API requests and responses. These models help in organizing and managing the data efficiently.
191
+
192
+ <details>
193
+ <summary>Below is a list of all available models with links to their detailed documentation:</summary>
194
+
195
+ | Name | Description |
196
+ | :----------------------------------------------------------------------------------------------- | :---------- |
197
+ | [ListDestinationsOkResponse](documentation/models/list_destinations_ok_response.md) | |
198
+ | [ListPackagesOkResponse](documentation/models/list_packages_ok_response.md) | |
199
+ | [CreatePurchaseV2OkResponse](documentation/models/create_purchase_v2_ok_response.md) | |
200
+ | [CreatePurchaseV2Request](documentation/models/create_purchase_v2_request.md) | |
201
+ | [ListPurchasesOkResponse](documentation/models/list_purchases_ok_response.md) | |
202
+ | [CreatePurchaseOkResponse](documentation/models/create_purchase_ok_response.md) | |
203
+ | [CreatePurchaseRequest](documentation/models/create_purchase_request.md) | |
204
+ | [TopUpEsimOkResponse](documentation/models/top_up_esim_ok_response.md) | |
205
+ | [TopUpEsimRequest](documentation/models/top_up_esim_request.md) | |
206
+ | [EditPurchaseOkResponse](documentation/models/edit_purchase_ok_response.md) | |
207
+ | [EditPurchaseRequest](documentation/models/edit_purchase_request.md) | |
208
+ | [GetPurchaseConsumptionOkResponse](documentation/models/get_purchase_consumption_ok_response.md) | |
209
+ | [GetEsimOkResponse](documentation/models/get_esim_ok_response.md) | |
210
+ | [GetEsimDeviceOkResponse](documentation/models/get_esim_device_ok_response.md) | |
211
+ | [GetEsimHistoryOkResponse](documentation/models/get_esim_history_ok_response.md) | |
212
+ | [TokenOkResponse](documentation/models/token_ok_response.md) | |
213
+ | [OAuthTokenResponse](documentation/models/o_auth_token_response.md) | |
214
+ | [OAuthTokenRequest](documentation/models/o_auth_token_request.md) | |
215
+ | [GrantType](documentation/models/grant_type.md) | |
216
+ | [BadRequest](documentation/models/bad_request.md) | |
217
+ | [Unauthorized](documentation/models/unauthorized.md) | |
218
+
219
+ </details>
220
+
221
+ ## License
222
+
223
+ This SDK is licensed under the MIT License.
224
+
225
+ See the [LICENSE](LICENSE) file for more details.
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Celitech
4
+ class Client
5
+ DEFAULT_BASE_URL = Environment::DEFAULT
6
+ TOKEN_URL = 'https://auth.celitech.net/oauth2/token'
7
+
8
+ def initialize(base_url: DEFAULT_BASE_URL, timeout: nil, timeout_ms: nil, client_id: nil, client_secret: nil, token_url: TOKEN_URL)
9
+ unless timeout_ms.nil?
10
+ warn '[DEPRECATION] `timeout_ms` is deprecated; use `timeout` (seconds) instead.', uplevel: 1
11
+ timeout = timeout_ms / 1000.0 if timeout.nil?
12
+ end
13
+ @token_manager = HTTP::OAuthTokenManager.new(
14
+ client_id: client_id,
15
+ client_secret: client_secret,
16
+ token_url: token_url,
17
+ )
18
+ @connection = HTTP::Connection.new(base_url, {}, timeout: timeout)
19
+ @destinations = Destinations.new(@connection, nil, token_manager: @token_manager)
20
+ @packages = Packages.new(@connection, nil, token_manager: @token_manager)
21
+ @purchases = Purchases.new(@connection, nil, token_manager: @token_manager)
22
+ @e_sim = ESim.new(@connection, nil, token_manager: @token_manager)
23
+ @i_frame = IFrame.new(@connection, nil, token_manager: @token_manager)
24
+ @o_auth = OAuth.new(@connection, nil, token_manager: @token_manager)
25
+ end
26
+
27
+ def destinations(config: nil)
28
+ return @destinations unless config
29
+
30
+ Destinations.new(@connection, config, token_manager: @token_manager)
31
+ end
32
+
33
+ def packages(config: nil)
34
+ return @packages unless config
35
+
36
+ Packages.new(@connection, config, token_manager: @token_manager)
37
+ end
38
+
39
+ def purchases(config: nil)
40
+ return @purchases unless config
41
+
42
+ Purchases.new(@connection, config, token_manager: @token_manager)
43
+ end
44
+
45
+ def e_sim(config: nil)
46
+ return @e_sim unless config
47
+
48
+ ESim.new(@connection, config, token_manager: @token_manager)
49
+ end
50
+
51
+ def i_frame(config: nil)
52
+ return @i_frame unless config
53
+
54
+ IFrame.new(@connection, config, token_manager: @token_manager)
55
+ end
56
+
57
+ def o_auth(config: nil)
58
+ return @o_auth unless config
59
+
60
+ OAuth.new(@connection, config, token_manager: @token_manager)
61
+ end
62
+
63
+ def client_id=(client_id)
64
+ @token_manager.client_id = client_id
65
+ end
66
+
67
+ def client_secret=(client_secret)
68
+ @token_manager.client_secret = client_secret
69
+ end
70
+
71
+ def environment=(env)
72
+ self.base_url = Environment.const_get(env.to_s.upcase)
73
+ rescue NameError
74
+ raise ArgumentError, "Unknown environment: #{env.inspect}"
75
+ end
76
+
77
+ def base_url=(url)
78
+ @connection.base_url = url
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Celitech
4
+ class Config
5
+ attr_reader :base_url, :timeout, :enable_response_validation, :return_raw, :additional_headers, :additional_query_parameters, :retry_config
6
+
7
+ def initialize(
8
+ base_url: nil,
9
+ timeout: nil,
10
+ timeout_ms: nil,
11
+ enable_response_validation: false,
12
+ return_raw: false,
13
+ additional_headers: nil,
14
+ additional_query_parameters: nil,
15
+ retry_config: nil
16
+ )
17
+ unless timeout_ms.nil?
18
+ warn '[DEPRECATION] `timeout_ms` is deprecated; use `timeout` (seconds) instead.', uplevel: 1
19
+ timeout = timeout_ms / 1000.0 if timeout.nil?
20
+ end
21
+ @base_url = base_url
22
+ @timeout = timeout
23
+ @enable_response_validation = enable_response_validation
24
+ @return_raw = return_raw
25
+ @additional_headers = additional_headers
26
+ @additional_query_parameters = additional_query_parameters
27
+ @retry_config = retry_config
28
+ end
29
+
30
+ def with(**overrides)
31
+ base = to_h
32
+ base.delete(:timeout) if overrides.key?(:timeout_ms) && !overrides.key?(:timeout)
33
+ self.class.new(**base, **overrides)
34
+ end
35
+
36
+ def to_h
37
+ {
38
+ base_url: @base_url,
39
+ timeout: @timeout,
40
+ enable_response_validation: @enable_response_validation,
41
+ return_raw: @return_raw,
42
+ additional_headers: @additional_headers,
43
+ additional_query_parameters: @additional_query_parameters,
44
+ retry_config: @retry_config,
45
+ }
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Celitech
4
+ module Environment
5
+ DEFAULT = 'https://api.celitech.net/v1'
6
+ end
7
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Celitech
4
+ class Error < StandardError; end
5
+
6
+ class APIError < Error
7
+ attr_reader :status, :body, :headers
8
+
9
+ def initialize(status, body, headers = {})
10
+ @status = status
11
+ @body = body
12
+ @headers = headers || {}
13
+ super("HTTP #{status}: #{body}")
14
+ end
15
+ end
16
+
17
+ class TimeoutError < Error
18
+ def initialize(msg = 'Request timed out')
19
+ super
20
+ end
21
+ end
22
+
23
+ class ValidationError < Error
24
+ attr_reader :field, :validation_message
25
+
26
+ def initialize(field, message)
27
+ @field = field
28
+ @validation_message = message
29
+ super("Validation failed for #{field}: #{message}")
30
+ end
31
+ end
32
+
33
+ class BadRequestError < APIError
34
+ attr_reader :data
35
+
36
+ def initialize(status, data, body, headers = {})
37
+ super(status, body, headers)
38
+ @data = data
39
+ end
40
+ end
41
+
42
+ class UnauthorizedError < APIError
43
+ attr_reader :data
44
+
45
+ def initialize(status, data, body, headers = {})
46
+ super(status, body, headers)
47
+ @data = data
48
+ end
49
+ end
50
+ end