From 931530aed263412f187240cfde124eb7d80e378d Mon Sep 17 00:00:00 2001 From: Samnang Chhun Date: Wed, 7 Jan 2026 16:45:26 +0700 Subject: [PATCH 1/6] Add more endpoints --- .tool-versions | 2 +- lib/cgrates/client.rb | 20 ++++++++++++++------ spec/cgrates/client_spec.rb | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/.tool-versions b/.tool-versions index 3f03c7a..5876619 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -ruby 3.4.7 +ruby 3.4.8 diff --git a/lib/cgrates/client.rb b/lib/cgrates/client.rb index 38820ec..a2ebb72 100644 --- a/lib/cgrates/client.rb +++ b/lib/cgrates/client.rb @@ -30,7 +30,7 @@ def set_tp_destination(prefixes:, **) end def get_tp_destination(**) - get_tp_resource("APIerSv1.GetTPDestination", **) + tp_resource_request("APIerSv1.GetTPDestination", **) end def set_tp_rate(rate_slots:, **) @@ -50,7 +50,11 @@ def set_tp_rate(rate_slots:, **) end def get_tp_rate(**) - get_tp_resource("APIerSv1.GetTPRate", **) + tp_resource_request("APIerSv1.GetTPRate", **) + end + + def remove_tp_rate(**) + tp_resource_request("APIerSv1.RemoveTPRate", **) end def set_tp_destination_rate(destination_rates:, **) @@ -71,7 +75,11 @@ def set_tp_destination_rate(destination_rates:, **) end def get_tp_destination_rate(**) - get_tp_resource("APIerSv1.GetTPDestinationRate", **) + tp_resource_request("APIerSv1.GetTPDestinationRate", **) + end + + def remove_tp_destination_rate(**) + tp_resource_request("APIerSv1.RemoveTPDestinationRate", **) end def set_tp_rating_plan(rating_plan_bindings:, **) @@ -89,7 +97,7 @@ def set_tp_rating_plan(rating_plan_bindings:, **) end def get_tp_rating_plan(**) - get_tp_resource("APIerSv1.GetTPRatingPlan", **) + tp_resource_request("APIerSv1.GetTPRatingPlan", **) end def set_tp_rating_profile(rating_plan_activations:, load_id:, category:, subject:, tenant: nil, **) @@ -111,7 +119,7 @@ def set_tp_rating_profile(rating_plan_activations:, load_id:, category:, subject end def get_tp_rating_profile(tp_id:, load_id:, tenant:, category:, subject:) - get_tp_resource( + tp_resource_request( "APIerSv1.GetTPRatingProfile", tp_id:, id: [ load_id, tenant, category, subject ].join(":"), @@ -152,7 +160,7 @@ def set_tp_resource(method, tp_id:, id:, &) api_request(method, { "TPid" => tp_id, "ID" => id }.merge(yield)) end - def get_tp_resource(method, tp_id:, id:, id_key: "ID") + def tp_resource_request(method, tp_id:, id:, id_key: "ID") api_request(method, { "TPid" => tp_id, id_key => id }) end diff --git a/spec/cgrates/client_spec.rb b/spec/cgrates/client_spec.rb index b1fbd19..1744d44 100644 --- a/spec/cgrates/client_spec.rb +++ b/spec/cgrates/client_spec.rb @@ -112,6 +112,15 @@ module CGRateS ) ) expect(WebMock).to have_requested_api_method("APIerSv1.GetTPRate") + + stub_api_request(result: "OK") + response = client.remove_tp_rate( + tp_id: "cgrates_client_test", + id: "Cambodia_Mobile_Rate" + ) + + expect(response).to have_attributes(result: "OK") + expect(WebMock).to have_requested_api_method("APIerSv1.RemoveTPRate") end end @@ -174,6 +183,15 @@ module CGRateS ) ) expect(WebMock).to have_requested_api_method("APIerSv1.GetTPDestinationRate") + + stub_api_request(result: "OK") + response = client.remove_tp_destination_rate( + tp_id: "cgrates_client_test", + id: "Cambodia_Mobile_Destination_Rate" + ) + + expect(response).to have_attributes(result: "OK") + expect(WebMock).to have_requested_api_method("APIerSv1.RemoveTPDestinationRate") end end From 95dde08396c14928b0a1d6b5c297f77c73b53533 Mon Sep 17 00:00:00 2001 From: Samnang Chhun Date: Thu, 8 Jan 2026 17:50:50 +0700 Subject: [PATCH 2/6] WIP --- lib/cgrates/client.rb | 4 ++++ spec/cgrates/client_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/cgrates/client.rb b/lib/cgrates/client.rb index a2ebb72..5b722be 100644 --- a/lib/cgrates/client.rb +++ b/lib/cgrates/client.rb @@ -100,6 +100,10 @@ def get_tp_rating_plan(**) tp_resource_request("APIerSv1.GetTPRatingPlan", **) end + def remove_tp_rating_plan(**) + tp_resource_request("APIerSv1.RemoveTPRatingPlan", **) + end + def set_tp_rating_profile(rating_plan_activations:, load_id:, category:, subject:, tenant: nil, **) set_tp_resource("APIerSv1.SetTPRatingProfile", **) do { diff --git a/spec/cgrates/client_spec.rb b/spec/cgrates/client_spec.rb index 1744d44..fed2558 100644 --- a/spec/cgrates/client_spec.rb +++ b/spec/cgrates/client_spec.rb @@ -244,6 +244,15 @@ module CGRateS ) ) expect(WebMock).to have_requested_api_method("APIerSv1.GetTPRatingPlan") + + stub_api_request(result: "OK") + response = client.remove_tp_rating_plan( + tp_id: "cgrates_client_test", + id: "Test_Rating_Plan" + ) + + expect(response).to have_attributes(result: "OK") + expect(WebMock).to have_requested_api_method("APIerSv1.RemoveTPRatingPlan") end end From 96ba48bdfe50336a49e8b45f0ac64189a788988b Mon Sep 17 00:00:00 2001 From: Samnang Chhun Date: Thu, 8 Jan 2026 19:12:59 +0700 Subject: [PATCH 3/6] WIP --- README.md | 1 - lib/cgrates/client.rb | 35 ++++++++++++++++++++++++++++- spec/cgrates/client_spec.rb | 44 +++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e2903ca..9dd3411 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,6 @@ client.get_tp_rating_plan(tp_id: "cgrates_client_test", id: "Test_Rating_Plan") client.set_tp_rating_profile( tp_id: "cgrates_client_test", - id: "Test_Rating_Profile", load_id: "TEST", category: "call", tenant: "cgrates.org", diff --git a/lib/cgrates/client.rb b/lib/cgrates/client.rb index 5b722be..9b2db9e 100644 --- a/lib/cgrates/client.rb +++ b/lib/cgrates/client.rb @@ -105,7 +105,7 @@ def remove_tp_rating_plan(**) end def set_tp_rating_profile(rating_plan_activations:, load_id:, category:, subject:, tenant: nil, **) - set_tp_resource("APIerSv1.SetTPRatingProfile", **) do + set_tp_resource("APIerSv1.SetTPRatingProfile", id: nil, **) do { "RatingPlanActivations" => rating_plan_activations.map do { @@ -131,6 +131,39 @@ def get_tp_rating_profile(tp_id:, load_id:, tenant:, category:, subject:) ) end + def set_account(account_id:, tenant: nil, **) + api_request( + "APIerSv2.SetAccount", + { + "Tenant" => tenant, + "Account" => account_id, + ** + } + ) + end + + def get_account(account_id:, tenant: nil, **) + api_request( + "APIerSv2.GetAccount", + { + "Tenant" => tenant, + "Account" => account_id, + ** + } + ) + end + + def remove_account(account_id:, tenant: nil, **) + api_request( + "APIerSv1.RemoveAccount", + { + "Tenant" => tenant, + "Account" => account_id, + ** + } + ) + end + private def api_request(method, *params) diff --git a/spec/cgrates/client_spec.rb b/spec/cgrates/client_spec.rb index fed2558..5938399 100644 --- a/spec/cgrates/client_spec.rb +++ b/spec/cgrates/client_spec.rb @@ -323,6 +323,50 @@ module CGRateS end end + describe "#set_account" do + it "executes the request" do + client = build_client + + stub_api_request(result: "OK") + response = client.set_account(account_id: "sample-account-sid", tenant: "cgrates.org") + + expect(response).to have_attributes(result: "OK") + expect(WebMock).to have_requested_api_method("APIerSv2.SetAccount") + + stub_api_request( + result: { + "ID" => "cgrates.org:sample-account-sid", + "BalanceMap" => nil, + "UnitCounters" => nil, + "ActionTriggers" => nil, + "AllowNegative" => false, + "Disabled" => false, + "UpdateTime" => "2026-01-08T11:49:44.172931119Z" + } + ) + + response = client.get_account( + tenant: "cgrates.org", + account_id: "sample-account-sid" + ) + + expect(response).to have_attributes( + result: hash_including( + "ID" => "cgrates.org:sample-account-sid", + ) + ) + expect(WebMock).to have_requested_api_method("APIerSv2.GetAccount") + + stub_api_request(result: "OK") + response = client.remove_account( + account_id: "sample-account-sid", + tenant: "cgrates.org" + ) + + expect(response).to have_attributes(result: "OK") + expect(WebMock).to have_requested_api_method("APIerSv1.RemoveAccount") + end + end it "handles invalid http responses" do client = build_client From a0502ded1c48d4906046b202a287ddabbb9888ef Mon Sep 17 00:00:00 2001 From: Samnang Chhun Date: Thu, 8 Jan 2026 19:16:47 +0700 Subject: [PATCH 4/6] WIP --- lib/cgrates/client.rb | 12 ++++++------ spec/cgrates/client_spec.rb | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/cgrates/client.rb b/lib/cgrates/client.rb index 9b2db9e..17d030c 100644 --- a/lib/cgrates/client.rb +++ b/lib/cgrates/client.rb @@ -131,34 +131,34 @@ def get_tp_rating_profile(tp_id:, load_id:, tenant:, category:, subject:) ) end - def set_account(account_id:, tenant: nil, **) + def set_account(account:, tenant: nil, **) api_request( "APIerSv2.SetAccount", { "Tenant" => tenant, - "Account" => account_id, + "Account" => account, ** } ) end - def get_account(account_id:, tenant: nil, **) + def get_account(account:, tenant: nil, **) api_request( "APIerSv2.GetAccount", { "Tenant" => tenant, - "Account" => account_id, + "Account" => account, ** } ) end - def remove_account(account_id:, tenant: nil, **) + def remove_account(account:, tenant: nil, **) api_request( "APIerSv1.RemoveAccount", { "Tenant" => tenant, - "Account" => account_id, + "Account" => account, ** } ) diff --git a/spec/cgrates/client_spec.rb b/spec/cgrates/client_spec.rb index 5938399..045b12a 100644 --- a/spec/cgrates/client_spec.rb +++ b/spec/cgrates/client_spec.rb @@ -328,7 +328,7 @@ module CGRateS client = build_client stub_api_request(result: "OK") - response = client.set_account(account_id: "sample-account-sid", tenant: "cgrates.org") + response = client.set_account(account: "sample-account-sid", tenant: "cgrates.org") expect(response).to have_attributes(result: "OK") expect(WebMock).to have_requested_api_method("APIerSv2.SetAccount") @@ -347,7 +347,7 @@ module CGRateS response = client.get_account( tenant: "cgrates.org", - account_id: "sample-account-sid" + account: "sample-account-sid" ) expect(response).to have_attributes( @@ -359,7 +359,7 @@ module CGRateS stub_api_request(result: "OK") response = client.remove_account( - account_id: "sample-account-sid", + account: "sample-account-sid", tenant: "cgrates.org" ) From 56f68b5d08d517c399a0115b0e2ca4e3bb99d140 Mon Sep 17 00:00:00 2001 From: Samnang Chhun Date: Fri, 9 Jan 2026 16:46:31 +0700 Subject: [PATCH 5/6] WIP --- lib/cgrates/client.rb | 9 +++++++++ spec/cgrates/client_spec.rb | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/cgrates/client.rb b/lib/cgrates/client.rb index 17d030c..ad930b6 100644 --- a/lib/cgrates/client.rb +++ b/lib/cgrates/client.rb @@ -131,6 +131,15 @@ def get_tp_rating_profile(tp_id:, load_id:, tenant:, category:, subject:) ) end + def remove_tp_rating_profile(tp_id:, load_id:, tenant:, category:, subject:) + tp_resource_request( + "APIerSv1.RemoveTPRatingProfile", + tp_id:, + id: [ load_id, tenant, category, subject ].join(":"), + id_key: "RatingProfileId" + ) + end + def set_account(account:, tenant: nil, **) api_request( "APIerSv2.SetAccount", diff --git a/spec/cgrates/client_spec.rb b/spec/cgrates/client_spec.rb index 045b12a..c02fa1d 100644 --- a/spec/cgrates/client_spec.rb +++ b/spec/cgrates/client_spec.rb @@ -320,6 +320,18 @@ module CGRateS ) ) expect(WebMock).to have_requested_api_method("APIerSv1.GetTPRatingProfile") + + stub_api_request(result: "OK") + response = client.remove_tp_rating_profile( + tp_id: "cgrates_client_test", + load_id: "TEST", + tenant: "cgrates.org", + category: "call", + subject: "my-account" + ) + + expect(response).to have_attributes(result: "OK") + expect(WebMock).to have_requested_api_method("APIerSv1.RemoveTPRatingProfile") end end From fdb0d09340f5499bbf1f5e9cbb0218fbc3a0c3bc Mon Sep 17 00:00:00 2001 From: Samnang Chhun Date: Mon, 12 Jan 2026 16:31:08 +0700 Subject: [PATCH 6/6] WIP --- lib/cgrates/client.rb | 10 ++++++++++ spec/cgrates/client_spec.rb | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lib/cgrates/client.rb b/lib/cgrates/client.rb index ad930b6..17ccddf 100644 --- a/lib/cgrates/client.rb +++ b/lib/cgrates/client.rb @@ -173,6 +173,16 @@ def remove_account(account:, tenant: nil, **) ) end + def load_tariff_plan_from_stor_db(tp_id:, dry_run: false, validate: true, **) + api_request( + "APIerSv1.LoadTariffPlanFromStorDb", + "TPid" => tp_id, + "DryRun" => dry_run, + "Validate" => validate, + ** + ) + end + private def api_request(method, *params) diff --git a/spec/cgrates/client_spec.rb b/spec/cgrates/client_spec.rb index c02fa1d..d86b51d 100644 --- a/spec/cgrates/client_spec.rb +++ b/spec/cgrates/client_spec.rb @@ -380,6 +380,18 @@ module CGRateS end end + describe "#load_tariff_plan_from_stor_db" do + it "executes the request" do + client = build_client + + stub_api_request(result: "OK") + response = client.load_tariff_plan_from_stor_db(tp_id: "cgrates_client_test") + + expect(response).to have_attributes(result: "OK") + expect(WebMock).to have_requested_api_method("APIerSv1.LoadTariffPlanFromStorDb") + end + end + it "handles invalid http responses" do client = build_client stub_api_request(status: 500)