lita-onewheel-amazon-product 0.5.0 → 0.6.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
  SHA1:
3
- metadata.gz: 69187fc6262c32d2a9f89dc7efb0bade62a77519
4
- data.tar.gz: e459127c39e54536ed78a14a3b32591ae741bbae
3
+ metadata.gz: 0756585dd3eacefdf2850b4e1ff923ee92a5a7f8
4
+ data.tar.gz: 574f1ba1be0e35917ac1038d9eeb5f6951f0ef02
5
5
  SHA512:
6
- metadata.gz: 0ea963d2fe6c8cd64146d9c3419082291c28113fcae98f3ee56488852e8ccb3d7e295865dcc95b6064b36a99646ddcc5b2527df7657ed2f8fcef55fa298e5c9a
7
- data.tar.gz: 9d54f7e4cadf9f58bd63ebdf05c15c895d9e329155e260c59b0028168a88688cd8a0b7aa788a4e10814732e1bbee2e7fd5b79cc191c31ec3e45a612cf0baa3c4
6
+ metadata.gz: a257480c4b42176b2b32b15156ce9e1cceb2a0bc0dd02a3f8cb698a1ff8231210813028680c252a2fce91ed46be927bceeba79df92d097ca6dd4f97c4acf52e4
7
+ data.tar.gz: d45e4853c952abd202c6002db7bea4e1fda4acd9b978177a5a31c06b421ca3cf69081e76aab8615d571daa4c90911b314ceb8ba336eff12bb8878dd584c40287
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Andrew Kreps
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -4,21 +4,28 @@ require 'rest-client'
4
4
  module Lita
5
5
  module Handlers
6
6
  class OnewheelAmazonProduct < Handler
7
- route /(http.*amazon.com\/.*\/*dp\/.*)\?*/i, :get_amazon_product
7
+ route /([htp:\/]*www.amazon.com\/.*\/*dp\/.*)\?*/i, :get_amazon_product
8
8
 
9
9
  def get_amazon_product(response)
10
10
  description = ''
11
- price = 0
12
11
  uri = response.matches[0][0]
13
12
  Lita.logger.debug "lita-onewheel-amazon-product: Grabbing URI #{uri}"
14
- doc = RestClient.get uri
15
13
 
16
- noko_doc = Nokogiri::HTML doc
17
- noko_doc.css('meta').each do |meta|
18
- attrs = meta.attributes
19
- if attrs['name'].to_s == 'title'
20
- description = process_description attrs['content'].to_s
14
+ noko_doc = nil
15
+ counter = 0
16
+ loop do
17
+ doc = RestClient.get uri
18
+
19
+ noko_doc = Nokogiri::HTML doc
20
+ noko_doc.css('meta').each do |meta|
21
+ attrs = meta.attributes
22
+ if attrs['name'].to_s == 'title'
23
+ description = process_description attrs['content'].to_s
24
+ end
21
25
  end
26
+
27
+ counter += 1
28
+ break if counter == 3 or description
22
29
  end
23
30
 
24
31
  if description.empty?
@@ -37,6 +44,7 @@ module Lita
37
44
  # Here we keep trying until we get something.
38
45
  def get_price(noko_doc)
39
46
  price_node = noko_doc.css('span#priceblock_ourprice')
47
+ price = nil
40
48
 
41
49
  # Typical product price
42
50
  if price_node.empty?
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-onewheel-amazon-product'
3
- spec.version = '0.5.0'
3
+ spec.version = '0.6.0'
4
4
  spec.authors = ['Andrew Kreps']
5
5
  spec.email = ['andrew.kreps@gmail.com']
6
6
  spec.description = %q{Lita interface to post information about amazon products.}
@@ -59,4 +59,10 @@ describe Lita::Handlers::OnewheelAmazonProduct, lita_handler: true do
59
59
  send_message('http://www.amazon.com/Tamarack-Technologies-2400-Film-Scanner/dp/B00004TH24')
60
60
  expect(replies.last).to eq('$159.99 Tamarack Technologies 2400 FS Film Scanner')
61
61
  end
62
+
63
+ it 'finds urls without the http.' do
64
+ mock_fixture('film_scanner_price')
65
+ send_message('www.amazon.com/Tamarack-Technologies-2400-Film-Scanner/dp/B00004TH24')
66
+ expect(replies.last).to eq('$159.99 Tamarack Technologies 2400 FS Film Scanner')
67
+ end
62
68
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-amazon-product
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-16 00:00:00.000000000 Z
11
+ date: 2016-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -146,6 +146,7 @@ files:
146
146
  - ".gitignore"
147
147
  - ".travis.yml"
148
148
  - Gemfile
149
+ - LICENSE
149
150
  - README.md
150
151
  - Rakefile
151
152
  - lib/lita-onewheel-amazon-product.rb
@@ -181,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
182
  version: '0'
182
183
  requirements: []
183
184
  rubyforge_project:
184
- rubygems_version: 2.4.5.1
185
+ rubygems_version: 2.5.1
185
186
  signing_key:
186
187
  specification_version: 4
187
188
  summary: See above.