lita-ship-to-pastebin 0.1.5 → 0.1.6

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: c6a20037881235c21425d08044541369bf28bf8b
4
- data.tar.gz: c5748075f25055583774317d4c45e3c7fd690d2c
3
+ metadata.gz: 1547015a664d24776e1ae54694b07877964ddc65
4
+ data.tar.gz: 5a672bc14ace993d1aa7ba58fc908caf07c182ef
5
5
  SHA512:
6
- metadata.gz: 9372830f2b002fa668988f2354b23e26c83314d6e856a71e6277c3b4d8f6ac13748e09de21120911055e9b19e2bb2539a1bba2cf0227f8f801d156d9c7d904c2
7
- data.tar.gz: 35269e80361ef19574bf0f727993c7957241de56a027a66e147036f5c92364c0de3241b5e67b9a1b758dca06a7d4d14e12fe31aea73f0cca262576799849b2b8
6
+ metadata.gz: d000b99fbd33484bad5b6f38fcce3e5d6cca0e5d9f508d1d970f9e17449379445e2c69824fe8c59dd49abc1a45ec48ca8c07c88ec9897942cbc6537975e4f90c
7
+ data.tar.gz: 781e05929ba6eeea87b740d26796e7f45ec00e487c17ce7f7b7dae8bdbd477336d4fadae5d44d3e5032cbb99189f3a09ab20d2ad38810b8a2a645b5ef9aa0cb4
@@ -9,12 +9,14 @@ module Lita
9
9
 
10
10
  PasteBinError = Class.new(StandardError)
11
11
 
12
- def save_to_pastebin(message, title: "Lita's Wall of Text", api_key: API_KEY_DEFAULT )
12
+ def save_to_pastebin(message, title: "Lita's Wall of Text",
13
+ api_key: API_KEY_DEFAULT )
13
14
  begin
14
15
  result = Faraday.post PASTEBIN_URL, {
15
16
  api_dev_key: api_key,
16
17
  api_paste_name: title,
17
18
  api_paste_code: message,
19
+ api_paste_expire_date: '1D', # delete after a day
18
20
  api_option: 'paste'
19
21
  }
20
22
  rescue Faraday::Error => err
@@ -22,7 +24,8 @@ module Lita
22
24
  end
23
25
 
24
26
  if !result.success? || result.body.include?('Bad API')
25
- raise PasteBinError, "Unable to deal with this Faraday response: [#{result.body}]"
27
+ raise PasteBinError,
28
+ "Unable to deal with this Faraday response: [#{result.body}]"
26
29
  end
27
30
 
28
31
  result.body
@@ -16,11 +16,14 @@ module Lita
16
16
  })
17
17
 
18
18
  def hide_bigtext(message)
19
- message.reply longtext
19
+ too_long = longtext
20
+ url_placeholder = snip_text too_long
21
+ message.reply url_placeholder
20
22
  end
21
23
 
22
24
  def snip_text(text)
23
- Lita::Extensions::ShipToPastebin.new.save_to_pastebin(text, api_key: config.pastebin_api_key)
25
+ Lita::Extensions::ShipToPastebin.new.
26
+ save_to_pastebin(text, api_key: config.pastebin_api_key)
24
27
  end
25
28
 
26
29
  def longtext
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-ship-to-pastebin'
3
- spec.version = '0.1.5'
3
+ spec.version = '0.1.6'
4
4
  spec.authors = ['Daniel J. Pritchett']
5
5
  spec.email = ['dpritchett@gmail.com']
6
6
  spec.description = 'Expose helper method to pastebin-ify any input text'
@@ -21,5 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'rake'
22
22
  spec.add_development_dependency 'rack-test'
23
23
  spec.add_development_dependency 'rspec', '>= 3.0.0'
24
+
25
+ # START:webmock
24
26
  spec.add_development_dependency 'webmock', '~> 3.3'
27
+ # END:webmock
25
28
  end
@@ -1,13 +1,15 @@
1
- require 'webmock/rspec'
2
1
  require 'spec_helper'
3
2
 
4
3
  describe Lita::Extensions::ShipToPastebin, lita: true do
5
4
  subject { Lita::Extensions::ShipToPastebin.new }
6
5
 
6
+ # thanks webmock!
7
7
  before { stub_pastebin_calls! }
8
8
 
9
9
  it 'saves text to pastebin' do
10
10
  actual = subject.save_to_pastebin 'hey john', title: 'hey there john'
11
- expect(actual).to include('https://pastebin.com/')
11
+
12
+ # e.g. https://pastebin.com/Vi4Cgn6i
13
+ expect(actual).to match(%r{^https:\/\/pastebin\.com\/[a-zA-Z0-9]+})
12
14
  end
13
15
  end
@@ -20,7 +20,16 @@ describe Lita::Handlers::Bigtext, lita_handler: true do
20
20
  expect(result.split.length > 10).to be_falsey
21
21
 
22
22
  # stubbing out Faraday calls to hide from Pastebin API limits
23
- expect(result).to include('https://pastebin.com/')
23
+ expect(result).to(
24
+ match(%r{^https:\/\/pastebin\.com\/[a-zA-Z0-9]+})
25
+ )
26
+ end
27
+
28
+ it 'should use pastebin extension when responding to users' do
29
+ send_message 'Lita bigtext'
30
+ expect(replies.last).to(
31
+ match(%r{^https:\/\/pastebin\.com\/[a-zA-Z0-9]+})
32
+ )
24
33
  end
25
34
  end
26
35
  end
@@ -5,20 +5,29 @@ require 'lita/rspec'
5
5
  # was generated with Lita 4, the compatibility mode should be left disabled.
6
6
  Lita.version_3_compatibility_mode = false
7
7
 
8
+ # START:stub_request
9
+ require 'webmock/rspec'
10
+
8
11
  # call me in a before block anywhere you're calling pastebin!
9
12
  # This will save you from fairly low-overhead API limits.
10
13
  def stub_pastebin_calls!
11
14
  stub_request(:post, 'https://pastebin.com/api/api_post.php')
12
15
  .with(body: {
13
- 'api_dev_key' => /[a-f0-9]+/,
14
- 'api_option' => 'paste',
15
- 'api_paste_code' => /\W+/,
16
- 'api_paste_name' => /\W+/ },
17
- headers: {
18
- 'Accept' => '*/*',
19
- 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
20
- 'Content-Type' => 'application/x-www-form-urlencoded',
21
- 'User-Agent' => 'Faraday v0.15.0'
22
- })
23
- .to_return(status: 200, body: 'https://pastebin.com/6ig4DLUQ', headers: {})
16
+ 'api_dev_key' => /[a-f0-9]+/,
17
+ 'api_option' => 'paste',
18
+ 'api_paste_expire_date' => '1D',
19
+ 'api_paste_code' => /\W+/,
20
+ 'api_paste_name' => /\W+/ },
21
+ headers: {
22
+ 'Accept' => '*/*',
23
+ 'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
24
+ 'Content-Type' => 'application/x-www-form-urlencoded',
25
+ 'User-Agent' => 'Faraday v0.15.0'
26
+ })
27
+ .to_return(
28
+ status: 200,
29
+ body: 'https://pastebin.com/6ig4DLUQ',
30
+ headers: {}
31
+ )
24
32
  end
33
+ # START:stub_request
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-ship-to-pastebin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Pritchett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-24 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita