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,106 @@
1
+ # encoding: utf-8
2
+ module Ayadn
3
+ class Alias < Thor
4
+
5
+ desc "alias create CHANNEL ALIAS", "Creates an alias for a channel"
6
+ long_desc Descriptions.alias_create
7
+ def create(*args)
8
+ begin
9
+ init
10
+ unless args.empty?
11
+ channel, channel_alias = args[0], args[1]
12
+ else
13
+ puts Status.wrong_arguments
14
+ exit
15
+ end
16
+ if channel.is_integer?
17
+ Databases.create_alias(channel, channel_alias)
18
+ Logs.rec.info "Added alias '#{channel_alias}' for channel #{channel}."
19
+ puts Status.done
20
+ else
21
+ puts Status.error_missing_channel_id
22
+ end
23
+ rescue => e
24
+ Errors.global_error("alias/create", args, e)
25
+ ensure
26
+ Databases.close_all
27
+ end
28
+ end
29
+
30
+ desc "alias delete ALIAS", "Deletes a previously created alias"
31
+ long_desc Descriptions.alias_delete
32
+ def delete(*args)
33
+ begin
34
+ init
35
+ unless args.empty?
36
+ Databases.delete_alias(args[0])
37
+ Logs.rec.info "Deleted alias '#{args[0]}'."
38
+ puts Status.done
39
+ else
40
+ puts Status.wrong_arguments
41
+ exit
42
+ end
43
+ rescue => e
44
+ Errors.global_error("alias/delete", args, e)
45
+ ensure
46
+ Databases.close_all
47
+ end
48
+ end
49
+
50
+ desc "alias import DATABASE", "Imports an aliases database from a backed up Ayadn account"
51
+ long_desc Descriptions.alias_import
52
+ def import(database)
53
+ begin
54
+ init
55
+ unless database.nil?
56
+ new_db = File.realpath(database)
57
+ else
58
+ puts Status.wrong_arguments
59
+ exit
60
+ end
61
+ if File.exist?(new_db)
62
+ Databases.import_aliases(new_db)
63
+ Logs.rec.info "Imported '#{new_db}' values in aliases database."
64
+ puts Status.done
65
+ else
66
+ puts "\nFile '#{new_db}' doesn't exist.".color(:red)
67
+ end
68
+ rescue => e
69
+ Errors.global_error("alias/import", database, e)
70
+ ensure
71
+ Databases.close_all
72
+ end
73
+ end
74
+
75
+ desc "alias list", "List previously created aliases"
76
+ long_desc Descriptions.alias_list
77
+ def list
78
+ begin
79
+ init
80
+ puts "\e[H\e[2J"
81
+ list = Databases.aliases
82
+ unless list.empty? || list.nil?
83
+ puts Workers.new.build_aliases_list(list)
84
+ puts "\n"
85
+ else
86
+ puts Status.empty_list
87
+ end
88
+ rescue => e
89
+ Errors.global_error("alias/list", args, e)
90
+ ensure
91
+ Databases.close_all
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def init
98
+ Settings.load_config
99
+ Settings.get_token
100
+ Settings.init_config
101
+ Logs.create_logger
102
+ Databases.open_databases
103
+ end
104
+
105
+ end
106
+ end
data/lib/ayadn/api.rb CHANGED
@@ -1,302 +1,313 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: utf-8
3
- class AyaDN
4
- class API
5
- def initialize(token)
6
- @token = token
7
- @endpoints = AyaDN::Endpoints.new(@token)
8
- end
9
- def makeAuthorizeURL
10
- @endpoints.authorize_url
11
- end
12
-
13
- def getHash
14
- JSON.parse(http_get(@url))
15
- end
16
-
17
- def checkLastPageID(last_page_id)
18
- @url += "&since_id=#{last_page_id}" if last_page_id != nil
19
- end
20
-
21
- def getAPIConfig
22
- @url = CONFIG_API_URL
23
- getHash
24
- end
25
-
26
- def getGlobal(last_page_id)
27
- @url = @endpoints.global
28
- @url += @endpoints.base_params
29
- @url += @endpoints.include_directed if $tools.config['timeline']['directed']
30
- checkLastPageID(last_page_id)
31
- getHash
32
- end
33
- def getUnified(last_page_id)
34
- @url = @endpoints.unified
35
- @url += @endpoints.base_params
36
- @url += @endpoints.include_directed if $tools.config['timeline']['directed']
37
- checkLastPageID(last_page_id)
38
- getHash
39
- end
40
- def getSimpleUnified
41
- @url = @endpoints.unified_streamback
42
- @url += @endpoints.base_params
43
- @url += @endpoints.include_directed if $tools.config['timeline']['directed']
44
- getHash
45
- end
46
- def getInteractions
47
- @url = @endpoints.interactions
48
- #checkLastPageID(last_page_id)
49
- getHash
50
- end
51
- def getHashtags(tag)
52
- @url = @endpoints.hashtags(tag)
53
- getHash
54
- end
55
- def getExplore(stream, last_page_id)
56
- @url = @endpoints.explore(stream)
57
- @url += @endpoints.base_params
58
- checkLastPageID(last_page_id)
59
- getHash
60
- end
61
- def getUserMentions(username, last_page_id)
62
- @url = @endpoints.mentions(username)
63
- @url += @endpoints.light_params
64
- checkLastPageID(last_page_id)
65
- getHash
66
- end
67
- def getUserPosts(username, last_page_id)
68
- @url = @endpoints.posts(username)
69
- @url += @endpoints.base_params
70
- checkLastPageID(last_page_id)
71
- getHash
72
- end
73
- def getUserInfos(username)
74
- @url = @endpoints.user_info(username)
75
- @url += @endpoints.base_params
76
- getHash
77
- end
78
- def getWhoReposted(post_id)
79
- @url = @endpoints.who_reposted(post_id)
80
- @url += @endpoints.light_params
81
- getHash
82
- end
83
- def getWhoStarred(post_id)
84
- @url = @endpoints.who_starred(post_id)
85
- @url += @endpoints.light_params
86
- getHash
87
- end
88
- def getPostInfos(post_id)
89
- @url = @endpoints.single_post(post_id)
90
- @url += @endpoints.base_params
91
- getHash
92
- end
93
- def getSinglePost(post_id)
94
- @url = @endpoints.single_post(post_id)
95
- @url += @endpoints.light_params
96
- getHash
97
- end
98
- def getStarredPosts(username)
99
- @url = @endpoints.starred_posts(username)
100
- @url += @endpoints.light_params
101
- getHash
102
- end
103
- def getPostReplies(post_id)
104
- @url = @endpoints.replies(post_id)
105
- @url += @endpoints.base_params
106
- getHash
107
- end
108
- def getPostMentions(post_id)
109
- @url = @endpoints.single_post(post_id)
110
- @url += @endpoints.light_params
111
- theHash = getHash
112
- postInfo = theHash['data']
113
- #rawText = postInfo['text']
114
- postMentionsArray = []
115
- postInfo['entities']['mentions'].each { |item| postMentionsArray.push(item['name']) }
116
- return postMentionsArray, postInfo['user']['username'], postInfo['repost_of']
117
- end
118
- def getUserName(username)
119
- @url = @endpoints.user_info(username)
120
- @url += @endpoints.light_params
121
- theHash = getHash
122
- theHash['data']['username']
123
- end
124
- def goDelete(post_id)
125
- @url = @endpoints.single_post(post_id)
126
- @url += @endpoints.light_params
127
- isTherePost, isYours = ifExists(post_id)
128
- return isTherePost, isYours
129
- end
130
- def starPost(post_id)
131
- @url = @endpoints.star(post_id)
132
- @url += @endpoints.light_params
133
- httpPost(@url)
134
- end
135
- def unstarPost(post_id)
136
- @url = @endpoints.star(post_id)
137
- @url += @endpoints.light_params
138
- $tools.checkHTTPResp(http_delete())
139
- end
140
- def repostPost(post_id)
141
- @url = @endpoints.repost(post_id)
142
- @url += @endpoints.light_params
143
- httpPost(@url)
144
- end
145
- def unrepostPost(post_id)
146
- @url = @endpoints.repost(post_id)
147
- @url += @endpoints.light_params
148
- $tools.checkHTTPResp(http_delete())
149
- end
150
- def ifExists(post_id)
151
- theHash = getHash
152
- postInfo = theHash['data']
153
- return postInfo['text'], postInfo['user']['username']
154
- end
155
- def getOriginalPost(post_id)
156
- theHash = getHash
157
- theHash['data']['repost_of']['id']
158
- end
159
- def getUserFollowInfo(username)
160
- @url = @endpoints.user_info(username)
161
- @url += @endpoints.light_params
162
- theHash = getHash
163
- {you_follow: theHash['data']['you_follow'], follows_you: theHash['data']['follows_you']}
164
- end
165
- def getUserMuteInfo(username)
166
- @url = @endpoints.user_info(username)
167
- @url += @endpoints.light_params
168
- theHash = getHash
169
- theHash['data']['you_muted']
170
- end
171
- def getUserBlockInfo(username)
172
- @url = @endpoints.user_info(username)
173
- @url += @endpoints.light_params
174
- theHash = getHash
175
- theHash['data']['you_blocked']
176
- end
177
- def muteUser(username)
178
- @url = @endpoints.mute(username)
179
- @url += @endpoints.light_params
180
- httpPost(@url)
181
- end
182
- def unmuteUser(username)
183
- @url = @endpoints.mute(username)
184
- @url += @endpoints.light_params
185
- $tools.checkHTTPResp(http_delete())
186
- end
187
- def blockUser(username)
188
- @url = @endpoints.block(username)
189
- @url += @endpoints.light_params
190
- httpPost(@url)
191
- end
192
- def unblockUser(username)
193
- @url = @endpoints.block(username)
194
- @url += @endpoints.light_params
195
- $tools.checkHTTPResp(http_delete())
196
- end
197
- def followUser(username)
198
- @url = @endpoints.follow(username)
199
- @url += @endpoints.light_params
200
- httpPost(@url)
201
- end
202
- def unfollowUser(username)
203
- @url = @endpoints.follow(username)
204
- @url += @endpoints.light_params
205
- $tools.checkHTTPResp(http_delete())
206
- end
207
- def getFollowings(username, beforeID)
208
- @url = @endpoints.following(username)
209
- @url += @endpoints.light_params
210
- @url += "&count=200"
211
- @url += "&before_id=#{beforeID}" if beforeID != nil
212
- getHash
213
- end
214
- def getFollowers(username, beforeID)
215
- @url = @endpoints.followers(username)
216
- @url += @endpoints.light_params
217
- @url += "&count=200"
218
- @url += "&before_id=#{beforeID}" if beforeID != nil
219
- getHash
220
- end
221
- def getMuted(username, beforeID)
222
- @url = @endpoints.muted(username)
223
- @url += @endpoints.light_params
224
- @url += "&count=200"
225
- @url += "&before_id=#{beforeID}" if beforeID != nil
226
- getHash
227
- end
228
- def getBlocked(username, beforeID)
229
- @url = @endpoints.blocked(username)
230
- @url += @endpoints.light_params
231
- @url += "&count=200"
232
- @url += "&before_id=#{beforeID}" if beforeID != nil
233
- getHash
234
- end
235
- def getSearch(words)
236
- @url = @endpoints.search(words)
237
- @url += @endpoints.base_params
238
- getHash
239
- end
240
- def unique_message(channel_id, message_id)
241
- @url = @endpoints.get_message(channel_id, message_id)
242
- @url += @endpoints.base_params
243
- end
244
- def getUniqueMessage(channel_id, message_id)
245
- @url = @endpoints.get_message(channel_id, message_id)
246
- @url += @endpoints.base_params
247
- getHash
248
- end
249
- def getMessages(channel, last_page_id)
250
- @url = @endpoints.messages(channel)
251
- @url += @endpoints.base_params
252
- @url += "&include_machine=1"
253
- checkLastPageID(last_page_id)
254
- getHash
255
- end
256
- def get_pm_channels
257
- @url = @endpoints.channels
258
- @url += @endpoints.base_params
259
- @url += "&channel_types=net.app.core.pm"
260
- @url += "&include_recent_message=1"
261
- getHash
262
- end
263
- def get_channels
264
- @url = @endpoints.channels
265
- @url += @endpoints.base_params
266
- @url += "&include_recent_message=1"
267
- getHash
268
- end
269
- def getFilesList(beforeID)
270
- @url = @endpoints.files_list
271
- @url += @endpoints.light_params
272
- @url += "&before_id=#{beforeID}" if beforeID != nil
273
- getHash
274
- end
275
- def getSingleFile(file_id)
276
- @url = @endpoints.get_file(file_id)
277
- @url += @endpoints.light_params
278
- getHash
279
- end
280
- def getMultipleFiles(file_ids)
281
- @url = @endpoints.get_multiple_files(file_ids)
282
- @url += @endpoints.light_params
283
- getHash
284
- end
285
- def deleteFile(file_id)
286
- @url = @endpoints.get_file(file_id)
287
- @url += @endpoints.light_params
288
- $tools.checkHTTPResp(http_delete())
289
- end
290
- def deleteMessage(channel_id, message_id)
291
- @url = @endpoints.get_message(channel_id, message_id)
292
- @url += @endpoints.access_token
293
- $tools.checkHTTPResp(http_delete())
294
- end
295
- # def deactivateChannel(channel_id)
296
- # @url = CHANNELS_URL + "#{channel_id}?"
297
- # @url += @endpoints.access_token
298
- # resp = http_delete
299
- # $tools.checkHTTPResp(resp)
300
- # end
301
- end
302
- end
2
+ module Ayadn
3
+ class API
4
+
5
+ def get_unified(options)
6
+ if options[:new] || options[:scroll]
7
+ options = {since_id: Databases.pagination['unified']}
8
+ end
9
+ get_parsed_response(Endpoints.new.unified(options))
10
+ end
11
+
12
+ def get_checkins(options)
13
+ if options[:new] || options[:scroll]
14
+ options = {since_id: Databases.pagination['explore:checkins']}
15
+ end
16
+ get_parsed_response(Endpoints.new.checkins(options))
17
+ end
18
+
19
+ def get_global(options)
20
+ if options[:new] || options[:scroll]
21
+ options = {since_id: Databases.pagination['global']}
22
+ end
23
+ get_parsed_response(Endpoints.new.global(options))
24
+ end
25
+
26
+ def get_trending(options)
27
+ if options[:new] || options[:scroll]
28
+ options = {since_id: Databases.pagination['explore:trending']}
29
+ end
30
+ get_explore(:trending, options)
31
+ end
32
+ def get_photos(options)
33
+ if options[:new] || options[:scroll]
34
+ options = {since_id: Databases.pagination['explore:photos']}
35
+ end
36
+ get_explore(:photos, options)
37
+ end
38
+ def get_conversations(options)
39
+ if options[:new] || options[:scroll]
40
+ options = {since_id: Databases.pagination['explore:replies']}
41
+ end
42
+ get_explore(:conversations, options)
43
+ end
44
+
45
+ def get_explore(explore, options)
46
+ url = Endpoints.new.trending(options) if explore == :trending
47
+ url = Endpoints.new.photos(options) if explore == :photos
48
+ url = Endpoints.new.conversations(options) if explore == :conversations
49
+ get_parsed_response(url)
50
+ end
51
+
52
+ def get_mentions(username, options)
53
+ get_parsed_response(Endpoints.new.mentions(username, options))
54
+ end
55
+
56
+ def get_posts(username, options)
57
+ get_parsed_response(Endpoints.new.posts(username, options))
58
+ end
59
+
60
+ def get_whatstarred(username, options)
61
+ get_parsed_response(Endpoints.new.whatstarred(username, options))
62
+ end
63
+
64
+ def get_interactions
65
+ get_parsed_response(Endpoints.new.interactions)
66
+ end
67
+
68
+ def get_token_info
69
+ get_parsed_response(Endpoints.new.token_info)
70
+ end
71
+
72
+ def get_whoreposted(post_id)
73
+ get_parsed_response(Endpoints.new.whoreposted(post_id))
74
+ end
75
+
76
+ def get_whostarred(post_id)
77
+ get_parsed_response(Endpoints.new.whostarred(post_id))
78
+ end
79
+
80
+ def get_convo(post_id, options)
81
+ get_parsed_response(Endpoints.new.convo(post_id, options))
82
+ end
83
+
84
+ def get_hashtag(hashtag)
85
+ get_parsed_response(Endpoints.new.hashtag(hashtag))
86
+ end
87
+
88
+ def get_search(words, options)
89
+ get_parsed_response(Endpoints.new.search(words, options))
90
+ end
91
+
92
+ def get_followings(username)
93
+ build_list(username, :followings)
94
+ end
95
+
96
+ def get_followers(username)
97
+ build_list(username, :followers)
98
+ end
99
+
100
+ def get_muted
101
+ build_list(nil, :muted)
102
+ end
103
+
104
+ def get_blocked
105
+ build_list(nil, :blocked)
106
+ end
107
+
108
+ def get_raw_list(username, target)
109
+ options = {:count => 200, :before_id => nil}
110
+ big = []
111
+ loop do
112
+ url = get_list_url(username, target, options)
113
+ resp = get_parsed_response(url)
114
+ big << resp
115
+ break if resp['meta']['min_id'] == nil || resp['meta']['more'] == false
116
+ options = {:count => 200, :before_id => resp['meta']['min_id']}
117
+ end
118
+ big
119
+ end
120
+
121
+ def get_user(username)
122
+ get_parsed_response(Endpoints.new.user(username))
123
+ end
124
+
125
+ def get_details(post_id, options = {})
126
+ get_parsed_response(Endpoints.new.single_post(post_id, options))
127
+ end
128
+
129
+ def get_files_list(options)
130
+ array_of_hashes = []
131
+ unless options[:all]
132
+ resp = get_parsed_response(Endpoints.new.files_list(options))
133
+ resp['data'].each { |p| array_of_hashes << p }
134
+ else
135
+ options = {:count => 200, :before_id => nil}
136
+ loop do
137
+ resp = get_parsed_response(Endpoints.new.files_list(options))
138
+ resp['data'].each { |p| array_of_hashes << p }
139
+ break unless resp['meta']['more']
140
+ options = {:count => 200, :before_id => resp['meta']['min_id']}
141
+ end
142
+ end
143
+ array_of_hashes
144
+ end
145
+
146
+ def get_file(file_id)
147
+ get_parsed_response(Endpoints.new.file(file_id))
148
+ end
149
+
150
+ def star(post_id)
151
+ JSON.parse(CNX.post(Endpoints.new.star(post_id)))
152
+ end
153
+
154
+ def follow(post_id)
155
+ JSON.parse(CNX.post(Endpoints.new.follow(post_id)))
156
+ end
157
+
158
+ def mute(post_id)
159
+ JSON.parse(CNX.post(Endpoints.new.mute(post_id)))
160
+ end
161
+
162
+ def block(username)
163
+ JSON.parse(CNX.post(Endpoints.new.block(username)))
164
+ end
165
+
166
+ def repost(post_id)
167
+ JSON.parse(CNX.post(Endpoints.new.repost(post_id)))
168
+ end
169
+
170
+ def delete_post(post_id)
171
+ JSON.parse(CNX.delete(Endpoints.new.delete_post(post_id)))
172
+ end
173
+
174
+ def unstar(post_id)
175
+ JSON.parse(CNX.delete(Endpoints.new.star(post_id)))
176
+ end
177
+
178
+ def unfollow(username)
179
+ JSON.parse(CNX.delete(Endpoints.new.follow(username)))
180
+ end
181
+
182
+ def unmute(username)
183
+ JSON.parse(CNX.delete(Endpoints.new.mute(username)))
184
+ end
185
+
186
+ def unblock(username)
187
+ JSON.parse(CNX.delete(Endpoints.new.block(username)))
188
+ end
189
+
190
+ def unrepost(post_id)
191
+ resp = JSON.parse(CNX.delete(Endpoints.new.repost(post_id)))
192
+ if resp['data']['repost_of']
193
+ JSON.parse(CNX.delete(Endpoints.new.repost(resp['data']['repost_of']['id'])))
194
+ else
195
+ resp
196
+ end
197
+ end
198
+
199
+ def get_channels
200
+ options = {:count => 200, :recent_message => 1, :annotations => 1, :before_id => nil}
201
+ get_parsed_response(Endpoints.new.channels(options))
202
+ # big = []
203
+ # loop do
204
+ # resp = get_parsed_response(Endpoints.new.channels(options))
205
+ # #check_response_meta_code(resp)
206
+ # big << resp
207
+ # break if resp['meta']['more'] == false
208
+ # options = {:count => 200, :before_id => resp['meta']['min_id']}
209
+ # end
210
+ # big
211
+ end
212
+
213
+ def get_messages(channel_id, options)
214
+ if options[:new] || options[:scroll]
215
+ options = {since_id: Databases.pagination["channel:#{channel_id}"]}
216
+ end
217
+ get_parsed_response(Endpoints.new.messages(channel_id, options))
218
+ end
219
+
220
+ def get_config
221
+ get_parsed_response(Endpoints.new.config_api_url)
222
+ end
223
+
224
+ def check_response_meta_code(res)
225
+ if res['meta']['code'] == 200
226
+ res
227
+ else
228
+ Errors.global_error("api/check_response_meta_code", nil, res['meta'])
229
+ end
230
+ end
231
+
232
+ def self.build_query(arg)
233
+ count = Settings.options[:counts][:default]
234
+ if arg[:count]
235
+ if arg[:count].to_s.is_integer?
236
+ count = arg[:count]
237
+ end
238
+ end
239
+ directed = Settings.options[:timeline][:directed]
240
+ if arg[:directed]
241
+ if arg[:directed] == 0 || arg[:directed] == 1
242
+ directed = arg[:directed]
243
+ end
244
+ end
245
+ deleted = Settings.options[:timeline][:deleted]
246
+ if arg[:deleted]
247
+ if arg[:deleted] == 0 || arg[:deleted] == 1
248
+ deleted = arg[:deleted]
249
+ end
250
+ end
251
+ html = Settings.options[:timeline][:html]
252
+ if arg[:html]
253
+ if arg[:html] == 0 || arg[:html] == 1
254
+ html = arg[:html]
255
+ end
256
+ end
257
+ annotations = Settings.options[:timeline][:annotations]
258
+ if arg[:annotations]
259
+ if arg[:annotations] == 0 || arg[:annotations] == 1
260
+ annotations = arg[:annotations]
261
+ end
262
+ end
263
+ if arg[:since_id]
264
+ "&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=#{deleted}&include_annotations=#{annotations}&since_id=#{arg[:since_id]}"
265
+ elsif arg[:recent_message]
266
+ "&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=#{deleted}&include_annotations=#{annotations}&include_recent_message=#{arg[:recent_message]}"
267
+ else
268
+ "&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=#{deleted}&include_annotations=#{annotations}"
269
+ end
270
+ end
271
+
272
+ private
273
+
274
+ def get_parsed_response(url)
275
+ JSON.parse(CNX.get_response_from(url))
276
+ end
277
+
278
+ def get_original_if_repost(resp)
279
+ if resp['repost_of']
280
+ resp['repost_of']
281
+ else
282
+ resp
283
+ end
284
+ end
285
+
286
+ def build_list(username, target)
287
+ options = {:count => 200, :before_id => nil}
288
+ big_hash = {}
289
+ loop do
290
+ url = get_list_url(username, target, options)
291
+ resp = get_parsed_response(url)
292
+ big_hash.merge!(Workers.extract_users(resp))
293
+ break if resp['meta']['min_id'] == nil
294
+ options = {:count => 200, :before_id => resp['meta']['min_id']}
295
+ end
296
+ big_hash
297
+ end
298
+
299
+ def get_list_url(username, target, options)
300
+ case target
301
+ when :followings
302
+ Endpoints.new.followings(username, options)
303
+ when :followers
304
+ Endpoints.new.followers(username, options)
305
+ when :muted
306
+ Endpoints.new.muted(options)
307
+ when :blocked
308
+ Endpoints.new.blocked(options)
309
+ end
310
+ end
311
+
312
+ end
313
+ end