ayadn 0.6.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,154 +1,221 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: utf-8
3
- class AyaDN
4
-
5
- AYADN_CLIENT_ID = "hFsCGArAjgJkYBHTHbZnUvzTmL4vaLHL"
6
- AYADN_CALLBACK_URL = "http://aya.io/ayadn/auth.html"
7
-
8
- BASE_URL = "https://alpha-api.app.net/"
9
-
10
- CONFIG_API_URL = BASE_URL + "stream/0/config"
11
-
12
- POSTS_URL = BASE_URL + "stream/0/posts/"
13
- USERS_URL = BASE_URL + "stream/0/users/"
14
- FILES_URL = BASE_URL + "stream/0/files/"
15
- CHANNELS_URL = BASE_URL + "stream/0/channels/"
16
- PM_URL = CHANNELS_URL + "pm/messages"
17
-
18
- class Endpoints
19
- def initialize(token)
20
- @token = token
21
- end
22
- def authorize_url
23
- "https://account.app.net/oauth/authenticate?client_id=#{AYADN_CLIENT_ID}&response_type=token&redirect_uri=#{AYADN_CALLBACK_URL}&scope=basic stream write_post follow public_messages messages files&include_marker=1"
24
- end
25
- def global
26
- POSTS_URL + "stream/global?access_token=#{@token}&count=#{$tools.config['counts']['global']}"
27
- end
28
- def unified
29
- POSTS_URL + "stream/unified?access_token=#{@token}&count=#{$tools.config['counts']['unified']}"
30
- end
31
- def unified_streamback
32
- POSTS_URL + "stream/unified?access_token=#{@token}&count=#{$tools.config['timeline']['streamback']}"
33
- end
34
- def single_post(post_id)
35
- POSTS_URL + "#{post_id}?access_token=#{@token}"
36
- end
37
- def explore(stream)
38
- case stream
39
- when "checkins"
40
- POSTS_URL + "stream/explore/checkins?access_token=#{@token}&count=#{$tools.config['counts']['checkins']}"
41
- when "trending", "conversations", "photos"
42
- POSTS_URL + "stream/explore/#{stream}?access_token=#{@token}&count=#{$tools.config['counts']['explore']}"
43
- end
44
- end
45
- def hashtags(tags)
46
- POSTS_URL + "tag/#{tags}"
47
- end
48
- def who_reposted(post_id)
49
- POSTS_URL + "#{post_id}/reposters/?access_token=#{@token}"
50
- end
51
- def who_starred(post_id)
52
- POSTS_URL + "#{post_id}/stars/?access_token=#{@token}"
53
- end
54
- def replies(post_id)
55
- POSTS_URL + "#{post_id}/replies/?access_token=#{@token}"
56
- end
57
- def star(post_id)
58
- POSTS_URL + "#{post_id}/star/?access_token=#{@token}"
59
- end
60
- def repost(post_id)
61
- POSTS_URL + "#{post_id}/repost/?access_token=#{@token}"
62
- end
63
- def search(words)
64
- POSTS_URL + "search?text=#{words}&access_token=#{@token}&count=#{$tools.config['counts']['search']}"
65
- end
66
- def mentions(username)
67
- USERS_URL + "#{username}/mentions/?access_token=#{@token}&count=#{$tools.config['counts']['mentions']}"
68
- end
69
- def posts(username)
70
- USERS_URL + "#{username}/posts/?access_token=#{@token}&count=#{$tools.config['counts']['posts']}"
71
- end
72
- def user_info(username)
73
- USERS_URL + "#{username}/?access_token=#{@token}"
74
- end
75
- def starred_posts(username)
76
- USERS_URL + "#{username}/stars/?access_token=#{@token}&count=#{$tools.config['counts']['starred']}"
77
- end
78
- def follow(username)
79
- USERS_URL + "#{username}/follow/?access_token=#{@token}"
80
- end
81
- def following(username)
82
- USERS_URL + "#{username}/following/?access_token=#{@token}"
83
- end
84
- def followers(username)
85
- USERS_URL + "#{username}/followers/?access_token=#{@token}"
86
- end
87
- def mute(username)
88
- USERS_URL + "#{username}/mute/?access_token=#{@token}"
89
- end
90
- def muted(username)
91
- USERS_URL + "#{username}/muted/?access_token=#{@token}"
92
- end
93
- def block(username)
94
- USERS_URL + "#{username}/block/?access_token=#{@token}"
95
- end
96
- def blocked(username)
97
- USERS_URL + "#{username}/blocked/?access_token=#{@token}"
98
- end
99
- def interactions
100
- USERS_URL + "me/interactions?access_token=#{@token}"
101
- end
102
- def channels
103
- CHANNELS_URL + "?access_token=#{@token}&count=200"
104
- end
105
- def messages(channel_id)
106
- CHANNELS_URL + "#{channel_id}/messages?access_token=#{@token}&count=200"
107
- end
108
- def get_message(channel_id, message_id)
109
- CHANNELS_URL + "#{channel_id}/messages/#{message_id}?access_token=#{@token}"
110
- end
111
- def files_list
112
- USERS_URL + "me/files?access_token=#{@token}"
113
- end
114
- def get_file(file_id)
115
- FILES_URL + "#{file_id}?access_token=#{@token}"
116
- end
117
- def get_multiple_files(file_ids)
118
- FILES_URL + "?ids=#{file_ids}&access_token=#{@token}"
119
- end
120
- def access_token
121
- "access_token=#{@token}"
122
- end
123
- def include_deleted
124
- "&include_deleted=1"
125
- end
126
- def exclude_deleted
127
- "&include_deleted=0"
128
- end
129
- def include_html
130
- "&include_html=1"
131
- end
132
- def exclude_html
133
- "&include_html=0"
134
- end
135
- def include_directed
136
- "&include_directed_posts=1"
137
- end
138
- def exclude_directed
139
- "&include_directed_posts=0"
140
- end
141
- def include_annotations
142
- "&include_annotations=1"
143
- end
144
- def exclude_annotations
145
- "&include_annotations=0"
146
- end
147
- def base_params
148
- "&include_html=0&include_annotations=1&include_deleted=1"
149
- end
150
- def light_params
151
- "&include_html=0&include_annotations=0&include_deleted=0"
152
- end
153
- end
154
- end
2
+ module Ayadn
3
+ class Endpoints
4
+
5
+ attr_accessor :ayadn_callback_url, :base_url, :config_api_url, :posts_url, :users_url, :files_url, :token_url, :channels_url, :pm_url
6
+
7
+ def initialize
8
+ @ayadn_callback_url = "http://aya.io/ayadn/auth.html"
9
+ @base_url = "https://alpha-api.app.net/"
10
+ @config_api_url = @base_url + "stream/0/config"
11
+ @posts_url = @base_url + "stream/0/posts/"
12
+ @users_url = @base_url + "stream/0/users/"
13
+ @files_url = @base_url + "stream/0/files/"
14
+ @token_url = @base_url + "stream/0/token/"
15
+ @channels_url = @base_url + "stream/0/channels/"
16
+ @pm_url = @channels_url + "pm/messages"
17
+ end
18
+
19
+ def authorize_url
20
+ "https://account.app.net/oauth/authenticate?client_id=#{Settings::AYADN_CLIENT_ID}&response_type=token&redirect_uri=#{@ayadn_callback_url}&scope=basic,stream,write_post,follow,public_messages,messages,files,update_profile&include_marker=1"
21
+ end
22
+
23
+ def token_info
24
+ "#{@token_url}?access_token=#{Settings.user_token}"
25
+ end
26
+
27
+ def file(file_id)
28
+ "#{@files_url}#{file_id}?access_token=#{Settings.user_token}"
29
+ end
30
+
31
+ def files
32
+ "#{@files_url}?access_token=#{Settings.user_token}"
33
+ end
34
+
35
+ def unified(options)
36
+ if options[:count] || options[:since_id]
37
+ @options_list = API.build_query(options)
38
+ else
39
+ @options_list = API.build_query({count: Settings.options[:counts][:unified]})
40
+ end
41
+ "#{@posts_url}stream/unified?access_token=#{Settings.user_token}#{@options_list}"
42
+ end
43
+
44
+ def checkins(options)
45
+ if options[:count] || options[:since_id]
46
+ @options_list = API.build_query(options)
47
+ else
48
+ @options_list = API.build_query({count: Settings.options[:counts][:checkins]})
49
+ end
50
+ "#{@posts_url}stream/explore/checkins?access_token=#{Settings.user_token}#{@options_list}"
51
+ end
52
+
53
+ def global(options)
54
+ if options[:count] || options[:since_id]
55
+ @options_list = API.build_query(options)
56
+ else
57
+ @options_list = API.build_query({count: Settings.options[:counts][:global]})
58
+ end
59
+ "#{@posts_url}stream/global?access_token=#{Settings.user_token}#{@options_list}"
60
+ end
61
+
62
+ def trending(options)
63
+ if options[:count] || options[:since_id]
64
+ @options_list = API.build_query(options)
65
+ else
66
+ @options_list = API.build_query({count: Settings.options[:counts][:trending]})
67
+ end
68
+ "#{@posts_url}stream/explore/trending?access_token=#{Settings.user_token}#{@options_list}"
69
+ end
70
+
71
+ def photos(options)
72
+ if options[:count] || options[:since_id]
73
+ @options_list = API.build_query(options)
74
+ else
75
+ @options_list = API.build_query({count: Settings.options[:counts][:photos]})
76
+ end
77
+ "#{@posts_url}stream/explore/photos?access_token=#{Settings.user_token}#{@options_list}"
78
+ end
79
+
80
+ def conversations(options)
81
+ if options[:count] || options[:since_id]
82
+ @options_list = API.build_query(options)
83
+ else
84
+ @options_list = API.build_query({count: Settings.options[:counts][:conversations]})
85
+ end
86
+ "#{@posts_url}stream/explore/conversations?access_token=#{Settings.user_token}#{@options_list}"
87
+ end
88
+
89
+ def mentions(username, options)
90
+ if options[:count]
91
+ @options_list = API.build_query(options)
92
+ else
93
+ @options_list = API.build_query({count: Settings.options[:counts][:mentions]})
94
+ end
95
+ "#{@users_url}#{username}/mentions/?access_token=#{Settings.user_token}#{@options_list}"
96
+ end
97
+
98
+ def posts(username, options)
99
+ if options[:count]
100
+ @options_list = API.build_query(options)
101
+ else
102
+ @options_list = API.build_query({count: Settings.options[:counts][:posts]})
103
+ end
104
+ "#{@users_url}#{username}/posts/?access_token=#{Settings.user_token}#{@options_list}"
105
+ end
106
+
107
+ def whatstarred(username, options)
108
+ if options[:count]
109
+ @options_list = API.build_query(options)
110
+ else
111
+ @options_list = API.build_query({count: Settings.options[:counts][:default]})
112
+ end
113
+ "#{@users_url}#{username}/stars/?access_token=#{Settings.user_token}#{@options_list}"
114
+ end
115
+
116
+ def interactions
117
+ "#{@users_url}me/interactions?access_token=#{Settings.user_token}"
118
+ end
119
+
120
+ def whoreposted(post_id)
121
+ "#{@posts_url}#{post_id}/reposters/?access_token=#{Settings.user_token}"
122
+ end
123
+
124
+ def whostarred(post_id)
125
+ "#{@posts_url}#{post_id}/stars/?access_token=#{Settings.user_token}"
126
+ end
127
+
128
+ def convo(post_id, options)
129
+ if options[:count]
130
+ @options_list = API.build_query(options)
131
+ else
132
+ @options_list = API.build_query({count: Settings.options[:counts][:convo]})
133
+ end
134
+ "#{@posts_url}#{post_id}/replies/?access_token=#{Settings.user_token}#{@options_list}"
135
+ end
136
+
137
+ def followings(username, options)
138
+ "#{@users_url}#{username}/following/?access_token=#{Settings.user_token}&count=#{options[:count]}&before_id=#{options[:before_id]}"
139
+ end
140
+
141
+ def followers(username, options)
142
+ "#{@users_url}#{username}/followers/?access_token=#{Settings.user_token}&count=#{options[:count]}&before_id=#{options[:before_id]}"
143
+ end
144
+
145
+ def muted(options)
146
+ "#{@users_url}me/muted/?access_token=#{Settings.user_token}&count=#{options[:count]}&before_id=#{options[:before_id]}"
147
+ end
148
+
149
+ def blocked(options)
150
+ "#{@users_url}me/blocked/?access_token=#{Settings.user_token}&count=#{options[:count]}&before_id=#{options[:before_id]}"
151
+ end
152
+
153
+ def hashtag(hashtag)
154
+ "#{@posts_url}tag/#{hashtag}"
155
+ end
156
+
157
+ def search(words, options)
158
+ if options[:count]
159
+ @options_list = API.build_query(options)
160
+ else
161
+ @options_list = API.build_query({count: Settings.options[:counts][:search]})
162
+ end
163
+ "#{@posts_url}search?text=#{words}&access_token=#{Settings.user_token}#{@options_list}"
164
+ end
165
+
166
+ def user(username)
167
+ "#{@users_url}#{username}?access_token=#{Settings.user_token}&include_user_annotations=1"
168
+ end
169
+
170
+ def single_post(post_id, options)
171
+ @options_list = API.build_query(options)
172
+ "#{@posts_url}#{post_id}?access_token=#{Settings.user_token}#{@options_list}"
173
+ end
174
+
175
+ def files_list(options)
176
+ if options[:count]
177
+ @options_list = API.build_query(options)
178
+ else
179
+ @options_list = API.build_query({count: Settings.options[:counts][:files]})
180
+ end
181
+ "#{@users_url}me/files?access_token=#{Settings.user_token}#{@options_list}"
182
+ end
183
+
184
+ def delete_post(post_id)
185
+ "#{@posts_url}#{post_id}?access_token=#{Settings.user_token}"
186
+ end
187
+
188
+ def follow(username)
189
+ "#{@users_url}#{username}/follow?access_token=#{Settings.user_token}"
190
+ end
191
+
192
+ def mute(username)
193
+ "#{@users_url}#{username}/mute?access_token=#{Settings.user_token}"
194
+ end
195
+
196
+ def block(username)
197
+ "#{@users_url}#{username}/block?access_token=#{Settings.user_token}"
198
+ end
199
+
200
+ def repost(post_id)
201
+ "#{@posts_url}#{post_id}/repost?access_token=#{Settings.user_token}"
202
+ end
203
+
204
+ def star(post_id)
205
+ "#{@posts_url}#{post_id}/star?access_token=#{Settings.user_token}"
206
+ end
207
+
208
+ def channels(options)
209
+ "#{@channels_url}?access_token=#{Settings.user_token}#{API.build_query(options)}"
210
+ end
211
+
212
+ def messages(channel_id, options)
213
+ "#{@channels_url}#{channel_id}/messages?access_token=#{Settings.user_token}#{API.build_query(options)}"
214
+ end
215
+
216
+ def ayadnlog
217
+ "#{@channels_url}47348/messages?access_token=#{Settings.user_token}"
218
+ end
219
+
220
+ end
221
+ end
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+ module Ayadn
3
+ class Errors
4
+ def self.global_error(where, args, error)
5
+ [where, args, error].each do |el|
6
+ self.detokenize(el)
7
+ end
8
+ Logs.rec.error "--BEGIN--"
9
+ Logs.rec.error "#{error}"
10
+ Logs.rec.debug "LOCATION: #{where}"
11
+ Logs.rec.debug "DATA: #{args}" unless args.nil?
12
+ Logs.rec.debug "STACK: #{caller}"
13
+ Logs.rec.error "--END--"
14
+ puts "\n(error logged in #{Settings.config[:paths][:log]}/ayadn.log)\n".color(:blue)
15
+ #raise error
16
+ exit
17
+ end
18
+ def self.error(status)
19
+ Logs.rec.error status
20
+ end
21
+ def self.warn(warning)
22
+ Logs.rec.warn warning
23
+ end
24
+ def self.info(msg)
25
+ Logs.rec.info msg
26
+ end
27
+ def self.repost(repost, original)
28
+ Logs.rec.info "Post #{repost} is a repost. Using original: #{original}."
29
+ end
30
+
31
+ private
32
+
33
+ def self.detokenize(string)
34
+ string.to_s.gsub!(/token=[a-zA-Z0-9_-]+/, "token=XXX") unless string.nil?
35
+ end
36
+ end
37
+ end
data/lib/ayadn/extend.rb CHANGED
@@ -1,9 +1,8 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: utf-8
3
2
  class String
4
- def is_integer?
5
- self.to_i.to_s == self
6
- end
3
+ def is_integer?
4
+ self.to_i.to_s == self
5
+ end
7
6
  end
8
7
  class Integer
9
8
  def to_filesize
@@ -13,11 +12,6 @@ class Integer
13
12
  'MB' => 1024 * 1024 * 1024,
14
13
  'GB' => 1024 * 1024 * 1024 * 1024,
15
14
  'TB' => 1024 * 1024 * 1024 * 1024 * 1024
16
- }.each_pair { |e, s| return "#{(self.to_f / (s / 1024)).round(2)}#{e}" if self < s }
15
+ }.each_pair { |e, s| return "#{(self.to_f / (s / 1024)).round(2)} #{e}" if self < s }
17
16
  end
18
17
  end
19
- class Numeric
20
- def percent_of(n)
21
- self.to_f / n.to_f * 100.0
22
- end
23
- end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ module Ayadn
3
+ class FileOps
4
+
5
+ def self.save_post(resp)
6
+ File.write(Settings.config[:paths][:posts] + "/#{resp['data']['id']}.json", resp['data'].to_json)
7
+ end
8
+
9
+ def self.save_message(resp)
10
+ File.write(Settings.config[:paths][:messages] + "/#{resp['data']['id']}.json", resp['data'].to_json)
11
+ end
12
+
13
+ def self.save_followings_list(list)
14
+ fg = get_users(list)
15
+ File.write(Settings.config[:paths][:lists] + "/followings.json", fg.to_json)
16
+ end
17
+
18
+ def self.save_followers_list(list)
19
+ fr = get_users(list)
20
+ File.write(Settings.config[:paths][:lists] + "/followers.json", fr.to_json)
21
+ end
22
+
23
+ def self.save_muted_list(list)
24
+ mt = get_users(list)
25
+ File.write(Settings.config[:paths][:lists] + "/muted.json", mt.to_json)
26
+ end
27
+
28
+ def self.download_url(name, url)
29
+ file = CNX.get_response_from(url)
30
+ File.write(Settings.config[:paths][:downloads] + "/#{name}", file)
31
+ end
32
+
33
+ def self.old_ayadn?
34
+ Dir.exist?(Dir.home + "/ayadn/data")
35
+ end
36
+
37
+ private
38
+
39
+ def get_users(list)
40
+ h = {}
41
+ list.each do |k,v|
42
+ h[k] = { username: v[0], name: v[1] }
43
+ end
44
+ h
45
+ end
46
+
47
+ end
48
+ end