fetcher-microdata 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +36 -0
- data/Rakefile +2 -0
- data/fetcher-microdata.gemspec +22 -0
- data/lib/fetcher-microdata.rb +44 -0
- data/lib/fetcher-microdata/article_small.rb +20 -0
- data/lib/fetcher-microdata/person_user.rb +19 -0
- data/lib/fetcher-microdata/version.rb +5 -0
- data/lib/writer/fetcher-microdata/article_small.rb +44 -0
- data/lib/writer/fetcher-microdata/person_user.rb +42 -0
- data/spec/fetcher/microdata/article_small_spec.rb +60 -0
- data/spec/fetcher/microdata/person_user_spec.rb +44 -0
- data/spec/fetcher/microdata_spec.rb +80 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/writer/fetcher/microdata/article_small_spec.rb +133 -0
- data/spec/writer/fetcher/microdata/person_user_spec.rb +93 -0
- metadata +118 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Xavier Via
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Fetcher::Microdata
|
2
|
+
|
3
|
+
Supported classes:
|
4
|
+
|
5
|
+
- schema.org/Person/User > Fetcher::Microdata::PersonUser
|
6
|
+
|
7
|
+
To do:
|
8
|
+
|
9
|
+
- Article/Small
|
10
|
+
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'fetcher-microdata'
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install fetcher-microdata
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
TODO: Write usage instructions here
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/fetcher-microdata/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Xavier Via"]
|
6
|
+
gem.email = ["xavierviacanel@gmail.com"]
|
7
|
+
gem.description = %q{Abstract classes for Fetcher Microdata serialization of social network data}
|
8
|
+
gem.summary = %q{Abstract classes for Fetcher Microdata serialization of social network data}
|
9
|
+
gem.homepage = "http://github.com/Fetcher/fetcher-microdata"
|
10
|
+
|
11
|
+
gem.add_dependency 'discoverer'
|
12
|
+
|
13
|
+
gem.add_development_dependency 'rspec'
|
14
|
+
gem.add_development_dependency 'pry'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($\)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.name = "fetcher-microdata"
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
gem.version = Fetcher::Microdata::VERSION
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'discoverer'
|
2
|
+
|
3
|
+
module Fetcher
|
4
|
+
class Microdata
|
5
|
+
include Discoverer::Writer
|
6
|
+
include Virtus
|
7
|
+
|
8
|
+
attr_reader :_type
|
9
|
+
|
10
|
+
def initialize *arguments
|
11
|
+
if arguments.first.is_a? Symbol
|
12
|
+
social_network = arguments.shift
|
13
|
+
self.attributes = coerce social_network, *arguments
|
14
|
+
elsif arguments.first.is_a? Hash
|
15
|
+
self.attributes = arguments.first
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def coerce social_network, *raw_data
|
20
|
+
begin
|
21
|
+
eval("::#{self.class}::#{social_network.to_s.capitalize}::Coercer").call *raw_data
|
22
|
+
rescue NameError => e
|
23
|
+
if e.message.include? "#{self.class}::#{social_network.to_s.capitalize}"
|
24
|
+
raise UnknownSocialNetworkError,
|
25
|
+
"Couldn't find coertion algorithm for '#{social_network}' social network, please require 'fetcher-microdata-#{social_network}' in your project and make sure it has a #{self.class}::#{social_network.to_s.capitalize}::Coercer"
|
26
|
+
else
|
27
|
+
raise e
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Exceptions
|
33
|
+
#######################################
|
34
|
+
|
35
|
+
class UnknownSocialNetworkError < StandardError; end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
require 'fetcher-microdata/version'
|
40
|
+
require 'fetcher-microdata/person_user'
|
41
|
+
require 'fetcher-microdata/article_small'
|
42
|
+
|
43
|
+
require 'writer/fetcher-microdata/person_user'
|
44
|
+
require 'writer/fetcher-microdata/article_small'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Fetcher
|
2
|
+
class Microdata
|
3
|
+
class ArticleSmall < Fetcher::Microdata
|
4
|
+
|
5
|
+
def initialize *args
|
6
|
+
super *args
|
7
|
+
@_type = "http://schema.org/Article/Small"
|
8
|
+
end
|
9
|
+
|
10
|
+
attribute :additionalType
|
11
|
+
attribute :id
|
12
|
+
attribute :articleBody
|
13
|
+
attribute :author
|
14
|
+
attribute :viewer
|
15
|
+
attribute :dateCreated
|
16
|
+
attribute :provider
|
17
|
+
attribute :url
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Fetcher
|
2
|
+
class Microdata
|
3
|
+
class PersonUser < Fetcher::Microdata
|
4
|
+
|
5
|
+
def initialize *args
|
6
|
+
super *args
|
7
|
+
@_type = 'http://schema.org/Person/User'
|
8
|
+
end
|
9
|
+
|
10
|
+
attribute :additionalType
|
11
|
+
attribute :id
|
12
|
+
attribute :name
|
13
|
+
attribute :dateRegistered
|
14
|
+
attribute :description
|
15
|
+
attribute :url
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Writer
|
2
|
+
module Fetcher
|
3
|
+
module Microdata
|
4
|
+
class ArticleSmall
|
5
|
+
attr_accessor :source
|
6
|
+
|
7
|
+
def initialize the_source
|
8
|
+
self.source = the_source
|
9
|
+
end
|
10
|
+
|
11
|
+
def hash
|
12
|
+
@attributes = @source.attributes
|
13
|
+
{
|
14
|
+
"type" => [@source._type],
|
15
|
+
"properties" => {
|
16
|
+
"additionalType" => [
|
17
|
+
@attributes[:additionalType]
|
18
|
+
],
|
19
|
+
"Item#id" => [
|
20
|
+
@attributes[:id]
|
21
|
+
],
|
22
|
+
"articleBody" => [
|
23
|
+
@attributes[:articleBody]
|
24
|
+
],
|
25
|
+
"author" => [
|
26
|
+
@attributes[:author].to.hash
|
27
|
+
],
|
28
|
+
"Item#viewer" => [
|
29
|
+
@attributes[:viewer].to.hash
|
30
|
+
],
|
31
|
+
"dateCreated" => [
|
32
|
+
@attributes[:dateCreated]
|
33
|
+
],
|
34
|
+
"provider" => @attributes[:provider],
|
35
|
+
"url" => [
|
36
|
+
@attributes[:url]
|
37
|
+
]
|
38
|
+
}
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Writer
|
2
|
+
module Fetcher
|
3
|
+
module Microdata
|
4
|
+
class PersonUser
|
5
|
+
attr_accessor :source
|
6
|
+
|
7
|
+
def initialize the_source
|
8
|
+
@source = the_source
|
9
|
+
end
|
10
|
+
|
11
|
+
def hash
|
12
|
+
@attributes = @source.attributes
|
13
|
+
{
|
14
|
+
"type" => [
|
15
|
+
@source._type
|
16
|
+
],
|
17
|
+
"properties" => {
|
18
|
+
"additionalType" => [
|
19
|
+
@attributes[:additionalType]
|
20
|
+
],
|
21
|
+
"Item#id" => [
|
22
|
+
@attributes[:id]
|
23
|
+
],
|
24
|
+
"name" => [
|
25
|
+
@attributes[:name]
|
26
|
+
],
|
27
|
+
"User#dateRegistered" => [
|
28
|
+
@attributes[:dateRegistered]
|
29
|
+
],
|
30
|
+
"description" => [
|
31
|
+
@attributes[:description]
|
32
|
+
],
|
33
|
+
"url" => [
|
34
|
+
@attributes[:url]
|
35
|
+
]
|
36
|
+
}
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fetcher::Microdata::ArticleSmall do
|
4
|
+
describe '.new' do
|
5
|
+
it 'should set the _type to schema.org/Article/Small' do
|
6
|
+
article = Fetcher::Microdata::ArticleSmall.new @argument, @viewer
|
7
|
+
article._type.should == "http://schema.org/Article/Small"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should inherit from Fetcher::Microdata' do
|
12
|
+
Fetcher::Microdata::ArticleSmall.superclass.should == Fetcher::Microdata
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'attributes' do
|
16
|
+
before do
|
17
|
+
Fetcher::Microdata::ArticleSmall.any_instance.stub :coerce
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should set attribute additionalType' do
|
21
|
+
Fetcher::Microdata::ArticleSmall.new(@argument_stub, @viewer_stub)
|
22
|
+
.attributes.should have_key :additionalType
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should set attribute id' do
|
26
|
+
Fetcher::Microdata::ArticleSmall.new(@argument_stub, @viewer_stub)
|
27
|
+
.attributes.should have_key :id
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should set attribute articleBody' do
|
31
|
+
Fetcher::Microdata::ArticleSmall.new(@argument_stub, @viewer_stub)
|
32
|
+
.attributes.should have_key :articleBody
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should set attribute author' do
|
36
|
+
Fetcher::Microdata::ArticleSmall.new(@argument_stub, @viewer_stub)
|
37
|
+
.attributes.should have_key :author
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should set attribute viewer' do
|
41
|
+
Fetcher::Microdata::ArticleSmall.new(@argument_stub, @viewer_stub)
|
42
|
+
.attributes.should have_key :viewer
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should set attribute dateCreated' do
|
46
|
+
Fetcher::Microdata::ArticleSmall.new(@argument_stub, @viewer_stub)
|
47
|
+
.attributes.should have_key :dateCreated
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should set attribute provider' do
|
51
|
+
Fetcher::Microdata::ArticleSmall.new(@argument_stub, @viewer_stub)
|
52
|
+
.attributes.should have_key :provider
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should set attribute url' do
|
56
|
+
Fetcher::Microdata::ArticleSmall.new(@argument_stub, @viewer_stub)
|
57
|
+
.attributes.should have_key :url
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fetcher::Microdata::PersonUser do
|
4
|
+
describe '.new' do
|
5
|
+
it 'should set the _type to schema.org/Person/User' do
|
6
|
+
person = Fetcher::Microdata::PersonUser.new @argument
|
7
|
+
person._type.should == "http://schema.org/Person/User"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should inherit from Fetcher::Microdata' do
|
12
|
+
Fetcher::Microdata::PersonUser.superclass.should == Fetcher::Microdata
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'attributes' do
|
16
|
+
before do
|
17
|
+
@argument_stub = {}
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should have the attribute additionalType' do
|
21
|
+
Fetcher::Microdata::PersonUser.new(@argument_stub).attributes.should have_key :additionalType
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should have the attribute id' do
|
25
|
+
Fetcher::Microdata::PersonUser.new(@argument_stub).attributes.should have_key :id
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should have the attribute name' do
|
29
|
+
Fetcher::Microdata::PersonUser.new(@argument_stub).attributes.should have_key :name
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should have the attribute dateRegistered' do
|
33
|
+
Fetcher::Microdata::PersonUser.new(@argument_stub).attributes.should have_key :dateRegistered
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should have the attribute description' do
|
37
|
+
Fetcher::Microdata::PersonUser.new(@argument_stub).attributes.should have_key :description
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should have the attribute url' do
|
41
|
+
Fetcher::Microdata::PersonUser.new(@argument_stub).attributes.should have_key :url
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Fetcher::Microdata do
|
4
|
+
before do
|
5
|
+
class OnTheFly < Fetcher::Microdata; end
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should include Discoverer::Writer' do
|
9
|
+
OnTheFly.ancestors.should include Discoverer::Writer
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should include Virtus' do
|
13
|
+
OnTheFly.ancestors.should include Virtus
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '.new' do
|
17
|
+
context 'a social network flag and a social network specific data is passed' do
|
18
|
+
it 'should call the right coercer' do
|
19
|
+
social_network = :facebook
|
20
|
+
user_data = stub 'user data'
|
21
|
+
final_data = stub 'final_data'
|
22
|
+
|
23
|
+
Fetcher::Microdata.any_instance
|
24
|
+
.should_receive(:coerce)
|
25
|
+
.with(social_network, user_data)
|
26
|
+
.and_return final_data
|
27
|
+
Fetcher::Microdata.any_instance.should_receive(:attributes=)
|
28
|
+
.with(final_data)
|
29
|
+
|
30
|
+
Fetcher::Microdata.new social_network, user_data
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'the person is initialized with a hash' do
|
35
|
+
it 'should accept the hash as an argument and pass it to attributes' do
|
36
|
+
attribute_hash = {}
|
37
|
+
Fetcher::Microdata.any_instance.should_receive(:attributes=)
|
38
|
+
.with attribute_hash
|
39
|
+
Fetcher::Microdata.new attribute_hash
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#coerce' do
|
45
|
+
context 'the right coercer exists for a subclass' do
|
46
|
+
it 'should return call the right coercer with the data and return the result' do
|
47
|
+
module Fetcher; class Microdata; class SubClass < Fetcher::Microdata; module Facebook; Coercer = proc {|message| }; end; end; end; end
|
48
|
+
|
49
|
+
raw_data = stub 'data'
|
50
|
+
final_data = stub 'final_data'
|
51
|
+
Fetcher::Microdata::SubClass::Facebook::Coercer.should_receive(:call)
|
52
|
+
.with(raw_data)
|
53
|
+
.and_return final_data
|
54
|
+
Fetcher::Microdata::SubClass.any_instance.should_receive(:attributes=).with final_data
|
55
|
+
Fetcher::Microdata::SubClass.new :facebook, raw_data
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'there is no such coercer' do
|
60
|
+
it 'should raise a relevant error' do
|
61
|
+
raw_data = stub 'data'
|
62
|
+
final_data = stub 'final_data'
|
63
|
+
Fetcher::Microdata.any_instance.stub(:attributes=)
|
64
|
+
expect { Fetcher::Microdata.new :strange, raw_data
|
65
|
+
}.to raise_error Fetcher::Microdata::UnknownSocialNetworkError,
|
66
|
+
"Couldn't find coertion algorithm for 'strange' social network, please require 'fetcher-microdata-strange' in your project and make sure it has a Fetcher::Microdata::Strange::Coercer"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'there was a name error but not implying the social network' do
|
71
|
+
it 'should let it rise' do
|
72
|
+
module Fetcher; class Microdata; module Red; Coercer = proc {}; end; end; end
|
73
|
+
raw_data = stub 'data'
|
74
|
+
Fetcher::Microdata::Red::Coercer.should_receive(:call).and_raise NameError.new 'no description'
|
75
|
+
expect { Fetcher::Microdata.new :red, raw_data
|
76
|
+
}.to raise_error NameError, 'no description'
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Writer::Fetcher::Microdata::ArticleSmall do
|
4
|
+
describe '#hash' do
|
5
|
+
before do
|
6
|
+
@schema_stub = stub 'schema'
|
7
|
+
@author_stub = stub 'author', :to => stub( :hash => nil)
|
8
|
+
@viewer_stub = stub 'viewer', :to => stub( :hash => nil)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should return a hash with the type' do
|
12
|
+
final_hash = {
|
13
|
+
"type" => [
|
14
|
+
'the type'
|
15
|
+
]
|
16
|
+
}
|
17
|
+
@schema_stub.should_receive(:_type).and_return "the type"
|
18
|
+
@schema_stub.should_receive(:attributes).and_return stub('the hash', :[] => @author_stub)
|
19
|
+
|
20
|
+
writer = Writer::Fetcher::Microdata::ArticleSmall.new @schema_stub
|
21
|
+
writer.hash.should include final_hash
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'properties hash' do
|
25
|
+
before do
|
26
|
+
@schema_stub.should_receive(:_type).and_return nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should include the additionalType' do
|
30
|
+
@properties_hash = {
|
31
|
+
"additionalType" => [
|
32
|
+
"http://getfetcher.net/Item"
|
33
|
+
]
|
34
|
+
}
|
35
|
+
@schema_stub.should_receive(:attributes)
|
36
|
+
.and_return :additionalType => "http://getfetcher.net/Item",
|
37
|
+
:author => @author_stub,
|
38
|
+
:viewer => @viewer_stub
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should include the Item#id' do
|
42
|
+
@properties_hash = {
|
43
|
+
"Item#id" => [
|
44
|
+
234536234
|
45
|
+
]
|
46
|
+
}
|
47
|
+
|
48
|
+
@schema_stub.should_receive(:attributes)
|
49
|
+
.and_return :id => 234536234, :author => @author_stub, :viewer => @viewer_stub
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should include the articleBody' do
|
53
|
+
@properties_hash = {
|
54
|
+
"articleBody" => [
|
55
|
+
"some body"
|
56
|
+
]
|
57
|
+
}
|
58
|
+
|
59
|
+
@schema_stub.should_receive(:attributes)
|
60
|
+
.and_return :articleBody => "some body", :author => @author_stub, :viewer => @viewer_stub
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should include the author' do
|
64
|
+
@author = stub 'author'
|
65
|
+
@author_writer = stub 'author writer'
|
66
|
+
@author_writer.should_receive(:hash).and_return "hi Im the author"
|
67
|
+
@author.should_receive(:to).and_return @author_writer
|
68
|
+
@properties_hash = {
|
69
|
+
"author" => [
|
70
|
+
"hi Im the author"
|
71
|
+
]
|
72
|
+
}
|
73
|
+
|
74
|
+
@schema_stub.should_receive(:attributes)
|
75
|
+
.and_return :author => @author, :viewer => @viewer_stub
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should include the viewer' do
|
79
|
+
@viewer = stub 'viewer'
|
80
|
+
@viewer_writer = stub 'viewer writer'
|
81
|
+
@viewer_writer.should_receive(:hash).and_return "hi Im the viewer"
|
82
|
+
@viewer.should_receive(:to).and_return @viewer_writer
|
83
|
+
@properties_hash = {
|
84
|
+
"Item#viewer" => [
|
85
|
+
"hi Im the viewer"
|
86
|
+
]
|
87
|
+
}
|
88
|
+
|
89
|
+
@schema_stub.should_receive(:attributes)
|
90
|
+
.and_return :viewer => @viewer, :author => @author_stub
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should include the dateCreated' do
|
94
|
+
@properties_hash = {
|
95
|
+
"dateCreated" => [
|
96
|
+
23456235
|
97
|
+
]
|
98
|
+
}
|
99
|
+
|
100
|
+
@schema_stub.should_receive(:attributes)
|
101
|
+
.and_return :dateCreated => 23456235, :author => @author_stub, :viewer => @viewer_stub
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should include the provider' do
|
105
|
+
@properties_hash = {
|
106
|
+
"provider" => [
|
107
|
+
"twitter",
|
108
|
+
"fetcher"
|
109
|
+
]
|
110
|
+
}
|
111
|
+
|
112
|
+
@schema_stub.should_receive(:attributes)
|
113
|
+
.and_return :provider => ["twitter", "fetcher"], :author => @author_stub, :viewer => @viewer_stub
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should include the url' do
|
117
|
+
@properties_hash = {
|
118
|
+
"url" => [
|
119
|
+
"http://myurl.info"
|
120
|
+
]
|
121
|
+
}
|
122
|
+
|
123
|
+
@schema_stub.should_receive(:attributes)
|
124
|
+
.and_return :url => "http://myurl.info", :author => @author_stub, :viewer => @viewer_stub
|
125
|
+
end
|
126
|
+
|
127
|
+
after :each do
|
128
|
+
writer = Writer::Fetcher::Microdata::ArticleSmall.new @schema_stub
|
129
|
+
writer.hash["properties"].should include @properties_hash
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Writer::Fetcher::Microdata::PersonUser do
|
4
|
+
it 'should have a proper initializer to a Writer' do
|
5
|
+
user_stub = stub 'user'
|
6
|
+
writer = Writer::Fetcher::Microdata::PersonUser.new user_stub
|
7
|
+
writer.source.should == user_stub
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#hash' do
|
11
|
+
before do
|
12
|
+
@user_stub = stub 'user'
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return the type' do
|
16
|
+
final_hash = {
|
17
|
+
"type" => [
|
18
|
+
"some type"
|
19
|
+
]
|
20
|
+
}
|
21
|
+
|
22
|
+
@user_stub.should_receive(:_type).and_return "some type"
|
23
|
+
@user_stub.should_receive(:attributes).and_return stub :[] => nil
|
24
|
+
writer = Writer::Fetcher::Microdata::PersonUser.new @user_stub
|
25
|
+
writer.hash.should include final_hash
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'properties hash' do
|
29
|
+
before do
|
30
|
+
@user_stub.should_receive :_type
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should include the additionalType' do
|
34
|
+
@properties_hash = {
|
35
|
+
"additionalType" => [
|
36
|
+
"http://getfetcher.net/Item"
|
37
|
+
]
|
38
|
+
}
|
39
|
+
@user_stub.should_receive(:attributes).and_return :additionalType => "http://getfetcher.net/Item"
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should include the Item#id' do
|
43
|
+
@properties_hash = {
|
44
|
+
"Item#id" => [
|
45
|
+
234525
|
46
|
+
]
|
47
|
+
}
|
48
|
+
@user_stub.should_receive(:attributes).and_return :id => 234525
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should include the name' do
|
52
|
+
@properties_hash = {
|
53
|
+
"name" => [
|
54
|
+
"Marcus"
|
55
|
+
]
|
56
|
+
}
|
57
|
+
@user_stub.should_receive(:attributes).and_return :name => "Marcus"
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should include the dateRegistered' do
|
61
|
+
@properties_hash = {
|
62
|
+
"User#dateRegistered" => [
|
63
|
+
456468768
|
64
|
+
]
|
65
|
+
}
|
66
|
+
@user_stub.should_receive(:attributes).and_return :dateRegistered => 456468768
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should include the description' do
|
70
|
+
@properties_hash = {
|
71
|
+
"description" => [
|
72
|
+
456468768
|
73
|
+
]
|
74
|
+
}
|
75
|
+
@user_stub.should_receive(:attributes).and_return :description => 456468768
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should include the url' do
|
79
|
+
@properties_hash = {
|
80
|
+
"url" => [
|
81
|
+
456468768
|
82
|
+
]
|
83
|
+
}
|
84
|
+
@user_stub.should_receive(:attributes).and_return :url => 456468768
|
85
|
+
end
|
86
|
+
|
87
|
+
after :each do
|
88
|
+
writer = Writer::Fetcher::Microdata::PersonUser.new @user_stub
|
89
|
+
writer.hash["properties"].should include @properties_hash
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fetcher-microdata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Xavier Via
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: discoverer
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: pry
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Abstract classes for Fetcher Microdata serialization of social network
|
63
|
+
data
|
64
|
+
email:
|
65
|
+
- xavierviacanel@gmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- fetcher-microdata.gemspec
|
76
|
+
- lib/fetcher-microdata.rb
|
77
|
+
- lib/fetcher-microdata/article_small.rb
|
78
|
+
- lib/fetcher-microdata/person_user.rb
|
79
|
+
- lib/fetcher-microdata/version.rb
|
80
|
+
- lib/writer/fetcher-microdata/article_small.rb
|
81
|
+
- lib/writer/fetcher-microdata/person_user.rb
|
82
|
+
- spec/fetcher/microdata/article_small_spec.rb
|
83
|
+
- spec/fetcher/microdata/person_user_spec.rb
|
84
|
+
- spec/fetcher/microdata_spec.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
- spec/writer/fetcher/microdata/article_small_spec.rb
|
87
|
+
- spec/writer/fetcher/microdata/person_user_spec.rb
|
88
|
+
homepage: http://github.com/Fetcher/fetcher-microdata
|
89
|
+
licenses: []
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.8.24
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Abstract classes for Fetcher Microdata serialization of social network data
|
112
|
+
test_files:
|
113
|
+
- spec/fetcher/microdata/article_small_spec.rb
|
114
|
+
- spec/fetcher/microdata/person_user_spec.rb
|
115
|
+
- spec/fetcher/microdata_spec.rb
|
116
|
+
- spec/spec_helper.rb
|
117
|
+
- spec/writer/fetcher/microdata/article_small_spec.rb
|
118
|
+
- spec/writer/fetcher/microdata/person_user_spec.rb
|