Class: Ayadn::Scroll

Inherits:
Object
  • 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
# File 'lib/ayadn/scroll.rb', line 5

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, options) ⇒ Object



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

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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ayadn/scroll.rb', line 72

def convo(post_id, options)
  options = check_raw(options)
  loop do
    begin
      stream = @api.get_convo(post_id, options)
      Debug.stream stream, options, post_id
      show_if_new(stream, options, "replies:#{post_id}")
      options = save_then_return(stream, options)
      countdown
    rescue Interrupt
      canceled
    end
  end
end

#mentions(username, options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ayadn/scroll.rb', line 40

def mentions(username, options)
  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
      show_if_new(stream, options, "mentions:#{id}")
      options = save_then_return(stream, options)
      countdown
    rescue Interrupt
      canceled
    end
  end
end

#messages(channel_id, options) ⇒ Object



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

def messages(channel_id, options)
  options = check_raw(options)
  loop do
    begin
      stream = @api.get_messages(channel_id, options)
      Debug.stream stream, options, channel_id
      show_if_new(stream, options, "channel:#{channel_id}")
      options = save_then_return(stream, options)
      countdown
    rescue Interrupt
      canceled
    end
  end
end

#posts(username, options) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ayadn/scroll.rb', line 56

def posts(username, options)
  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
      show_if_new(stream, options, "posts:#{id}")
      options = save_then_return(stream, options)
      countdown
    rescue Interrupt
      canceled
    end
  end
end

#scroll_it(target, options) ⇒ Object



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

def scroll_it(target, options)
  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)
      show_if_new(stream, options, target, niceranks)
      target = orig_target if target =~ /explore/
      options = save_then_return(stream, options)
      countdown
    rescue Interrupt
      canceled
    end
  end
end