Class: ADNChannels::GetMessages
- Inherits:
-
Object
- Object
- ADNChannels::GetMessages
- Defined in:
- lib/TokiCLI/get_messages.rb
Instance Method Summary collapse
- #get_messages(channel_id) ⇒ Object
-
#initialize(token) ⇒ GetMessages
constructor
A new instance of GetMessages.
Constructor Details
#initialize(token) ⇒ GetMessages
Returns a new instance of GetMessages.
5 6 7 8 |
# File 'lib/TokiCLI/get_messages.rb', line 5 def initialize(token) @base_url = 'http://api.app.net' @token = token end |
Instance Method Details
#get_messages(channel_id) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/TokiCLI/get_messages.rb', line 9 def (channel_id) args = {:count => 200, :before_id => nil} = [] @index = 1 puts "Downloading synced objects (200/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| << m } break unless resp['meta']['more'] @index += 1 args = {:count => 200, :before_id => resp['meta']['min_id']} end end |