Skip to content

Commit c8c698b

Browse files
committed
feat(campaign): add campaign endpoints
1 parent 4d7358d commit c8c698b

File tree

1 file changed

+98
-2
lines changed

1 file changed

+98
-2
lines changed

lib/stream-chat/client.rb

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ def search(filter_conditions, query, sort: nil, **options)
206206
get('search', params: { payload: options.merge(to_merge).to_json })
207207
end
208208

209-
# <b>DEPRECATED:</b> Please use <tt>upsert_users</tt> instead.
209+
# @deprecated Use {#upsert_users} instead.
210210
T::Sig::WithoutRuntime.sig { params(users: T::Array[StringKeyHash]).returns(StreamChat::StreamResponse) }
211211
def update_users(users)
212212
warn '[DEPRECATION] `update_users` is deprecated. Please use `upsert_users` instead.'
213213
upsert_users(users)
214214
end
215215

216-
# <b>DEPRECATED:</b> Please use <tt>upsert_user</tt> instead.
216+
# @deprecated Use {#upsert_user} instead.
217217
T::Sig::WithoutRuntime.sig { params(user: StringKeyHash).returns(StreamChat::StreamResponse) }
218218
def update_user(user)
219219
warn '[DEPRECATION] `update_user` is deprecated. Please use `upsert_user` instead.'
@@ -834,26 +834,122 @@ def list_push_providers
834834
get('push_providers')
835835
end
836836

837+
# Creates a signed URL for imports.
838+
# @example
839+
# url_resp = client.create_import_url('myfile.json')
840+
# Faraday.put(url_resp['upload_url'], File.read('myfile.json'), 'Content-Type' => 'application/json')
841+
# client.create_import(url_resp['path'], 'upsert')
837842
T::Sig::WithoutRuntime.sig { params(filename: String).returns(StreamChat::StreamResponse) }
838843
def create_import_url(filename)
839844
post('import_urls', data: { filename: filename })
840845
end
841846

847+
# Creates a new import.
848+
# @example
849+
# url_resp = client.create_import_url('myfile.json')
850+
# Faraday.put(url_resp['upload_url'], File.read('myfile.json'), 'Content-Type' => 'application/json')
851+
# client.create_import(url_resp['path'], 'upsert')
842852
T::Sig::WithoutRuntime.sig { params(path: String, mode: String).returns(StreamChat::StreamResponse) }
843853
def create_import(path, mode)
844854
post('imports', data: { path: path, mode: mode })
845855
end
846856

857+
# Returns an import by id.
847858
T::Sig::WithoutRuntime.sig { params(id: String).returns(StreamChat::StreamResponse) }
848859
def get_import(id)
849860
get("imports/#{id}")
850861
end
851862

863+
# Lists imports. Options dictionary can contain 'offset' and 'limit' keys for pagination.
852864
T::Sig::WithoutRuntime.sig { params(options: T.untyped).returns(StreamChat::StreamResponse) }
853865
def list_imports(options)
854866
get('imports', params: options)
855867
end
856868

869+
# Creates a campaign.
870+
T::Sig::WithoutRuntime.sig { params(campaign: StringKeyHash).returns(StreamChat::StreamResponse) }
871+
def create_campaign(campaign)
872+
post('campaigns', data: { campaign: campaign })
873+
end
874+
875+
# Gets a campaign.
876+
T::Sig::WithoutRuntime.sig { params(campaign_id: String).returns(StreamChat::StreamResponse) }
877+
def get_campaign(campaign_id)
878+
get("campaigns/#{campaign_id}")
879+
end
880+
881+
# Lists all campaigns. Options dictionary can contain 'offset' and 'limit' keys for pagination.
882+
T::Sig::WithoutRuntime.sig { params(options: StringKeyHash).returns(StreamChat::StreamResponse) }
883+
def list_campaigns(options)
884+
get('campaigns', params: options)
885+
end
886+
887+
# Updates a campaign.
888+
T::Sig::WithoutRuntime.sig { params(campaign_id: String, campaign: StringKeyHash).returns(StreamChat::StreamResponse) }
889+
def update_campaign(campaign_id, campaign)
890+
put("campaigns/#{campaign_id}", data: { campaign: campaign })
891+
end
892+
893+
# Deletes a campaign.
894+
T::Sig::WithoutRuntime.sig { params(campaign_id: String).returns(StreamChat::StreamResponse) }
895+
def delete_campaign(campaign_id)
896+
delete("campaigns/#{campaign_id}")
897+
end
898+
899+
# Schedules a campaign.
900+
T::Sig::WithoutRuntime.sig { params(campaign_id: String, send_at: Integer).returns(StreamChat::StreamResponse) }
901+
def schedule_campaign(campaign_id, send_at)
902+
patch("campaigns/#{campaign_id}/schedule", data: { send_at: send_at })
903+
end
904+
905+
# Stops a campaign.
906+
T::Sig::WithoutRuntime.sig { params(campaign_id: String).returns(StreamChat::StreamResponse) }
907+
def stop_campaign(campaign_id)
908+
patch("campaigns/#{campaign_id}/stop")
909+
end
910+
911+
# Resumes a campaign.
912+
T::Sig::WithoutRuntime.sig { params(campaign_id: String).returns(StreamChat::StreamResponse) }
913+
def resume_campaign(campaign_id)
914+
patch("campaigns/#{campaign_id}/resume")
915+
end
916+
917+
# Tests a campaign.
918+
T::Sig::WithoutRuntime.sig { params(campaign_id: String, users: T::Array[StringKeyHash]).returns(StreamChat::StreamResponse) }
919+
def test_campaign(campaign_id, users)
920+
post("campaigns/#{campaign_id}/test", data: { users: users })
921+
end
922+
923+
# Creates a campaign segment.
924+
T::Sig::WithoutRuntime.sig { params(segment: StringKeyHash).returns(StreamChat::StreamResponse) }
925+
def create_segment(segment)
926+
post('segments', data: { segment: segment })
927+
end
928+
929+
# Gets a campaign segment.
930+
T::Sig::WithoutRuntime.sig { params(segment_id: String).returns(StreamChat::StreamResponse) }
931+
def get_segment(segment_id)
932+
get("segments/#{segment_id}")
933+
end
934+
935+
# Lists all campaign segments. Options dictionary can contain 'offset' and 'limit' keys for pagination.
936+
T::Sig::WithoutRuntime.sig { params(options: StringKeyHash).returns(StreamChat::StreamResponse) }
937+
def list_segments(options)
938+
get('segments', params: options)
939+
end
940+
941+
# Updates a campaign segment.
942+
T::Sig::WithoutRuntime.sig { params(segment_id: String, segment: StringKeyHash).returns(StreamChat::StreamResponse) }
943+
def update_segment(segment_id, segment)
944+
put("segments/#{segment_id}", data: { segment: segment })
945+
end
946+
947+
# Deletes a campaign segment.
948+
T::Sig::WithoutRuntime.sig { params(segment_id: String).returns(StreamChat::StreamResponse) }
949+
def delete_segment(segment_id)
950+
delete("segments/#{segment_id}")
951+
end
952+
857953
private
858954

859955
T::Sig::WithoutRuntime.sig { returns(T::Hash[String, String]) }

0 commit comments

Comments
 (0)