ayadn 0.6.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.
data/bin/ayadn ADDED
@@ -0,0 +1,358 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # App.net command-line client
4
+ # by Eric Dejonckheere
5
+ # http://alpha.app.net/ericd
6
+ # © 2013
7
+
8
+ require 'ayadn'
9
+ puts "\n\nAYADN".red + " - " + "App.net command-line client\n".brown
10
+
11
+ $status = AyaDN::ClientStatus.new
12
+ $tools = AyaDN::Tools.new
13
+ $files = AyaDN::Files.new
14
+ $files.makedir($tools.ayadn_configuration[:db_path])
15
+
16
+ token = $files.auth_read
17
+ if token != nil
18
+ client = AyaDN.new(token)
19
+ client.configAPI
20
+ else
21
+ puts $status.errorNotAuthorized
22
+ AyaDN.new(nil).ayadnAuthorize(nil)
23
+ exit
24
+ end
25
+
26
+ arg1, arg2, arg3, arg4 = ARGV[0], ARGV[1], ARGV[2], ARGV[3]
27
+
28
+ case arg1
29
+
30
+ when "scroll"
31
+ client.ayadnScroll(arg2, arg3)
32
+
33
+ when nil
34
+ client.ayadnUnified(nil)
35
+
36
+ when "unified", "uni"
37
+ client.ayadnUnified(arg2)
38
+
39
+ when "write", "w"
40
+ arg2 != nil ? client.ayadnSendPost(arg2, nil) : client.ayadn_compose_post
41
+
42
+ when "reply", "r"
43
+ if arg2 != nil
44
+ arg2.is_integer? ? client.ayadn_reply(arg2) : (puts $status.errorPostID(arg2))
45
+ else
46
+ puts $status.errorNoID
47
+ end
48
+
49
+ when "global", "g"
50
+ client.ayadnGlobal(arg2)
51
+
52
+ when "mentions", "m"
53
+ (arg2 =~ /^@/ || arg2 == "me") ? client.ayadnUserMentions(arg2, arg3) : (puts $status.errorUserID(arg2))
54
+
55
+ when "posts", "p"
56
+ (arg2 =~ /^@/ || arg2 == "me") ? client.ayadnUserPosts(arg2, arg3) : (puts $status.errorUserID(arg2))
57
+
58
+ when "trending", "conversations", "checkins", "photos"
59
+ client.ayadnExplore(arg1, arg2)
60
+
61
+ when "infos", "i", "info"
62
+ if arg2 =~ /^@/ || arg2 == "me"
63
+ client.ayadnUserInfos(arg2)
64
+ elsif arg2.is_integer?
65
+ client.ayadnPostInfos(arg2)
66
+ else
67
+ puts $status.errorInfos(arg2)
68
+ end
69
+
70
+ when "convo", "c", "thread"
71
+ arg2.is_integer? ? client.ayadnConversation(arg2) : (puts $status.errorPostID(arg2))
72
+
73
+ when "tag", "t", "hashtag"
74
+ theTag = arg2.dup
75
+ theTag[0] = "" if theTag =~ /^#/
76
+ client.ayadnHashtags(theTag)
77
+
78
+ when "delete"
79
+ if arg2.is_integer?
80
+ puts "\nAre you sure you want to delete post ".green + "#{arg2}? ".brown + "(n/y) ".green
81
+ input = STDIN.getch
82
+ (input == "y" || input == "Y") ? client.ayadnDeletePost(arg2) : (puts "\nCanceled.\n\n".red)
83
+ else
84
+ puts $status.errorPostID(arg2)
85
+ end
86
+
87
+ when "list"
88
+ case arg2
89
+ when "followings", "fwings"
90
+ (arg3 =~ /^@/ || arg3 == "me") ? client.ayadnShowList("followings", arg3) : (puts $status.errorSyntax)
91
+ when "followers", "fwers"
92
+ (arg3 =~ /^@/ || arg3 == "me") ? client.ayadnShowList("followers", arg3) : (puts $status.errorSyntax)
93
+ when "muted"
94
+ client.ayadnShowList("muted", "me")
95
+ when "blocked"
96
+ client.ayadnShowList("blocked", "me")
97
+ when "files"
98
+ client.ayadn_list_files(arg3)
99
+ when "options","config"
100
+ client.ayadn_show_options
101
+ when "channels", "ch"
102
+ client.get_loaded_channels
103
+ client.ayadn_get_channels
104
+ when "aliases", "alias", "channel-alias", "alias-channel"
105
+ client.ayadn_list_aliases
106
+ else
107
+ puts $status.errorSyntax
108
+ end
109
+
110
+ when "star"
111
+ arg2.is_integer? ? client.ayadnStarringPost("star", arg2) : (puts $status.errorPostID(arg2))
112
+
113
+ when "unstar"
114
+ arg2.is_integer? ? client.ayadnStarringPost("unstar", arg2) : (puts $status.errorPostID(arg2))
115
+
116
+ when "repost"
117
+ arg2.is_integer? ? client.ayadnReposting("repost", arg2) : (puts $status.errorPostID(arg2))
118
+
119
+ when "unrepost"
120
+ arg2.is_integer? ? client.ayadnReposting("unrepost", arg2) : (puts $status.errorPostID(arg2))
121
+
122
+ when "follow"
123
+ arg2 =~ /^@/ ? client.ayadnFollowing("follow", arg2) : (puts $status.errorUserID(arg2))
124
+
125
+ when "unfollow"
126
+ arg2 =~ /^@/ ? client.ayadnFollowing("unfollow", arg2) : (puts $status.errorUserID(arg2))
127
+
128
+ when "pm"
129
+ if arg2 =~ /^@/
130
+ if arg3 != nil
131
+ # ayadn pm @ericd "hello!"
132
+ client.ayadnSendMessage(arg2, arg3)
133
+ else
134
+ client.ayadnComposeMessage(arg2)
135
+ end
136
+ else
137
+ puts $status.errorSyntax
138
+ end
139
+
140
+ when "send"
141
+ if arg3 != nil
142
+ # ayadn send 12345 "hello, channel!"
143
+ client.ayadnSendMessageToChannel(arg2, arg3)
144
+ else
145
+ client.ayadnComposeMessageToChannel(arg2)
146
+ end
147
+
148
+ when "channels", "ch"
149
+ client.get_loaded_channels
150
+ client.ayadn_get_channels
151
+
152
+ when "messages", "msg"
153
+ # arg2 is integer -> display channel stream
154
+ # arg3 == nil = with pagination, arg3 == "all" = no pagination
155
+ client.ayadnGetMessages(arg2, arg3)
156
+
157
+ when "quote", "comment", "q"
158
+ if arg2.is_integer?
159
+ client.ayadn_quote(arg2)
160
+ else
161
+ puts $status.errorSyntax
162
+ end
163
+
164
+ when "nowplaying", "itunes", "np"
165
+ client.ayadn_nowplaying
166
+
167
+ when "search", "s"
168
+ arg2 != nil ? client.ayadnSearch(arg2) : (puts $status.errorSyntax)
169
+
170
+ when "starred"
171
+ if arg2 =~ /^@/ || arg2 == "me"
172
+ client.ayadnStarredPosts(arg2, arg3)
173
+ elsif arg2.is_integer?
174
+ client.ayadnWhoStarred(arg2)
175
+ else
176
+ puts $status.errorUserID(arg2)
177
+ end
178
+
179
+ when "reposted"
180
+ arg2.is_integer? ? client.ayadnWhoReposted(arg2) : (puts $status.errorPostID(arg2))
181
+
182
+ when "inter", "interactions", "events"
183
+ client.ayadnInteractions
184
+
185
+ when "save"
186
+ arg2.is_integer? ? client.ayadnSavePost(arg2) : (puts $status.errorPostID(arg2))
187
+
188
+ when "load"
189
+ arg2.is_integer? ? client.ayadnLoadPost(arg2) : (puts $status.errorPostID(arg2))
190
+
191
+ when "backup"
192
+ if arg2 == "followings"
193
+ (arg3 =~ /^@/ || arg3 == "me") ? client.ayadnSaveList("followings", arg3) : (puts $status.errorSyntax)
194
+ elsif arg2 == "followers"
195
+ (arg3 =~ /^@/ || arg3 == "me") ? client.ayadnSaveList("followers", arg3) : (puts $status.errorSyntax)
196
+ elsif arg2 == "muted"
197
+ client.ayadnSaveList("muted", "me")
198
+ end
199
+
200
+ when "help", "h"
201
+ puts $tools.helpScreen
202
+
203
+ when "commands", "usage"
204
+ puts $tools.list_of_commands
205
+
206
+ when "webhelp"
207
+ puts $tools.helpScreen
208
+ begin
209
+ $tools.startBrowser("https://github.com/ericdke/ayadn#ayadn")
210
+ rescue
211
+ puts "\nFailed to start a browser automatically. Please visit ".cyan + "https://github.com/ericdke/ayadn#ayadn".magenta
212
+ end
213
+
214
+ when "options"
215
+ client.ayadn_show_options
216
+
217
+ when "debug"
218
+ if arg2 == nil
219
+ client.ayadnDebugStream
220
+ elsif arg2 =~ /^@/
221
+ client.ayadnDebugUser(arg2)
222
+ elsif arg3.is_integer?
223
+ if arg2 == "post"
224
+ client.ayadnDebugPost(arg3)
225
+ elsif arg2 == "message"
226
+ # channel_id, message_id
227
+ client.ayadnDebugMessage(arg3, arg4)
228
+ elsif arg2 == "channel"
229
+ client.ayadnDebugChannel(arg3)
230
+ end
231
+ end
232
+
233
+ when "skip-source", "skip-client"
234
+ case arg2
235
+ when "add"
236
+ client.ayadn_skip_add("sources", arg3)
237
+ when "remove"
238
+ client.ayadn_skip_remove("sources", arg3)
239
+ when "show"
240
+ client.ayadn_show_options
241
+ else
242
+ puts $status.errorSyntax
243
+ end
244
+
245
+ when "skip-tag", "skip-hashtag"
246
+ case arg2
247
+ when "add"
248
+ client.ayadn_skip_add("hashtags", arg3)
249
+ when "remove"
250
+ client.ayadn_skip_remove("hashtags", arg3)
251
+ when "show"
252
+ client.ayadn_show_options
253
+ else
254
+ puts $status.errorSyntax
255
+ end
256
+
257
+ when "skip-mention", "skip-name", "skip-username"
258
+ case arg2
259
+ when "add"
260
+ client.ayadn_skip_add("mentions", arg3)
261
+ when "remove"
262
+ client.ayadn_skip_remove("mentions", arg3)
263
+ when "show"
264
+ client.ayadn_show_options
265
+ else
266
+ puts $status.errorSyntax
267
+ end
268
+
269
+ when "mute"
270
+ arg2 =~ /^@/ ? client.ayadnMuting("mute", arg2) : (puts $status.errorUserID(arg2))
271
+
272
+ when "unmute"
273
+ arg2 =~ /^@/ ? client.ayadnMuting("unmute", arg2) : (puts $status.errorUserID(arg2))
274
+
275
+ when "block"
276
+ arg2 =~ /^@/ ? client.ayadnBlocking("block", arg2) : (puts $status.errorUserID(arg2))
277
+
278
+ when "unblock"
279
+ arg2 =~ /^@/ ? client.ayadnBlocking("unblock", arg2) : (puts $status.errorUserID(arg2))
280
+
281
+ when "reset"
282
+ if arg2 == "pagination"
283
+ client.ayadnReset(arg3, arg4)
284
+ elsif arg2 == nil
285
+ client.ayadnReset(nil, nil)
286
+ end
287
+
288
+ # when "deactivate"
289
+ # # deactivate a user channel
290
+ # client.ayadnDeactivateChannel(arg2)
291
+
292
+ when "random"
293
+ # just for fun :)
294
+ api = AyaDN::API.new(token)
295
+ puts "Fetching random posts, wait a second... (quit with CTRL+C)\n\n".green
296
+ $tools.config['counts']['global'] = 20
297
+ hash = api.getGlobal(nil)
298
+ last_post = hash['data'][0]['id'].to_i
299
+ loop do
300
+ begin
301
+ rnd_post_num = rand(last_post + 1)
302
+ hash = api.getPostInfos("call", rnd_post_num)
303
+ hash = hash['data']
304
+ if hash['text'] == nil
305
+ sleep 0.2
306
+ next
307
+ end
308
+ puts AyaDN::View.new(nil).buildSimplePost(hash)
309
+ sleep 2
310
+ rescue Exception
311
+ abort($status.stopped)
312
+ end
313
+ end
314
+
315
+ when "delete-message"
316
+ client.ayadn_delete_message(arg2, arg3) #channel, message
317
+
318
+ when "download"
319
+ client.ayadn_download_files(arg2)
320
+
321
+ when "delete-file"
322
+ client.ayadn_delete_file(arg2)
323
+
324
+ when "upload"
325
+ client.ayadn_upload_files(arg2)
326
+
327
+ when "private", "public"
328
+ client.ayadn_attribute_file(arg1, arg2)
329
+
330
+ when "pin"
331
+ client.ayadnBookmark(ARGV)
332
+
333
+ when "alias-channel"
334
+ client.ayadn_alias_channel(arg2, arg3)
335
+
336
+ when "stream_global"
337
+ client.ayadn_userstream
338
+
339
+ when "does", "do", "is", "has"
340
+ client.ayadn_does(ARGV)
341
+
342
+ when "authorize", "login"
343
+ AyaDN.new(nil).ayadnAuthorize("reset")
344
+
345
+ when "install"
346
+ if arg2 == "config"
347
+ $tools.installConfig
348
+ else
349
+ puts $status.errorSyntax
350
+ end
351
+
352
+ else
353
+ # if not any known argument
354
+ puts $status.errorSyntax
355
+ puts "#{ARGV.join(" ")} ".brown + "is not a valid option.\n\n".red
356
+ puts $tools.helpScreen
357
+
358
+ end
data/config.yml ADDED
@@ -0,0 +1,35 @@
1
+ ---
2
+ counts: # number of elements retrieved by a stream on the first access, 200 max
3
+ global: 100
4
+ unified: 100
5
+ checkins: 100
6
+ explore: 100
7
+ mentions: 100
8
+ posts: 100
9
+ starred: 100
10
+ search: 200
11
+ timeline:
12
+ # if true, the timeline is displayed from old to recent
13
+ downside: true
14
+ # if true, the unified timeline includes directed posts
15
+ directed: true
16
+ # number of stream posts displayed after a successful post
17
+ streamback: 30
18
+ countdown_1: 5
19
+ countdown_2: 15
20
+ show_client: false
21
+ show_symbols: true
22
+ show_reposters: true
23
+ files:
24
+ ayadnfiles: "/ayadn/data"
25
+ auto_save_sent_messages: false # auto backup your sent private messages
26
+ auto_save_sent_posts: false
27
+ identity: # change this prefix in each folder for your username in you're using several ADN accounts (don't use "@")
28
+ prefix: me
29
+ skipped: # posts matching these values won't show up
30
+ sources: []
31
+ hashtags: []
32
+ mentions: []
33
+ pinboard:
34
+ username:
35
+ password:
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ class AyaDN
4
+ def ayadn_download_files(target)
5
+ with_url = false
6
+ $files.makedir($tools.ayadn_configuration[:files_path])
7
+ if target.split(",").length == 1
8
+ view, file_url, file_name = @view.new(@api.getSingleFile(target)).showFileInfo(with_url)
9
+ puts "\nDownloading file ".green + target.to_s.brown
10
+ puts view
11
+ $files.download_file(file_url, "#{file_name}", @token)
12
+ else
13
+ @hash = @api.getMultipleFiles(target)
14
+ @hash['data'].each do |unique_file|
15
+ view, file_url, file_name = @view.new(nil).buildFileInfo(unique_file, with_url)
16
+ unique_file_id = unique_file['id']
17
+ puts "\nDownloading file ".green + unique_file_id.to_s.brown
18
+ puts view
19
+ $files.download_file(file_url, "#{unique_file_id}_#{file_name}", @token)
20
+ end
21
+ end
22
+ end
23
+ def ayadn_delete_file(target)
24
+ puts "\nWARNING: ".red + "delete a file ONLY is you're sure it's not referenced by a post or a message.\n\n".pink
25
+ puts "Do you wish to continue? (y/N) ".reddish
26
+ if STDIN.getch == ("y" || "Y")
27
+ puts "\nPlease wait...".green
28
+ $files.delete_file(target, @token)
29
+ puts "\nDone!\n\n".green
30
+ else
31
+ puts "\n\nCanceled.\n\n".red
32
+ exit
33
+ end
34
+ end
35
+ def ayadn_upload_files(target)
36
+ case $tools.ayadn_configuration[:platform]
37
+ when $tools.winplatforms
38
+ puts "\nThis feature doesn't work on Windows yet. Sorry.\n\n".red
39
+ exit
40
+ end
41
+ $files.makedir($tools.ayadn_configuration[:files_path])
42
+ uploaded_ids = []
43
+ target.split(",").each do |file|
44
+ puts "Uploading ".cyan + "#{File.basename(file)}".brown + "\n\n"
45
+ begin
46
+ resp = JSON.parse($files.uploadFiles(file, @token))
47
+ rescue => e
48
+ puts "\nERROR: ".red + e.inspect.red + "\n\n"
49
+ exit
50
+ end
51
+ $tools.meta(resp['meta'])
52
+ uploaded_ids.push(resp['data']['id'])
53
+ end
54
+ params = @view.new(@api.getFilesList(nil)).showFilesList(nil, false)
55
+ uploaded_ids.each do |id|
56
+ params[0].gsub!("#{id}", "#{id}".reverse_color)
57
+ end
58
+ puts params[0]
59
+ end
60
+ def ayadn_attribute_file(attribute, target)
61
+ puts "\nChanging file attribute...".green
62
+ if attribute == "public"
63
+ data = {
64
+ "public" => true
65
+ }.to_json
66
+ else
67
+ data = {
68
+ "public" => false
69
+ }.to_json
70
+ end
71
+ response = @api.httpPutFile(target, data)
72
+ resp = JSON.parse(response.body)
73
+ meta = resp['meta']
74
+ if meta['code'] == 200
75
+ puts "\nDone!\n".green
76
+ changed_file_id = resp['data']['id']
77
+ params = @view.new(@api.getFilesList(nil)).showFilesList(nil, false)
78
+ params[0].gsub!("#{changed_file_id}", "#{changed_file_id}".reverse_color)
79
+ puts params[0]
80
+ else
81
+ puts "\nERROR: #{meta.inspect}\n".red
82
+ end
83
+ end
84
+ end