Class: Ayadn::Scroll

Inherits:
Object show all
Defined in:
lib/ayadn/scroll.rb

Instance Method Summary collapse

Constructor Details

#initialize(api, view) ⇒ Scroll

Returns a new instance of Scroll.



5
6
7
8
9
10
11
# File 'lib/ayadn/scroll.rb', line 5

def initialize(api, view)
  @api = api
  @view = view
  @view.hide_cursor
  @chars = %w{ - \\ | / }
  at_exit { @view.show_cursor }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, options) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/ayadn/scroll.rb', line 13

def method_missing(meth, options)
  case meth.to_s
  when 'trending', 'photos', 'checkins', 'replies', 'global', 'unified'
    scroll_it(meth.to_s, options)
  else
    super
  end
end

Instance Method Details

#convo(post_id, options) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ayadn/scroll.rb', line 83

def convo(post_id, options)
  Settings.global[:scrolling] = true
  options = check_raw(options)
  loop do
    begin
      stream = @api.get_convo(post_id, options)
      Debug.stream stream, options, post_id
      clear() if Settings.options[:scroll][:spinner] == true
      show_if_new(stream, options, "replies:#{post_id}")
      options = save_then_return(stream, options, "replies:#{post_id}")
      countdown
      print "..." if Settings.options[:scroll][:spinner] == true
    rescue Interrupt
      canceled
    end
  end
end

#mentions(username, options) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ayadn/scroll.rb', line 45

def mentions(username, options)
  Settings.global[:scrolling] = true
  options = check_raw(options)
  id = @api.get_user(username)['data']['id']
  loop do
    begin
      stream = @api.get_mentions(username, options)
      Debug.stream stream, options, username
      clear() if Settings.options[:scroll][:spinner] == true
      show_if_new(stream, options, "mentions:#{id}")
      options = save_then_return(stream, options, "mentions:#{id}")
      countdown
      print "..." if Settings.options[:scroll][:spinner] == true
    rescue Interrupt
      canceled
    end
  end
end

#messages(channel_id, options) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/ayadn/scroll.rb', line 101

def messages(channel_id, options)
  Settings.global[:scrolling] = true
  options = check_raw(options)
  loop do
    begin
      stream = @api.get_messages(channel_id, options)
      Debug.stream stream, options, channel_id
      clear() if Settings.options[:scroll][:spinner] == true
      show_if_new(stream, options, "channel:#{channel_id}")
      if Settings.options[:marker][:messages] == true
        unless resp['meta']['max_id'].nil?
          marked = @api.update_marker("channel:#{channel_id}", stream['meta']['max_id'])
          updated = JSON.parse(marked)
          if updated['meta']['code'] != 200
            Errors.warn "couldn't update channel #{channel_id} as read"
          end
        end
      end
      options = save_then_return(stream, options, "channel:#{channel_id}")
      countdown
      print "..." if Settings.options[:scroll][:spinner] == true
    rescue Interrupt
      canceled
    end
  end
end

#posts(username, options) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ayadn/scroll.rb', line 64

def posts(username, options)
  Settings.global[:scrolling] = true
  options = check_raw(options)
  id = @api.get_user(username)['data']['id']
  loop do
    begin
      stream = @api.get_posts(username, options)
      Debug.stream stream, options, username
      clear() if Settings.options[:scroll][:spinner] == true
      show_if_new(stream, options, "posts:#{id}")
      options = save_then_return(stream, options, "posts:#{id}")
      countdown
      print "..." if Settings.options[:scroll][:spinner] == true
    rescue Interrupt
      canceled
    end
  end
end

#scroll_it(target, options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ayadn/scroll.rb', line 22

def scroll_it(target, options)
  Settings.global[:scrolling] = true
  options = check_raw(options)
  orig_target = target
  @nr = NiceRank.new
  loop do
    begin
      stream = get(target, options)
      stream['data'].empty? ? niceranks = {} : niceranks = @nr.get_ranks(stream)
      Debug.stream stream, options, target
      target = "explore:#{target}" if explore?(target) # explore but not global
      clear() if Settings.options[:scroll][:spinner] == true
      show_if_new(stream, options, target, niceranks)
      target = orig_target if target =~ /explore/
      options = save_then_return(stream, options, target)
      countdown
      print "..." if Settings.options[:scroll][:spinner] == true
    rescue Interrupt
      canceled
    end
  end
end