ayadn 1.4.2 → 1.4.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ayadn/alias.rb CHANGED
@@ -21,7 +21,7 @@ module Ayadn
21
21
  puts Status.error_missing_channel_id
22
22
  end
23
23
  rescue => e
24
- Errors.global_error("alias/create", args, e)
24
+ Errors.global_error({error: e, caller: caller, data: [args]})
25
25
  ensure
26
26
  Databases.close_all
27
27
  end
@@ -41,7 +41,7 @@ module Ayadn
41
41
  Action.quit Status.wrong_arguments
42
42
  end
43
43
  rescue => e
44
- Errors.global_error("alias/delete", args, e)
44
+ Errors.global_error({error: e, caller: caller, data: [args]})
45
45
  ensure
46
46
  Databases.close_all
47
47
  end
@@ -65,7 +65,7 @@ module Ayadn
65
65
  puts "\nFile '#{new_db}' doesn't exist.".color(:red)
66
66
  end
67
67
  rescue => e
68
- Errors.global_error("alias/import", database, e)
68
+ Errors.global_error({error: e, caller: caller, data: [database]})
69
69
  ensure
70
70
  Databases.close_all
71
71
  end
@@ -90,7 +90,7 @@ module Ayadn
90
90
  puts Status.empty_list
91
91
  end
92
92
  rescue => e
93
- Errors.global_error("alias/list", args, e)
93
+ Errors.global_error({error: e, caller: caller, data: [options]})
94
94
  ensure
95
95
  Databases.close_all
96
96
  end
@@ -110,7 +110,7 @@ module Ayadn
110
110
  abort Status.canceled
111
111
  end
112
112
  rescue => e
113
- Errors.global_error("alias/clear", args, e)
113
+ Errors.global_error({error: e, caller: caller, data: []})
114
114
  ensure
115
115
  Databases.close_all
116
116
  end
data/lib/ayadn/api.rb CHANGED
@@ -65,7 +65,7 @@ module Ayadn
65
65
  get_parsed_response(Endpoints.new.whostarred(post_id))
66
66
  end
67
67
 
68
- def get_convo(post_id, options)
68
+ def get_convo(post_id, options = {})
69
69
  get_parsed_response(Endpoints.new.convo(post_id, options))
70
70
  end
71
71
 
@@ -230,7 +230,7 @@ module Ayadn
230
230
  if res['meta']['code'] == 200
231
231
  res
232
232
  else
233
- Errors.global_error("api/check_response_meta_code", nil, res['meta'])
233
+ Errors.global_error({error: nil, caller: caller, data: [res['meta']]})
234
234
  end
235
235
  end
236
236
 
@@ -300,6 +300,7 @@ module Ayadn
300
300
  big_hash = {}
301
301
  loop do
302
302
  resp = get_parsed_response(get_list_url(username, target, options))
303
+ abort(Status.user_404(username)) if resp['meta']['code'] == 404
303
304
  big_hash.merge!(Workers.extract_users(resp))
304
305
  break if resp['meta']['min_id'] == nil
305
306
  options = {:count => 200, :before_id => resp['meta']['min_id']}
data/lib/ayadn/app.rb CHANGED
@@ -419,7 +419,8 @@ module Ayadn
419
419
  desc "nowplaying", "Post the current iTunes track (-np)"
420
420
  map "-np" => :nowplaying
421
421
  long_desc Descriptions.nowplaying
422
- option :no_url, type: :boolean, desc: "Don't append preview or album art at the end of the post"
422
+ option :no_url, aliases: "-n", type: :boolean, desc: "Don't append preview or album art at the end of the post"
423
+ option :lastfm, aliases: "-l", type: :boolean, desc: "Get current track from Last.fm instead of iTunes"
423
424
  def nowplaying
424
425
  Action.new.nowplaying(options)
425
426
  end
data/lib/ayadn/cnx.rb CHANGED
@@ -3,10 +3,20 @@ module Ayadn
3
3
  class CNX
4
4
 
5
5
  def self.download url
6
+ working = true
6
7
  begin
7
8
  RestClient.get(url) {|response, request, result| response}
9
+ rescue SocketError, SystemCallError, OpenSSL::SSL::SSLError, RestClient::RequestTimeout => e
10
+ if working == true
11
+ working = false
12
+ puts "\nOoops, '#{url}' didn't respond. Trying again in 5 secs.\n".color(:red)
13
+ sleep 5
14
+ retry
15
+ end
16
+ puts "\nConnexion error.\n\n".color(:red)
17
+ Errors.global_error({error: e, caller: caller, data: [url, response]})
8
18
  rescue => e
9
- Errors.global_error("cnx.rb/download", url, e)
19
+ Errors.global_error({error: e, caller: caller, data: [url, response]})
10
20
  end
11
21
  end
12
22
 
@@ -26,7 +36,7 @@ module Ayadn
26
36
  Errors.nr "URL: #{url}"
27
37
  return {'meta' => {'code' => 666}, 'data' => "#{e}"}.to_json
28
38
  rescue => e
29
- Errors.global_error("cnx.rb/get", url, e)
39
+ Errors.global_error({error: e, caller: caller, data: [url, response]})
30
40
  end
31
41
  end
32
42
 
@@ -36,7 +46,7 @@ module Ayadn
36
46
  response
37
47
  when 204
38
48
  puts "\nError: the NiceRank filter made too many requests to the server. You may either wait for a little while before scrolling the filtered Global again, or set the scroll timer to a greater value (example: `ayadn set scroll timer 5`). (see http://ayadn-app.net/doc).\n".color(:red)
39
- Errors.global_error("cnx.rb/get", [url, response.inspect, response.headers], "NiceRank: TOO MANY REQUESTS")
49
+ Errors.global_error({error: "NiceRank: TOO MANY REQUESTS", caller: caller, data: [url, response.inspect, response.headers]})
40
50
  else
41
51
  response
42
52
  end
@@ -55,9 +65,9 @@ module Ayadn
55
65
  retry
56
66
  end
57
67
  puts "\nConnection error.".color(:red)
58
- Errors.global_error("cnx.rb/get_response_from", url, e)
68
+ Errors.global_error({error: e, caller: caller, data: [url]})
59
69
  rescue => e
60
- Errors.global_error("cnx.rb/get_response_from", url, e)
70
+ Errors.global_error({error: e, caller: caller, data: [url, response]})
61
71
  end
62
72
  end
63
73
 
@@ -77,29 +87,29 @@ module Ayadn
77
87
  response
78
88
  when 204
79
89
  puts "\n#{message}".color(:red)
80
- Errors.global_error("cnx.rb", [message, response.headers], "NO CONTENT")
90
+ Errors.global_error({error: "NO CONTENT", caller: caller, data: [message, response.headers]})
81
91
  when 400
82
92
  puts "\n#{message}".color(:red)
83
- Errors.global_error("cnx.rb", [message, response.headers], "BAD REQUEST")
93
+ Errors.global_error({error: "BAD REQUEST", caller: caller, data: [message, response.headers]})
84
94
  when 401
85
95
  puts "\n#{message}".color(:red)
86
- Errors.global_error("cnx.rb", [message, response.headers], "UNAUTHORIZED")
96
+ Errors.global_error({error: "UNAUTHORIZED", caller: caller, data: [message, response.headers]})
87
97
  when 403
88
98
  puts "\n#{message}".color(:red)
89
- Errors.global_error("cnx.rb", [message, response.headers], "FORBIDDEN")
99
+ Errors.global_error({error: "FORBIDDEN", caller: caller, data: [message, response.headers]})
90
100
  when 405
91
101
  puts "\n#{message}".color(:red)
92
- Errors.global_error("cnx.rb", [message, response.headers], "METHOD NOT ALLOWED")
102
+ Errors.global_error({error: "METHOD NOT ALLOWED", caller: caller, data: [message, response.headers]})
93
103
  when 429
94
104
  puts "\n#{message}".color(:red)
95
105
  puts "\n\nAyadn made too many requests to the App.net API. You should wait at least ".color(:cyan) + "#{response.headers[:retry_after]} ".color(:red) + "seconds before trying again. Maybe you launched a lot of Ayadn instances at the same time? That's no problem, but in this case you should increase the value of the scroll timer (with `ayadn set scroll timer 5` for example). App.net allows 5000 requests per hour per account maximum.".color(:cyan)
96
- Errors.global_error("cnx.rb", [message, response.headers], "TOO MANY REQUESTS")
106
+ Errors.global_error({error: "TOO MANY REQUESTS", caller: caller, data: [message, response.headers]})
97
107
  when 500
98
108
  puts "\n#{message}".color(:red)
99
- Errors.global_error("cnx.rb", [message, response.headers], "APP.NET SERVER ERROR")
109
+ Errors.global_error({error: "APP.NET SERVER ERROR", caller: caller, data: [message, response.headers]})
100
110
  when 507
101
111
  puts "\n#{message}".color(:red)
102
- Errors.global_error("cnx.rb", [message, response.headers], "INSUFFICIENT STORAGE")
112
+ Errors.global_error({error: "INSUFFICIENT STORAGE", caller: caller, data: [message, response.headers]})
103
113
  else
104
114
  response
105
115
  end
@@ -107,19 +117,15 @@ module Ayadn
107
117
 
108
118
  def self.delete(url)
109
119
  begin
110
- #RestClient::Resource.new(url).delete
111
120
  RestClient.delete(url) do |response, request, result|
112
121
  Debug.http response, url
113
122
  check response
114
123
  end
115
- rescue SocketError => e
116
- puts "\nConnection error.".color(:red)
117
- Errors.global_error("cnx.rb/delete", url, e)
118
- rescue SystemCallError => e
124
+ rescue SocketError, SystemCallError => e
119
125
  puts "\nConnection error.".color(:red)
120
- Errors.global_error("cnx.rb/delete", url, e)
126
+ Errors.global_error({error: e, caller: caller, data: [url]})
121
127
  rescue => e
122
- Errors.global_error("cnx.rb/delete", url, e)
128
+ Errors.global_error({error: e, caller: caller, data: [url]})
123
129
  end
124
130
  end
125
131
 
@@ -129,14 +135,11 @@ module Ayadn
129
135
  Debug.http response, url
130
136
  check response
131
137
  end
132
- rescue SocketError => e
138
+ rescue SocketError, SystemCallError => e
133
139
  puts "\nConnection error.".color(:red)
134
- Errors.global_error("cnx.rb/post", url, e)
135
- rescue SystemCallError => e
136
- puts "\nConnection error.".color(:red)
137
- Errors.global_error("cnx.rb/post", url, e)
140
+ Errors.global_error({error: e, caller: caller, data: [url, payload]})
138
141
  rescue => e
139
- Errors.global_error("cnx.rb/post", [url, payload], e)
142
+ Errors.global_error({error: e, caller: caller, data: [url, payload]})
140
143
  end
141
144
  end
142
145
 
@@ -146,14 +149,11 @@ module Ayadn
146
149
  Debug.http response, url
147
150
  check response
148
151
  end
149
- rescue SocketError => e
150
- puts "\nConnection error.".color(:red)
151
- Errors.global_error("cnx.rb/put", url, e)
152
- rescue SystemCallError => e
152
+ rescue SocketError, SystemCallError => e
153
153
  puts "\nConnection error.".color(:red)
154
- Errors.global_error("cnx.rb/put", url, e)
154
+ Errors.global_error({error: e, caller: caller, data: [url, payload]})
155
155
  rescue => e
156
- Errors.global_error("cnx.rb/put", [url, payload], e)
156
+ Errors.global_error({error: e, caller: caller, data: [url, payload]})
157
157
  end
158
158
  end
159
159
 
@@ -24,12 +24,8 @@ module Ayadn
24
24
  def self.close_all
25
25
 
26
26
  if @nicerank.size > 10000
27
- limit = Time.now - (3600 * 168)
27
+ limit = Time.now - (3600 * 48)
28
28
  @nicerank.each {|k,v| @nicerank.delete(k) if v[:cached] < limit}
29
- if @nicerank.size > 10000
30
- limit = Time.now - (3600 * 48)
31
- @nicerank.each {|k,v| @nicerank.delete(k) if v[:cached] < limit}
32
- end
33
29
  end
34
30
 
35
31
  Debug.db all_dbs
@@ -140,7 +136,7 @@ module Ayadn
140
136
  @index.each {|id, values| return values if values[:count] == number}
141
137
  else
142
138
  puts Status.must_be_in_index
143
- Errors.global_error("databases/get_post_from_index", number, "out of range")
139
+ Errors.global_error({error: "Out of range", caller: caller, data: [number]})
144
140
  end
145
141
  end
146
142
 
data/lib/ayadn/debug.rb CHANGED
@@ -4,11 +4,13 @@ module Ayadn
4
4
 
5
5
  def self.http response, url
6
6
  if Settings.options[:timeline][:show_debug] == true
7
- deb = ":::::\n"
8
- deb << "Url:\t\t#{url}\n\n"
9
- deb << "Headers:\t#{response.headers}\n"
10
- deb << ":::::\n"
11
- puts deb.color(Settings.options[:colors][:debug])
7
+ # deb = ":::::\n"
8
+ # deb << "Url:\t\t#{url}\n\n"
9
+ # deb << "Headers:\t#{response.headers}\n"
10
+ # deb << ":::::\n"
11
+ # puts deb.color(Settings.options[:colors][:debug])
12
+ Logs.rec.debug "HTTP/URL: #{url}"
13
+ Logs.rec.debug "HTTP/HEADERS: #{response.headers}"
12
14
  end
13
15
  end
14
16
 
@@ -17,73 +19,88 @@ module Ayadn
17
19
  puts "/////\nSETTINGS\n"
18
20
  jj JSON.parse((Settings.config).to_json)
19
21
  jj JSON.parse((Settings.options).to_json)
22
+ Logs.rec.debug "SETTINGS/CONFIG: #{Settings.config}"
23
+ Logs.rec.debug "SETTINGS/OPTIONS: #{Settings.options}"
20
24
  puts "/////\n\n"
21
25
 
22
- puts ">>>>>\nDATABASES\n"
26
+ #puts ">>>>>\nDATABASES\n"
23
27
  dbs.each do |db|
24
- puts "Path:\t#{db.file}\nLength:\t#{db.size}\nSize:\t#{db.bytesize / 1024}KB"
28
+ #puts "Path:\t#{db.file}\nLength:\t#{db.size}\nSize:\t#{db.bytesize / 1024}KB"
29
+ Logs.rec.debug "DB: #{File.basename(db.file)} - Length: #{db.size}, Size: #{db.bytesize / 1024}KB"
25
30
  end
26
- puts ">>>>>\n\n"
31
+ #puts ">>>>>\n\n"
27
32
 
28
- puts "^^^^^\nTOKEN\n"
29
- puts Settings.user_token
30
- puts "^^^^^\n\n"
33
+ # puts "^^^^^\nTOKEN\n"
34
+ # puts Settings.user_token
35
+ # puts "^^^^^\n\n"
31
36
  end
32
37
  end
33
38
 
34
- def self.err error
39
+ def self.err error, stack
35
40
  if Settings.options[:timeline][:show_debug] == true
36
- puts "--*--\nTRACE:\n"
41
+ puts "\n--*--\nERROR:\n"
37
42
  raise error
43
+ puts "\n--*--\nSTACK:\n"
44
+ puts stack
38
45
  puts "\n--*--\n\n"
39
46
  end
40
47
  end
41
48
 
42
49
  def self.how_many_ranks niceranks, get_these
43
50
  if Settings.options[:timeline][:show_debug] == true
44
- deb = "=====\n"
45
- deb << "NR from DB:\t#{niceranks}\n\n"
46
- deb << "NR to get:\t#{get_these}\n"
47
- deb << "=====\n"
48
- puts deb.color(Settings.options[:colors][:debug])
51
+ # deb = "=====\n"
52
+ # deb << "NR from DB:\t#{niceranks}\n\n"
53
+ # deb << "NR to get:\t#{get_these}\n"
54
+ # deb << "=====\n"
55
+ # puts deb.color(Settings.options[:colors][:debug])
56
+ Logs.rec.debug "NR/FROM DB: #{niceranks}"
57
+ Logs.rec.debug "NR/TO GET: #{get_these}"
49
58
  end
50
59
  end
51
60
 
52
61
  def self.ranks_pool niceranks
53
62
  if Settings.options[:timeline][:show_debug] == true
54
- deb = "=====\n"
55
- deb << "NR in pool:\t#{niceranks}\n"
56
- deb << "=====\n"
57
- puts deb.color(Settings.options[:colors][:debug])
63
+ # deb = "=====\n"
64
+ # deb << "NR in pool:\t#{niceranks}\n"
65
+ # deb << "=====\n"
66
+ # puts deb.color(Settings.options[:colors][:debug])
67
+ Logs.rec.debug "NR/IN POOL: #{niceranks}"
58
68
  end
59
69
  end
60
70
 
61
71
  def self.niceranks_error resp
62
72
  if Settings.options[:timeline][:show_debug] == true
63
- deb = "=====\n"
64
- deb << "NR Error:\t#{resp}\n"
65
- deb << "=====\n"
66
- puts deb.color(Settings.options[:colors][:debug])
73
+ # deb = "=====\n"
74
+ # deb << "NR Error:\t#{resp}\n"
75
+ # deb << "=====\n"
76
+ # puts deb.color(Settings.options[:colors][:debug])
77
+ Logs.rec.error "NR/ERROR: #{resp}"
67
78
  end
68
79
  end
69
80
 
70
81
  def self.total_ranks niceranks
71
82
  if Settings.options[:timeline][:show_debug] == true
72
- deb = "=====\n"
73
- deb << "NiceRanks:\t#{niceranks}\n\n"
74
- deb << "DB size:\t#{Databases.nicerank.size}\n"
75
- deb << "=====\n"
76
- puts deb.color(Settings.options[:colors][:debug])
83
+ # deb = "=====\n"
84
+ # deb << "NiceRanks:\t#{niceranks}\n\n"
85
+ # deb << "DB size:\t#{Databases.nicerank.size}\n"
86
+ # deb << "=====\n"
87
+ # puts deb.color(Settings.options[:colors][:debug])
88
+ Logs.rec.debug "NR/RANKS: #{niceranks}"
89
+ Logs.rec.debug "NR/DB SIZE: #{Databases.nicerank.size}"
77
90
  end
78
91
  end
79
92
 
80
93
  def self.stream stream, options, target
81
94
  if Settings.options[:timeline][:show_debug] == true
82
- deb = "+++++\nStream meta:\t#{stream['meta']}\n\n"
83
- deb << "Options:\t#{options.inspect}\n\n"
84
- deb << "Target:\t\t#{target.inspect}\n\n"
85
- deb << "Posts:\t\t#{stream['data'].length}\n+++++\n"
86
- puts deb.color(Settings.options[:colors][:debug])
95
+ # deb = "+++++\nStream meta:\t#{stream['meta']}\n\n"
96
+ # deb << "Options:\t#{options.inspect}\n\n"
97
+ # deb << "Target:\t\t#{target.inspect}\n\n"
98
+ # deb << "Posts:\t\t#{stream['data'].length}\n+++++\n"
99
+ # puts deb.color(Settings.options[:colors][:debug])
100
+ Logs.rec.debug "STREAM/META: #{stream['meta']}"
101
+ Logs.rec.debug "STREAM/OPTIONS: #{options.inspect}"
102
+ Logs.rec.debug "STREAM/TARGET: #{target.inspect}"
103
+ Logs.rec.debug "STREAM/POSTS: #{stream['data'].length}"
87
104
  end
88
105
  end
89
106
 
data/lib/ayadn/errors.rb CHANGED
@@ -1,17 +1,21 @@
1
1
  # encoding: utf-8
2
2
  module Ayadn
3
3
  class Errors
4
- def self.global_error(where, args, error)
5
- #elems = []
6
- #args.each {|arg| elems << self.detokenize(arg)} #TODO: make it work
4
+ def self.global_error(args)
7
5
  Logs.rec.error "--BEGIN--"
8
- Logs.rec.error "#{error}"
9
- Logs.rec.debug "LOCATION: #{where}"
10
- Logs.rec.debug "DATA: #{args}"
11
- Logs.rec.debug "STACK: #{caller}"
6
+ Logs.rec.error "CAUSE: #{args[:error]}"
7
+ Logs.rec.debug "DATA: #{args[:data]}"
8
+ stack = args[:caller].map do |path|
9
+ splitted = path.split('/')
10
+ file = splitted.pop
11
+ dir = splitted.pop
12
+ "#{dir}/#{file}"
13
+ end
14
+ Logs.rec.debug "STACK: #{stack}"
15
+ #Logs.rec.debug "STACK: #{args[:caller]}"
12
16
  Logs.rec.error "--END--"
13
- puts "\n(error logged in #{Settings.config[:paths][:log]}/ayadn.log)\n".color(:blue)
14
- Debug.err error
17
+ puts "\nError logged in #{Settings.config[:paths][:log]}/ayadn.log\n".color(:blue)
18
+ Debug.err(args[:error], stack)
15
19
  exit
16
20
  end
17
21
  def self.error(status)
@@ -29,11 +33,5 @@ module Ayadn
29
33
  def self.nr msg
30
34
  Logs.nr.warn msg
31
35
  end
32
-
33
- private
34
-
35
- def self.detokenize(string)
36
- string.dup.to_s.gsub!(/token=[a-zA-Z0-9_-]+/, "token=XXX") unless string.nil?
37
- end
38
36
  end
39
37
  end
data/lib/ayadn/logs.rb CHANGED
@@ -9,11 +9,11 @@ module Ayadn
9
9
  def self.create_logger
10
10
  @rec = Logger.new(Settings.config[:paths][:log] + "/ayadn.log", 'monthly')
11
11
  @rec.formatter = proc do |severity, datetime, progname, msg|
12
- "#{datetime} (#{Settings.config[:version]}) #{severity} -- #{msg}\n"
12
+ "#{datetime} (#{Settings.config[:version]}) #{severity} * #{msg}\n"
13
13
  end
14
14
  @nr = Logger.new(Settings.config[:paths][:log] + "/nicerank.log", 'monthly')
15
15
  @nr.formatter = proc do |severity, datetime, progname, msg|
16
- "#{datetime} (#{Settings.config[:version]}) #{severity} -- #{msg}\n"
16
+ "#{datetime} (#{Settings.config[:version]}) #{severity} * #{msg}\n"
17
17
  end
18
18
  end
19
19
 
data/lib/ayadn/mark.rb CHANGED
@@ -49,7 +49,7 @@ module Ayadn
49
49
  Logs.rec.info "Added conversation bookmark for post #{bookmark[:id]}."
50
50
  puts Status.done
51
51
  rescue => e
52
- Errors.global_error("mark/add", args, e)
52
+ Errors.global_error({error: e, caller: caller, data: [args]})
53
53
  ensure
54
54
  Databases.close_all
55
55
  end
@@ -70,7 +70,7 @@ module Ayadn
70
70
  puts "\n"
71
71
  list.each {|marked| puts make_entry marked; puts "\n"}
72
72
  rescue => e
73
- Errors.global_error("mark/list", nil, e)
73
+ Errors.global_error({error: e, caller: caller, data: [args, options]})
74
74
  ensure
75
75
  Databases.close_all
76
76
  end
@@ -90,7 +90,7 @@ module Ayadn
90
90
  abort Status.canceled
91
91
  end
92
92
  rescue => e
93
- Errors.global_error("mark/clear", nil, e)
93
+ Errors.global_error({error: e, caller: caller, data: []})
94
94
  ensure
95
95
  Databases.close_all
96
96
  end
@@ -106,7 +106,7 @@ module Ayadn
106
106
  Databases.delete_bookmark post_id
107
107
  puts Status.done
108
108
  rescue => e
109
- Errors.global_error("mark/delete", args, e)
109
+ Errors.global_error({error: e, caller: caller, data: [args]})
110
110
  ensure
111
111
  Databases.close_all
112
112
  end
@@ -126,7 +126,7 @@ module Ayadn
126
126
  Databases.rename_bookmark post_id, new_title
127
127
  puts Status.done
128
128
  rescue => e
129
- Errors.global_error("mark/rename", args, e)
129
+ Errors.global_error({error: e, caller: caller, data: [args]})
130
130
  ensure
131
131
  Databases.close_all
132
132
  end
@@ -16,7 +16,7 @@ module Ayadn
16
16
  abort(Status.canceled)
17
17
  rescue => e
18
18
  puts Status.wtf
19
- Errors.global_error("pinboard/ask_credentials", pin_username, e)
19
+ Errors.global_error({error: e, caller: caller, data: [pin_username]})
20
20
  end
21
21
  save_credentials(encode(pin_username, pin_password))
22
22
  end
data/lib/ayadn/post.rb CHANGED
@@ -11,14 +11,7 @@ module Ayadn
11
11
  end
12
12
 
13
13
  def compose
14
- # case Settings.config[:platform]
15
- # when /mswin|mingw|cygwin/
16
- # post = classic
17
- # else
18
- require "readline"
19
- readline
20
- # end
21
- # post
14
+ readline()
22
15
  end
23
16
 
24
17
  def send_embedded text, files
@@ -61,7 +54,12 @@ module Ayadn
61
54
  "height" => dic['height'],
62
55
  "title" => dic['title'],
63
56
  "url" => dic['artwork'],
64
- "embeddable_url" => dic['artwork']
57
+ "embeddable_url" => dic['artwork'],
58
+ "provider_url" => "https://itunes.apple.com",
59
+ "provider_name" => "iTunes",
60
+ "thumbnail_url" => dic['artwork_thumb'],
61
+ "thumbnail_width" => dic['width_thumb'],
62
+ "thumbnail_height" => dic['height_thumb']
65
63
  }
66
64
  }
67
65
  end
@@ -115,19 +113,6 @@ module Ayadn
115
113
  return base
116
114
  end
117
115
 
118
- # def auto_classic
119
- # loop do
120
- # begin
121
- # print "#{Settings.config[:identity][:handle]} >> ".color(:red)
122
- # t = STDIN.gets.chomp
123
- # send_post(t)
124
- # puts Status.done
125
- # rescue Interrupt
126
- # abort(Status.canceled)
127
- # end
128
- # end
129
- # end
130
-
131
116
  def auto_readline
132
117
  loop do
133
118
  begin
@@ -150,18 +135,11 @@ module Ayadn
150
135
  post << buffer
151
136
  end
152
137
  rescue Interrupt
153
- #Errors.info "Write post: canceled."
154
138
  abort(Status.canceled)
155
139
  end
156
140
  post
157
141
  end
158
142
 
159
- # def classic
160
- # puts Status.classic
161
- # input_text = STDIN.gets.chomp
162
- # [input_text]
163
- # end
164
-
165
143
  def reply(new_post, replied_to)
166
144
  replied_to = replied_to.values[0]
167
145
  reply = replied_to[:handle].dup
@@ -82,13 +82,13 @@ module Ayadn
82
82
  begin
83
83
  @options = YAML.load(File.read(config_file))
84
84
  rescue => e
85
- Errors.global_error("myconfig/load config.yml", nil, e)
85
+ Errors.global_error({error: e, caller: caller, data: []})
86
86
  end
87
87
  else
88
88
  begin
89
89
  self.write_config_file(config_file, @options)
90
90
  rescue => e
91
- Errors.global_error("myconfig/create config.yml from defaults", nil, e)
91
+ Errors.global_error({error: e, caller: caller, data: []})
92
92
  end
93
93
  end
94
94
  end
data/lib/ayadn/status.rb CHANGED
@@ -54,37 +54,37 @@ module Ayadn
54
54
  "\nStarring #{post_id}".inverse
55
55
  end
56
56
  def self.not_deleted(post_id)
57
- "Could not delete post #{post_id} (post isn't yours, or is already deleted)\n".color(:red)
57
+ "\nCould not delete post #{post_id} (post isn't yours, or is already deleted)\n".color(:red)
58
58
  end
59
59
  def self.not_starred(post_id)
60
- "Could not star post #{post_id} (post doesn't exist, or is already starred)\n".color(:red)
60
+ "\nCould not star post #{post_id} (post doesn't exist, or is already starred)\n".color(:red)
61
61
  end
62
62
  def self.not_unreposted(post_id)
63
- "Could not unrepost post #{post_id} (post isn't yours, isn't a repost, or has been deleted)\n".color(:red)
63
+ "\nCould not unrepost post #{post_id} (post isn't yours, isn't a repost, or has been deleted)\n".color(:red)
64
64
  end
65
65
  def self.not_reposted(post_id)
66
- "Could not repost post #{post_id} (post has been deleted?)\n".color(:red)
66
+ "\nCould not repost post #{post_id} (post has been deleted?)\n".color(:red)
67
67
  end
68
68
  def self.not_unstarred(post_id)
69
- "Could not unstar post #{post_id} (post isn't yours, isn't starred, or has been deleted)\n".color(:red)
69
+ "\nCould not unstar post #{post_id} (post isn't yours, isn't starred, or has been deleted)\n".color(:red)
70
70
  end
71
71
  def self.not_unfollowed(post_id)
72
- "Could not unfollow user #{username} (doesn't exist, or wasn't already followed)\n".color(:red)
72
+ "\nCould not unfollow user #{username} (doesn't exist, or wasn't already followed)\n".color(:red)
73
73
  end
74
74
  def self.not_followed(post_id)
75
- "Could not follow user #{username} (doesn't exist, or you already follow)\n".color(:red)
75
+ "\nCould not follow user #{username} (doesn't exist, or you already follow)\n".color(:red)
76
76
  end
77
77
  def self.not_unmuted(post_id)
78
- "Could not unmute user #{username} (doesn't exist, or wasn't already muted)\n".color(:red)
78
+ "\nCould not unmute user #{username} (doesn't exist, or wasn't already muted)\n".color(:red)
79
79
  end
80
80
  def self.not_muted(post_id)
81
- "Could not mute user #{username} (doesn't exist, or is already muted)\n".color(:red)
81
+ "\nCould not mute user #{username} (doesn't exist, or is already muted)\n".color(:red)
82
82
  end
83
83
  def self.not_unblocked(post_id)
84
- "Could not unblock user #{username} (doesn't exist, or wasn't already blocked)\n".color(:red)
84
+ "\nCould not unblock user #{username} (doesn't exist, or wasn't already blocked)\n".color(:red)
85
85
  end
86
86
  def self.not_blocked(post_id)
87
- "Could not block user #{username} (doesn't exist, or is already blocked)\n".color(:red)
87
+ "\nCould not block user #{username} (doesn't exist, or is already blocked)\n".color(:red)
88
88
  end
89
89
  def self.deleted(post_id)
90
90
  "\nPost #{post_id} has been deleted.\n".color(:green)
@@ -210,7 +210,7 @@ module Ayadn
210
210
  "\nSaving post text and links to Pinboard...\n\n".color(:yellow)
211
211
  end
212
212
  def self.error_only_osx
213
- "\nThis feature only works with Mac OS X and iTunes, sorry.\n\n".color(:red)
213
+ "\nThis feature only works with iTunes by default. If you've got a Last.fm account, add the option:\n\n`ayadn -np --lastfm` (short: `-l`).\n\n".color(:red)
214
214
  end
215
215
  def self.empty_fields
216
216
  "\nCanceled: couldn't get enough information (empty field).\n\n".color(:red)
@@ -287,5 +287,11 @@ module Ayadn
287
287
  def self.no_curl
288
288
  "\n\nAyadn needs 'curl' to upload files. Please install 'curl' (or check that it's properly declared in your $PATH).\n\n".color(:red)
289
289
  end
290
+ def self.itunes_store
291
+ "Fetching informations from the Itunes Store...\n".color(:green)
292
+ end
293
+ def self.fetching_from source
294
+ "\nFetching informations from #{source}...\n".color(:green)
295
+ end
290
296
  end
291
297
  end