ayadn 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7f8e1b7b05ad05985a512f87bd25bafae49b4349
4
- data.tar.gz: 0a014cf6c284723edffca3829533561515cd0586
3
+ metadata.gz: af910b3cdf032bba6a40ec67f9ef72b26f85bcce
4
+ data.tar.gz: 30406883a202fe07dea4b2f4c64ab1db07579118
5
5
  SHA512:
6
- metadata.gz: c66cc072a0717d04de64fbd4d8269ff2dccb1f2a2c7aedf9e28c888c3a5dda5302380c75c6f97d6000f0030b9ce498fbf46b98a5a2a85a76d35c9e0ea5c25ad1
7
- data.tar.gz: 3c91d658e3d6d6108f654b1b9da544788e183d7b9c134176ec78aabe25c36dc1504a0d69e62bcecbe4e1af1acb34f5392890b0798110fb20e44cf54b8fe030fe
6
+ metadata.gz: c96df00a81872453044d605c2c2391f21a2e96847660bcb299cbade0cc7e5f7e76fe910dfcdb951c23c0635681d589b4e88585fd718f789b5178b74265ae56a4
7
+ data.tar.gz: 02c601968b84ef5cd20b37835efefbb0551fa3cf35641f7837151f430e3616823703beaf9eee2afc38a807bed877f237bd3130714e0caf9449f7dad1da8a364b
data/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # 1.0.2
2
+
3
+ - Fixed a critical bug in Reply (when the original post was a repost)
4
+ - Tests for Databases
5
+ - Tests for Posts & Messages
6
+ - Better layout for checkins
7
+ - Better alert message if error 429
8
+
9
+ # 1.0.1
10
+
11
+ Release!
12
+
13
+ It should have been 1.0.0, but a PEBKAC happened and, yeah, so 1.0.1 it is.
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Gem Version](https://badge.fury.io/rb/ayadn.svg)](http://badge.fury.io/rb/ayadn)
1
2
  [![Build Status](https://travis-ci.org/ericdke/na.svg?branch=master)](https://travis-ci.org/ericdke/na)
2
3
 
3
4
  AYADN
data/lib/ayadn/action.rb CHANGED
@@ -758,6 +758,11 @@ module Ayadn
758
758
  puts Status.replying_to(post_id)
759
759
  replied_to = @api.get_details(post_id)
760
760
  post_404(post_id) if meta_404(replied_to)
761
+ post_id = get_original_id(post_id, replied_to)
762
+ if post_id == replied_to['data']['repost_of']['id']
763
+ replied_to = @api.get_details(post_id)
764
+ post_404(post_id) if meta_404(replied_to)
765
+ end
761
766
  poster = Post.new
762
767
  puts Status.reply
763
768
  lines_array = poster.compose
data/lib/ayadn/cnx.rb CHANGED
@@ -39,7 +39,7 @@ module Ayadn
39
39
  Errors.global_error("cnx.rb", response.headers, "METHOD NOT ALLOWED")
40
40
  when 429
41
41
  puts "\n'Too many requests'".color(:red)
42
- 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 (do `ayadn set scroll timer 2.5` for example).".color(:cyan)
42
+ 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)
43
43
  Errors.global_error("cnx.rb", response.headers, "TOO MANY REQUESTS")
44
44
  when 500
45
45
  puts "\n'App.net server error'".color(:red)
data/lib/ayadn/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Ayadn
3
- VERSION = "1.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
data/lib/ayadn/view.rb CHANGED
@@ -455,14 +455,20 @@ module Ayadn
455
455
  hd << "\n"
456
456
  formatted = { header: hd }
457
457
  content[:checkins].each do |key, val|
458
- formatted[key] = val unless (val.nil? || !val)
458
+ #formatted[key] = val unless (val.nil? || !val)
459
+ formatted[key] = val
459
460
  end
460
461
 
462
+ formatted[:name] = "" if formatted[:name].nil?
461
463
  chk = formatted[:header]
462
- unless formatted[:name].nil?
464
+ unless formatted[:name] == ""
463
465
  chk << formatted[:name].color(Settings.options[:colors][:dots])
464
466
  chk << "\n"
465
467
  end
468
+ unless formatted[:title].nil? || formatted[:title] == formatted[:name]
469
+ chk << formatted[:title]
470
+ chk << "\n"
471
+ end
466
472
  unless formatted[:address].nil?
467
473
  chk << formatted[:address]
468
474
  chk << "\n"
@@ -471,22 +477,37 @@ module Ayadn
471
477
  chk << formatted[:address_extended]
472
478
  chk << "\n"
473
479
  end
474
- unless formatted[:country_code].nil?
475
- cc = "(#{formatted[:country_code]})".upcase
476
- else
477
- cc = ""
478
- end
480
+
479
481
  unless formatted[:postcode].nil?
480
482
  unless formatted[:locality].nil?
481
- chk << "#{formatted[:postcode]}, #{formatted[:locality]} #{cc}"
482
- chk << "\n"
483
+ chk << "#{formatted[:postcode]}, #{formatted[:locality]}"
484
+ else
485
+ chk << "#{formatted[:postcode]}"
483
486
  end
487
+ chk << "\n"
484
488
  else
485
489
  unless formatted[:locality].nil?
486
- chk << "#{formatted[:locality]} #{cc}"
490
+ chk << "#{formatted[:locality]}"
491
+ chk << "\n"
492
+ end
493
+ end
494
+
495
+ formatted[:country_code].nil? ? cc = "" : cc = formatted[:country_code]
496
+
497
+ if formatted[:region].nil?
498
+ unless cc == ""
499
+ chk << "(#{cc})".upcase
487
500
  chk << "\n"
488
501
  end
502
+ else
503
+ unless cc == ""
504
+ chk << "#{formatted[:region]} (#{cc.upcase})"
505
+ else
506
+ chk << "#{formatted[:region]}"
507
+ end
508
+ chk << "\n"
489
509
  end
510
+
490
511
  unless formatted[:website].nil?
491
512
  chk << formatted[:website]
492
513
  chk << "\n"
data/lib/ayadn/workers.rb CHANGED
@@ -349,6 +349,12 @@ module Ayadn
349
349
  checkins[:longitude] = obj['value']['longitude']
350
350
  checkins[:latitude] = obj['value']['latitude']
351
351
  end
352
+ unless obj['value']['title'].nil?
353
+ checkins[:title] = obj['value']['title']
354
+ end
355
+ unless obj['value']['region'].nil?
356
+ checkins[:region] = obj['value']['region']
357
+ end
352
358
  #when "net.app.core.oembed"
353
359
  #has_checkins = true
354
360
  #checkins[:embeddable_url] = obj['value']['embeddable_url']
Binary file
Binary file
Binary file
Binary file
Binary file
data/spec/spec_helper.rb CHANGED
@@ -10,5 +10,5 @@ RSpec.configure do |config|
10
10
  # the seed, which is printed after each run.
11
11
  # --seed 1234
12
12
  config.order = 'random'
13
- #config.include FakeFS::SpecHelpers, fakefs: true
13
+ config.include FakeFS::SpecHelpers, fakefs: true
14
14
  end
@@ -1,5 +1,49 @@
1
1
  require 'spec_helper'
2
+ require 'helpers'
2
3
 
3
4
  describe Ayadn::Databases do
5
+ before do
6
+ Ayadn::Settings.stub(:config).and_return({
7
+ paths: {
8
+ db: 'spec/mock/',
9
+ pagination: 'spec/mock/'
10
+ }
11
+ })
12
+ Ayadn::Databases.open_databases
13
+ end
14
+ describe ".add_to_users_db" do
15
+ it "adds a user" do
16
+ Ayadn::Databases.add_to_users_db(33, 'test', 'Mr Test')
17
+ expect(Ayadn::Databases.users.keys).to eq ['33']
18
+ u = Ayadn::Databases.users[33]
19
+ expect(u['test']).to eq 'Mr Test'
20
+ end
21
+ end
22
+ describe ".add_to_users_db_from_list" do
23
+ it "imports users from a list" do
24
+ list = {12=>['yolo', 'Miss YOLO'], 666=>['lucy', 'Lucy Fair']}
25
+ Ayadn::Databases.add_to_users_db_from_list(list)
26
+ expect(Ayadn::Databases.users.keys).to eq ['12', '666']
27
+ u = Ayadn::Databases.users[12]
28
+ expect(u['yolo']).to eq 'Miss YOLO'
29
+ u = Ayadn::Databases.users[666]
30
+ expect(u['lucy']).to eq 'Lucy Fair'
31
+ end
32
+ end
33
+ # describe ".save_max_id" do
34
+ # it "saves pagination" do
4
35
 
36
+
37
+ # end
38
+ # end
39
+ # describe ".has_new?" do
40
+ # it "check if new posts since last pagination record" do
41
+ # stream = {'meta'=>{'max_id'=>33666}}
42
+
43
+ # end
44
+ # end
45
+ after do
46
+ Ayadn::Databases.users.clear
47
+ Ayadn::Databases.close_all
48
+ end
5
49
  end
@@ -36,59 +36,37 @@ describe Ayadn::Post do
36
36
  },
37
37
  post_max_length: 256,
38
38
  message_max_length: 2048,
39
- version: Ayadn::VERSION
39
+ version: 'wee'
40
40
  })
41
- Ayadn::Settings.stub(:user_token).and_return('XXX')
41
+ Ayadn::Settings.stub(:user_token).and_return('XYZ')
42
+ Ayadn::Settings.stub(:check_for_accounts)
42
43
  Ayadn::Errors.stub(:warn).and_return("warned")
43
44
  Ayadn::Logs.stub(:rec).and_return("logged")
44
45
  end
45
46
 
46
47
  let(:post) { Ayadn::Post.new }
48
+ let(:rest) {Ayadn::CNX = double} #verbose in RSpec output, but useful
47
49
 
48
50
  describe "#post" do
51
+ before do
52
+ rest.stub(:post).and_return(File.read("spec/mock/posted.json"))
53
+ end
49
54
  it "should raise an error if args are empty" do
50
55
  printed = capture_stdout do
51
56
  post.post([])
52
57
  end
53
58
  expect(printed).to include "You should provide some text."
54
59
  end
60
+ it "posts a post" do
61
+ expect(rest).to receive(:post).with("https://alpha-api.app.net/stream/0/posts/?include_annotations=1&access_token=XYZ", {"text"=>"YOLO", "entities"=>{"parse_markdown_links"=>true, "parse_links"=>true}, "annotations"=>[{"type"=>"com.ayadn.user", "value"=>{"+net.app.core.user"=>{"user_id"=>"@test", "format"=>"basic"}}}, {"type"=>"com.ayadn.client", "value"=>{"url"=>"http://ayadn-app.net", "author"=>{"name"=>"Eric Dejonckheere", "username"=>"ericd", "id"=>"69904", "email"=>"eric@aya.io"}, "version"=>"wee"}}]})
62
+ x = post.post(['YOLO'])
63
+ end
64
+ it "returns the posted post" do
65
+ x = post.post(['whatever'])
66
+ expect(x['data']['text']).to eq 'TEST'
67
+ end
55
68
  end
56
69
 
57
- # let(:rest) {RestClient = double}
58
- # let(:res) {response = double}
59
- # let(:db) {Ayadn::Databases = double}
60
-
61
- # describe "#post" do
62
- # before do
63
- # db.stub(:blacklist) {"x"}
64
- # res.stub(:code) {200}
65
- # rest.stub(:post) {File.read("spec/mock/posted.json")}
66
- # end
67
- # # Those 2 tests return a fake response, but this fake
68
- # # response wouldn't be returned if the tests failed
69
- # # I should intercept what goes into the fake RestClient
70
- # # instead, but have no idea how to do it at the moment ¯\(ツ)/¯
71
- # #
72
- # # As their warning messages are pretty annoying, I disabled
73
- # # them but you can uncomment to run the test
74
- # it "sends a post" do
75
- # a = post.post(["TEST"])
76
- # printed = capture_stdout do
77
- # Ayadn::View.new.show_posted(a)
78
- # end
79
- # expect(printed).to include '@aya_tests'
80
- # expect(printed).to include 'TEST'
81
- # end
82
- # it "sends a message" do
83
- # a = post.send_message(666, 'TEST')
84
- # printed = capture_stdout do
85
- # Ayadn::View.new.show_posted(a)
86
- # end
87
- # expect(printed).to include '@aya_tests'
88
- # expect(printed).to include 'TEST'
89
- # end
90
- # end
91
-
92
70
  describe "#reply" do
93
71
  it "formats a reply" do
94
72
  new_post = "Hey guys!"
@@ -125,12 +103,23 @@ describe Ayadn::Post do
125
103
  it "checks normal post length" do
126
104
  post.check_post_length(["allo", "wtf"]).should be nil #no error
127
105
  end
106
+ it "checks excessive post length" do
107
+ printed = capture_stderr do
108
+ lambda {post.check_post_length(["allo", "wtf dude", "ok whatever pfff", "Black malt berliner weisse, filter. Ibu degrees plato alcohol. ipa hard cider ester infusion conditioning tank. Dry stout bottom fermenting yeast wort chiller wort chiller lager hand pump ! All-malt dunkle bright beer grainy, original gravity wheat beer glass."])}.should raise_error(SystemExit)
109
+ end
110
+ expect(printed).to include 'Canceled: too long. 256 max, 32 characters to remove.'
111
+ end
128
112
  end
129
113
 
130
114
  describe "#check_message_length" do
131
115
  it "checks normal message length" do
132
116
  post.check_message_length(["allo", "wtf"]).should be nil #no error
133
117
  end
118
+ it "checks excessive message length" do
119
+ printed = capture_stderr do
120
+ lambda {post.check_message_length(["Black malt berliner weisse, filter. Ibu degrees plato alcohol. ipa hard cider ester infusion conditioning tank. Dry stout bottom fermenting yeast wort chiller wort chiller lager hand pump ! All-malt dunkle bright beer grainy, original gravity wheat beer glass!!" * 8])}.should raise_error(SystemExit)
121
+ end
122
+ expect(printed).to include 'Canceled: too long. 2048 max, 40 characters to remove.'
123
+ end
134
124
  end
135
-
136
125
  end
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.0.1
4
+ version: 1.0.2
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-04-04 00:00:00.000000000 Z
11
+ date: 2014-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -190,6 +190,7 @@ files:
190
190
  - ".gitignore"
191
191
  - ".rspec"
192
192
  - ".travis.yml"
193
+ - CHANGELOG.md
193
194
  - Gemfile
194
195
  - Guardfile
195
196
  - LICENSE.txt
@@ -226,10 +227,15 @@ files:
226
227
  - spec/helpers.rb
227
228
  - spec/mock/@ericd.json
228
229
  - spec/mock/@m.json
230
+ - spec/mock/aliases.db
231
+ - spec/mock/blacklist.db
229
232
  - spec/mock/checkins.json
230
233
  - spec/mock/fwr_@ayadn.json
234
+ - spec/mock/index.db
235
+ - spec/mock/pagination.db
231
236
  - spec/mock/posted.json
232
237
  - spec/mock/stream.json
238
+ - spec/mock/users.db
233
239
  - spec/spec_helper.rb
234
240
  - spec/unit/api_spec.rb
235
241
  - spec/unit/databases_spec.rb
@@ -267,10 +273,15 @@ test_files:
267
273
  - spec/helpers.rb
268
274
  - spec/mock/@ericd.json
269
275
  - spec/mock/@m.json
276
+ - spec/mock/aliases.db
277
+ - spec/mock/blacklist.db
270
278
  - spec/mock/checkins.json
271
279
  - spec/mock/fwr_@ayadn.json
280
+ - spec/mock/index.db
281
+ - spec/mock/pagination.db
272
282
  - spec/mock/posted.json
273
283
  - spec/mock/stream.json
284
+ - spec/mock/users.db
274
285
  - spec/spec_helper.rb
275
286
  - spec/unit/api_spec.rb
276
287
  - spec/unit/databases_spec.rb
@@ -280,3 +291,4 @@ test_files:
280
291
  - spec/unit/status_spec.rb
281
292
  - spec/unit/view_spec.rb
282
293
  - spec/unit/workers_spec.rb
294
+ has_rdoc: