lita-onewheel-filmplot 0.0.2 → 0.1.0

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
  SHA256:
3
- metadata.gz: 63fdf561eee692ec695744a1a6375546c0b1f3e1a7261432a7df6c786cc32d61
4
- data.tar.gz: c69022b2f335234ba66257d15a2d16dea18b43d43ca489d7c510da6f6391ffdf
3
+ metadata.gz: 015d87a547242abace2df04bc11022d8868cc56226bab10022be706bc8935265
4
+ data.tar.gz: 34999c17449f39b45c5eb4fde6ab1a278786f1443f4eded6d1b209e2da8c3067
5
5
  SHA512:
6
- metadata.gz: dc3fd466097e604724a6d8594483cf4ae79f66be59785e1bf2621ae29d3fb201052aa74015fc8c5cee9b5b3c8e3de5414ad5c0b68d0ffcbee6d12c9a968e8ce3
7
- data.tar.gz: 513019dcc5152680be0d8cfa7c1a0eb0061b34ee766e472ee3ca286650a38321a3c8cfc85b1956049da88fbf63b31c7f8ea6d22af85a4283e152d2672ec561ea
6
+ metadata.gz: c9b12ae6a0f005f998b5a79c3a952d5b73a16e310ea0a3e6c6a53c6a31202173a2a40026d862e6badb2dfc3913ecb371e702a3941b0d37c76aa7912c592dd0f0
7
+ data.tar.gz: 384e83cc3d05214d546647b80a5fe42e1538bbdcd7ee143c3ca06c0c3ff19668a6666291838e1d281af9233384fdddc7c5e13c414676eb2fb24026d7d9969717
@@ -1,5 +1,6 @@
1
1
  require 'rest-client'
2
2
  require 'nokogiri'
3
+ require 'cgi'
3
4
 
4
5
  module Lita
5
6
  module Handlers
@@ -17,11 +18,34 @@ module Lita
17
18
  command: true
18
19
 
19
20
  def get_plot(response)
20
- movie_slug = response.matches[0][0].gsub ' ', '_'
21
+
22
+ title = response.matches[0][0]
23
+ url_root = 'https://www.rottentomatoes.com'
24
+
25
+ if title.match? '\s'
26
+ # search
27
+
28
+ search_term = CGI.escape(title)
29
+ search_url = "https://www.rottentomatoes.com/search/?search=#{search_term}"
30
+ Lita.logger.debug("Search mode! #{search_url}")
31
+ r = RestClient.get(search_url)
32
+ if match = r.match(/RT.PrivateApiV2FrontendHost, '.*', ({.*})/)
33
+ movie_json = JSON.parse match[1]
34
+ slug = movie_json['movies'][0]['url']
35
+ get_url = "#{url_root}#{slug}"
36
+ Lita.logger.debug("Searching for #{get_url}")
37
+ end
38
+ else
39
+ movie_slug = title.gsub ' ', '_'
40
+ get_url = "#{url_root}/m/#{movie_slug}"
41
+ Lita.logger.debug("Getting #{get_url}")
42
+ end
43
+
21
44
  begin
22
- r = RestClient.get("https://www.rottentomatoes.com/m/#{movie_slug}")
45
+ r = RestClient.get(get_url)
23
46
  noko_doc = Nokogiri::HTML(r)
24
47
  node = noko_doc.css('div#movieSynopsis')
48
+ Lita.logger.debug("Replying with #{node.text.strip}")
25
49
  response.reply node.text.strip
26
50
  rescue RestClient::ResourceNotFound => e
27
51
  response.reply "#{movie_slug} not found."
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-onewheel-filmplot'
3
- spec.version = '0.0.2'
3
+ spec.version = '0.1.0'
4
4
  spec.authors = ['Andrew Kreps']
5
5
  spec.email = ['andrew.kreps@gmail.com']
6
6
  spec.description = 'Film plot retrieval bot.'
@@ -4,22 +4,22 @@ describe Lita::Handlers::OnewheelFilmplot, lita_handler: true do
4
4
  it { is_expected.to route_command('filmplot x') }
5
5
  it { is_expected.to route_command('plotline x') }
6
6
 
7
- def mock(file)
7
+ def mock(file, param)
8
8
  mock = File.open("spec/fixtures/#{file}.html").read
9
- allow(RestClient).to receive(:get) { mock }
9
+ allow(RestClient).to receive(:get).with(param) { mock }
10
10
  end
11
11
 
12
12
  it 'should get timecop' do
13
- mock('timecop')
13
+ mock('timecop', 'https://www.rottentomatoes.com/m/timecop')
14
14
  send_command('filmplot timecop')
15
15
  expect(replies.last).to eq "Based on a comic book story, this futuristic film follows the time-travel exploits of policeman Max Walker (Jean Claude Van Damme). In 1994, Walker's wife Melissa (Mia Sara) is about to tell him that she is expecting their first child when they are attacked by a group of criminals. Walker is shot and beaten and lies helplessly on his lawn while he sees their home and his wife blown up by the killers. Ten years later, Walker remains an employee of the Time Enforcement Commission, a federal agency which was set up in 1994 after the U.S. government learned that time travel technology is feasible. The commission's role is to prevent time travel to protect U.S. economic interests. Walker learns that the corrupt Senator McComb (Ron Silver), who helped establish the agency, is exploiting it for personal gain, trying to establish a monopoly on time travel so that he can enrich himself in the stock market. Walker travels back in time to stop McComb from murdering his former partner. At the same time, Walker hopes to rescue his wife, and he learns that the attack on his home was ordered by McComb to stop Walker from foiling his plans. ~ Michael Betzold, Rovi"
16
16
  end
17
17
 
18
- # it 'should find infinity war by the wrong name' do
19
- # mock('search')
20
- # mock('infinity')
21
- #
22
- # end
18
+ it 'should find infinity war by the wrong name' do
19
+ # mock('search', 'https://www.rottentomatoes.com/search/?search=infinity%20war')
20
+ # mock('infinity', 'https://www.rottentomatoes.com/m/avengers_infinity_war')
21
+ send_command('filmplot infinity war')
22
+ end
23
23
 
24
24
  it '404s' do
25
25
  allow(RestClient).to receive(:get).and_raise(RestClient::ResourceNotFound)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-filmplot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps