meta_hari 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/meta_hari.rb +1 -1
- data/lib/meta_hari/helpers.rb +1 -0
- data/lib/meta_hari/helpers/addressable_factory.rb +38 -0
- data/lib/meta_hari/product.rb +2 -0
- data/lib/meta_hari/spyglass/base.rb +1 -1
- data/lib/meta_hari/version.rb +1 -1
- data/meta_hari.gemspec +1 -0
- data/spec/lib/meta_hari/helpers/addressable_factory_spec.rb +31 -0
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b527913e023c68cdb8fe0c29fd1b353c4ea936ec
|
4
|
+
data.tar.gz: 3e891458ea7d2d25871b134c33bbfdae0ed06155
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7106a1fd62a18020d24d736dfd06c2ee47b03976875306a377184ee8cd434a40a06cc042d293c033564e1b6fc28e778d40300c29473d168a4d4d4b4be600faf
|
7
|
+
data.tar.gz: 2ef28481ac8e80537fd29499742ec7eb08524c21089d65a1138ab3de06dc06f86ec6d5f432f256c648537905ccbdce59175ecb4c5285ddd3b48003f90b2b6bd2
|
data/README.md
CHANGED
@@ -33,8 +33,9 @@ In order to receive product informations, just pass the URL containing
|
|
33
33
|
thous informations to the method `MetaHari.spy`.
|
34
34
|
|
35
35
|
```ruby
|
36
|
-
product = MetaHari.spy('
|
37
|
-
product.inspect # => #<MetaHari::Product:
|
36
|
+
product = MetaHari.spy('www.amazon.de/Gastroback-42429-Design-Wasserkocher-Advanced/dp/B000LQXC2Q/ref=sr_1_1')
|
37
|
+
product.inspect # => #<MetaHari::Product:0x007fa3429de030 @uri=#<Addressable::URI:0x3fd1a18d5c04 URI:http://www.amazon.de/Gastroback-42429-Design-Wasserkocher-Advanced/dp/B000LQXC2Q/ref=sr_1_1>, @name="Gastroback 42429 Design Wasserkocher Advanced Pro", @image="http://ecx.images-amazon.com/images/I/814Yl6mxLsL._SL1500_.jpg", @description="">
|
38
|
+
product.uri.to_s # => http://www.amazon.de/Gastroback-42429-Design-Wasserkocher-Advanced/dp/B000LQXC2Q/ref=sr_1_1
|
38
39
|
```
|
39
40
|
|
40
41
|
## Implemented spyglasses
|
data/lib/meta_hari.rb
CHANGED
@@ -21,7 +21,7 @@ require 'meta_hari/spyglass'
|
|
21
21
|
module MetaHari
|
22
22
|
class <<self
|
23
23
|
def spy(uri, iteration = 0)
|
24
|
-
uri =
|
24
|
+
uri = Helpers::AddressableFactory.parse uri.to_s
|
25
25
|
spyglass = suitable_spyglass_instance uri, iteration
|
26
26
|
spyglass.spy
|
27
27
|
rescue RedirectNotification => redirect
|
data/lib/meta_hari/helpers.rb
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'addressable/uri'
|
2
|
+
|
3
|
+
# The AddressableFactory helper is trying to guess a URL out of a given string.
|
4
|
+
#
|
5
|
+
# Example
|
6
|
+
# -------
|
7
|
+
# ```ruby
|
8
|
+
# uri = MetaHari::Helpers::AddressableFactory.parse('example.com/foo')
|
9
|
+
# # => http://example.com/foo
|
10
|
+
# ```
|
11
|
+
#
|
12
|
+
module MetaHari
|
13
|
+
module Helpers
|
14
|
+
module AddressableFactory
|
15
|
+
class <<self
|
16
|
+
def parse(url)
|
17
|
+
uri = Addressable::URI.parse(url)
|
18
|
+
fix_scheme uri
|
19
|
+
fix_host uri
|
20
|
+
uri
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def fix_scheme(uri)
|
26
|
+
uri.scheme ||= 'http'
|
27
|
+
end
|
28
|
+
|
29
|
+
def fix_host(uri)
|
30
|
+
return unless uri.host.nil?
|
31
|
+
host, *path = uri.path.split('/')
|
32
|
+
uri.path = '/' + path.join('/')
|
33
|
+
uri.host = host
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/meta_hari/product.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module MetaHari
|
2
2
|
class Product
|
3
|
+
attr_reader :uri
|
3
4
|
attr_reader :name
|
4
5
|
attr_reader :image
|
5
6
|
attr_reader :description
|
@@ -9,6 +10,7 @@ module MetaHari
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def apply(attributes)
|
13
|
+
@uri = attributes['uri'] if uri.nil?
|
12
14
|
@name = attributes['name'] if blank? name
|
13
15
|
@image = attributes['image'] if blank? image
|
14
16
|
@description = attributes['description'] if blank? description
|
data/lib/meta_hari/version.rb
CHANGED
data/meta_hari.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
20
|
spec.add_dependency 'microdata', '~> 0.0.3'
|
21
|
+
spec.add_dependency 'addressable', '~> 2.3.8'
|
21
22
|
|
22
23
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
23
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MetaHari::Helpers::AddressableFactory do
|
4
|
+
subject { described_class }
|
5
|
+
|
6
|
+
it { should respond_to :parse }
|
7
|
+
|
8
|
+
it 'is not changing a valid URL' do
|
9
|
+
uri = subject.parse 'https://example.com/foo'
|
10
|
+
expect(uri.to_s).to eql 'https://example.com/foo'
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'without scheme' do
|
14
|
+
it 'adds http as default scheme' do
|
15
|
+
uri = subject.parse '//example.com/foo'
|
16
|
+
expect(uri.to_s).to eql 'http://example.com/foo'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'without a host' do
|
21
|
+
it 'uses the first part of the path as host' do
|
22
|
+
uri = subject.parse 'example.com/foo'
|
23
|
+
expect(uri.to_s).to eql 'http://example.com/foo'
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'works with an empty path' do
|
27
|
+
uri = subject.parse 'example.com'
|
28
|
+
expect(uri.to_s).to eql 'http://example.com/'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meta_hari
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Spieker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: microdata
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.0.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: addressable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.3.8
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.3.8
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,6 +180,7 @@ files:
|
|
166
180
|
- Rakefile
|
167
181
|
- lib/meta_hari.rb
|
168
182
|
- lib/meta_hari/helpers.rb
|
183
|
+
- lib/meta_hari/helpers/addressable_factory.rb
|
169
184
|
- lib/meta_hari/helpers/json_ld.rb
|
170
185
|
- lib/meta_hari/helpers/microdata.rb
|
171
186
|
- lib/meta_hari/helpers/open_graph.rb
|
@@ -177,6 +192,7 @@ files:
|
|
177
192
|
- lib/meta_hari/spyglass/base.rb
|
178
193
|
- lib/meta_hari/version.rb
|
179
194
|
- meta_hari.gemspec
|
195
|
+
- spec/lib/meta_hari/helpers/addressable_factory_spec.rb
|
180
196
|
- spec/lib/meta_hari/helpers/json_ld_spec.rb
|
181
197
|
- spec/lib/meta_hari/helpers/microdata_spec.rb
|
182
198
|
- spec/lib/meta_hari/helpers/open_graph_spec.rb
|
@@ -214,6 +230,7 @@ signing_key:
|
|
214
230
|
specification_version: 4
|
215
231
|
summary: Receiving product informations from a given link.
|
216
232
|
test_files:
|
233
|
+
- spec/lib/meta_hari/helpers/addressable_factory_spec.rb
|
217
234
|
- spec/lib/meta_hari/helpers/json_ld_spec.rb
|
218
235
|
- spec/lib/meta_hari/helpers/microdata_spec.rb
|
219
236
|
- spec/lib/meta_hari/helpers/open_graph_spec.rb
|