Sha256: dcf1ad129efd200bb0c65009aeab16276b86b8ac83072a2d6f056a8fe2fcb831
Contents?: true
Size: 1 KB
Versions: 6
Compression:
Stored size: 1 KB
Contents
require 'json' require 'rest_client' module ADNChannels class GetMessages def initialize(token) @base_url = 'http://api.app.net' @token = token end def get_messages(channel_id) args = {:count => 200, :before_id => nil} messages = [] @index = 1 puts "Downloading synced objects (~1MB/page):\n\n" loop do puts "--Downloading from page #{@index}...\n" @url = "#{@base_url}/channels/#{channel_id}/messages?access_token=#{@token}&include_machine=1&include_message_annotations=1&include_deleted=0&include_html=0&count=#{args[:count]}&before_id=#{args[:before_id]}" begin data = RestClient.get(@url) rescue Interrupt puts TokiCLI::Status.canceled exit end resp = JSON.parse(data) resp['data'].each { |m| messages << m } break unless resp['meta']['more'] @index += 1 args = {:count => 200, :before_id => resp['meta']['min_id']} end messages end end end
Version data entries
6 entries across 6 versions & 1 rubygems