ayadn 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ayadn/view.rb ADDED
@@ -0,0 +1,270 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ class AyaDN
4
+ class View
5
+ def initialize(hash)
6
+ @hash = hash
7
+ end
8
+ def getData(hash)
9
+ hash['data'].reverse
10
+ end
11
+ def getDataNormal(hash)
12
+ hash['data']
13
+ end
14
+ def showMessagesFromChannel
15
+ buildMessages(getData(@hash))
16
+ end
17
+ def showStream
18
+ $tools.config['timeline']['downside'] ? the_hash = getData(@hash) : the_hash = getDataNormal(@hash)
19
+ buildStream(the_hash)
20
+ end
21
+ def showCompleteStream
22
+ $tools.config['timeline']['downside'] ? the_hash = getData(@hash) : the_hash = getDataNormal(@hash)
23
+ stream, pagination_array = buildCompleteStream(the_hash)
24
+ end
25
+ def show_pm_channels
26
+ stream, pagination_array = build_pm_channels_infos
27
+ end
28
+ def show_channels
29
+ stream, pagination_array = build_channels_infos
30
+ end
31
+ def showDebugStream
32
+ begin
33
+ puts "\n"
34
+ jj getDataNormal(@hash)
35
+ rescue => e
36
+ puts "\n"
37
+ jj @hash
38
+ puts e.inspect
39
+ end
40
+ end
41
+ def showUsersList
42
+ buildUsersList(getDataNormal(@hash))
43
+ end
44
+ def showInteractions
45
+ buildInteractions(getData(@hash))
46
+ end
47
+ def showUsers
48
+ users = ""
49
+ @hash = @hash.sort_by {|id, arr| arr[0]}
50
+ @hash.each do |id, arr|
51
+ users << "#{arr[0]} ".red.ljust(30) + "#{arr[1]}\n".green
52
+ end
53
+ return users, @hash.length
54
+ end
55
+ def showUsersInfos(name)
56
+ buildUserInfos(name, getDataNormal(@hash))
57
+ end
58
+ def showPostInfos(post_id, is_mine)
59
+ buildPostInfo(getDataNormal(@hash), is_mine)
60
+ end
61
+ def showFileInfo(with_url)
62
+ buildFileInfo(getDataNormal(@hash), with_url)
63
+ end
64
+ def buildStream(post_hash)
65
+ post_string = "\n"
66
+ post_string << post_hash.map {|item| create_content_string(item, nil, false)}
67
+ return post_string
68
+ end
69
+ def buildMessages(messages_stream)
70
+ messages_string = "\n"
71
+ for item in messages_stream do
72
+ @source_name_and_link = objectSource(item)
73
+ messages_string << create_content_string(item, checkins_annotations(item), false) # create_content_string(item, annotations, me_mentioned)
74
+ end
75
+ last_viewed = messages_stream.last
76
+ last_id = last_viewed['pagination_id'] unless last_viewed == nil
77
+ return messages_string, last_id
78
+ end
79
+ def buildCompleteStream(post_hash)
80
+ post_string = ""
81
+ pagination_array = []
82
+ saved_tags = []
83
+ if $tools.config['skipped']['hashtags'] != nil
84
+ saved_tags = $tools.config['skipped']['hashtags'].map {|tag| tag.downcase}
85
+ end
86
+ for item in post_hash do
87
+ pagination_array.push(item['pagination_id'])
88
+ next if item['text'] == nil
89
+ @source_name_and_link = objectSource(item)
90
+ case @source_name_and_link[:name]
91
+ when *$tools.config['skipped']['sources']
92
+ next
93
+ end
94
+ next if skip_hashtags(item, saved_tags)
95
+ postMentionsArray = []
96
+ @skipped_mentions_encountered = false
97
+ for mention in item['entities']['mentions'] do
98
+ case mention['name']
99
+ when *$tools.config['skipped']['mentions']
100
+ @skipped_mentions_encountered = true
101
+ next
102
+ end
103
+ postMentionsArray.push(mention['name'])
104
+ end
105
+ next if @skipped_mentions_encountered
106
+ me_mentioned = false
107
+ for name in postMentionsArray do
108
+ if name == ($tools.config['identity']['prefix'] || $files.users_read("me"))
109
+ me_mentioned = true
110
+ end
111
+ end
112
+ post_string << create_content_string(item, checkins_annotations(item), me_mentioned)
113
+ end
114
+ return post_string, pagination_array
115
+ end
116
+ def buildSimplePost(post_hash)
117
+ create_content_string(post_hash, nil, false)
118
+ end
119
+ def buildSimplePostInfo(post_hash)
120
+ #the_post_id = post_hash['id']
121
+ post_text = post_hash['text']
122
+ post_URL = post_hash['canonical_url']
123
+ post_details = "\nPost URL: ".cyan + post_URL.brown + "\n"
124
+ is_reply = post_hash['reply_to']
125
+ post_details << ("This post is a reply to post ".cyan + is_reply.brown + "\n") if is_reply != nil
126
+ if post_text != nil
127
+ without_braces = $tools.withoutSquareBraces($tools.getMarkdownText(post_text.dup))
128
+ post_details << "\nLength: ".cyan + without_braces.length.to_s.reddish
129
+ end
130
+ return post_details + "\n\n"
131
+ end
132
+ def buildPostInfo(post_hash, is_mine)
133
+ post_text = post_hash['text']
134
+ post_text != nil ? (colored_post = $tools.colorize(post_text)) : (puts "\n--Post deleted--\n\n".red; exit)
135
+ params = objectNames(post_hash['user'])
136
+ created_day, created_hour = objectDate(post_hash)
137
+ post_details = "\n" + created_day.cyan + ' ' + created_hour.cyan + ' ' + params[:user_handle].green
138
+ post_details << (" [#{params[:user_real_name]}]".reddish) if !params[:user_real_name].empty?
139
+ post_details << " (follows you)".blue if post_hash['user']['follows_you']
140
+ post_details << " (you follow)".blue if post_hash['user']['you_follow']
141
+ unless post_hash['user']['follows_you'] || post_hash['user']['you_follow']
142
+ post_details << " (you don't follow, doesn't follow you)".blue unless params[:user_name] == $tools.config['identity']['prefix']
143
+ end
144
+ post_details << "\n"
145
+ post_details << "\n" + colored_post + "\n\n"
146
+ post_details << "ID: ".cyan + post_hash['id'].to_s.green + "\n"
147
+ post_details << objectLinks(post_hash)
148
+ post_details << "Post URL: ".cyan + post_hash['canonical_url'].brown
149
+ is_reply = post_hash['reply_to']
150
+ repost_of = post_hash['repost_of']
151
+ post_details << ("\nThis post is a reply to post ".cyan + is_reply.brown) if is_reply != nil
152
+ if is_mine == false
153
+ if repost_of != nil
154
+ post_details << "\nThis post is a repost of post ".cyan + repost_of['id'].brown
155
+ else
156
+ post_details << "\nReplies: ".cyan + post_hash['num_replies'].to_s.reddish
157
+ post_details << " Reposts: ".cyan + post_hash['num_reposts'].to_s.reddish
158
+ post_details << " Stars: ".cyan + post_hash['num_stars'].to_s.reddish
159
+ end
160
+ post_details << ("\nYou reposted this post.".cyan) if post_hash['you_reposted']
161
+ post_details << ("\nYou starred this post.".cyan) if post_hash['you_starred']
162
+ post_details << "\nPosted with: ".cyan + post_hash['source']['name'].reddish
163
+ post_details << " Locale: ".cyan + post_hash['user']['locale'].reddish
164
+ post_details << " Timezone: ".cyan + post_hash['user']['timezone'].reddish
165
+ else
166
+ without_braces = $tools.withoutSquareBraces($tools.getMarkdownText(post_text.dup))
167
+ post_details << "\nLength: ".cyan + without_braces.length.to_s.reddish
168
+ end
169
+ post_details << "\n\n\n"
170
+ end
171
+ def buildUsersList(users_hash)
172
+ users_string = "\n"
173
+ users_hash.each do |item|
174
+ param = objectNames(item)
175
+ users_string << param[:user_real_name].green + " #{param[:user_handle]}\n".cyan
176
+ end
177
+ users_string << "\n\n"
178
+ end
179
+ def buildFollowList
180
+ users_hash = {}
181
+ @hash['data'].each do |item|
182
+ user_handle = "@" + item['username']
183
+ users_hash[item['id']] = [user_handle, item['name']]
184
+ end
185
+ return users_hash, @hash['meta']['min_id']
186
+ end
187
+ def buildFileInfo(resp_hash, with_url)
188
+ files_details_hash = filesDetails(resp_hash)
189
+ #file_url_expires = resp_hash['url_expires']
190
+ #derived_files = resp_hash['derived_files']
191
+ list_string = file_view(files_details_hash)
192
+ if files_details_hash[:file_is_public]
193
+ list_string << "\nThis file is ".cyan + "public".blue
194
+ file_url = files_details_hash[:file_url]
195
+ else
196
+ list_string << "\nThis file is ".cyan + "private".red
197
+ file_url = resp_hash['url']
198
+ end
199
+ if with_url
200
+ list_string << "\nURL: ".cyan + file_url
201
+ #list_string << derivedFilesDetails(derived_files)
202
+ end
203
+ list_string << "\n\n"
204
+ return list_string, file_url, files_details_hash[:name]
205
+ end
206
+ def showFilesList(with_url, reverse)
207
+ reverse ? resp_hash = getDataNormal(@hash) : resp_hash = getData(@hash)
208
+ list_string = ""
209
+ file_url = nil
210
+ pagination_array = []
211
+ resp_hash.each do |item|
212
+ pagination_array.push(item['pagination_id'])
213
+ files_details_hash = filesDetails(item)
214
+ #file_url_expires = item['url_expires']
215
+ #derived_files = item['derived_files']
216
+ list_string << "\nID: ".cyan + files_details_hash[:id].brown
217
+ list_string << file_view(files_details_hash)
218
+ if files_details_hash[:file_is_public]
219
+ list_string << "\nThis file is ".cyan + "public".blue
220
+ list_string << "\nLink: ".cyan + item['url_permanent'].magenta
221
+ else
222
+ list_string << "\nThis file is ".cyan + "private".red
223
+ if with_url
224
+ file_url = item['url']
225
+ list_string << "\nURL: ".cyan + file_url.brown
226
+ #list_string << derivedFilesDetails(derived_files)
227
+ end
228
+ end
229
+ list_string << "\n"
230
+ end
231
+ list_string << "\n"
232
+ return list_string, file_url, pagination_array
233
+ end
234
+ def buildUserInfos(name, adn_data)
235
+ name_params = objectNames(adn_data)
236
+ $files.users_write("me", name_params[:user_name]) if name == "me"
237
+ $files.users_write(adn_data['id'], name_params[:user_name]) if $files.users_read(adn_data['id']) == nil
238
+ created_at = adn_data['created_at']
239
+ user_show = "\nID: ".cyan.ljust(22) + adn_data['id'].green + "\n"
240
+ user_show << ("Name: ".cyan.ljust(21) + name_params[:user_real_name].green + "\n") if name_params[:user_real_name] != nil
241
+ adn_data['description'] != nil ? user_descr = adn_data['description']['text'] : user_descr = "No description available.".cyan
242
+ user_timezone = adn_data['timezone']
243
+ user_show << ("Timezone: ".cyan.ljust(21) + user_timezone.green + "\n") if user_timezone != nil
244
+ locale = adn_data['locale']
245
+ user_show << ("Locale: ".cyan.ljust(21) + locale.green + "\n") if locale != nil
246
+ user_show << "Posts: ".cyan.ljust(21) + adn_data['counts']['posts'].to_s.green + "\n" + "Followers: ".cyan.ljust(21) + adn_data['counts']['followers'].to_s.green + "\n" + "Following: ".cyan.ljust(21) + adn_data['counts']['following'].to_s.green + "\n"
247
+ user_show << "Web: ".cyan.ljust(21) + "http://".green + adn_data['verified_domain'].green + "\n" if adn_data['verified_domain'] != nil
248
+ user_show << "Joined: ".cyan.ljust(21) + created_at[0...10].green + " " + created_at[11...19].green + "\n"
249
+ user_show << "\n"
250
+ user_show << name_params[:user_handle].brown
251
+ if name != "me"
252
+ if adn_data['follows_you']
253
+ user_show << " follows you\n".green
254
+ else
255
+ user_show << " doesn't follow you\n".reddish
256
+ end
257
+ if adn_data['you_follow']
258
+ user_show << "You follow ".green + name_params[:user_handle].brown + "\n"
259
+ else
260
+ user_show << "You don't follow ".reddish + name_params[:user_handle].brown + "\n"
261
+ end
262
+ user_show << ("You muted ".reddish + name_params[:user_handle].brown + "\n") if adn_data['you_muted']
263
+ else
264
+ user_show << " => " + "yourself!".brown + "\n"
265
+ end
266
+ user_show << "\n"
267
+ user_show << "Bio: \n\n".cyan + user_descr + "\n\n"
268
+ end
269
+ end
270
+ end
data/lib/ayadn.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'ayadn/requires.rb'
2
+ require 'ayadn/adn_files.rb'
3
+ require 'ayadn/api.rb'
4
+ require 'ayadn/authorize.rb'
5
+ require 'ayadn/client-http.rb'
6
+ require 'ayadn/colors.rb'
7
+ require 'ayadn/debug.rb'
8
+ require 'ayadn/endpoints.rb'
9
+ require 'ayadn/extend.rb'
10
+ require 'ayadn/files.rb'
11
+ require 'ayadn/get-api.rb'
12
+ require 'ayadn/help.rb'
13
+ require 'ayadn/list.rb'
14
+ require 'ayadn/main.rb'
15
+ require 'ayadn/pinboard.rb'
16
+ require 'ayadn/post.rb'
17
+ require 'ayadn/skip.rb'
18
+ require 'ayadn/status.rb'
19
+ require 'ayadn/tools.rb'
20
+ require 'ayadn/user-stream.rb'
21
+ require 'ayadn/view-channels.rb'
22
+ require 'ayadn/view-interactions.rb'
23
+ require 'ayadn/view-object.rb'
24
+ require 'ayadn/view.rb'
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ class AyaDN
4
+ # experimenting without curl
5
+ # def ayadnFileUpload(file_name)
6
+ # # puts "\nUploading ".green + file_name.brown + "\n"
7
+ # # response = @api.createIncompleteFileUpload(file_name)
8
+ # # puts response.inspect #SUCCESS
9
+ # # THEN multipart => #FAIL
10
+ # end
11
+
12
+
13
+ # def ayadnDeactivateChannel(channel_id)
14
+ # resp = @api.deactivateChannel(channel_id)
15
+ # puts resp
16
+ # end
17
+
18
+
19
+ ### experiment
20
+ ### not DRY at all, this is ok, chill out
21
+ # def ayadnRecord(item)
22
+ # # first create with curl -i -H 'Authorization: BEARER xxx' "https://stream-channel.app.net/stream/user?auto_delete=1&include_annotations=1"
23
+ # # it stays open and returns a stream_id in the headers
24
+ # # TODO: replace curl with a good connection system with HTTP or Rest-Client
25
+
26
+ # command = "sleep 1; curl -i -H 'Authorization: BEARER #{@token}' 'https://stream-channel.app.net/stream/user?auto_delete=1&include_annotations=1'"
27
+ # pid = Process.spawn(command)
28
+ # Process.detach(pid)
29
+
30
+ # puts "Enter stream id: "
31
+ # stream_id = STDIN.gets.chomp
32
+ # last_page_id = nil
33
+ # start = Time.now
34
+ # case item
35
+ # when "global" # works :)
36
+ # @url = "https://alpha-api.app.net/stream/0/posts/stream/global?connection_id=#{stream_id}&since_id=#{last_page_id}"
37
+ # when "unified" # doesn't work, have to implement some sort of real keep-alive connection
38
+ # @url = "https://alpha-api.app.net/stream/0/posts/stream/unified?connection_id=#{stream_id}&since_id=#{last_page_id}&include_directed_posts=1"
39
+ # end
40
+ # puts "\nRecording stream in #{$tools.ayadn_configuration[:files_path]}/rec-#{item}.json\n\n"
41
+ # uri = URI.parse(@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
+ # response = https.request(request)
49
+ # @hash = JSON.parse(response.body)
50
+ # big_stream = @hash['data']
51
+ # f = File.new($tools.ayadn_configuration[:files_path] + "/rec-#{item}.json", 'w')
52
+ # f.puts(big_stream.to_json)
53
+ # f.close
54
+ # stream, last_page_id = completeStream
55
+ # displayScrollStream(stream)
56
+ # number_of_connections = 1
57
+ # file_operations_timer = 0
58
+ # loop do
59
+ # begin
60
+ # case item
61
+ # when "global"
62
+ # @url = "https://alpha-api.app.net/stream/0/posts/stream/global?connection_id=#{stream_id}&since_id=#{last_page_id}"
63
+ # when "unified"
64
+ # @url = "https://alpha-api.app.net/stream/0/posts/stream/unified?connection_id=#{stream_id}&since_id=#{last_page_id}&include_directed_posts=1"
65
+ # end
66
+ # uri = URI.parse(@url)
67
+ # request = Net::HTTP::Get.new(uri.request_uri)
68
+ # request["Authorization"] = "Bearer #{@token}"
69
+ # request["Content-Type"] = "application/json"
70
+ # before_request_id = last_page_id
71
+ # response = https.request(request)
72
+ # @hash = JSON.parse(response.body)
73
+ # stream, last_page_id = completeStream
74
+ # displayScrollStream(stream)
75
+ # if last_page_id == nil
76
+ # last_page_id = before_request_id
77
+ # sleep 0.5 # trying to play nice with the API limits
78
+ # number_of_connections += 1
79
+ # next
80
+ # end
81
+ # # don't let it run for days, it will eat your RAM
82
+ # # + the simple file dump isn't ok in the long run
83
+ # big_stream << @hash['data']
84
+ # number_of_connections += 1
85
+ # file_operations_timer += 1
86
+ # sleep 0.2 # trying to play nice with the API limits
87
+ # if file_operations_timer == 10
88
+ # puts "\nRecording stream in #{$tools.ayadn_configuration[:files_path]}/rec-#{item}.json\n\n".green
89
+ # #big_json = JSON.parse(IO.read($tools.ayadn_configuration[:files_path] + "/rec-#{item}.json"))
90
+ # f = File.new($tools.ayadn_configuration[:files_path] + "/rec-#{item}.json", 'w')
91
+ # f.puts(big_stream.to_json)
92
+ # f.close
93
+ # file_operations_timer = 0
94
+ # end
95
+ # rescue Exception => e
96
+ # puts e.inspect
97
+ # puts e.to_s
98
+ # finish = Time.now
99
+ # elapsed = finish.to_f - start.to_f
100
+ # mins, secs = elapsed.divmod 60.0
101
+ # puts "\nRequests: #{number_of_connections}\n"
102
+ # puts "Elapsed time (min:secs.msecs): "
103
+ # puts("%3d:%04.2f"%[mins.to_i, secs])
104
+ # puts "\nStream recorded in #{$tools.ayadn_configuration[:files_path]}/rec-#{item}.json"
105
+ # exit
106
+ # end
107
+ # end
108
+ # end
109
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ayadn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ platform: ruby
6
+ authors:
7
+ - Eric Dejonckheere
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pinboard
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.1
41
+ description: ! 'AyaDN features all kinds of tools to access and manage your App.net
42
+ account. It''s an ADN client (posts, streams, PM, channels, files, etc) and a toolbelt
43
+ at the same time: it can save post links to Pinboard, post your currently-playing
44
+ iTunes song, backup data associated with your ADN account such as followings, followers,
45
+ muted users, and many other features.
46
+
47
+ '
48
+ email: eric@aya.io
49
+ executables:
50
+ - ayadn
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - CHANGELOG.md
55
+ - CONTRIBUTORS.md
56
+ - LICENSE.md
57
+ - README.md
58
+ - bin/ayadn
59
+ - config.yml
60
+ - lib/ayadn.rb
61
+ - lib/ayadn/adn_files.rb
62
+ - lib/ayadn/api.rb
63
+ - lib/ayadn/authorize.rb
64
+ - lib/ayadn/client-http.rb
65
+ - lib/ayadn/colors.rb
66
+ - lib/ayadn/debug.rb
67
+ - lib/ayadn/endpoints.rb
68
+ - lib/ayadn/extend.rb
69
+ - lib/ayadn/files.rb
70
+ - lib/ayadn/get-api.rb
71
+ - lib/ayadn/help.rb
72
+ - lib/ayadn/list.rb
73
+ - lib/ayadn/main.rb
74
+ - lib/ayadn/pinboard.rb
75
+ - lib/ayadn/post.rb
76
+ - lib/ayadn/requires.rb
77
+ - lib/ayadn/skip.rb
78
+ - lib/ayadn/status.rb
79
+ - lib/ayadn/tools.rb
80
+ - lib/ayadn/user-stream.rb
81
+ - lib/ayadn/view-channels.rb
82
+ - lib/ayadn/view-interactions.rb
83
+ - lib/ayadn/view-object.rb
84
+ - lib/ayadn/view.rb
85
+ - lib/experiments.rb
86
+ homepage: http://www.ayadn-app.net/
87
+ licenses:
88
+ - ISC
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: 1.9.3
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: App.net command-line client
110
+ test_files: []