Skip to content

Commit

Permalink
Merge pull request #4 from vatsu/master
Browse files Browse the repository at this point in the history
testing count messages
  • Loading branch information
nathmisaki committed Jun 9, 2016
2 parents 494edb4 + afcd07a commit dc7afaa
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions lib/qblox/api/message.rb
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 dc7afaa

Please sign in to comment.