fetcher-microdata-twitter 0.0.1 → 0.0.2

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.
@@ -2,8 +2,12 @@ Given /^the tweet:$/ do |json_tweet|
2
2
  @tweet = JSON.parse json_tweet
3
3
  end
4
4
 
5
+ And /^the viewer:$/ do |json_viewer|
6
+ @viewer = JSON.parse json_viewer
7
+ end
8
+
5
9
  When /^I convert it into schema.org\/Article\/Small$/ do
6
- @translated = Fetcher::Microdata::Twitter::ArticleSmall.new @tweet
10
+ @translated = Fetcher::Microdata::Twitter::ArticleSmall.new @tweet, @viewer
7
11
  end
8
12
 
9
13
  Then /^I should have:$/ do |json_schema|
@@ -68,6 +68,16 @@ Scenario: Converting a json tweet into a json schema
68
68
  }
69
69
  }
70
70
  """
71
+ And the viewer:
72
+ """
73
+ {
74
+ "created_at": "Sun Aug 01 09:52:47 +0000 2010",
75
+ "id": 173389269,
76
+ "name": "Xavier Via",
77
+ "description": "Web Developer specialized in Ruby.\r\n\r\nComputer Science enthusiast.",
78
+ "screen_name": "xaviervia"
79
+ }
80
+ """
71
81
  When I convert it into schema.org/Article/Small
72
82
  Then I should have:
73
83
  """
@@ -112,6 +122,33 @@ Scenario: Converting a json tweet into a json schema
112
122
  }
113
123
  }
114
124
  ],
125
+ "Item#viewer": [
126
+ {
127
+ "type": [
128
+ "http://schema.org/Person/User"
129
+ ],
130
+ "properties": {
131
+ "additionalType": [
132
+ "http://getfetcher.net/Item"
133
+ ],
134
+ "Item#id": [
135
+ 173389269
136
+ ],
137
+ "name": [
138
+ "Xavier Via"
139
+ ],
140
+ "User#dateRegistered": [
141
+ 1280656367
142
+ ],
143
+ "description": [
144
+ "Web Developer specialized in Ruby.\r\n\r\nComputer Science enthusiast."
145
+ ],
146
+ "url": [
147
+ "https://twitter.com/xaviervia"
148
+ ]
149
+ }
150
+ }
151
+ ],
115
152
  "dateCreated": [
116
153
  1329859747
117
154
  ],
@@ -11,21 +11,23 @@ module Fetcher
11
11
  attribute :id
12
12
  attribute :articleBody
13
13
  attribute :author
14
+ attribute :viewer
14
15
  attribute :dateCreated
15
16
  attribute :provider
16
17
  attribute :url
17
18
 
18
- def initialize original_tweet
19
+ def initialize original_tweet, viewer
19
20
  @_type = 'http://schema.org/Article/Small'
20
21
  @additionalType = 'http://getfetcher.net/Item'
21
22
 
22
- coerce original_tweet
23
+ coerce original_tweet, viewer
23
24
  end
24
25
 
25
- def coerce original_tweet
26
+ def coerce original_tweet, viewer
26
27
  @id = original_tweet["id"]
27
28
  @articleBody = original_tweet["text"]
28
29
  @author = PersonUser.new original_tweet["user"]
30
+ @viewer = PersonUser.new viewer
29
31
  @dateCreated = Service.instance.created_at_to_timestamp original_tweet["created_at"]
30
32
  @provider = ["twitter", original_tweet["source"]]
31
33
  @url = "https://twitter.com/#{original_tweet["user"]["screen_name"]}/status/#{original_tweet["id"]}"
@@ -1,7 +1,7 @@
1
1
  module Fetcher
2
2
  module Microdata
3
3
  module Twitter
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
6
6
  end
7
7
  end
@@ -26,6 +26,9 @@ module Writer
26
26
  "author" => [
27
27
  @attributes[:author].to.hash
28
28
  ],
29
+ "Item#viewer" => [
30
+ @attributes[:viewer].to.hash
31
+ ],
29
32
  "dateCreated" => [
30
33
  @attributes[:dateCreated]
31
34
  ],
@@ -4,21 +4,24 @@ describe Fetcher::Microdata::Twitter::ArticleSmall do
4
4
  describe '.new' do
5
5
  before do
6
6
  @argument_stub = stub 'arg'
7
+ @viewer_stub = stub 'viewer'
7
8
  end
8
- it 'should receive an argument' do
9
+
10
+ it 'should receive two arguments' do
9
11
  Fetcher::Microdata::Twitter::ArticleSmall.any_instance.stub :coerce
10
- Fetcher::Microdata::Twitter::ArticleSmall.new @argument_stub
12
+ Fetcher::Microdata::Twitter::ArticleSmall.new @argument_stub, @viewer_stub
11
13
  end
12
14
 
13
15
  it 'should set up the additionalType' do
14
16
  Fetcher::Microdata::Twitter::ArticleSmall.any_instance.stub :coerce
15
- adapter = Fetcher::Microdata::Twitter::ArticleSmall.new @argument_stub
17
+ adapter = Fetcher::Microdata::Twitter::ArticleSmall.new @argument_stub, @viewer_stub
16
18
  adapter.additionalType.should == 'http://getfetcher.net/Item'
17
19
  end
18
20
 
19
21
  it 'should call coerce to coerce the values the argument values into the final form' do
20
- Fetcher::Microdata::Twitter::ArticleSmall.any_instance.should_receive(:coerce).with @argument_stub
21
- Fetcher::Microdata::Twitter::ArticleSmall.new @argument_stub
22
+ Fetcher::Microdata::Twitter::ArticleSmall.any_instance.should_receive(:coerce)
23
+ .with @argument_stub, @viewer_stub
24
+ Fetcher::Microdata::Twitter::ArticleSmall.new @argument_stub, @viewer_stub
22
25
  end
23
26
  end
24
27
 
@@ -26,16 +29,18 @@ describe Fetcher::Microdata::Twitter::ArticleSmall do
26
29
  it 'should return the schema.org type' do
27
30
  Fetcher::Microdata::Twitter::ArticleSmall.any_instance.stub :coerce
28
31
  argument_stub = stub 'argument'
29
- adapter = Fetcher::Microdata::Twitter::ArticleSmall.new argument_stub
32
+ viewer_stub = stub 'viewer'
33
+ adapter = Fetcher::Microdata::Twitter::ArticleSmall.new argument_stub, viewer_stub
30
34
  adapter._type.should == 'http://schema.org/Article/Small'
31
35
  end
32
36
  end
33
37
 
34
38
  describe '#coerce' do
35
- context 'the adapter receives a valid tweet' do
39
+ context 'the adapter receives a valid tweet and a valid viewer' do
36
40
  before do
37
41
  @tweet = JSON.parse File.read 'spec/tweet.json'
38
- @adapter = Fetcher::Microdata::Twitter::ArticleSmall.new @tweet
42
+ @viewer = JSON.parse File.read 'spec/viewer.json'
43
+ @adapter = Fetcher::Microdata::Twitter::ArticleSmall.new @tweet, @viewer
39
44
  end
40
45
 
41
46
  it 'should set #id with the value of "id"' do
@@ -50,6 +55,10 @@ describe Fetcher::Microdata::Twitter::ArticleSmall do
50
55
  @adapter.author.attributes.should == Fetcher::Microdata::Twitter::PersonUser.new(@tweet["user"]).attributes
51
56
  end
52
57
 
58
+ it 'should set #viewer with the Person from the value of "user" > "name"' do
59
+ @adapter.viewer.attributes.should == Fetcher::Microdata::Twitter::PersonUser.new(@viewer).attributes
60
+ end
61
+
53
62
  it 'should set #dateCreated with the timestamp obtained from "created_at"' do
54
63
  @adapter.dateCreated.should == 1329859747
55
64
  end
@@ -78,31 +87,43 @@ describe Fetcher::Microdata::Twitter::ArticleSmall do
78
87
  end
79
88
 
80
89
  it 'should set attribute additionalType' do
81
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub).attributes.should have_key :additionalType
90
+ Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
91
+ .attributes.should have_key :additionalType
82
92
  end
83
93
 
84
94
  it 'should set attribute id' do
85
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub).attributes.should have_key :id
95
+ Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
96
+ .attributes.should have_key :id
86
97
  end
87
98
 
88
99
  it 'should set attribute articleBody' do
89
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub).attributes.should have_key :articleBody
100
+ Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
101
+ .attributes.should have_key :articleBody
90
102
  end
91
103
 
92
104
  it 'should set attribute author' do
93
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub).attributes.should have_key :author
105
+ Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
106
+ .attributes.should have_key :author
94
107
  end
95
108
 
109
+ it 'should set attribute viewer' do
110
+ Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
111
+ .attributes.should have_key :viewer
112
+ end
113
+
96
114
  it 'should set attribute dateCreated' do
97
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub).attributes.should have_key :dateCreated
115
+ Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
116
+ .attributes.should have_key :dateCreated
98
117
  end
99
118
 
100
119
  it 'should set attribute provider' do
101
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub).attributes.should have_key :provider
120
+ Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
121
+ .attributes.should have_key :provider
102
122
  end
103
123
 
104
124
  it 'should set attribute url' do
105
- Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub).attributes.should have_key :url
125
+ Fetcher::Microdata::Twitter::ArticleSmall.new(@argument_stub, @viewer_stub)
126
+ .attributes.should have_key :url
106
127
  end
107
128
  end
108
129
  end
@@ -0,0 +1,7 @@
1
+ {
2
+ "created_at": "Sun Aug 01 09:52:47 +0000 2010",
3
+ "id": 173389269,
4
+ "name": "Xavier Via",
5
+ "description": "Web Developer specialized in Ruby.\r\n\r\nComputer Science enthusiast.",
6
+ "screen_name": "xaviervia"
7
+ }
@@ -5,6 +5,7 @@ describe Writer::Fetcher::Microdata::Twitter::ArticleSmall do
5
5
  before do
6
6
  @schema_stub = stub 'schema'
7
7
  @author_stub = stub 'author', :to => stub( :hash => nil)
8
+ @viewer_stub = stub 'viewer', :to => stub( :hash => nil)
8
9
  end
9
10
 
10
11
  it 'should return a hash with the type' do
@@ -31,7 +32,10 @@ describe Writer::Fetcher::Microdata::Twitter::ArticleSmall do
31
32
  "http://getfetcher.net/Item"
32
33
  ]
33
34
  }
34
- @schema_stub.should_receive(:attributes).and_return :additionalType => "http://getfetcher.net/Item", :author => @author_stub
35
+ @schema_stub.should_receive(:attributes)
36
+ .and_return :additionalType => "http://getfetcher.net/Item",
37
+ :author => @author_stub,
38
+ :viewer => @viewer_stub
35
39
  end
36
40
 
37
41
  it 'should include the Item#id' do
@@ -41,7 +45,8 @@ describe Writer::Fetcher::Microdata::Twitter::ArticleSmall do
41
45
  ]
42
46
  }
43
47
 
44
- @schema_stub.should_receive(:attributes).and_return :id => 234536234, :author => @author_stub
48
+ @schema_stub.should_receive(:attributes)
49
+ .and_return :id => 234536234, :author => @author_stub, :viewer => @viewer_stub
45
50
  end
46
51
 
47
52
  it 'should include the articleBody' do
@@ -51,7 +56,8 @@ describe Writer::Fetcher::Microdata::Twitter::ArticleSmall do
51
56
  ]
52
57
  }
53
58
 
54
- @schema_stub.should_receive(:attributes).and_return :articleBody => "some body", :author => @author_stub
59
+ @schema_stub.should_receive(:attributes)
60
+ .and_return :articleBody => "some body", :author => @author_stub, :viewer => @viewer_stub
55
61
  end
56
62
 
57
63
  it 'should include the author' do
@@ -65,7 +71,23 @@ describe Writer::Fetcher::Microdata::Twitter::ArticleSmall do
65
71
  ]
66
72
  }
67
73
 
68
- @schema_stub.should_receive(:attributes).and_return :author => @author
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
69
91
  end
70
92
 
71
93
  it 'should include the dateCreated' do
@@ -75,7 +97,8 @@ describe Writer::Fetcher::Microdata::Twitter::ArticleSmall do
75
97
  ]
76
98
  }
77
99
 
78
- @schema_stub.should_receive(:attributes).and_return :dateCreated => 23456235, :author => @author_stub
100
+ @schema_stub.should_receive(:attributes)
101
+ .and_return :dateCreated => 23456235, :author => @author_stub, :viewer => @viewer_stub
79
102
  end
80
103
 
81
104
  it 'should include the provider' do
@@ -86,7 +109,8 @@ describe Writer::Fetcher::Microdata::Twitter::ArticleSmall do
86
109
  ]
87
110
  }
88
111
 
89
- @schema_stub.should_receive(:attributes).and_return :provider => ["twitter", "fetcher"], :author => @author_stub
112
+ @schema_stub.should_receive(:attributes)
113
+ .and_return :provider => ["twitter", "fetcher"], :author => @author_stub, :viewer => @viewer_stub
90
114
  end
91
115
 
92
116
  it 'should include the url' do
@@ -96,7 +120,8 @@ describe Writer::Fetcher::Microdata::Twitter::ArticleSmall do
96
120
  ]
97
121
  }
98
122
 
99
- @schema_stub.should_receive(:attributes).and_return :url => "http://myurl.info", :author => @author_stub
123
+ @schema_stub.should_receive(:attributes)
124
+ .and_return :url => "http://myurl.info", :author => @author_stub, :viewer => @viewer_stub
100
125
  end
101
126
 
102
127
  after :each do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetcher-microdata-twitter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-31 00:00:00.000000000 Z
12
+ date: 2012-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: discoverer
@@ -91,6 +91,7 @@ files:
91
91
  - spec/spec_helper.rb
92
92
  - spec/tweet.json
93
93
  - spec/user.json
94
+ - spec/viewer.json
94
95
  - spec/writer/fetcher/microdata/twitter/article_small_spec.rb
95
96
  - spec/writer/fetcher/microdata/twitter/person_user_spec.rb
96
97
  - tweet.yaml
@@ -108,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
109
  version: '0'
109
110
  segments:
110
111
  - 0
111
- hash: 273088467
112
+ hash: -976156881
112
113
  required_rubygems_version: !ruby/object:Gem::Requirement
113
114
  none: false
114
115
  requirements:
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  segments:
119
120
  - 0
120
- hash: 273088467
121
+ hash: -976156881
121
122
  requirements: []
122
123
  rubyforge_project:
123
124
  rubygems_version: 1.8.24
@@ -135,5 +136,6 @@ test_files:
135
136
  - spec/spec_helper.rb
136
137
  - spec/tweet.json
137
138
  - spec/user.json
139
+ - spec/viewer.json
138
140
  - spec/writer/fetcher/microdata/twitter/article_small_spec.rb
139
141
  - spec/writer/fetcher/microdata/twitter/person_user_spec.rb