Skip to content

Commit

Permalink
testing count messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustavo Sales committed Jun 6, 2016
1 parent 494edb4 commit afcd07a
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/qblox/api/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,13 @@ def index(chat_dialog_id, options = {})

response = query(:get) do |req|
req.headers = headers.merge('Content-Type' => 'application/json')
req.body = JSON.dump(options)
#req.body = JSON.dump(options)
req.params = { chat_dialog_id: chat_dialog_id }
end
data = json_parse(response.body)
return data unless all

unless count
response = query(:get) do |req|
req.headers = headers.merge('Content-Type' => 'application/json')
req.body = JSON.dump(options)
req.params = { chat_dialog_id: chat_dialog_id, count: 1 }
end
count = json_parse(response.body)
count = count['items']['count'].to_i
end
count ||= count_messages(chat_dialog_id)

if result
result['items'].concat(data['items'])
Expand Down Expand Up @@ -70,6 +62,16 @@ def destroy(message_id, options = {})
return true
end

def count_messages(chat_dialog_id)
response = query(:get) do |req|
req.headers = headers.merge('Content-Type' => 'application/json')
#req.body = JSON.dump(options)
req.params = { chat_dialog_id: chat_dialog_id, count: 1 }
end
count = json_parse(response.body)
count['items']['count'].to_i
end

private

def validate_params(data)
Expand Down

0 comments on commit afcd07a

Please sign in to comment.