spartera_api_sdk 1.0.58
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.
- checksums.yaml +7 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +69 -0
- data/LICENSE +21 -0
- data/README.md +360 -0
- data/Rakefile +10 -0
- data/config.json +10 -0
- data/docs/APIKeysApi.md +353 -0
- data/docs/Alert.md +36 -0
- data/docs/AlertsApi.md +511 -0
- data/docs/Apikey.md +36 -0
- data/docs/Asset.md +110 -0
- data/docs/AssetPriceHistoryApi.md +573 -0
- data/docs/Assetpricehistory.md +38 -0
- data/docs/AssetsApi.md +1131 -0
- data/docs/CloudProvidersApi.md +341 -0
- data/docs/Cloudprovider.md +30 -0
- data/docs/CompaniesApi.md +619 -0
- data/docs/Company.md +44 -0
- data/docs/Connection.md +54 -0
- data/docs/ConnectionsApi.md +497 -0
- data/docs/Error.md +24 -0
- data/docs/Favorite.md +36 -0
- data/docs/FavoritesApi.md +581 -0
- data/docs/InlineObject.md +22 -0
- data/docs/InlineObject1.md +20 -0
- data/docs/InlineObject2.md +20 -0
- data/docs/InlineObject3.md +20 -0
- data/docs/User.md +34 -0
- data/docs/UsersApi.md +357 -0
- data/example.rb +51 -0
- data/git_push.sh +57 -0
- data/lib/spartera_api_sdk/api/alerts_api.rb +543 -0
- data/lib/spartera_api_sdk/api/api_keys_api.rb +345 -0
- data/lib/spartera_api_sdk/api/asset_price_history_api.rb +576 -0
- data/lib/spartera_api_sdk/api/assets_api.rb +1106 -0
- data/lib/spartera_api_sdk/api/cloud_providers_api.rb +315 -0
- data/lib/spartera_api_sdk/api/companies_api.rb +571 -0
- data/lib/spartera_api_sdk/api/connections_api.rb +501 -0
- data/lib/spartera_api_sdk/api/favorites_api.rb +610 -0
- data/lib/spartera_api_sdk/api/users_api.rb +367 -0
- data/lib/spartera_api_sdk/api_client.rb +393 -0
- data/lib/spartera_api_sdk/api_error.rb +58 -0
- data/lib/spartera_api_sdk/configuration.rb +320 -0
- data/lib/spartera_api_sdk/models/alert.rb +353 -0
- data/lib/spartera_api_sdk/models/apikey.rb +370 -0
- data/lib/spartera_api_sdk/models/asset.rb +686 -0
- data/lib/spartera_api_sdk/models/assetpricehistory.rb +345 -0
- data/lib/spartera_api_sdk/models/cloudprovider.rb +292 -0
- data/lib/spartera_api_sdk/models/company.rb +389 -0
- data/lib/spartera_api_sdk/models/connection.rb +434 -0
- data/lib/spartera_api_sdk/models/error.rb +285 -0
- data/lib/spartera_api_sdk/models/favorite.rb +353 -0
- data/lib/spartera_api_sdk/models/inline_object.rb +240 -0
- data/lib/spartera_api_sdk/models/inline_object1.rb +229 -0
- data/lib/spartera_api_sdk/models/inline_object2.rb +229 -0
- data/lib/spartera_api_sdk/models/inline_object3.rb +229 -0
- data/lib/spartera_api_sdk/models/user.rb +327 -0
- data/lib/spartera_api_sdk/version.rb +15 -0
- data/lib/spartera_api_sdk.rb +62 -0
- data/spartera_api_sdk.gemspec +28 -0
- data/spec/api/alerts_api_spec.rb +126 -0
- data/spec/api/api_keys_api_spec.rb +93 -0
- data/spec/api/asset_price_history_api_spec.rb +134 -0
- data/spec/api/assets_api_spec.rb +228 -0
- data/spec/api/cloud_providers_api_spec.rb +88 -0
- data/spec/api/companies_api_spec.rb +134 -0
- data/spec/api/connections_api_spec.rb +119 -0
- data/spec/api/favorites_api_spec.rb +138 -0
- data/spec/api/users_api_spec.rb +95 -0
- data/spec/models/alert_spec.rb +90 -0
- data/spec/models/apikey_spec.rb +90 -0
- data/spec/models/asset_spec.rb +312 -0
- data/spec/models/assetpricehistory_spec.rb +96 -0
- data/spec/models/cloudprovider_spec.rb +72 -0
- data/spec/models/company_spec.rb +114 -0
- data/spec/models/connection_spec.rb +144 -0
- data/spec/models/error_spec.rb +54 -0
- data/spec/models/favorite_spec.rb +90 -0
- data/spec/models/inline_object1_spec.rb +42 -0
- data/spec/models/inline_object2_spec.rb +42 -0
- data/spec/models/inline_object3_spec.rb +42 -0
- data/spec/models/inline_object_spec.rb +48 -0
- data/spec/models/user_spec.rb +84 -0
- data/spec/spec_helper.rb +111 -0
- data/test.sh +42 -0
- metadata +204 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b6d65b4c64e6ac1a91252149df7bc5f7add045f68779b159da3c991b85d151b3
|
4
|
+
data.tar.gz: 4278e31c87be48c22ede9b646e7d1aa0cbbc83c6dd18f8dabb1949b600f3dcce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 26b5c022aac4399e2564602125befc3542066ce3ce1652a59b1d64ed54900dd7482a5387c84016e7d7b3ebec633fb9dbfee374e6aba86deed37501495cda2130
|
7
|
+
data.tar.gz: 301d140cc89222517b18f6876bd5ae8efb67e8306fd17efee5125f5849dccdb5a941e86b1b1b89b4fddbf80df1c7474c65e720a22dbdb41c13a212f6a40b4eef
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
spartera_api_sdk (1.0.58)
|
5
|
+
faraday (>= 1.0.1, < 3.0)
|
6
|
+
faraday-multipart (~> 1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.8.7)
|
12
|
+
public_suffix (>= 2.0.2, < 7.0)
|
13
|
+
base64 (0.3.0)
|
14
|
+
bigdecimal (3.2.2)
|
15
|
+
crack (1.0.0)
|
16
|
+
bigdecimal
|
17
|
+
rexml
|
18
|
+
diff-lcs (1.6.2)
|
19
|
+
faraday (2.13.1)
|
20
|
+
faraday-net_http (>= 2.0, < 3.5)
|
21
|
+
json
|
22
|
+
logger
|
23
|
+
faraday-multipart (1.1.1)
|
24
|
+
multipart-post (~> 2.0)
|
25
|
+
faraday-net_http (3.4.1)
|
26
|
+
net-http (>= 0.5.0)
|
27
|
+
hashdiff (1.2.0)
|
28
|
+
json (2.12.2)
|
29
|
+
logger (1.7.0)
|
30
|
+
multipart-post (2.4.1)
|
31
|
+
net-http (0.6.0)
|
32
|
+
uri
|
33
|
+
public_suffix (6.0.2)
|
34
|
+
rake (13.3.0)
|
35
|
+
rexml (3.4.1)
|
36
|
+
rspec (3.13.1)
|
37
|
+
rspec-core (~> 3.13.0)
|
38
|
+
rspec-expectations (~> 3.13.0)
|
39
|
+
rspec-mocks (~> 3.13.0)
|
40
|
+
rspec-core (3.13.4)
|
41
|
+
rspec-support (~> 3.13.0)
|
42
|
+
rspec-expectations (3.13.5)
|
43
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
44
|
+
rspec-support (~> 3.13.0)
|
45
|
+
rspec-mocks (3.13.5)
|
46
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
47
|
+
rspec-support (~> 3.13.0)
|
48
|
+
rspec-support (3.13.4)
|
49
|
+
uri (1.0.3)
|
50
|
+
vcr (6.3.1)
|
51
|
+
base64
|
52
|
+
webmock (3.25.1)
|
53
|
+
addressable (>= 2.8.0)
|
54
|
+
crack (>= 0.3.2)
|
55
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
56
|
+
|
57
|
+
PLATFORMS
|
58
|
+
arm64-darwin-24
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
rake (~> 13.0)
|
63
|
+
rspec (~> 3.0)
|
64
|
+
spartera_api_sdk!
|
65
|
+
vcr (~> 6.0)
|
66
|
+
webmock (~> 3.0)
|
67
|
+
|
68
|
+
BUNDLED WITH
|
69
|
+
2.6.9
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 Spartera Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,360 @@
|
|
1
|
+
# Ruby SDK Documentation
|
2
|
+
|
3
|
+
## Overview
|
4
|
+
The Ruby SDK for Spartera API provides a convenient way to interact with the Spartera platform from Ruby applications.
|
5
|
+
|
6
|
+
**Install:** `gem install spartera_api_sdk`
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
- Ruby 2.7 or higher
|
10
|
+
- Bundler
|
11
|
+
|
12
|
+
## 🚀 Sell Your First Data Product in 4 API Calls
|
13
|
+
|
14
|
+
Transform your data into revenue in under 5 minutes! Here's how to create and sell a data product on the Spartera marketplace:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
require 'spartera_api_sdk'
|
18
|
+
require 'json'
|
19
|
+
|
20
|
+
# Configure client
|
21
|
+
SparteraApiSdk.configure do |config|
|
22
|
+
config.host = 'https://api.spartera.com'
|
23
|
+
config.api_key['X-API-Key'] = 'your-api-key-here'
|
24
|
+
end
|
25
|
+
|
26
|
+
COMPANY_ID = 'your-company-id'
|
27
|
+
USER_ID = 'your-user-id'
|
28
|
+
|
29
|
+
def sell_data_product
|
30
|
+
# Step 1: Discover available data platforms
|
31
|
+
puts '🔍 Step 1: Discovering available platforms...'
|
32
|
+
cloud_providers_api = SparteraApiSdk::CloudProvidersApi.new
|
33
|
+
|
34
|
+
engines = cloud_providers_api.cloud_providers_get
|
35
|
+
bigquery_engine_id = 1 # BigQuery engine ID
|
36
|
+
puts "✅ Found #{engines.length} supported platforms"
|
37
|
+
|
38
|
+
# Step 2: Create a data connection (with credentials in one call!)
|
39
|
+
puts '🔗 Step 2: Creating BigQuery connection...'
|
40
|
+
connections_api = SparteraApiSdk::ConnectionsApi.new
|
41
|
+
|
42
|
+
# Your BigQuery service account JSON (replace with your actual credentials)
|
43
|
+
service_account_json = {
|
44
|
+
type: 'service_account',
|
45
|
+
project_id: 'your-project-id',
|
46
|
+
private_key_id: 'key-id',
|
47
|
+
private_key: "-----BEGIN PRIVATE KEY-----\nYOUR_PRIVATE_KEY\n-----END PRIVATE KEY-----\n",
|
48
|
+
client_email: 'your-service@your-project.iam.gserviceaccount.com',
|
49
|
+
client_id: 'client-id',
|
50
|
+
auth_uri: 'https://accounts.google.com/o/oauth2/auth',
|
51
|
+
token_uri: 'https://oauth2.googleapis.com/token'
|
52
|
+
}
|
53
|
+
|
54
|
+
connection_data = SparteraApiSdk::Connection.new(
|
55
|
+
company_id: COMPANY_ID,
|
56
|
+
user_id: USER_ID,
|
57
|
+
engine_id: bigquery_engine_id,
|
58
|
+
name: 'My BigQuery Data Warehouse',
|
59
|
+
description: "Connection to our company's analytics data",
|
60
|
+
visibility: 'PRIVATE',
|
61
|
+
credential_type: 'SERVICE_ACCOUNT',
|
62
|
+
credentials: service_account_json.to_json,
|
63
|
+
verified_usage_ability: true # Legal compliance - you have rights to this data
|
64
|
+
)
|
65
|
+
|
66
|
+
connection = connections_api.companies_company_id_connections_post(COMPANY_ID, connection_data)
|
67
|
+
connection_id = connection.connection_id
|
68
|
+
puts "✅ Created connection: #{connection_id}"
|
69
|
+
|
70
|
+
# Step 3: Create a marketplace asset
|
71
|
+
puts '📊 Step 3: Creating marketplace asset...'
|
72
|
+
assets_api = SparteraApiSdk::AssetsApi.new
|
73
|
+
|
74
|
+
asset_data = SparteraApiSdk::Asset.new(
|
75
|
+
name: 'Average Temperature Analytics',
|
76
|
+
description: 'Real-time weather temperature analytics from our IoT sensors across major cities',
|
77
|
+
company_id: COMPANY_ID,
|
78
|
+
connection_id: connection_id,
|
79
|
+
asset_type: 'CALCULATION',
|
80
|
+
sql_logic: 'SELECT AVERAGE(temperature) AS avg_temp, city, COUNT(*) AS readings FROM `your-project.weather.sensor_data` WHERE timestamp >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 24 HOUR) GROUP BY city ORDER BY avg_temp DESC',
|
81
|
+
sell_in_marketplace: true, # 🔥 This makes it available for purchase!
|
82
|
+
source: 'MANUAL',
|
83
|
+
visibility: 'PUBLIC'
|
84
|
+
)
|
85
|
+
|
86
|
+
asset = assets_api.companies_company_id_assets_post(COMPANY_ID, asset_data)
|
87
|
+
asset_id = asset.asset_id
|
88
|
+
puts "✅ Created marketplace asset: #{asset_id}"
|
89
|
+
|
90
|
+
# Step 4: Set your price and start earning!
|
91
|
+
puts '💰 Step 4: Setting price...'
|
92
|
+
pricing_api = SparteraApiSdk::AssetPriceHistoryApi.new
|
93
|
+
|
94
|
+
price_data = SparteraApiSdk::Assetpricehistory.new(
|
95
|
+
price_usd: 2.00 # $2.00 per analysis (credits calculated automatically)
|
96
|
+
)
|
97
|
+
|
98
|
+
price = pricing_api.companies_company_id_assets_asset_id_prices_post(COMPANY_ID, asset_id, price_data)
|
99
|
+
puts "✅ Price set: $#{price.price_usd} (≈#{price.price_credits} credits)"
|
100
|
+
|
101
|
+
puts "\n🎉 SUCCESS! Your data product is now live on the Spartera marketplace!"
|
102
|
+
puts "📈 Asset URL: https://marketplace.spartera.com/assets/#{asset_id}"
|
103
|
+
puts '💡 Customers can now discover and purchase your analytics!'
|
104
|
+
rescue SparteraApiSdk::ApiError => e
|
105
|
+
puts "Error: #{e.message}"
|
106
|
+
raise e
|
107
|
+
end
|
108
|
+
|
109
|
+
# Run the function
|
110
|
+
sell_data_product
|
111
|
+
```
|
112
|
+
|
113
|
+
**That's it!** You're now selling data analytics. Every time someone runs your analysis, you earn money!
|
114
|
+
|
115
|
+
### 🎯 What You Just Built
|
116
|
+
- **Data Connection**: Secure link to your BigQuery warehouse
|
117
|
+
- **Analytics Product**: Temperature analysis that buyers can purchase
|
118
|
+
- **Marketplace Listing**: Your product is discoverable by thousands of potential customers
|
119
|
+
- **Automated Pricing**: Credits are calculated automatically based on your USD price
|
120
|
+
|
121
|
+
### 💰 Revenue Model
|
122
|
+
- You set the price ($2.00 in this example)
|
123
|
+
- Customers pay in credits (auto-converted)
|
124
|
+
- You earn revenue each time someone uses your analytics
|
125
|
+
- Spartera handles billing, payments, and customer support
|
126
|
+
|
127
|
+
---
|
128
|
+
|
129
|
+
## 📚 Detailed Documentation
|
130
|
+
|
131
|
+
### Authentication
|
132
|
+
|
133
|
+
Get your API key from the [Spartera Dashboard](https://app.spartera.com/settings/api-keys):
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
require 'spartera_api_sdk'
|
137
|
+
|
138
|
+
# Option 1: Direct configuration
|
139
|
+
SparteraApiSdk.configure do |config|
|
140
|
+
config.host = 'https://api.spartera.com'
|
141
|
+
config.api_key['X-API-Key'] = 'your-api-key-here'
|
142
|
+
end
|
143
|
+
|
144
|
+
# Option 2: Environment variables (recommended)
|
145
|
+
ENV['SPARTERA_API_KEY'] = 'your-api-key'
|
146
|
+
ENV['SPARTERA_COMPANY_ID'] = 'your-company-id'
|
147
|
+
|
148
|
+
SparteraApiSdk.configure do |config|
|
149
|
+
config.host = 'https://api.spartera.com'
|
150
|
+
config.api_key['X-API-Key'] = ENV['SPARTERA_API_KEY']
|
151
|
+
end
|
152
|
+
|
153
|
+
# Create API instances
|
154
|
+
companies_api = SparteraApiSdk::CompaniesApi.new
|
155
|
+
assets_api = SparteraApiSdk::AssetsApi.new
|
156
|
+
```
|
157
|
+
|
158
|
+
### Environment Variables
|
159
|
+
|
160
|
+
```bash
|
161
|
+
export SPARTERA_API_KEY="your-api-key"
|
162
|
+
export SPARTERA_COMPANY_ID="your-company-id"
|
163
|
+
export SPARTERA_API_BASE_URL="https://api.spartera.com"
|
164
|
+
```
|
165
|
+
|
166
|
+
### Connection Types
|
167
|
+
|
168
|
+
Create connections to different data platforms:
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
# BigQuery
|
172
|
+
bigquery_credentials = {
|
173
|
+
type: 'service_account',
|
174
|
+
project_id: 'your-project',
|
175
|
+
# ... your service account JSON
|
176
|
+
}
|
177
|
+
|
178
|
+
# Snowflake
|
179
|
+
snowflake_connection = SparteraApiSdk::Connection.new(
|
180
|
+
credential_type: 'USERNAME_PASSWORD',
|
181
|
+
username: 'your-username',
|
182
|
+
password: 'your-password'
|
183
|
+
)
|
184
|
+
|
185
|
+
# API Data Source
|
186
|
+
api_connection = SparteraApiSdk::Connection.new(
|
187
|
+
credential_type: 'API_KEY',
|
188
|
+
api_endpoint: 'https://api.yourcompany.com/data',
|
189
|
+
api_key_param: 'x-api-key',
|
190
|
+
credentials: 'your-api-key-value'
|
191
|
+
)
|
192
|
+
```
|
193
|
+
|
194
|
+
### Asset Types
|
195
|
+
|
196
|
+
Create different types of marketplace products:
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
# SQL-based Analytics
|
200
|
+
calculation_asset = SparteraApiSdk::Asset.new(
|
201
|
+
asset_type: 'CALCULATION',
|
202
|
+
sql_logic: 'SELECT COUNT(*) as total_sales, AVG(amount) as avg_order FROM sales WHERE date >= CURRENT_DATE()'
|
203
|
+
)
|
204
|
+
|
205
|
+
# Visualization/Dashboard
|
206
|
+
visualization_asset = SparteraApiSdk::Asset.new(
|
207
|
+
asset_type: 'VISUALIZATION',
|
208
|
+
viz_chart_type: 'BAR',
|
209
|
+
viz_dep_var_col_name: 'sales_amount',
|
210
|
+
viz_indep_var_col_name: 'month'
|
211
|
+
)
|
212
|
+
```
|
213
|
+
|
214
|
+
### Pricing Strategies
|
215
|
+
|
216
|
+
Set different pricing models:
|
217
|
+
|
218
|
+
```ruby
|
219
|
+
# Fixed price per analysis
|
220
|
+
basic_pricing = SparteraApiSdk::Assetpricehistory.new(price_usd: 1.50)
|
221
|
+
|
222
|
+
# Premium analytics
|
223
|
+
premium_pricing = SparteraApiSdk::Assetpricehistory.new(price_usd: 10.00)
|
224
|
+
|
225
|
+
# Bulk discount with sales
|
226
|
+
sale_pricing = SparteraApiSdk::Assetpricehistory.new(
|
227
|
+
price_usd: 5.00,
|
228
|
+
discount_percentage: 20.0,
|
229
|
+
sale_start_date: '2024-01-01T00:00:00Z',
|
230
|
+
sale_end_date: '2024-01-31T23:59:59Z'
|
231
|
+
)
|
232
|
+
```
|
233
|
+
|
234
|
+
### Marketplace Management
|
235
|
+
|
236
|
+
Manage your products after launch:
|
237
|
+
|
238
|
+
```ruby
|
239
|
+
# Update asset details
|
240
|
+
update_data = SparteraApiSdk::Asset.new(
|
241
|
+
description: 'Updated description with new features'
|
242
|
+
)
|
243
|
+
assets_api.companies_company_id_assets_asset_id_patch(COMPANY_ID, asset_id, update_data)
|
244
|
+
|
245
|
+
# Change pricing
|
246
|
+
new_price = SparteraApiSdk::Assetpricehistory.new(price_usd: 3.00)
|
247
|
+
pricing_api.companies_company_id_assets_asset_id_prices_post(COMPANY_ID, asset_id, new_price)
|
248
|
+
|
249
|
+
# Remove from marketplace (but keep private)
|
250
|
+
marketplace_update = SparteraApiSdk::Asset.new(sell_in_marketplace: false)
|
251
|
+
assets_api.companies_company_id_assets_asset_id_patch(COMPANY_ID, asset_id, marketplace_update)
|
252
|
+
|
253
|
+
# Get sales analytics
|
254
|
+
analytics = companies_api.companies_company_id_analytics_sales_get(COMPANY_ID)
|
255
|
+
puts "Total revenue: $#{analytics.total_revenue}"
|
256
|
+
```
|
257
|
+
|
258
|
+
### Error Handling
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
begin
|
262
|
+
asset = assets_api.companies_company_id_assets_post(COMPANY_ID, asset_data)
|
263
|
+
rescue SparteraApiSdk::ApiError => e
|
264
|
+
puts "API Error: #{e.message}"
|
265
|
+
puts "Status: #{e.code}"
|
266
|
+
puts "Response: #{e.response_body}"
|
267
|
+
|
268
|
+
# Handle specific errors
|
269
|
+
case e.code
|
270
|
+
when 400
|
271
|
+
puts 'Check your asset data format'
|
272
|
+
when 401
|
273
|
+
puts 'Check your API key'
|
274
|
+
when 403
|
275
|
+
puts 'Check your permissions'
|
276
|
+
when 404
|
277
|
+
puts 'Check your IDs'
|
278
|
+
else
|
279
|
+
puts "HTTP #{e.code}: #{e.message}"
|
280
|
+
end
|
281
|
+
|
282
|
+
raise e
|
283
|
+
end
|
284
|
+
```
|
285
|
+
|
286
|
+
### Advanced Features
|
287
|
+
|
288
|
+
```ruby
|
289
|
+
# Batch operations
|
290
|
+
connection_ids = []
|
291
|
+
%w[bigquery snowflake redshift].each do |platform|
|
292
|
+
conn = connections_api.companies_company_id_connections_post(COMPANY_ID, platform_config)
|
293
|
+
connection_ids << conn.connection_id
|
294
|
+
end
|
295
|
+
|
296
|
+
# Asset recommendations
|
297
|
+
recommendations = assets_api.companies_company_id_assets_asset_id_recommendations_get(
|
298
|
+
COMPANY_ID,
|
299
|
+
asset_id,
|
300
|
+
{ limit: 10 }
|
301
|
+
)
|
302
|
+
|
303
|
+
# Performance analytics
|
304
|
+
performance = companies_api.companies_company_id_analytics_assets_get(
|
305
|
+
COMPANY_ID,
|
306
|
+
start_date: '2024-01-01',
|
307
|
+
end_date: '2024-12-31'
|
308
|
+
)
|
309
|
+
```
|
310
|
+
|
311
|
+
### Rails Integration
|
312
|
+
|
313
|
+
For Ruby on Rails applications:
|
314
|
+
|
315
|
+
```ruby
|
316
|
+
# Gemfile
|
317
|
+
gem 'spartera_api_sdk'
|
318
|
+
|
319
|
+
# config/initializers/spartera.rb
|
320
|
+
SparteraApiSdk.configure do |config|
|
321
|
+
config.host = Rails.application.credentials.spartera[:api_url] || 'https://api.spartera.com'
|
322
|
+
config.api_key['X-API-Key'] = Rails.application.credentials.spartera[:api_key]
|
323
|
+
end
|
324
|
+
|
325
|
+
# app/services/spartera_service.rb
|
326
|
+
class SparteraService
|
327
|
+
def self.companies_api
|
328
|
+
@companies_api ||= SparteraApiSdk::CompaniesApi.new
|
329
|
+
end
|
330
|
+
|
331
|
+
def self.assets_api
|
332
|
+
@assets_api ||= SparteraApiSdk::AssetsApi.new
|
333
|
+
end
|
334
|
+
|
335
|
+
def self.get_company(company_id)
|
336
|
+
companies_api.companies_company_id_get(company_id)
|
337
|
+
rescue SparteraApiSdk::ApiError => e
|
338
|
+
Rails.logger.error "Spartera API Error: #{e.message}"
|
339
|
+
nil
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
# Usage in controllers
|
344
|
+
class AssetsController < ApplicationController
|
345
|
+
def show
|
346
|
+
@company = SparteraService.get_company(params[:company_id])
|
347
|
+
# ...
|
348
|
+
end
|
349
|
+
end
|
350
|
+
```
|
351
|
+
|
352
|
+
## Package Manager
|
353
|
+
- **Platform**: RubyGems
|
354
|
+
- **Install**: `gem install spartera_api_sdk`
|
355
|
+
- **Import**: `require 'spartera_api_sdk'`
|
356
|
+
|
357
|
+
## Publishing
|
358
|
+
1. Build: `gem build *.gemspec`
|
359
|
+
2. Push: `gem push *.gem`
|
360
|
+
3. Install: `gem install spartera_api_sdk`
|
data/Rakefile
ADDED
data/config.json
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"gemName": "spartera_api_sdk",
|
3
|
+
"gemVersion": "1.0.58",
|
4
|
+
"gemDescription": "Official SDK for Spartera API - Interface to manage companies' accounts and process insights remotely",
|
5
|
+
"gemAuthor": "Tony D",
|
6
|
+
"gemAuthorEmail": "tony@spartera.com",
|
7
|
+
"gemHomepage": "https://github.com/spartera-com/spartera-ruby-sdk",
|
8
|
+
"moduleName": "SparteraApiSdk",
|
9
|
+
"gemLicense": "Apache-2.0"
|
10
|
+
}
|