Skip to content
Closed
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
63 changes: 63 additions & 0 deletions docs/DefaultApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Method | HTTP request | Description
[**get_notification_history**](DefaultApi.md#get_notification_history) | **POST** /notifications/{notification_id}/history | Notification History
[**get_notifications**](DefaultApi.md#get_notifications) | **GET** /notifications | View notifications
[**get_outcomes**](DefaultApi.md#get_outcomes) | **GET** /apps/{app_id}/outcomes | View Outcomes
[**get_segment**](DefaultApi.md#get_segment) | **GET** /apps/{app_id}/segments/{segment_id} | View Segment
[**get_segments**](DefaultApi.md#get_segments) | **GET** /apps/{app_id}/segments | Get Segments
[**get_user**](DefaultApi.md#get_user) | **GET** /apps/{app_id}/users/by/{alias_label}/{alias_id} |
[**rotate_api_key**](DefaultApi.md#rotate_api_key) | **POST** /apps/{app_id}/auth/tokens/{token_id}/rotate | Rotate API key
Expand Down Expand Up @@ -1908,6 +1909,68 @@ Name | Type | Description | Required | Notes
[[Back to top]](#) [[Back to API list]](https://github.com/OneSignal/onesignal-rust-api#full-api-reference) [[Back to README]](https://github.com/OneSignal/onesignal-rust-api)


## get_segment

> crate::models::GetSegmentSuccessResponse get_segment(app_id, segment_id, include_segment_detail)
View Segment

Retrieve details for a single segment by its ID, including subscriber count and optionally segment metadata and filters.

### Example

```rust
use onesignal_rust_api::apis::configuration::Configuration;
use onesignal_rust_api::apis::default_api;


#[tokio::main]
async fn main() {
let mut configuration = Configuration::new();
configuration.rest_api_key_token = Some("YOUR_REST_API_KEY".to_string());


// Realistic values are pulled from the spec's `example:` fields where present.
let app_id: &str = "YOUR_APP_ID";
let segment_id: &str = "d6c5a3e1-9f17-44a1-9d10-7c0e4a2b1c8e";
let include_segment_detail: Option<bool> = None;

match default_api::get_segment(&configuration, app_id, segment_id, include_segment_detail).await {
Ok(resp) => println!("{:?}", resp),
Err(e @ onesignal_rust_api::apis::Error::ResponseError(_)) => {
// `e.error_messages()` flattens any error-envelope shape to a Vec<String>;
// the raw response remains on the ResponseError variant.
eprintln!("get_segment failed: {:?}", e.error_messages());
}
Err(e) => eprintln!("get_segment failed: {:?}", e),
}
}
```

### Parameters


Name | Type | Description | Required | Notes
------------- | ------------- | ------------- | ------------- | -------------
**app_id** | **String** | The OneSignal App ID for your app. Available in Keys & IDs. | [required] |
**segment_id** | **String** | The segment's unique identifier. Can be found using the View Segments API or in the URL of the segment when viewing it in the dashboard. | [required] |
**include_segment_detail** | Option<**bool**> | Set to true to include segment metadata and filters in the response. | |

### Return type

[**crate::models::GetSegmentSuccessResponse**](GetSegmentSuccessResponse.md)

### Authorization

[rest_api_key](https://github.com/OneSignal/onesignal-rust-api#configuration)

### HTTP request headers

- **Content-Type**: Not defined
- **Accept**: application/json

[[Back to top]](#) [[Back to API list]](https://github.com/OneSignal/onesignal-rust-api#full-api-reference) [[Back to README]](https://github.com/OneSignal/onesignal-rust-api)


## get_segments

> crate::models::GetSegmentsSuccessResponse get_segments(app_id, offset, limit)
Expand Down
12 changes: 12 additions & 0 deletions docs/GetSegmentSuccessResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# GetSegmentSuccessResponse

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**subscriber_count** | Option<**i32**> | The number of subscribers matching this segment. | [optional]
**payload** | Option<[**crate::models::SegmentDetails**](SegmentDetails.md)> | | [optional]

[[Back to API list]](https://github.com/OneSignal/onesignal-rust-api#full-api-reference) [[Back to README]](https://github.com/OneSignal/onesignal-rust-api)


16 changes: 16 additions & 0 deletions docs/SegmentDetails.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SegmentDetails

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | Option<**String**> | The unique identifier for the segment (UUID v4). | [optional]
**name** | Option<**String**> | The segment name. | [optional]
**description** | Option<**String**> | Human-readable description for the segment. `null` when unset. Maximum 255 characters. | [optional]
**created_at** | Option<**i32**> | Unix timestamp when the segment was created. | [optional]
**source** | Option<**String**> | The source of the segment. | [optional]
**filters** | Option<[**Vec<crate::models::FilterExpression>**](FilterExpression.md)> | Array of filter and operator objects defining the segment criteria. Uses the same format as the Create Segment API, so filters can be directly used to recreate or update the segment. | [optional]

[[Back to API list]](https://github.com/OneSignal/onesignal-rust-api#full-api-reference) [[Back to README]](https://github.com/OneSignal/onesignal-rust-api)


49 changes: 49 additions & 0 deletions src/apis/default_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,17 @@ pub enum GetOutcomesError {
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_segment`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSegmentError {
Status400(crate::models::GenericError),
Status404(crate::models::GenericError),
Status429(crate::models::RateLimitError),
DefaultResponse(crate::models::GenericError),
UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_segments`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
Expand Down Expand Up @@ -1499,6 +1510,44 @@ pub async fn get_outcomes(configuration: &configuration::Configuration, app_id:
}
}

/// Retrieve details for a single segment by its ID, including subscriber count and optionally segment metadata and filters.
pub async fn get_segment(configuration: &configuration::Configuration, app_id: &str, segment_id: &str, include_segment_detail: Option<bool>) -> Result<crate::models::GetSegmentSuccessResponse, Error<GetSegmentError>> {
let configuration = configuration;

let client = &configuration.client;

let uri_str = format!("{}/apps/{app_id}/segments/{segment_id}", configuration.base_path, app_id=crate::apis::urlencode(app_id), segment_id=crate::apis::urlencode(segment_id));
let mut req_builder = client.request(reqwest::Method::GET, uri_str.as_str());

if let Some(ref str) = include_segment_detail {
req_builder = req_builder.query(&[("include-segment-detail", &str.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}

// Adds a telemetry header
req_builder = req_builder.header("OS-Usage-Data", "kind=sdk, sdk-name=onesignal-rust, version=5.10.0");

if let Some(ref token) = configuration.rest_api_key_token {
req_builder = req_builder.header("Authorization", format!("Key {}", token.to_owned()));
}

let req = req_builder.build()?;
let resp = client.execute(req).await?;

let status = resp.status();
let content = resp.text().await?;

if !status.is_client_error() && !status.is_server_error() {
serde_json::from_str(&content).map_err(Error::from)
} else {
let entity: Option<GetSegmentError> = serde_json::from_str(&content).ok();
let error = ResponseContent { status: status, content: content, entity: entity };
Err(Error::ResponseError(error))
}
}

/// Returns an array of segments from an app.
pub async fn get_segments(configuration: &configuration::Configuration, app_id: &str, offset: Option<i32>, limit: Option<i32>) -> Result<crate::models::GetSegmentsSuccessResponse, Error<GetSegmentsError>> {
let configuration = configuration;
Expand Down
32 changes: 32 additions & 0 deletions src/models/get_segment_success_response.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* OneSignal
*
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.10.0
* Contact: devrel@onesignal.com
* Generated by: https://openapi-generator.tech
*/




#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct GetSegmentSuccessResponse {
/// The number of subscribers matching this segment.
#[serde(rename = "subscriber_count", skip_serializing_if = "Option::is_none")]
pub subscriber_count: Option<i32>,
#[serde(rename = "payload", skip_serializing_if = "Option::is_none")]
pub payload: Option<Box<crate::models::SegmentDetails>>,
}

impl GetSegmentSuccessResponse {
pub fn new() -> GetSegmentSuccessResponse {
GetSegmentSuccessResponse {
subscriber_count: None,
payload: None,
}
}
}


4 changes: 4 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub mod generic_success_bool_response;
pub use self::generic_success_bool_response::GenericSuccessBoolResponse;
pub mod get_notification_history_request_body;
pub use self::get_notification_history_request_body::GetNotificationHistoryRequestBody;
pub mod get_segment_success_response;
pub use self::get_segment_success_response::GetSegmentSuccessResponse;
pub mod get_segments_success_response;
pub use self::get_segments_success_response::GetSegmentsSuccessResponse;
pub mod language_string_map;
Expand Down Expand Up @@ -98,6 +100,8 @@ pub mod segment;
pub use self::segment::Segment;
pub mod segment_data;
pub use self::segment_data::SegmentData;
pub mod segment_details;
pub use self::segment_details::SegmentDetails;
pub mod segment_notification_target;
pub use self::segment_notification_target::SegmentNotificationTarget;
pub mod start_live_activity_request;
Expand Down
67 changes: 67 additions & 0 deletions src/models/segment_details.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* OneSignal
*
* A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at onesignal.com
*
* The version of the OpenAPI document: 5.10.0
* Contact: devrel@onesignal.com
* Generated by: https://openapi-generator.tech
*/

/// SegmentDetails : Segment details. Only included when the include-segment-detail query parameter is set to true.



#[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)]
pub struct SegmentDetails {
/// The unique identifier for the segment (UUID v4).
#[serde(rename = "id", skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
/// The segment name.
#[serde(rename = "name", skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// Human-readable description for the segment. `null` when unset. Maximum 255 characters.
#[serde(rename = "description", skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// Unix timestamp when the segment was created.
#[serde(rename = "created_at", skip_serializing_if = "Option::is_none")]
pub created_at: Option<i32>,
/// The source of the segment.
#[serde(rename = "source", skip_serializing_if = "Option::is_none")]
pub source: Option<SourceType>,
/// Array of filter and operator objects defining the segment criteria. Uses the same format as the Create Segment API, so filters can be directly used to recreate or update the segment.
#[serde(rename = "filters", skip_serializing_if = "Option::is_none")]
pub filters: Option<Vec<crate::models::FilterExpression>>,
}

impl SegmentDetails {
/// Segment details. Only included when the include-segment-detail query parameter is set to true.
pub fn new() -> SegmentDetails {
SegmentDetails {
id: None,
name: None,
description: None,
created_at: None,
source: None,
filters: None,
}
}
}

/// The source of the segment.
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub enum SourceType {
#[serde(rename = "default")]
Default,
#[serde(rename = "custom")]
Custom,
#[serde(rename = "quickstart")]
Quickstart,
}

impl Default for SourceType {
fn default() -> SourceType {
Self::Default
}
}