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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d588a4900a63c06626caa3b9474757320d223f6
4
- data.tar.gz: e5129bc542ec83386fc0c372fff7a0c093b1a475
3
+ metadata.gz: b527913e023c68cdb8fe0c29fd1b353c4ea936ec
4
+ data.tar.gz: 3e891458ea7d2d25871b134c33bbfdae0ed06155
5
5
  SHA512:
6
- metadata.gz: 345088ec4c31789da877a5987fa82fc71e2cbcc92e6867c7df4807d9d492f70754e82c8c2791bc8d4882e7f8d500cdcd3c907cc9650802c29bff3aac90e49d75
7
- data.tar.gz: e5748efbcfa759d3181c0eef50f4da419347f618d3be997001aee3e19ab59fb1362c2886d26df098d9ba99170dcf1243251b23d1667a490e9c81363508eb22e2
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('http://www.amazon.de/Gastroback-42429-Design-Wasserkocher-Advanced/dp/B000LQXC2Q/ref=sr_1_1')
37
- product.inspect # => #<MetaHari::Product:0x007fd9dba99158 @name="Gastroback 42429 Design Wasserkocher Advanced Pro", @image="http://ecx.images-amazon.com/images/I/814Yl6mxLsL._SL1500_.jpg", @description="">
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
@@ -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 = URI.parse uri unless uri.is_a? 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
@@ -1,3 +1,4 @@
1
+ require 'meta_hari/helpers/addressable_factory'
1
2
  require 'meta_hari/helpers/json_ld'
2
3
  require 'meta_hari/helpers/microdata'
3
4
  require 'meta_hari/helpers/open_graph'
@@ -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
@@ -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
@@ -17,7 +17,7 @@ module MetaHari
17
17
 
18
18
  def spy
19
19
  spy_list.map { |method| send method }
20
- .inject(MetaHari::Product.new) { |a, e| a.apply e }
20
+ .inject(MetaHari::Product.new 'uri' => uri) { |a, e| a.apply e }
21
21
  end
22
22
 
23
23
  protected
@@ -1,4 +1,4 @@
1
1
  # MetaHari version
2
2
  module MetaHari
3
- VERSION = '0.0.5'
3
+ VERSION = '0.0.6'
4
4
  end
@@ -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.5
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-06-03 00:00:00.000000000 Z
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