ayadn 1.1.3 → 1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75a5a7fbde96a935ba9615c876c9a218309011b4
4
- data.tar.gz: 5393c466010698aad630ff249882e181acd437b0
3
+ metadata.gz: 4779d6542900526f73e85eeacb33e0473027c1b6
4
+ data.tar.gz: 96819f77d6f435a0b4e2268c9a860abfa1eba24e
5
5
  SHA512:
6
- metadata.gz: 556f017fe92fcef40812aeddc39b21b6f92ad60f4f02750da86e8c48feeebfc72ce3562adff10de5f052ab6a75bbf4731bb6b6263824a292eb575bebd7b599da
7
- data.tar.gz: 5a6e6e0787fdb6051367362d043f5656e11efe329e169ee2ee77e11dd56950a9b698a89c83d46c9a54dc09bbc2c47294471e30d54e354e3b8f1ff0fde6098e4e
6
+ metadata.gz: ed28a4ad43ddcd1434fb39982e39c42b70eba503c9bd8f83eebe84b047df048a8706e006845a174914495ad9fbe4bdeffd65413fac47b03720797d82a9ddb5bd
7
+ data.tar.gz: f1bbc610a629b57a5e132bbb726cab40313bc04d1367a600813d140a464ffdbe43e36d9c03519ee6996520324dfbe8d4e81ce258f05bc1f989a1a1fd495f01ab
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.2.0 - 'Jason'
2
+
3
+ - @matigo's NiceRank filter for the Global stream
4
+
1
5
  # 1.1.3 - 'Kevin'
2
6
 
3
7
  - Bookmark a conversation
data/README.md CHANGED
@@ -17,7 +17,7 @@ Ayadn is configurable: colors, timelines, durations, aliases, etc.
17
17
 
18
18
  You can also specify many options, like show the raw JSON instead of the formatted response, show only a number of most recents posts, show only new posts, etc.
19
19
 
20
- There's also exclusive features, like the Blacklist: feed this mini database with usernames, client names or hashtags and Ayadn will never show you any post containing any of these elements.
20
+ There's also two exclusive antispam and filtering features: a blacklist, and Jason Irwin's NiceRank.
21
21
 
22
22
  Last but not least: Ayadn supports multiple ADN accounts! Authorize as many accounts as you wish and simply switch between them with a keystroke.
23
23
 
data/lib/ayadn/action.rb CHANGED
@@ -42,14 +42,17 @@ module Ayadn
42
42
  end
43
43
  end
44
44
 
45
- def global(options)
45
+ def global(settings)
46
46
  begin
47
+ options = settings.dup
48
+ options[:filter] = true
47
49
  doing(options)
48
50
  stream = @api.get_global(options)
51
+ niceranks = @api.get_niceranks stream
49
52
  (no_new_posts unless Databases.has_new?(stream, 'global')) if options[:new]
50
53
  Databases.save_max_id(stream)
51
- render_view(stream, options)
52
- Scroll.new(@api, @view).global(options) if options[:scroll]
54
+ render_view(stream, options, niceranks)
55
+ Scroll.new(@api, @view).global(options, niceranks) if options[:scroll]
53
56
  rescue => e
54
57
  Errors.global_error("action/global", options, e)
55
58
  ensure
@@ -1075,10 +1078,9 @@ module Ayadn
1075
1078
  post_id
1076
1079
  end
1077
1080
 
1078
- def render_view(data, options = {})
1081
+ def render_view(data, options = {}, niceranks = {})
1079
1082
  unless options[:raw]
1080
- #@view.clear_screen
1081
- get_view(data['data'], options)
1083
+ get_view(data['data'], options, niceranks)
1082
1084
  else
1083
1085
  @view.show_raw(data)
1084
1086
  end
@@ -1095,12 +1097,12 @@ module Ayadn
1095
1097
  response['data']
1096
1098
  end
1097
1099
 
1098
- def get_view(stream, options = {})
1100
+ def get_view(stream, options = {}, niceranks = {})
1099
1101
  @view.clear_screen
1100
1102
  if options[:index]
1101
- @view.show_posts_with_index(stream, options)
1103
+ @view.show_posts_with_index(stream, options, niceranks)
1102
1104
  else
1103
- @view.show_posts(stream, options)
1105
+ @view.show_posts(stream, options, niceranks)
1104
1106
  end
1105
1107
  end
1106
1108
 
data/lib/ayadn/api.rb CHANGED
@@ -200,6 +200,24 @@ module Ayadn
200
200
  end
201
201
  end
202
202
 
203
+ def get_niceranks stream
204
+ ranks, user_ids, table, niceranks = [], [], {}, {}
205
+ stream['data'].each do |post|
206
+ user_ids << post['user']['id'].to_i
207
+ table[post['user']['id'].to_i] = post['user']['username']
208
+ end
209
+ user_ids.uniq!
210
+ resp = JSON.parse(CNX.get "http://api.search-adn.net/user/nicerank?ids=#{user_ids.join(',')}")
211
+ return {} if resp['meta']['code'] != 200
212
+ resp['data'].each do |obj|
213
+ niceranks[obj['user_id']] = {
214
+ username: table[obj['user_id']],
215
+ rank: obj['rank']
216
+ }
217
+ end
218
+ niceranks
219
+ end
220
+
203
221
  def get_channels
204
222
  options = {:count => 200, :recent_message => 1, :annotations => 1, :before_id => nil}
205
223
  get_parsed_response(Endpoints.new.channels(options))
data/lib/ayadn/app.rb CHANGED
@@ -448,8 +448,7 @@ module Ayadn
448
448
  puts "\nAYADN\n".color(:red)
449
449
  puts "Version:\t".color(:cyan) + "#{VERSION}\n".color(:green)
450
450
  puts "Changelog:\t".color(:cyan) + "https://github.com/ericdke/na/blob/master/CHANGELOG.md\n".color(:yellow)
451
- puts "Readme:\t\t".color(:cyan) + "https://github.com/ericdke/na/blob/master/README.md".color(:yellow)
452
- puts "Manual:\t\t".color(:cyan) + "https://github.com/ericdke/na/blob/master/MANUAL.md".color(:yellow)
451
+ puts "Docs:\t\t".color(:cyan) + "http://ayadn-app.net/doc/".color(:yellow)
453
452
  puts "\n"
454
453
  end
455
454
 
data/lib/ayadn/cnx.rb CHANGED
@@ -2,6 +2,22 @@
2
2
  module Ayadn
3
3
  class CNX
4
4
 
5
+ def self.get url
6
+ begin
7
+ RestClient.get(url) do |response, request, result|
8
+ response
9
+ end
10
+ rescue SocketError => e
11
+ puts "\nConnection error.".color(:red)
12
+ Errors.global_error("cnx.rb/get", url, e)
13
+ rescue SystemCallError => e
14
+ puts "\nConnection error.".color(:red)
15
+ Errors.global_error("cnx.rb/get", url, e)
16
+ rescue => e
17
+ Errors.global_error("cnx.rb/get", url, e)
18
+ end
19
+ end
20
+
5
21
  def self.get_response_from(url)
6
22
  begin
7
23
  RestClient.get(url) do |response, request, result| #, :verify_ssl => OpenSSL::SSL::VERIFY_NONE
@@ -109,6 +109,8 @@ module Ayadn
109
109
  Show only new posts:
110
110
 
111
111
  ayadn -gl -n
112
+
113
+ See `ayadn set` for the NiceRank filter.
112
114
  \n\n
113
115
  USAGE
114
116
  end
@@ -804,6 +806,20 @@ module Ayadn
804
806
  \n\n
805
807
  USAGE
806
808
  end
809
+ def self.set_nicerank
810
+ <<-USAGE
811
+ Set NiceRank values.
812
+
813
+ Examples:
814
+
815
+ ayadn set nicerank filter true
816
+
817
+ ayadn set nicerank filter_unranked true
818
+
819
+ ayadn set timeline show_nicerank true
820
+ \n\n
821
+ USAGE
822
+ end
807
823
  def self.set_defaults
808
824
  <<-USAGE
809
825
  Sets back the configuration to default values.
data/lib/ayadn/scroll.rb CHANGED
@@ -7,23 +7,32 @@ module Ayadn
7
7
  @view = view
8
8
  end
9
9
 
10
- def method_missing(meth, options)
10
+ def method_missing(meth, options, niceranks = {})
11
11
  case meth.to_s
12
12
  when 'trending', 'photos', 'checkins', 'replies', 'global', 'unified'
13
- scroll_it(meth.to_s, options)
13
+ scroll_it(meth.to_s, options, niceranks)
14
14
  else
15
15
  super
16
16
  end
17
17
  end
18
18
 
19
- def scroll_it(target, options)
19
+ def scroll_it(target, options, niceranks)
20
20
  options = check_raw(options)
21
21
  orig_target = target
22
22
  loop do
23
23
  begin
24
24
  stream = get(target, options)
25
+ if options[:filter] == true
26
+ unless stream['data'].empty?
27
+ niceranks = @api.get_niceranks stream
28
+ else
29
+ niceranks = {}
30
+ end
31
+ else
32
+ niceranks = {}
33
+ end
25
34
  target = "explore:#{target}" if explore?(target)
26
- show_if_new(stream, options, target)
35
+ show_if_new(stream, options, target, niceranks)
27
36
  target = orig_target if target =~ /explore/
28
37
  options = save_then_return(stream, options)
29
38
  pause
@@ -125,33 +134,45 @@ module Ayadn
125
134
  sleep Settings.options[:scroll][:timer]
126
135
  end
127
136
 
128
- def show_if_new(stream, options, target)
129
- show(stream, options) if Databases.has_new?(stream, target)
137
+ def show_if_new(stream, options, target, niceranks = {})
138
+ show(stream, options, niceranks) if Databases.has_new?(stream, target)
130
139
  end
131
140
 
132
141
  def save_then_return(stream, options)
133
142
  unless stream['meta']['max_id'].nil?
134
143
  Databases.save_max_id(stream)
135
- return options_hash(stream)
144
+ return options_hash(stream, options)
136
145
  end
137
146
  options
138
147
  end
139
148
 
140
149
  def check_raw(options)
141
150
  if options[:raw]
142
- {count: 200, since_id: nil, raw: true, scroll: true}
151
+ if options[:filter] == true
152
+ {count: 200, since_id: nil, raw: true, scroll: true, filter: true}
153
+ else
154
+ {count: 200, since_id: nil, raw: true, scroll: true}
155
+ end
143
156
  else
144
- {count: 200, since_id: nil, scroll: true}
157
+ if options[:filter] == true
158
+ {count: 200, since_id: nil, scroll: true, filter: true}
159
+ else
160
+ {count: 200, since_id: nil, scroll: true}
161
+ end
145
162
  end
146
163
  end
147
164
 
148
- def options_hash(stream)
149
- {:count => 50, :since_id => stream['meta']['max_id'], scroll: true}
165
+ def options_hash(stream, options)
166
+ if options[:filter] == true
167
+ {:count => 50, :since_id => stream['meta']['max_id'], scroll: true, filter: true}
168
+ else
169
+ {:count => 50, :since_id => stream['meta']['max_id'], scroll: true}
170
+ end
150
171
  end
151
172
 
152
- def show(stream, options)
173
+ def show(stream, options, niceranks)
153
174
  unless options[:raw]
154
- @view.show_posts(stream['data'], options)
175
+ @view.show_posts(stream['data'], options, niceranks)
155
176
  else
156
177
  jj stream
157
178
  end
data/lib/ayadn/set.rb CHANGED
@@ -15,6 +15,19 @@ module Ayadn
15
15
  scroll_config.save
16
16
  end
17
17
 
18
+ desc "nicerank ITEM VALUE", "Set NiceRank filter values"
19
+ long_desc Descriptions.set_nicerank
20
+ def nicerank *args
21
+ nicerank_config = SetNiceRank.new
22
+ if args[0]
23
+ nicerank_config.send(args[0], args[1])
24
+ else
25
+ abort(Status.error_missing_parameters)
26
+ end
27
+ nicerank_config.log(args)
28
+ nicerank_config.save
29
+ end
30
+
18
31
  desc "timeline ITEM TRUE/FALSE", "Set ITEM to be activated or not"
19
32
  long_desc Descriptions.set_timeline
20
33
  def timeline(*args)
@@ -141,6 +154,42 @@ module Ayadn
141
154
  end
142
155
  end
143
156
 
157
+ class SetNiceRank
158
+ def initialize
159
+ Settings.load_config
160
+ Settings.get_token
161
+ Settings.init_config
162
+ Logs.create_logger
163
+ unless Settings.options[:nicerank]
164
+ Settings.options[:nicerank] = {
165
+ threshold: 2.1,
166
+ filter: false,
167
+ filter_unranked: false
168
+ }
169
+ end
170
+ unless Settings.options[:colors][:nicerank]
171
+ Settings.options[:colors][:nicerank] = :cyan
172
+ end
173
+ end
174
+ def log(args)
175
+ x = "New value for '#{args[0]}' in 'NiceRank' => #{args[1]}"
176
+ puts "\n#{x}\n".color(:cyan)
177
+ Logs.rec.info x
178
+ end
179
+ def save
180
+ Settings.save_config
181
+ end
182
+ def filter value
183
+ Settings.options[:nicerank][:filter] = Validators.boolean(value)
184
+ end
185
+ def filter_unranked value
186
+ Settings.options[:nicerank][:filter_unranked] = Validators.boolean(value)
187
+ end
188
+ def threshold value
189
+ Settings.options[:nicerank][:threshold] = value.to_f
190
+ end
191
+ end
192
+
144
193
  class SetBackup
145
194
  def initialize
146
195
  Settings.load_config
@@ -314,6 +363,19 @@ module Ayadn
314
363
  def show_date(value)
315
364
  Settings.options[:timeline][:show_date] = value
316
365
  end
366
+ def show_nicerank value
367
+ unless Settings.options[:nicerank]
368
+ Settings.options[:nicerank] = {
369
+ threshold: 2.1,
370
+ filter: false,
371
+ filter_unranked: false
372
+ }
373
+ end
374
+ unless Settings.options[:colors][:nicerank]
375
+ Settings.options[:colors][:nicerank] = :cyan
376
+ end
377
+ Settings.options[:timeline][:show_nicerank] = value
378
+ end
317
379
  end
318
380
 
319
381
  class SetColor
@@ -151,7 +151,8 @@ module Ayadn
151
151
  show_source: true,
152
152
  show_symbols: true,
153
153
  show_real_name: true,
154
- show_date: true
154
+ show_date: true,
155
+ show_nicerank: false
155
156
  },
156
157
  counts: {
157
158
  default: 50,
@@ -187,7 +188,8 @@ module Ayadn
187
188
  hashtags: :cyan,
188
189
  mentions: :red,
189
190
  source: :cyan,
190
- symbols: :green
191
+ symbols: :green,
192
+ nicerank: :cyan
191
193
  },
192
194
  backup: {
193
195
  auto_save_sent_posts: false,
@@ -196,6 +198,11 @@ module Ayadn
196
198
  },
197
199
  scroll: {
198
200
  timer: 3
201
+ },
202
+ nicerank: {
203
+ threshold: 2.1,
204
+ filter: false,
205
+ filter_unranked: false
199
206
  }
200
207
  }
201
208
  end
data/lib/ayadn/status.rb CHANGED
@@ -221,7 +221,7 @@ module Ayadn
221
221
  "\nSomething wrong happened. :(\n\n".color(:red)
222
222
  end
223
223
  def self.redirecting
224
- "\nPost is a repost. Redirecting...\n\n".color(:cyan)
224
+ "\nPost is a repost. Redirecting...\n".color(:cyan)
225
225
  end
226
226
  def self.nobody_reposted
227
227
  "\nNobody reposted this post.\n\n".color(:red)
data/lib/ayadn/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Ayadn
3
- VERSION = "1.1.3"
3
+ VERSION = "1.2.0"
4
4
  end
data/lib/ayadn/view.rb CHANGED
@@ -6,14 +6,14 @@ module Ayadn
6
6
  @workers = Workers.new
7
7
  end
8
8
 
9
- def show_posts_with_index(data, options)
10
- posts, view = build_stream_with_index(data, options)
9
+ def show_posts_with_index(data, options, niceranks = {})
10
+ posts, view = build_stream_with_index(data, options, niceranks)
11
11
  puts view
12
12
  Databases.save_indexed_posts(posts)
13
13
  end
14
14
 
15
- def show_posts(data, options)
16
- puts build_stream_without_index(data, options)
15
+ def show_posts(data, options, niceranks = {})
16
+ puts build_stream_without_index(data, options, niceranks)
17
17
  end
18
18
 
19
19
  def show_raw(stream)
@@ -22,7 +22,7 @@ module Ayadn
22
22
  end
23
23
 
24
24
  def show_simple_post(post, options)
25
- view = build_stream_without_index(post, options)
25
+ view = build_stream_without_index(post, options, {})
26
26
  puts view
27
27
  end
28
28
 
@@ -276,9 +276,31 @@ module Ayadn
276
276
  end
277
277
  end
278
278
 
279
- def build_stream_with_index(data, options) #expects an array
279
+ def filter_nicerank posts, options
280
+ if options[:filter] == true # only if this option is true in Action (only global for now)
281
+ unless Settings.options[:nicerank].nil? #in case config file not initialized
282
+ if Settings.options[:nicerank][:filter] == true
283
+ filtered = {}
284
+ posts.each do |id,content|
285
+ (next if content[:nicerank] == false) if Settings.options[:nicerank][:filter_unranked] == true
286
+ next if content[:nicerank] < Settings.options[:nicerank][:threshold]
287
+ filtered[id] = content
288
+ end
289
+ return filtered
290
+ end
291
+ return posts
292
+ end
293
+ return posts
294
+ end
295
+ return posts
296
+ end
297
+
298
+ def build_stream_with_index(data, options, niceranks) #expects an array
280
299
  @view = ""
281
- posts = @workers.build_posts(data.reverse)
300
+ posts = @workers.build_posts(data.reverse, niceranks)
301
+
302
+ posts = filter_nicerank posts, options
303
+
282
304
  posts.each do |id,content|
283
305
  count = "%03d" % content[:count]
284
306
  if content[:username] == Settings.config[:identity][:username]
@@ -294,9 +316,12 @@ module Ayadn
294
316
  return posts, @view
295
317
  end
296
318
 
297
- def build_stream_without_index(data, options) #expects an array
319
+ def build_stream_without_index(data, options, niceranks) #expects an array
298
320
  @view = ""
299
- posts = @workers.build_posts(data.reverse)
321
+ posts = @workers.build_posts(data.reverse, niceranks)
322
+
323
+ posts = filter_nicerank posts, options
324
+
300
325
  posts.each do |id,content|
301
326
  if content[:username] == Settings.config[:identity][:username]
302
327
  @view << content[:id].to_s.color(Settings.options[:colors][:id]).inverse + " "
@@ -428,6 +453,12 @@ module Ayadn
428
453
  header << " "
429
454
  header << content[:name].color(Settings.options[:colors][:name])
430
455
  end
456
+
457
+ if Settings.options[:timeline][:show_nicerank] && content[:nicerank] && Settings.options[:nicerank][:filter]
458
+ header << " "
459
+ header << "[#{content[:nicerank]}]".color(Settings.options[:colors][:nicerank])
460
+ end
461
+
431
462
  if Settings.options[:timeline][:show_date]
432
463
  header << " "
433
464
  header << content[:date].color(Settings.options[:colors][:date])
data/lib/ayadn/workers.rb CHANGED
@@ -90,7 +90,7 @@ module Ayadn
90
90
  table
91
91
  end
92
92
 
93
- def build_posts(data)
93
+ def build_posts(data, niceranks = {})
94
94
  # builds a hash of hashes, each hash is a normalized post with post id as a key
95
95
  posts = {}
96
96
 
@@ -115,6 +115,12 @@ module Ayadn
115
115
  end
116
116
  next if @skip
117
117
 
118
+ if niceranks[post['user']['id'].to_i]
119
+ rank = niceranks[post['user']['id'].to_i][:rank]
120
+ else
121
+ rank = false
122
+ end
123
+
118
124
  if post['user'].has_key?('name')
119
125
  name = post['user']['name'].to_s.force_encoding("UTF-8")
120
126
  else
@@ -129,6 +135,8 @@ module Ayadn
129
135
  name: name,
130
136
  thread_id: post['thread_id'],
131
137
  username: post['user']['username'],
138
+ user_id: post['user']['id'].to_i,
139
+ nicerank: rank,
132
140
  handle: "@#{post['user']['username']}",
133
141
  type: post['user']['type'],
134
142
  date: parsed_time(post['created_at']),
@@ -75,7 +75,7 @@ describe Ayadn::View do
75
75
  describe "#show_posts_with_index" do
76
76
  it 'outputs the indexed stream' do
77
77
  printed = capture_stdout do
78
- Ayadn::View.new.show_posts_with_index(stream['data'], {})
78
+ Ayadn::View.new.show_posts_with_index(stream['data'], {}, {})
79
79
  end
80
80
  expect(printed).to include "001"
81
81
  expect(printed).to include "Backer of the Day"
@@ -41,7 +41,7 @@ describe Ayadn::Workers do
41
41
  expect(posts[23187443][:has_checkins]).to be false
42
42
  expect(posts[23187443][:mentions]).to eq []
43
43
  expect(posts[23187443][:checkins]).to be_empty
44
- expect(posts[23187443].length).to eq 29
44
+ expect(posts[23187443].length).to eq 31
45
45
  end
46
46
  it "gets oembed link from checkins post" do
47
47
  posts = Ayadn::Workers.new.build_posts(checkins['data'])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ayadn
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Dejonckheere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-17 00:00:00.000000000 Z
11
+ date: 2014-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor