ayadn 0.6.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +20 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +17 -0
  5. data/Gemfile +14 -0
  6. data/Guardfile +26 -0
  7. data/LICENSE.txt +22 -0
  8. data/MANUAL.md +946 -0
  9. data/README.md +26 -411
  10. data/Rakefile +6 -0
  11. data/ayadn.gemspec +39 -0
  12. data/bin/ayadn +3 -3
  13. data/lib/ayadn.rb +12 -25
  14. data/lib/ayadn/action.rb +1121 -0
  15. data/lib/ayadn/alias.rb +106 -0
  16. data/lib/ayadn/api.rb +312 -301
  17. data/lib/ayadn/app.rb +429 -365
  18. data/lib/ayadn/authorize.rb +127 -28
  19. data/lib/ayadn/blacklist.rb +116 -0
  20. data/lib/ayadn/cnx.rb +105 -0
  21. data/lib/ayadn/databases.rb +110 -0
  22. data/lib/ayadn/descriptions.rb +1043 -0
  23. data/lib/ayadn/endpoints.rb +220 -153
  24. data/lib/ayadn/errors.rb +37 -0
  25. data/lib/ayadn/extend.rb +4 -10
  26. data/lib/ayadn/fileops.rb +48 -0
  27. data/lib/ayadn/logs.rb +32 -0
  28. data/lib/ayadn/pinboard.rb +46 -35
  29. data/lib/ayadn/post.rb +229 -212
  30. data/lib/ayadn/scroll.rb +251 -0
  31. data/lib/ayadn/set.rb +377 -0
  32. data/lib/ayadn/settings.rb +195 -0
  33. data/lib/ayadn/status.rb +226 -165
  34. data/lib/ayadn/switch.rb +72 -0
  35. data/lib/ayadn/version.rb +4 -0
  36. data/lib/ayadn/view.rb +506 -269
  37. data/lib/ayadn/workers.rb +362 -0
  38. data/spec/helpers.rb +19 -0
  39. data/spec/mock/@ericd.json +160 -0
  40. data/spec/mock/@m.json +45 -0
  41. data/spec/mock/checkins.json +1856 -0
  42. data/spec/mock/fwr_@ayadn.json +1077 -0
  43. data/spec/mock/posted.json +1 -0
  44. data/spec/mock/stream.json +1 -0
  45. data/spec/spec_helper.rb +14 -0
  46. data/spec/unit/api_spec.rb +61 -0
  47. data/spec/unit/databases_spec.rb +5 -0
  48. data/spec/unit/descriptions_spec.rb +9 -0
  49. data/spec/unit/endpoints_spec.rb +35 -0
  50. data/spec/unit/post_spec.rb +136 -0
  51. data/spec/unit/status_spec.rb +9 -0
  52. data/spec/unit/view_spec.rb +119 -0
  53. data/spec/unit/workers_spec.rb +147 -0
  54. metadata +216 -40
  55. data/CHANGELOG.md +0 -250
  56. data/CONTRIBUTORS.md +0 -5
  57. data/LICENSE.md +0 -14
  58. data/lib/ayadn/adn_files.rb +0 -84
  59. data/lib/ayadn/client-http.rb +0 -226
  60. data/lib/ayadn/colors.rb +0 -62
  61. data/lib/ayadn/config.yml +0 -35
  62. data/lib/ayadn/debug.rb +0 -36
  63. data/lib/ayadn/files.rb +0 -184
  64. data/lib/ayadn/get-api.rb +0 -43
  65. data/lib/ayadn/help.rb +0 -152
  66. data/lib/ayadn/list.rb +0 -89
  67. data/lib/ayadn/main.rb +0 -542
  68. data/lib/ayadn/requires.rb +0 -12
  69. data/lib/ayadn/skip.rb +0 -27
  70. data/lib/ayadn/tools.rb +0 -208
  71. data/lib/ayadn/user-stream.rb +0 -91
  72. data/lib/ayadn/view-channels.rb +0 -120
  73. data/lib/ayadn/view-interactions.rb +0 -57
  74. data/lib/ayadn/view-object.rb +0 -195
  75. data/lib/experiments.rb +0 -109
@@ -0,0 +1,251 @@
1
+ # encoding: utf-8
2
+ module Ayadn
3
+ class Scroll
4
+
5
+ def initialize(api, view)
6
+ @api = api
7
+ @view = view
8
+ end
9
+
10
+ def global(options)
11
+ options = check_raw(options)
12
+ loop do
13
+ begin
14
+ stream = @api.get_global(options)
15
+ if Databases.has_new?(stream, 'global')
16
+ show(stream, options)
17
+ end
18
+ unless stream['meta']['max_id'].nil?
19
+ Databases.save_max_id(stream)
20
+ options = options_hash(stream)
21
+ end
22
+ sleep Settings.options[:scroll][:timer]
23
+ rescue Interrupt
24
+ canceled
25
+ rescue => e
26
+ raise e
27
+ end
28
+ end
29
+ end
30
+
31
+ def unified(options)
32
+ options = check_raw(options)
33
+ loop do
34
+ begin
35
+ stream = @api.get_unified(options)
36
+ if Databases.has_new?(stream, 'unified')
37
+ show(stream, options)
38
+ end
39
+ unless stream['meta']['max_id'].nil?
40
+ Databases.save_max_id(stream)
41
+ options = options_hash(stream)
42
+ end
43
+ sleep Settings.options[:scroll][:timer]
44
+ rescue Interrupt
45
+ canceled
46
+ rescue => e
47
+ raise e
48
+ end
49
+ end
50
+ end
51
+
52
+ def mentions(username, options)
53
+ options = check_raw(options)
54
+ user = @api.get_user(username)
55
+ id = user['data']['id']
56
+ loop do
57
+ begin
58
+ stream = @api.get_mentions(username, options)
59
+ if Databases.has_new?(stream, "mentions:#{id}")
60
+ show(stream, options)
61
+ end
62
+ unless stream['meta']['max_id'].nil?
63
+ Databases.save_max_id(stream)
64
+ options = options_hash(stream)
65
+ end
66
+ sleep Settings.options[:scroll][:timer]
67
+ rescue Interrupt
68
+ canceled
69
+ rescue => e
70
+ raise e
71
+ end
72
+ end
73
+ end
74
+
75
+ def posts(username, options)
76
+ options = check_raw(options)
77
+ user = @api.get_user(username)
78
+ id = user['data']['id']
79
+ loop do
80
+ begin
81
+ stream = @api.get_posts(username, options)
82
+ if Databases.has_new?(stream, "posts:#{id}")
83
+ show(stream, options)
84
+ end
85
+ unless stream['meta']['max_id'].nil?
86
+ Databases.save_max_id(stream)
87
+ options = options_hash(stream)
88
+ end
89
+ sleep Settings.options[:scroll][:timer]
90
+ rescue Interrupt
91
+ canceled
92
+ rescue => e
93
+ raise e
94
+ end
95
+ end
96
+ end
97
+
98
+ def convo(post_id, options)
99
+ options = check_raw(options)
100
+ loop do
101
+ begin
102
+ stream = @api.get_convo(post_id, options)
103
+ if Databases.has_new?(stream, "replies:#{post_id}")
104
+ show(stream, options)
105
+ end
106
+ unless stream['meta']['max_id'].nil?
107
+ Databases.save_max_id(stream)
108
+ options = options_hash(stream)
109
+ end
110
+ sleep Settings.options[:scroll][:timer]
111
+ rescue Interrupt
112
+ canceled
113
+ rescue => e
114
+ raise e
115
+ end
116
+ end
117
+ end
118
+
119
+ def conversations(options)
120
+ options = check_raw(options)
121
+ loop do
122
+ begin
123
+ stream = @api.get_conversations(options)
124
+ if Databases.has_new?(stream, 'explore:replies')
125
+ show(stream, options)
126
+ end
127
+ unless stream['meta']['max_id'].nil?
128
+ Databases.save_max_id(stream)
129
+ options = options_hash(stream)
130
+ end
131
+ sleep Settings.options[:scroll][:timer]
132
+ rescue Interrupt
133
+ canceled
134
+ rescue => e
135
+ raise e
136
+ end
137
+ end
138
+ end
139
+
140
+ def trending(options)
141
+ options = check_raw(options)
142
+ loop do
143
+ begin
144
+ stream = @api.get_trending(options)
145
+ if Databases.has_new?(stream, 'explore:trending')
146
+ show(stream, options)
147
+ end
148
+ unless stream['meta']['max_id'].nil?
149
+ Databases.save_max_id(stream)
150
+ options = options_hash(stream)
151
+ end
152
+ sleep Settings.options[:scroll][:timer]
153
+ rescue Interrupt
154
+ canceled
155
+ rescue => e
156
+ raise e
157
+ end
158
+ end
159
+ end
160
+
161
+ def checkins(options)
162
+ options = check_raw(options)
163
+ loop do
164
+ begin
165
+ stream = @api.get_checkins(options)
166
+ if Databases.has_new?(stream, 'explore:checkins')
167
+ show(stream, options)
168
+ end
169
+ unless stream['meta']['max_id'].nil?
170
+ Databases.save_max_id(stream)
171
+ options = options_hash(stream)
172
+ end
173
+ sleep Settings.options[:scroll][:timer]
174
+ rescue Interrupt
175
+ canceled
176
+ rescue => e
177
+ raise e
178
+ end
179
+ end
180
+ end
181
+
182
+ def photos(options)
183
+ options = check_raw(options)
184
+ loop do
185
+ begin
186
+ stream = @api.get_photos(options)
187
+ if Databases.has_new?(stream, 'explore:photos')
188
+ show(stream, options)
189
+ end
190
+ unless stream['meta']['max_id'].nil?
191
+ Databases.save_max_id(stream)
192
+ options = options_hash(stream)
193
+ end
194
+ sleep Settings.options[:scroll][:timer]
195
+ rescue Interrupt
196
+ canceled
197
+ rescue => e
198
+ raise e
199
+ end
200
+ end
201
+ end
202
+
203
+ def messages(channel_id, options)
204
+ options = check_raw(options)
205
+ loop do
206
+ begin
207
+ stream = @api.get_messages(channel_id, options)
208
+ if Databases.has_new?(stream, "channel:#{channel_id}")
209
+ show(stream, options)
210
+ end
211
+ unless stream['meta']['max_id'].nil?
212
+ Databases.save_max_id(stream)
213
+ options = options_hash(stream)
214
+ end
215
+ sleep Settings.options[:scroll][:timer]
216
+ rescue Interrupt
217
+ canceled
218
+ rescue => e
219
+ raise e
220
+ end
221
+ end
222
+ end
223
+
224
+ private
225
+
226
+ def check_raw(options)
227
+ if options[:raw]
228
+ {count: 200, since_id: nil, raw: true, scroll: true}
229
+ else
230
+ {count: 200, since_id: nil, scroll: true}
231
+ end
232
+ end
233
+
234
+ def options_hash(stream)
235
+ {:count => 50, :since_id => stream['meta']['max_id'], scroll: true}
236
+ end
237
+
238
+ def show(stream, options)
239
+ unless options[:raw]
240
+ @view.show_posts(stream['data'], options)
241
+ else
242
+ jj stream
243
+ end
244
+ end
245
+
246
+ def canceled
247
+ puts Status.canceled
248
+ exit
249
+ end
250
+ end
251
+ end
data/lib/ayadn/set.rb ADDED
@@ -0,0 +1,377 @@
1
+ module Ayadn
2
+
3
+ class Set < Thor
4
+
5
+ desc "set scroll ITEM VALUE", "Set the waiting time (in seconds, min 0.7) between two requests when scrolling"
6
+ def scroll(*args)
7
+ scroll_config = SetScroll.new
8
+ if args[0]
9
+ param = scroll_config.validate(args[1])
10
+ scroll_config.send(args[0], param)
11
+ else
12
+ abort(Status.error_missing_parameters)
13
+ end
14
+ scroll_config.log(args)
15
+ scroll_config.save
16
+ end
17
+
18
+ desc "set timeline ITEM TRUE/FALSE", "Set ITEM to be activated or not"
19
+ long_desc Descriptions.set_timeline
20
+ def timeline(*args)
21
+ timeline_config = SetTimeline.new
22
+ if args[0]
23
+ begin
24
+ param = timeline_config.validate(args[1])
25
+ timeline_config.send(args[0], param)
26
+ rescue NoMethodError
27
+ puts Status.error_missing_parameters
28
+ exit
29
+ rescue => e
30
+ raise e
31
+ end
32
+ else
33
+ abort(Status.error_missing_parameters)
34
+ end
35
+ timeline_config.log(args)
36
+ timeline_config.save
37
+ end
38
+
39
+ desc "set count ITEM NUMBER", "Set ITEM to retrieve NUMBER of elements by default"
40
+ long_desc Descriptions.set_counts
41
+ map "counts" => :count
42
+ def count(*args)
43
+ counts_config = SetCounts.new
44
+ if args[0]
45
+ begin
46
+ param = counts_config.validate(args[1])
47
+ counts_config.send(args[0], param)
48
+ rescue NoMethodError
49
+ puts Status.error_missing_parameters
50
+ exit
51
+ rescue => e
52
+ raise e
53
+ end
54
+ else
55
+ abort(Status.error_missing_parameters)
56
+ end
57
+ counts_config.log(args)
58
+ counts_config.save
59
+ end
60
+
61
+ # desc "format ITEM NUMBER", "Set ITEM parameter to NUMBER by default"
62
+ # map "formats" => :format
63
+ # def format(*args)
64
+ # puts args
65
+ # end
66
+
67
+ desc "set color ITEM COLOR", "Set ITEM to COLOR"
68
+ long_desc Descriptions.set_color
69
+ map "colors" => :color
70
+ map "colour" => :color
71
+ map "colours" => :color
72
+ def color(*args)
73
+ color_config = SetColor.new
74
+ if args[0]
75
+ begin
76
+ color_config.validate(args[1])
77
+ color_config.send(args[0], args[1])
78
+ rescue NoMethodError
79
+ puts Status.error_missing_parameters
80
+ exit
81
+ rescue => e
82
+ raise e
83
+ end
84
+ else
85
+ abort(Status.error_missing_parameters)
86
+ end
87
+ color_config.log(args)
88
+ color_config.save
89
+ end
90
+
91
+ desc "set backup ITEM TRUE/FALSE", "Set ITEM to be activated or not"
92
+ long_desc Descriptions.set_backup
93
+ def backup(*args)
94
+ backup_config = SetBackup.new
95
+ if args[0]
96
+ begin
97
+ param = backup_config.validate(args[1])
98
+ backup_config.send(args[0], param)
99
+ rescue NoMethodError
100
+ puts Status.error_missing_parameters
101
+ exit
102
+ rescue => e
103
+ raise e
104
+ end
105
+ else
106
+ abort(Status.error_missing_parameters)
107
+ end
108
+ backup_config.log(args)
109
+ backup_config.save
110
+ end
111
+
112
+ desc "set defaults", "Sets back the configuration to defaults values"
113
+ long_desc Descriptions.set_defaults
114
+ def defaults
115
+ Settings.restore_defaults
116
+ puts Status.done
117
+ end
118
+
119
+ end
120
+
121
+ class SetScroll
122
+ def initialize
123
+ Settings.load_config
124
+ Settings.get_token
125
+ Settings.init_config
126
+ Logs.create_logger
127
+ end
128
+ def log(args)
129
+ x = "New value for '#{args[0]}' in 'Scroll' => #{args[1]}"
130
+ puts "\n#{x}\n".color(:cyan)
131
+ Logs.rec.info x
132
+ end
133
+ def save
134
+ Settings.save_config
135
+ end
136
+ def validate(t)
137
+ t = t.to_i
138
+ t >= 0.7 ? t : 1.5
139
+ end
140
+ def timer(t)
141
+ Settings.options[:scroll][:timer] = t
142
+ end
143
+ end
144
+
145
+ class SetBackup
146
+ def initialize
147
+ Settings.load_config
148
+ Settings.get_token
149
+ Settings.init_config
150
+ Logs.create_logger
151
+ end
152
+ def log(args)
153
+ x = "New value for '#{args[0]}' in 'Backup' => #{args[1]}"
154
+ puts "\n#{x}\n".color(:cyan)
155
+ Logs.rec.info x
156
+ end
157
+ def save
158
+ Settings.save_config
159
+ end
160
+ def validate(value)
161
+ case value
162
+ when "TRUE", "true", "1", "yes"
163
+ true
164
+ when "FALSE", "false", "0", "no"
165
+ false
166
+ end
167
+ end
168
+ def auto_save_sent_posts(value)
169
+ Settings.options[:backup][:auto_save_sent_posts] = value
170
+ end
171
+ def auto_save_sent_messages(value)
172
+ Settings.options[:backup][:auto_save_sent_messages] = value
173
+ end
174
+ def auto_save_lists(value)
175
+ Settings.options[:backup][:auto_save_lists] = value
176
+ end
177
+ end
178
+
179
+ class SetCounts
180
+ def initialize
181
+ Settings.load_config
182
+ Settings.get_token
183
+ Settings.init_config
184
+ Logs.create_logger
185
+ end
186
+ def log(args)
187
+ x = "New value for '#{args[0]}' in 'Counts' => #{args[1]}"
188
+ puts "\n#{x}\n".color(:cyan)
189
+ Logs.rec.info x
190
+ end
191
+ def save
192
+ Settings.save_config
193
+ end
194
+ def validate(value)
195
+ if value.is_integer?
196
+ x = value
197
+ else
198
+ x = value.to_i
199
+ end
200
+ if x >= 1 && x <= 200
201
+ x
202
+ else
203
+ abort(Status.must_be_integer)
204
+ end
205
+ end
206
+ def default(value)
207
+ Settings.options[:counts][:default] = value
208
+ end
209
+ def unified(value)
210
+ Settings.options[:counts][:unified] = value
211
+ end
212
+ def global(value)
213
+ Settings.options[:counts][:global] = value
214
+ end
215
+ def checkins(value)
216
+ Settings.options[:counts][:checkins] = value
217
+ end
218
+ def conversations(value)
219
+ Settings.options[:counts][:conversations] = value
220
+ end
221
+ def photos(value)
222
+ Settings.options[:counts][:photos] = value
223
+ end
224
+ def trending(value)
225
+ Settings.options[:counts][:trending] = value
226
+ end
227
+ def mentions(value)
228
+ Settings.options[:counts][:mentions] = value
229
+ end
230
+ def convo(value)
231
+ Settings.options[:counts][:convo] = value
232
+ end
233
+ def posts(value)
234
+ Settings.options[:counts][:posts] = value
235
+ end
236
+ def messages(value)
237
+ Settings.options[:counts][:messages] = value
238
+ end
239
+ def search(value)
240
+ Settings.options[:counts][:search] = value
241
+ end
242
+ def whoreposted(value)
243
+ Settings.options[:counts][:whoreposted] = value
244
+ end
245
+ def whostarred(value)
246
+ Settings.options[:counts][:whostarred] = value
247
+ end
248
+ def whatstarred(value)
249
+ Settings.options[:counts][:whatstarred] = value
250
+ end
251
+ def files(value)
252
+ Settings.options[:counts][:files] = value
253
+ end
254
+ end
255
+
256
+ class SetTimeline
257
+ def initialize
258
+ Settings.load_config
259
+ Settings.get_token
260
+ Settings.init_config
261
+ Logs.create_logger
262
+ end
263
+ def validate(value)
264
+ case value
265
+ when "TRUE", "true", "1", "yes"
266
+ 1
267
+ when "FALSE", "false", "0", "no"
268
+ 0
269
+ end
270
+ end
271
+ def log(args)
272
+ x = "New value for '#{args[0]}' in 'Timeline' => #{args[1]}"
273
+ puts "\n#{x}\n".color(:cyan)
274
+ Logs.rec.info x
275
+ end
276
+ def save
277
+ Settings.save_config
278
+ end
279
+ def directed(value)
280
+ Settings.options[:timeline][:directed] = value
281
+ end
282
+ def deleted(value)
283
+ #Settings.options[:timeline][:deleted] = value
284
+ abort(Status.not_mutable)
285
+ end
286
+ def html(value)
287
+ Settings.options[:timeline][:html] = value
288
+ end
289
+ def annotations(value)
290
+ #Settings.options[:timeline][:annotations] = value
291
+ abort(Status.not_mutable)
292
+ end
293
+ def show_source(value)
294
+ Settings.options[:timeline][:show_source] = value
295
+ end
296
+ def show_symbols(value)
297
+ Settings.options[:timeline][:show_symbols] = value
298
+ end
299
+ def show_real_name(value)
300
+ Settings.options[:timeline][:show_real_name] = value
301
+ end
302
+ def show_date(value)
303
+ Settings.options[:timeline][:show_date] = value
304
+ end
305
+ end
306
+
307
+ class SetColor
308
+ def initialize
309
+ Settings.load_config
310
+ Settings.get_token
311
+ Settings.init_config
312
+ Logs.create_logger
313
+ end
314
+
315
+ def validate(color)
316
+ colors_list = %w{red green magenta cyan yellow blue white}
317
+ unless colors_list.include?(color)
318
+ puts Status.error_missing_parameters
319
+ abort(Status.valid_colors(colors_list))
320
+ end
321
+ end
322
+
323
+ def log(args)
324
+ x = "New value for '#{args[0]}' in 'Colors' => #{args[1]}"
325
+ puts "\n#{x}\n".color(:cyan)
326
+ Logs.rec.info x
327
+ end
328
+
329
+ def save
330
+ Settings.save_config
331
+ end
332
+
333
+ def id(color)
334
+ Settings.options[:colors][:id] = color.to_sym
335
+ end
336
+
337
+ def index(color)
338
+ Settings.options[:colors][:index] = color.to_sym
339
+ end
340
+
341
+ def username(color)
342
+ Settings.options[:colors][:username] = color.to_sym
343
+ end
344
+
345
+ def name(color)
346
+ Settings.options[:colors][:name] = color.to_sym
347
+ end
348
+
349
+ def date(color)
350
+ Settings.options[:colors][:date] = color.to_sym
351
+ end
352
+
353
+ def link(color)
354
+ Settings.options[:colors][:link] = color.to_sym
355
+ end
356
+
357
+ def dots(color)
358
+ Settings.options[:colors][:dots] = color.to_sym
359
+ end
360
+
361
+ def hashtags(color)
362
+ Settings.options[:colors][:hashtags] = color.to_sym
363
+ end
364
+
365
+ def mentions(color)
366
+ Settings.options[:colors][:mentions] = color.to_sym
367
+ end
368
+
369
+ def source(color)
370
+ Settings.options[:colors][:source] = color.to_sym
371
+ end
372
+
373
+ def symbols(color)
374
+ Settings.options[:colors][:symbols] = color.to_sym
375
+ end
376
+ end
377
+ end