Class: PostProxy::Resources::Chats

Inherits:
Object
  • Object
show all
Defined in:
lib/postproxy/resources/chats.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Chats

Returns a new instance of Chats.



4
5
6
# File 'lib/postproxy/resources/chats.rb', line 4

def initialize(client)
  @client = client
end

Instance Method Details

#archive(chat_id, profile_group_id: nil) ⇒ Object



39
40
41
42
# File 'lib/postproxy/resources/chats.rb', line 39

def archive(chat_id, profile_group_id: nil)
  result = @client.request(:post, "/chats/#{chat_id}/archive", profile_group_id: profile_group_id)
  Chat.new(**result)
end

#create(profile_id, participant_external_id, participant_username: nil, participant_name: nil, profile_group_id: nil) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/postproxy/resources/chats.rb', line 25

def create(profile_id, participant_external_id, participant_username: nil, participant_name: nil, profile_group_id: nil)
  json_body = { participant_external_id: participant_external_id }
  json_body[:participant_username] = participant_username if participant_username
  json_body[:participant_name] = participant_name if participant_name

  result = @client.request(:post, "/profiles/#{profile_id}/chats", json: json_body, profile_group_id: profile_group_id)
  Chat.new(**result)
end

#get(chat_id, profile_group_id: nil) ⇒ Object



34
35
36
37
# File 'lib/postproxy/resources/chats.rb', line 34

def get(chat_id, profile_group_id: nil)
  result = @client.request(:get, "/chats/#{chat_id}", profile_group_id: profile_group_id)
  Chat.new(**result)
end

#list(profile_id, page: nil, per_page: nil, before: nil, after: nil, profile_group_id: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/postproxy/resources/chats.rb', line 8

def list(profile_id, page: nil, per_page: nil, before: nil, after: nil, profile_group_id: nil)
  params = {}
  params[:page] = page if page
  params[:per_page] = per_page if per_page
  params[:before] = format_time(before) if before
  params[:after] = format_time(after) if after

  result = @client.request(:get, "/profiles/#{profile_id}/chats", params: params, profile_group_id: profile_group_id)
  chats = (result[:data] || []).map { |c| Chat.new(**c) }
  PaginatedResponse.new(
    data: chats,
    total: result[:total],
    page: result[:page],
    per_page: result[:per_page]
  )
end

#unarchive(chat_id, profile_group_id: nil) ⇒ Object



44
45
46
47
# File 'lib/postproxy/resources/chats.rb', line 44

def unarchive(chat_id, profile_group_id: nil)
  result = @client.request(:delete, "/chats/#{chat_id}/archive", profile_group_id: profile_group_id)
  Chat.new(**result)
end