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
data/CONTRIBUTORS.md DELETED
@@ -1,5 +0,0 @@
1
- # Contributors
2
- Contributors are identified by name and ADN handle.
3
-
4
- - Code: Eric Dejonckheere (@ericd)
5
- - Gem: Jeremy W. Sherman (@jws)
data/LICENSE.md DELETED
@@ -1,14 +0,0 @@
1
- Copyright (c) 2014, [Eric Dejonckheere](https://alpha.app.net/ericd)
2
- and contributors (see CONTRIBUTORS.md).
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted, provided that the above
6
- copyright notice and this permission notice appear in all copies.
7
-
8
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -1,84 +0,0 @@
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
@@ -1,226 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'json'
3
- require 'net/http'
4
- require 'openssl'
5
-
6
- # encoding: utf-8
7
- class AyaDN
8
- class API
9
- # WIP
10
- # TESTING DIFFERENT WAYS
11
- # TODO: DRY
12
- def check_http_error_code(body)
13
- code = JSON.parse(body)
14
- case code['meta']['code']
15
- when 204
16
- puts "\nNo content (or incomplete).\n\n".red
17
- exit
18
- when 400
19
- puts "\nBad request.\n\n".red
20
- puts code['meta'].inspect
21
- exit
22
- when 401
23
- puts "\nUnauthorized.\n\n".red
24
- exit
25
- when 403
26
- puts "\nForbidden.\n\n".red
27
- exit
28
- when 404
29
- puts "\nDoes not exist (or has been deleted) => \n\n#{code}\n\n".red
30
- exit
31
- when 429
32
- puts "\nToo many requests.\n\n".red
33
- exit
34
- when 507
35
- puts "\nInsufficient storage.\n\n".red
36
- exit
37
- end
38
- end
39
- def http_get(target)
40
- encoded_url = URI.encode("#{target}")
41
- uri = URI.parse(encoded_url)
42
- https = Net::HTTP.new(uri.host,uri.port)
43
- https.use_ssl = true
44
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
45
- request = Net::HTTP::Get.new(uri.request_uri)
46
- request["Authorization"] = "Bearer #{@token}"
47
- request["Content-Type"] = "application/json"
48
- if @progress_indicator == false
49
- #print "Connecting to #{uri.host}#{uri.path} ...\n\n".cyan
50
- response = https.request(request)
51
- check_http_error_code(response.body)
52
- return response.body
53
- else
54
- #print "\rConnecting to #{uri.host}#{uri.path}".cyan
55
- body = ''
56
- https.request(request) do |res|
57
- #fileSize = res['Content-Length'].to_i
58
- #bytesTransferred = 0
59
- res.read_body do |part|
60
- #bytesTransferred += part.length
61
- #rounded = bytesTransferred.percent_of(fileSize).round(2)
62
- #print "\rFetching data: ".cyan + "#{rounded} ".brown
63
- # print "\rDownloading response from App.net\t#{bytesTransferred.to_filesize}"
64
- body << part
65
- end
66
- end
67
- #print "\r "
68
- #puts ""
69
- check_http_error_code(body)
70
- return body
71
- end
72
- end
73
- def http_delete
74
- uri = URI("#{@url}")
75
- https = Net::HTTP.new(uri.host,uri.port)
76
- https.use_ssl = true
77
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
78
- request = Net::HTTP::Delete.new(uri.path)
79
- request["Authorization"] = "Bearer #{@token}"
80
- request["Content-Type"] = "application/json"
81
- https.request(request)
82
- end
83
- def http_download(target=nil)
84
- uri = URI("#{target}")
85
- final_uri = ''
86
- open(uri) do |h|
87
- final_uri = h.base_uri.to_s
88
- end
89
- new_uri = URI.parse(final_uri)
90
- https = Net::HTTP.new(new_uri.host,new_uri.port)
91
- https.use_ssl = true
92
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
93
- request = Net::HTTP::Get.new(new_uri.request_uri)
94
- request["Authorization"] = "Bearer #{@token}"
95
- request["Content-Type"] = "application/json"
96
- https.request(request)
97
- end
98
- #####
99
- # experimenting
100
- # def createIncompleteFileUpload(file_name) #this part works
101
- # https, request = connectWithHTTP(FILES_URL)
102
- # payload = {
103
- # "kind" => "image",
104
- # "type" => "com.ayadn.files",
105
- # "name" => File.basename(file_name),
106
- # "public" => true
107
- # }.to_json
108
- # response = https.request(request, payload)
109
- # return response.body
110
- # end
111
- # def setFileContentUpload(file_id, file_path, file_token) #this one doesn't
112
- # url = FILES_URL + "#{file_id}/content?file_token=#{file_token}"
113
- # uri = URI("#{url}")
114
- # # ...
115
- # end
116
- #####
117
-
118
- def httpPutFile(file, data) # data must be json
119
- url = "https://alpha-api.app.net/stream/0/files/#{file}"
120
- uri = URI("#{url}")
121
- https = Net::HTTP.new(uri.host,uri.port)
122
- https.use_ssl = true
123
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
124
- request = Net::HTTP::Put.new(uri.path)
125
- request["Authorization"] = "Bearer #{@token}"
126
- request["Content-Type"] = "application/json"
127
- return https.request(request, data)
128
- end
129
-
130
- def connectWithHTTP(url)
131
- uri = URI("#{url}")
132
- https = Net::HTTP.new(uri.host,uri.port)
133
- https.use_ssl = true
134
- https.verify_mode = OpenSSL::SSL::VERIFY_NONE
135
- request = Net::HTTP::Post.new(uri.path)
136
- request["Authorization"] = "Bearer #{@token}"
137
- request["Content-Type"] = "application/json"
138
- return https, request
139
- end
140
- def httpPost(url)
141
- https, request = connectWithHTTP(url)
142
- return https.request(request)
143
- end
144
- def httpSendMessage(target, text)
145
- url = PM_URL
146
- url += "?include_annotations=1"
147
- https, request = connectWithHTTP(url)
148
- entities_content = {
149
- "parse_markdown_links" => true,
150
- "parse_links" => true
151
- }
152
- ayadnAnno = clientAnnotations
153
- destinations = []
154
- payload = {
155
- "text" => "#{text}",
156
- "destinations" => destinations.push(target),
157
- "entities" => entities_content,
158
- "annotations" => ayadnAnno
159
- }.to_json
160
- response = https.request(request, payload)
161
- return response.body
162
- end
163
- def httpSendMessageToChannel(target, text)
164
- url = CHANNELS_URL
165
- url += "#{target}/messages"
166
- #url += "&include_annotations=1"
167
-
168
- https, request = connectWithHTTP(url)
169
- entities_content = {
170
- "parse_markdown_links" => true,
171
- "parse_links" => true
172
- }
173
- ayadnAnno = clientAnnotations
174
- #destinations = []
175
- payload = {
176
- "text" => "#{text}",
177
- "entities" => entities_content,
178
- "annotations" => ayadnAnno
179
- }.to_json
180
- response = https.request(request, payload)
181
- return response.body
182
- end
183
- def httpSend(text, replyto = nil)
184
- url = POSTS_URL
185
- url += "?include_annotations=1"
186
- https, request = connectWithHTTP(url)
187
- entities_content = {
188
- "parse_markdown_links" => true,
189
- "parse_links" => true
190
- }
191
- ayadnAnno = clientAnnotations
192
- if replyto == nil
193
- payload = {
194
- "text" => "#{text}",
195
- "entities" => entities_content,
196
- "annotations" => ayadnAnno
197
- }.to_json
198
- else
199
- payload = {
200
- "text" => "#{text}",
201
- "reply_to" => "#{replyto}",
202
- "entities" => entities_content,
203
- "annotations" => ayadnAnno
204
- }.to_json
205
- end
206
- response = https.request(request, payload)
207
- return response.body
208
- end
209
-
210
- def clientAnnotations
211
- ayadn_annotations = [{
212
- "type" => "com.ayadn.client",
213
- "value" => {
214
- "+net.app.core.user" => {
215
- "user_id" => "@ayadn",
216
- "format" => "basic"
217
- }
218
- }
219
- },{
220
- "type" => "com.ayadn.client",
221
- "value" => { "url" => "http://ayadn-app.net" }
222
- }]
223
- return ayadn_annotations
224
- end
225
- end
226
- end
data/lib/ayadn/colors.rb DELETED
@@ -1,62 +0,0 @@
1
- class String
2
- def reddish;
3
- "\033[1;31m#{self}\033[0m"
4
- end
5
- def pink;
6
- "\033[1;35m#{self}\033[0m"
7
- end
8
- def black;
9
- "\033[30m#{self}\033[0m"
10
- end
11
- def red;
12
- "\033[31m#{self}\033[0m"
13
- end
14
- def green;
15
- "\033[32m#{self}\033[0m"
16
- end
17
- def brown;
18
- "\033[33m#{self}\033[0m"
19
- end
20
- def blue;
21
- "\033[34m#{self}\033[0m"
22
- end
23
- def magenta;
24
- "\033[35m#{self}\033[0m"
25
- end
26
- def cyan;
27
- "\033[36m#{self}\033[0m"
28
- end
29
- def gray;
30
- "\033[37m#{self}\033[0m"
31
- end
32
- def bg_black;
33
- "\033[40m#{self}\0330m"
34
- end
35
- def bg_red;
36
- "\033[41m#{self}\033[0m"
37
- end
38
- def bg_green;
39
- "\033[42m#{self}\033[0m"
40
- end
41
- def bg_brown;
42
- "\033[43m#{self}\033[0m"
43
- end
44
- def bg_blue;
45
- "\033[44m#{self}\033[0m"
46
- end
47
- def bg_magenta;
48
- "\033[45m#{self}\033[0m"
49
- end
50
- def bg_cyan;
51
- "\033[46m#{self}\033[0m"
52
- end
53
- def bg_gray;
54
- "\033[47m#{self}\033[0m"
55
- end
56
- def bold;
57
- "\033[1m#{self}\033[22m"
58
- end
59
- def reverse_color;
60
- "\033[7m#{self}\033[27m"
61
- end
62
- end
data/lib/ayadn/config.yml DELETED
@@ -1,35 +0,0 @@
1
- ---
2
- counts: # number of elements retrieved by a stream on the first access, 200 max
3
- global: 50
4
- unified: 50
5
- checkins: 50
6
- explore: 50
7
- mentions: 50
8
- posts: 50
9
- starred: 50
10
- search: 50
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: true
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:
data/lib/ayadn/debug.rb DELETED
@@ -1,36 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # encoding: utf-8
3
- class AyaDN
4
- def debugStream
5
- puts @view.new(@hash).showDebugStream
6
- end
7
- def ayadnDebugStream
8
- @hash = @api.getUnified(nil)
9
- debugStream
10
- end
11
- def ayadnDebugPost(postID)
12
- @hash = @api.getPostInfos(postID)
13
- debugStream
14
- end
15
- def ayadnDebugUser(username)
16
- @hash = @api.getUserInfos(username)
17
- debugStream
18
- end
19
- def ayadnDebugMessage(channel_id, message_id)
20
- @hash = @api.getUniqueMessage(channel_id, message_id)
21
- debugStream
22
- end
23
- def buildDebugStream(post_hash)
24
- # ret_string = ""
25
- # post_hash.each do |k, v|
26
- # ret_string << "#{k}: #{v}\n\n"
27
- # end
28
- jj post_hash
29
- #exit
30
- #return ret_string
31
- end
32
- def ayadnDebugChannel(channel)
33
- @hash = @api.getMessages(channel, nil)
34
- jj @hash
35
- end
36
- end