fletcher 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/fletcher.gemspec +2 -2
- data/lib/fletcher.rb +7 -3
- data/lib/fletcher/data.rb +1 -5
- data/lib/fletcher/models/amazon.rb +7 -4
- data/spec/factories/models.rb +5 -0
- data/spec/lib/fletcher/models/amazon_spec.rb +4 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.5
|
data/fletcher.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "fletcher"
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dave Hulihan", "Hulihan Applications"]
|
12
|
-
s.date = "2013-11-
|
12
|
+
s.date = "2013-11-28"
|
13
13
|
s.description = "Easily fetch product/model information from third party websites such as Amazon, eBay, etc."
|
14
14
|
s.email = "dave@hulihanapplications.com"
|
15
15
|
s.executables = ["fletcher"]
|
data/lib/fletcher.rb
CHANGED
@@ -8,6 +8,12 @@ require File.expand_path("fletcher/string", File.dirname(__FILE__))
|
|
8
8
|
require File.expand_path("fletcher/nokogiri", File.dirname(__FILE__))
|
9
9
|
|
10
10
|
module Fletcher
|
11
|
+
LIBRARY_PATH = File.join(File.dirname(__FILE__), 'fletcher')
|
12
|
+
CLI_PATH = File.join(LIBRARY_PATH, 'cli')
|
13
|
+
MODEL_PATH = File.join(LIBRARY_PATH, 'models')
|
14
|
+
# User Agent (Chrome)
|
15
|
+
USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36"
|
16
|
+
|
11
17
|
# Module Methods
|
12
18
|
class << self
|
13
19
|
# Fetch information based on url
|
@@ -61,9 +67,7 @@ module Fletcher
|
|
61
67
|
end
|
62
68
|
end
|
63
69
|
|
64
|
-
|
65
|
-
CLI_PATH = File.join(LIBRARY_PATH, 'cli')
|
66
|
-
MODEL_PATH = File.join(LIBRARY_PATH, 'models')
|
70
|
+
|
67
71
|
|
68
72
|
# Autoload CLI
|
69
73
|
module CLI
|
data/lib/fletcher/data.rb
CHANGED
@@ -6,17 +6,13 @@ module Fletcher
|
|
6
6
|
class Data
|
7
7
|
# Get read url and get data object
|
8
8
|
def self.read(url, options = {})
|
9
|
-
|
10
|
-
options[:user_agent] ||= "Ruby/#{RUBY_VERSION}"
|
11
|
-
|
12
|
-
response = open(url, "User-Agent" => options[:user_agent])
|
9
|
+
response = open(url, "User-Agent" => Fletcher::USER_AGENT)
|
13
10
|
doc = ::Nokogiri::HTML(response.read)
|
14
11
|
|
15
12
|
# Save contents of URL/Remote File for debugging
|
16
13
|
# response.rewind
|
17
14
|
# last_response_file = File.expand_path(File.join("..", "..", "last_response"), File.dirname(__FILE__))
|
18
15
|
# File.new(last_response_file, "w+").write(response.read)
|
19
|
-
|
20
16
|
return doc
|
21
17
|
end
|
22
18
|
end
|
@@ -13,21 +13,24 @@ module Fletcher
|
|
13
13
|
case doc
|
14
14
|
when Nokogiri::HTML::Document
|
15
15
|
# Get Name
|
16
|
-
self.name = doc.css("h1#title").first_string
|
16
|
+
self.name = doc.css("h1#title").first_string
|
17
|
+
self.name = doc.xpath("string(//title)").split(" - ").first unless self.name
|
17
18
|
|
18
19
|
# Get Description
|
19
|
-
self.description = doc.css("
|
20
|
+
self.description = doc.css(".productDescriptionWrapper").first_string
|
20
21
|
|
21
22
|
# Get description from meta title if not found
|
22
23
|
self.description = doc.xpath("//meta[@name='description']/@content").first_string if description.nil?
|
23
24
|
|
24
25
|
# Get Price
|
25
|
-
parse_price(doc.css("#
|
26
|
-
|
26
|
+
parse_price(doc.css("#actualPriceValue").first_string)
|
27
|
+
parse_price(doc.css("#priceblock_ourprice").first_string) unless self.price
|
27
28
|
parse_price(doc.css("#priceblock_saleprice").first_string) unless self.price
|
29
|
+
parse_price(doc.xpath("//span[contains(@id, 'price')]").first_string) unless self.price
|
28
30
|
|
29
31
|
# Get Images
|
30
32
|
self.images = doc.xpath("//*[@data-action='main-image-click']//img").attribute_array
|
33
|
+
self.images = doc.xpath("//*[@id='imageBlock']//img").attribute_array unless self.images
|
31
34
|
self.image = images.first
|
32
35
|
end
|
33
36
|
end
|
data/spec/factories/models.rb
CHANGED
@@ -30,6 +30,11 @@ FactoryGirl.define do
|
|
30
30
|
url "http://www.amazon.com/gp/product/B0093162RM/"
|
31
31
|
end
|
32
32
|
|
33
|
+
# Create multiple amazon models, since markup varies greatly between products
|
34
|
+
factory :amazon2, :parent => :base do
|
35
|
+
url "http://www.amazon.com/gp/product/B000P4W3LU/"
|
36
|
+
end
|
37
|
+
|
33
38
|
# This may need to be updated if the item is expired/deleted
|
34
39
|
factory :ebay, :parent => :base do
|
35
40
|
url "http://www.ebay.com/itm/Unicycle-20-Silver-Chrome-Unicycles-Wheel-Cycling-Outdoor-Sports-Fitness-New-/310729787186?pt=LH_DefaultDomain_0&hash=item4858f04732"
|
@@ -23,8 +23,10 @@ end
|
|
23
23
|
describe Fletcher::Model::Amazon do
|
24
24
|
describe "parse", :vcr do
|
25
25
|
context "with valid data" do
|
26
|
-
|
27
|
-
|
26
|
+
%w{amazon amazon2}.each do |name|
|
27
|
+
it "should fetch valid info for #{name}" do
|
28
|
+
amazon_check(FactoryGirl.build(name.to_sym).url)
|
29
|
+
end
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fletcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-11-
|
13
|
+
date: 2013-11-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hashie
|
@@ -280,7 +280,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
280
280
|
version: '0'
|
281
281
|
segments:
|
282
282
|
- 0
|
283
|
-
hash:
|
283
|
+
hash: 454072605
|
284
284
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
285
285
|
none: false
|
286
286
|
requirements:
|