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
@@ -1,12 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
-
4
- %w{rubygems pstore date open-uri net/http json io/console fileutils yaml pinboard base64}.each do |r|
5
- require "#{r}"
6
- end
7
-
8
- winPlatforms = ['mswin', 'mingw', 'mingw_18', 'mingw_19', 'mingw_20', 'mingw32']
9
- case Gem::Platform.local.os
10
- when *winPlatforms
11
- require 'win32console'
12
- end
data/lib/ayadn/skip.rb DELETED
@@ -1,27 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
- class AyaDN
4
- def ayadn_skip_add(kind, target) #kind: sources,hashtags,mentions
5
- puts "Current skipped #{kind}: ".green + $tools.config['skipped']["#{kind}"].join(", ").red + "\n\n"
6
- puts "Adding ".green + target.red + " to the skipped #{kind}.".green + "\n\n"
7
- $tools.config['skipped']["#{kind}"].each do |in_config|
8
- if in_config == target
9
- puts target.red + " is already skipped.\n\n".green
10
- exit
11
- end
12
- end
13
- $tools.config['skipped']["#{kind}"].push(target)
14
- puts "New skipped #{kind}: ".green + $tools.config['skipped']["#{kind}"].join(", ").red + "\n\n"
15
- $tools.saveConfig
16
- end
17
- def ayadn_skip_remove(kind, target)
18
- puts "Removing ".green + target.red + " from the skipped #{kind}.".green + "\n\n"
19
- $tools.config['skipped']["#{kind}"].each do |in_config|
20
- if in_config == target
21
- $tools.config['skipped']["#{kind}"].delete(in_config)
22
- end
23
- end
24
- puts "New skipped #{kind}: ".green + $tools.config['skipped']["#{kind}"].join(", ").red + "\n\n"
25
- $tools.saveConfig
26
- end
27
- end
data/lib/ayadn/tools.rb DELETED
@@ -1,208 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
- require 'yaml'
4
- require 'rubygems'
5
- require 'pinboard'
6
-
7
- class AyaDN
8
- class Tools
9
- def initialize
10
- @default_ayadn_data_path = Dir.home + "/ayadn/data"
11
- @installed_config_path = "#{@default_ayadn_data_path}/config.yml"
12
- @configFileContents = loadConfig
13
- identityPrefix = @configFileContents['identity']['prefix']
14
- ayadn_data_path = Dir.home + @configFileContents['files']['ayadnfiles']
15
- @ayadn_configuration = {
16
- data_path: ayadn_data_path,
17
- posts_path: ayadn_data_path + "/#{identityPrefix}/posts",
18
- lists_path: ayadn_data_path + "/#{identityPrefix}/lists",
19
- files_path: ayadn_data_path + "/#{identityPrefix}/files",
20
- db_path: ayadn_data_path + "/#{identityPrefix}/db",
21
- last_page_id_path: ayadn_data_path + "/#{identityPrefix}/.pagination",
22
- messages_path: ayadn_data_path + "/#{identityPrefix}/messages",
23
- authorization_path: ayadn_data_path + "/#{identityPrefix}/.auth",
24
- api_config_path: ayadn_data_path + "/#{identityPrefix}/.api",
25
- progress_indicator: false,
26
- platform: RbConfig::CONFIG['host_os']
27
- }
28
- end
29
- def loadConfig
30
- if File.exists?(@installed_config_path)
31
- YAML::load_file(@installed_config_path)
32
- elsif File.exists?(File.expand_path(File.dirname(__FILE__)) + '/config.yml')
33
- YAML::load_file(File.expand_path(File.dirname(__FILE__)) + '/config.yml')
34
- else
35
- {
36
- "counts" => {
37
- "global" => 100,
38
- "unified" => 100,
39
- "checkins" => 100,
40
- "explore" => 100,
41
- "mentions" => 100,
42
- "starred" => 100,
43
- "posts" => 100,
44
- "search" => 200
45
- },
46
- "timeline" => {
47
- "downside" => true,
48
- "directed" => true,
49
- "streamback" => 30,
50
- "countdown_1" => 5,
51
- "countdown_2" => 15,
52
- "show_client" => true,
53
- "show_symbols" => true,
54
- "show_reposters" => true
55
- },
56
- "files" => {
57
- "ayadnfiles" => "/ayadn/data",
58
- "auto_save_sent_messages" => false,
59
- "auto_save_sent_posts" => false
60
- },
61
- "identity" => { "prefix" => "me" },
62
- "skipped" => {
63
- "sources" => [],
64
- "hashtags" => [],
65
- "mentions" => []
66
- },
67
- "pinboard" => {
68
- "username" => "",
69
- "password" => ""
70
- }
71
- }
72
- end
73
- end
74
- def saveConfig
75
- if File.exists?(@installed_config_path)
76
- File.open(@installed_config_path, 'w') {|f| f.write config.to_yaml }
77
- puts "\nDone!\n\n".green
78
- # else
79
- # File.open(File.expand_path(File.dirname(__FILE__)) + '/config.yml', 'w') {|f| f.write config.to_yaml }
80
- # puts "\nDone!\n\n".green
81
- end
82
- end
83
- def installConfig
84
- if File.exists?(@installed_config_path)
85
- puts "\nInstalled config file already exists. Replace with the new one? (N/y) ".red
86
- if STDIN.getch == ("y" || "Y")
87
- copyConfigFromMaster
88
- else
89
- abort("\nCanceled.\n\n".red)
90
- end
91
- else
92
- copyConfigFromMaster
93
- end
94
- end
95
- def copyConfigFromMaster
96
- FileUtils.cp(File.expand_path(File.dirname(__FILE__)) + '/config.yml', @installed_config_path)
97
- puts "\nDone.\n\n".green
98
- end
99
- def config
100
- @configFileContents
101
- end
102
- def ayadn_configuration
103
- @ayadn_configuration
104
- end
105
- def winplatforms
106
- /mswin|mingw|mingw32|cygwin/
107
- end
108
- def colorize(contentText)
109
- content = Array.new
110
- for word in contentText.split(" ") do
111
- if word =~ /#\w+/
112
- content.push(word.gsub(/#([A-Za-z0-9_]{1,255})(?![\w+])/, '#\1'.pink))
113
- #content.push(removeEndCharIfSpecial(word, "pink"))
114
- elsif word =~ /@\w+/
115
- content.push(word.gsub(/@([A-Za-z0-9_]{1,20})(?![\w+])/, '@\1'.red))
116
- #content.push(removeEndCharIfSpecial(word, "red"))
117
- #elsif word =~ /^http/ or word =~ /^photos.app.net/ or word =~ /^files.app.net/ or word =~ /^chimp.li/ or word =~ /^bli.ms/
118
- #content.push(word.magenta)
119
- else
120
- content.push(word)
121
- end
122
- end
123
- content.join(" ")
124
- end
125
- def removeEndCharIfSpecial(word, color)
126
- word_array = word.chars.to_a
127
- last_char = word_array.last
128
- if last_char =~ /[.,:;?!-'`&"()\/]/
129
- word_array.pop
130
- if color == "red"
131
- word_colored = word_array.join("").red
132
- elsif color == "pink"
133
- word_colored = word_array.join("").pink
134
- end
135
- word_colored.chars.to_a.push(last_char).join("")
136
- else
137
- if color == "red"
138
- word.red
139
- elsif color == "pink"
140
- word.pink
141
- end
142
- end
143
- end
144
-
145
- def getMarkdownText(str)
146
- str.gsub %r{
147
- \[ # Literal opening bracket
148
- ( # Capture what we find in here
149
- [^\]]+ # One or more characters other than close bracket
150
- ) # Stop capturing
151
- \] # Literal closing bracket
152
- \( # Literal opening parenthesis
153
- ( # Capture what we find in here
154
- [^)]+ # One or more characters other than close parenthesis
155
- ) # Stop capturing
156
- \) # Literal closing parenthesis
157
- }x, '\1'
158
- end
159
- def withoutSquareBraces(str)
160
- str.gsub %r{
161
- \[ # Literal opening bracket
162
- ( # Capture what we find in here
163
- [^\]]+ # One or more characters other than close bracket
164
- ) # Stop capturing
165
- \] # Literal closing bracket
166
- }x, ''
167
- end
168
- def countdown(value)
169
- value.downto(1) do |i|
170
- print "\r#{sprintf("%02d", i)} sec... QUIT WITH [CTRL+C]".cyan
171
- sleep 1
172
- end
173
- end
174
- def startBrowser(url)
175
- Process.detach(Process.spawn("sleep 1; open '#{url}'"))
176
- end
177
- def meta(meta)
178
- case meta['code']
179
- when 200
180
- puts "\nDone!\n".green
181
- when 301,302
182
- puts "\nRedirected.\n\n".red
183
- puts "#{meta.inspect}\n".red
184
- when 404
185
- puts "Does not exist (or has been deleted) => #{meta['code']}\n".red
186
- exit
187
- else
188
- abort("\nERROR: #{meta.to_s}\n".red)
189
- end
190
- end
191
- def checkHTTPResp(resp)
192
- case resp.code
193
- when !200
194
- abort("\nERROR: does not exist (or has been deleted) => #{resp.code} #{resp.body}\n".red)
195
- end
196
- end
197
- def saveToPinboard(post_id, pin_username, pin_password, link, tags, post_text, user_name)
198
- unless tags.nil?
199
- tags += ",ADN"
200
- else
201
- tags = "ADN"
202
- end
203
- post_text += " http://alpha.app.net/#{user_name}/post/#{post_id}"
204
- pinboard = Pinboard::Client.new(:username => pin_username, :password => pin_password)
205
- pinboard.add(:url => link, :tags => tags, :extended => post_text, :description => link)
206
- end
207
- end
208
- end
@@ -1,91 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
- require 'net/http'
4
- require 'openssl'
5
-
6
- class AyaDN
7
-
8
- # EXPERIMENT!!!
9
-
10
- def ayadn_userstream
11
- # first create with curl -i -H 'Authorization: BEARER xxx' "https://stream-channel.app.net/stream/user?auto_delete=1&include_annotations=1&include_html=0"
12
- # it stays open and returns a stream_id in the headers
13
- # TODO: replace curl with a good connection system: HTTP or Rest-Client
14
-
15
- puts "1. Create user stream\n".cyan
16
- puts "2. Connect to user stream\n".cyan
17
- puts "\n\nYour choice? \n\n".brown
18
- case STDIN.getch
19
- when "1"
20
- command = "sleep 1; curl -i -H 'Authorization: BEARER #{@token}' 'https://stream-channel.app.net/stream/user?auto_delete=1&include_annotations=1&include_html=0'"
21
- pid = Process.spawn(command)
22
- Process.detach(pid)
23
- exit
24
- when "2"
25
- puts "Paste stream id: "
26
- stream_id = STDIN.gets.chomp
27
- else
28
- puts $status.errorSyntax
29
- end
30
- last_page_id = nil
31
- start = Time.now
32
- $files.makedir($tools.ayadn_configuration[:data_path] + "/.temp/")
33
- f = File.new($tools.ayadn_configuration[:data_path] + "/.temp/#{stream_id}", "w")
34
- f.puts(stream_id)
35
- f.close
36
- @url = "https://alpha-api.app.net/stream/0/posts/stream/global?connection_id=#{stream_id}&since_id=#{last_page_id}&include_deleted=0"
37
- uri = URI.parse(@url)
38
- https = Net::HTTP.new(uri.host,uri.port)
39
- https.use_ssl = true
40
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
41
- request = Net::HTTP::Get.new(uri.request_uri)
42
- request["Authorization"] = "Bearer #{@token}"
43
- request["Content-Type"] = "application/json"
44
- response = https.request(request)
45
- @hash = JSON.parse(response.body)
46
- stream, last_page_id = completeStream
47
- displayScrollStream(stream)
48
- number_of_connections = 1
49
- total_size = 0
50
- loop do
51
- begin
52
- @url = "https://alpha-api.app.net/stream/0/posts/stream/global?connection_id=#{stream_id}&since_id=#{last_page_id}&include_deleted=0"
53
- uri = URI.parse(@url)
54
- request = Net::HTTP::Get.new(uri.request_uri)
55
- request["Authorization"] = "Bearer #{@token}"
56
- request["Content-Type"] = "application/json"
57
- before_request_id = last_page_id
58
- response = https.request(request)
59
- chunk_size = response['Content-Length']
60
- @hash = JSON.parse(response.body)
61
- stream, last_page_id = completeStream
62
- displayScrollStream(stream)
63
- last_page_id = before_request_id if last_page_id == nil
64
- number_of_connections += 1
65
- # puts "\nData chunks: \t#{number_of_connections}".magenta
66
- # puts "Chunk size: \t#{chunk_size.to_i.to_filesize}".magenta
67
- total_size += chunk_size.to_i
68
- # puts "Total size: \t#{total_size.to_filesize}".magenta
69
- # finish = Time.now
70
- # elapsed = finish.to_f - start.to_f
71
- # mins, secs = elapsed.divmod 60.0
72
- # puts "Total time:\t".magenta + "%3d:%04.2f".magenta%[mins.to_i, secs]
73
- # req_sec = number_of_connections.to_f/secs
74
- # puts "Req/sec: \t#{req_sec.round(2)}".magenta
75
- rescue Exception => e
76
- puts "\n\n"
77
- puts e.inspect
78
- finish = Time.now
79
- elapsed = finish.to_f - start.to_f
80
- mins, secs = elapsed.divmod 60.0
81
- puts "\n\nData chunks: #{number_of_connections}\n"
82
- puts "Total size: #{total_size.to_filesize}"
83
- puts "Elapsed time (min:secs.msecs): "
84
- puts("%3d:%04.2f"%[mins.to_i, secs])
85
- req_sec = number_of_connections.to_f/secs.to_f
86
- puts "Req/sec: #{req_sec.round(2)}\n\n"
87
- exit
88
- end
89
- end
90
- end
91
- end
@@ -1,120 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
- class AyaDN
4
- class View
5
- def build_pm_channels_infos
6
- $files.makedir($tools.ayadn_configuration[:messages_path])
7
- #meta = @hash['meta']
8
- #unread_messages = meta['unread_counts']['net.app.core.pm']
9
- the_channels = ""
10
- channels_list = []
11
- puts "\nGetting users infos, please wait a few seconds... (could take a while the first time if you have a lot of channels activated)\n".cyan
12
- @hash['data'].each do |item|
13
- channel_id = item['id']
14
- channel_type = item['type']
15
- if channel_type == "net.app.core.pm"
16
- channels_list.push(channel_id)
17
- total_messages = item['counts']['messages']
18
- #owner = "@" + item['owner']['username']
19
- #readers = item['readers']['user_ids']
20
- #you_write = item['writers']['you']
21
- #you_read = item['readers']['you']
22
- the_writers = []
23
- item['writers']['user_ids'].each do |writer|
24
- if writer != nil
25
- known_user = $files.users_read(writer)
26
- if known_user
27
- handle = "@" + known_user
28
- puts "\n#{writer} already known: #{handle}. Skipping the username search".green
29
- else
30
- puts "\nFetching username of user ##{writer}".green
31
- user = AyaDN::API.new(@token).getUserInfos(writer)
32
- username = user['data']['username']
33
- handle = "@" + username
34
- $files.users_write(writer, username)
35
- end
36
- $files.save_channel_id(channel_id, handle)
37
- the_writers.push(handle)
38
- end
39
- end
40
- the_channels << "\nChannel ID: ".cyan + "#{channel_id}\n".brown
41
- #the_channels << "Creator: ".cyan + owner.magenta + "\n"
42
- #the_channels << "Channels type: ".cyan + "#{channel_type}\n".brown
43
- the_channels << "Interlocutor(s): ".cyan + the_writers.join(", ").magenta + "\n"
44
- the_channels << "Messages: ".cyan + total_messages.to_s.green + "\n"
45
- if item['recent_message']
46
- if item['recent_message']['text']
47
- message_date = objectDate(item['recent_message']).join(" ")
48
- the_channels << "Last message by @#{item['recent_message']['user']['username']} (#{message_date}): \n".cyan + item['recent_message']['text'] + "\n"
49
- # id, text, username, message_date
50
- params = {
51
- id: channel_id,
52
- text: item['recent_message']['text'],
53
- username: item['recent_message']['user']['username'],
54
- message_date: message_date
55
- }
56
- $files.save_channel_message(params)
57
- end
58
- end
59
- end
60
- end
61
- the_channels << "\n"
62
- return the_channels, channels_list
63
- end
64
- def build_channels_infos
65
- the_channels = ""
66
- channels_list = []
67
- @hash['data'].each do |item|
68
- channel_id = item['id']
69
- channel_type = item['type']
70
- if channel_type != "net.app.core.pm"
71
- channels_list.push(channel_id)
72
- case channel_type
73
- when "net.app.ohai.journal"
74
- $files.save_channel_id(channel_id, "Ohai Journal")
75
- the_channels << "\nChannel ID: ".cyan + "#{channel_id}\n".brown + " -> " + "your Ohai Journal channel\n".green
76
- when "net.paste-app.clips"
77
- $files.save_channel_id(channel_id, "Paste-App Clips")
78
- the_channels << "\nChannel ID: ".cyan + "#{channel_id}\n".brown + " -> " + "your Paste-App Clips channel\n".green
79
- when "net.app.core.broadcast"
80
- item['annotations'].each do |anno|
81
- if anno['type'] == "net.app.core.broadcast.metadata"
82
- broadcast_name = anno['value']['title']
83
- $files.save_channel_id(channel_id, "#{broadcast_name} [Broadcast]")
84
- the_channels << "\nChannel ID: ".cyan + "#{channel_id}\n".brown + " -> " + "Broadcast channel: #{broadcast_name}\n".green
85
- end
86
- end
87
- when "net.patter-app.room"
88
- item['annotations'].each do |anno|
89
- if anno['type'] == "net.patter-app.settings"
90
- patter_room_name = anno['value']['name']
91
- $files.save_channel_id(channel_id, "#{patter_room_name} [Patter-App Room]")
92
- the_channels << "\nChannel ID: ".cyan + "#{channel_id}\n".brown + " -> " + "Patter-App Room: #{patter_room_name}\n".green
93
- next
94
- end
95
- end
96
- else
97
- $files.save_channel_id(channel_id, channel_type)
98
- the_channels << "\nChannel ID: ".cyan + "#{channel_id}\n".brown + " -> " + "#{channel_type}\n"
99
- end
100
- if item['recent_message']
101
- if item['recent_message']['text']
102
- message_date = objectDate(item['recent_message']).join(" ")
103
- the_channels << "Last message by @#{item['recent_message']['user']['username']} (#{message_date}): \n".cyan + item['recent_message']['text'] + "\n"
104
- # id, text, username, message_date
105
- params = {
106
- id: channel_id,
107
- text: item['recent_message']['text'],
108
- username: item['recent_message']['user']['username'],
109
- message_date: message_date
110
- }
111
- $files.save_channel_message(params)
112
- end
113
- end
114
- end
115
- end
116
- the_channels << "\n"
117
- return the_channels, channels_list
118
- end
119
- end
120
- end