Skip to content

Commit 3a1d611

Browse files
committed
Add endpoint for set_tp_rating_profile
1 parent 684b8f6 commit 3a1d611

File tree

3 files changed

+148
-2
lines changed

3 files changed

+148
-2
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,40 @@ client.get_tp_rating_plan(tp_id: "cgrates_client_test", id: "Test_Rating_Plan")
6969
#<data Response
7070
id="ee134421-01dd-4a6b-b7a4-ee9980dc466e",
7171
result={"TPid" => "cgrates_client_test", "ID" => "Test_Rating_Plan", "RatingPlanBindings" => [{"DestinationRatesId" => "Cambodia_Mobile", "TimingId" => "*any", "Weight" => 10}]}>
72+
73+
client.set_tp_rating_profile(
74+
tp_id: "cgrates_client_test",
75+
id: "Test_Rating_Profile",
76+
load_id: "TEST",
77+
category: "call",
78+
tenant: "cgrates.org",
79+
subject: "my-account",
80+
rating_plan_activations: [
81+
{
82+
activation_time: "2025-12-03T19:55:23+07:00",
83+
fallback_subjects: "foobar",
84+
rating_plan_id: "Test_Rating_Plan"
85+
}
86+
]
87+
)
88+
=> #<data Response id="4827cf6e-54e2-4699-8801-d73b34b8331e", result="OK">
89+
client.get_tp_rating_profile(
90+
tp_id: "cgrates_client_test",
91+
load_id: "TEST",
92+
tenant: "cgrates.org",
93+
category: "call",
94+
subject: "my-account"
95+
)
96+
=>
97+
#<data Response
98+
id="210b6cc6-e7be-4a3f-b657-0c5e5f0666b2",
99+
result=
100+
{"TPid" => "cgrates_client_test",
101+
"LoadId" => "TEST",
102+
"Tenant" => "cgrates.org",
103+
"Category" => "call",
104+
"Subject" => "my-account",
105+
"RatingPlanActivations" => [{"ActivationTime" => "2025-12-03T19:55:23+07:00", "RatingPlanId" => "Test_Rating_Plan", "FallbackSubjects" => "foobar"}]}>
72106
```
73107

74108
## Development

lib/cgrates/client.rb

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,33 @@ def get_tp_rating_plan(**)
9292
get_tp_resource("APIerSv1.GetTPRatingPlan", **)
9393
end
9494

95+
def set_tp_rating_profile(rating_plan_activations:, load_id:, category:, subject:, tenant: nil, **)
96+
set_tp_resource("APIerSv1.SetTPRatingProfile", **) do
97+
{
98+
"RatingPlanActivations" => rating_plan_activations.map do
99+
{
100+
"ActivationTime" => it[:activation_time],
101+
"FallbackSubjects" => it[:fallback_subjects],
102+
"RatingPlanId" => it[:rating_plan_id]
103+
}
104+
end,
105+
"LoadId" => load_id,
106+
"Category" => category,
107+
"Subject" => subject,
108+
"Tenant" => tenant
109+
}
110+
end
111+
end
112+
113+
def get_tp_rating_profile(tp_id:, load_id:, tenant:, category:, subject:)
114+
get_tp_resource(
115+
"APIerSv1.GetTPRatingProfile",
116+
tp_id:,
117+
id: [ load_id, tenant, category, subject ].join(":"),
118+
id_key: "RatingProfileId"
119+
)
120+
end
121+
95122
private
96123

97124
def api_request(method, *params)
@@ -125,8 +152,8 @@ def set_tp_resource(method, tp_id:, id:, &)
125152
api_request(method, { "TPid" => tp_id, "ID" => id }.merge(yield))
126153
end
127154

128-
def get_tp_resource(method, tp_id:, id:)
129-
api_request(method, { "TPid" => tp_id, "ID" => id })
155+
def get_tp_resource(method, tp_id:, id:, id_key: "ID")
156+
api_request(method, { "TPid" => tp_id, id_key => id })
130157
end
131158

132159
def default_http_client(host, username:, password:)

spec/cgrates/client_spec.rb

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,74 @@ module CGRateS
229229
end
230230
end
231231

232+
describe "#set_tp_rating_profile" do
233+
it "executes the request" do
234+
client = build_client
235+
set_tp_rating_plan(client, tp_id: "cgrates_client_test", id: "Test_Rating_Plan")
236+
237+
stub_api_request(result: "OK")
238+
response = client.set_tp_rating_profile(
239+
tp_id: "cgrates_client_test",
240+
id: "Test_Rating_Profile",
241+
load_id: "TEST",
242+
category: "call",
243+
tenant: "cgrates.org",
244+
subject: "my-account",
245+
rating_plan_activations: [
246+
{
247+
activation_time: "2025-12-03T19:55:23+07:00",
248+
fallback_subjects: "foobar",
249+
rating_plan_id: "Test_Rating_Plan"
250+
}
251+
]
252+
)
253+
expect(response).to have_attributes(result: "OK")
254+
expect(WebMock).to have_requested_api_method("APIerSv1.SetTPRatingProfile")
255+
256+
stub_api_request(
257+
result: {
258+
"LoadId" => "TEST",
259+
"Tenant" => "cgrates.org",
260+
"Category" => "call",
261+
"Subject" => "my-account",
262+
"RatingPlanActivations" => [
263+
{
264+
"ActivationTime" => "2025-12-03T19:55:23+07:00",
265+
"FallbackSubjects" => "foobar",
266+
"RatingPlanId" => "Test_Rating_Plan"
267+
}
268+
]
269+
}
270+
)
271+
272+
response = client.get_tp_rating_profile(
273+
tp_id: "cgrates_client_test",
274+
load_id: "TEST",
275+
tenant: "cgrates.org",
276+
category: "call",
277+
subject: "my-account"
278+
)
279+
280+
expect(response).to have_attributes(
281+
result: hash_including(
282+
"LoadId" => "TEST",
283+
"Tenant" => "cgrates.org",
284+
"Category" => "call",
285+
"Subject" => "my-account",
286+
"RatingPlanActivations" => [
287+
hash_including(
288+
"ActivationTime" =>"2025-12-03T19:55:23+07:00",
289+
"FallbackSubjects" => "foobar",
290+
"RatingPlanId" => "Test_Rating_Plan"
291+
)
292+
]
293+
)
294+
)
295+
expect(WebMock).to have_requested_api_method("APIerSv1.GetTPRatingProfile")
296+
end
297+
end
298+
299+
232300
it "handles invalid http responses" do
233301
client = build_client
234302
stub_api_request(status: 500)
@@ -321,5 +389,22 @@ def set_tp_destination_rate(client, **params)
321389
**params
322390
)
323391
end
392+
393+
def set_tp_rating_plan(client, **params)
394+
set_tp_destination_rate(client, tp_id: "cgrates_client_test", id: "Cambodia_Mobile_Destination_Rate")
395+
stub_api_request(result: "OK")
396+
client.set_tp_rating_plan(
397+
tp_id: "cgrates_client_test",
398+
id: "Test_Rating_Plan",
399+
rating_plan_bindings: [
400+
{
401+
timing_id: "*any",
402+
weight: 10,
403+
destination_rates_id: "Cambodia_Mobile_Destination_Rate"
404+
}
405+
],
406+
**params
407+
)
408+
end
324409
end
325410
end

0 commit comments

Comments
 (0)