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/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 38820ec..17ccddf 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,11 +97,15 @@ 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 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 + set_tp_resource("APIerSv1.SetTPRatingProfile", id: nil, **) do { "RatingPlanActivations" => rating_plan_activations.map do { @@ -111,7 +123,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(":"), @@ -119,6 +131,58 @@ 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", + { + "Tenant" => tenant, + "Account" => account, + ** + } + ) + end + + def get_account(account:, tenant: nil, **) + api_request( + "APIerSv2.GetAccount", + { + "Tenant" => tenant, + "Account" => account, + ** + } + ) + end + + def remove_account(account:, tenant: nil, **) + api_request( + "APIerSv1.RemoveAccount", + { + "Tenant" => tenant, + "Account" => account, + ** + } + ) + 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) @@ -152,7 +216,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..d86b51d 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 @@ -226,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 @@ -293,9 +320,77 @@ 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 + + describe "#set_account" do + it "executes the request" do + client = build_client + + stub_api_request(result: "OK") + 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") + + 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: "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: "sample-account-sid", + tenant: "cgrates.org" + ) + + expect(response).to have_attributes(result: "OK") + expect(WebMock).to have_requested_api_method("APIerSv1.RemoveAccount") 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