twithub 0.1.2 → 0.1.3
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/lib/twithub/entries.rb +18 -0
- data/lib/twithub/feed_entry.rb +6 -2
- data/lib/twithub/version.rb +1 -1
- data/lib/twithub.rb +10 -1
- data/spec/twithub/feed_entry_spec.rb +18 -0
- data/spec/twithub/github_entry_spec.rb +1 -1
- data/spec/twithub/twitter_entry_spec.rb +1 -1
- data/spec/twithub_spec.rb +35 -0
- metadata +11 -10
@@ -0,0 +1,18 @@
|
|
1
|
+
module Twithub
|
2
|
+
class Entries
|
3
|
+
def from_json(json)
|
4
|
+
parsed = JSON.parse(json)
|
5
|
+
return entry_for(parsed) if parsed.is_a?(Hash)
|
6
|
+
if parsed.is_a?(Array)
|
7
|
+
return parsed.map {|e| entry_for(e) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def entry_for(hash)
|
13
|
+
entry = hash["origin"] == Twithub::TWITTER ? Twithub::TwitterEntry.new : Twithub::GithubEntry.new
|
14
|
+
time = Time.parse(hash["posted_at"])
|
15
|
+
entry.with_content(hash["content"]).with_username(hash["username"]).with_posted_at(time)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/twithub/feed_entry.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
+
|
1
2
|
module Twithub
|
2
3
|
class FeedEntry
|
3
4
|
include Comparable
|
4
|
-
TWITTER = "twitter"
|
5
|
-
GITHUB = "github"
|
6
5
|
attr_reader :content, :posted_at, :origin, :username
|
7
6
|
|
8
7
|
def <=>(other_entry)
|
9
8
|
other_entry.posted_at <=> posted_at
|
10
9
|
end
|
10
|
+
|
11
|
+
def to_json(*args)
|
12
|
+
{ :content => content, :username => username,
|
13
|
+
:posted_at => posted_at, :origin => origin }.to_json
|
14
|
+
end
|
11
15
|
end
|
12
16
|
end
|
data/lib/twithub/version.rb
CHANGED
data/lib/twithub.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'json'
|
1
2
|
require 'twitter'
|
2
3
|
require 'feedzirra'
|
3
4
|
require_relative 'twithub/entry_builder_methods'
|
@@ -6,11 +7,19 @@ require_relative 'twithub/twitter'
|
|
6
7
|
require_relative 'twithub/github'
|
7
8
|
require_relative 'twithub/twitter_entry'
|
8
9
|
require_relative 'twithub/github_entry'
|
10
|
+
require_relative 'twithub/entries'
|
9
11
|
|
10
12
|
module Twithub
|
13
|
+
TWITTER = "twitter"
|
14
|
+
GITHUB = "github"
|
11
15
|
def entries_for(params)
|
12
16
|
entries = Twitter.entries_for(params[:twitter]) + Github.entries_for(params[:github])
|
13
|
-
entries.sort
|
17
|
+
entries.sort.take(params[:count] || entries.size)
|
14
18
|
end
|
15
19
|
module_function :entries_for
|
20
|
+
|
21
|
+
def from_json(json)
|
22
|
+
Entries.new.from_json(json)
|
23
|
+
end
|
24
|
+
module_function :from_json
|
16
25
|
end
|
@@ -23,5 +23,23 @@ describe Twithub::FeedEntry do
|
|
23
23
|
(old_entry < new_entry).should be_false
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
describe "an entry with stubbed out attributes" do
|
28
|
+
let(:entry) { Twithub::FeedEntry.new }
|
29
|
+
let(:time) { Time.now }
|
30
|
+
let(:expected_hash) { {"posted_at" => time.to_s, "content" => "the content",
|
31
|
+
"username" => "pzimbelman", "origin" => "twitter" } }
|
32
|
+
|
33
|
+
before do
|
34
|
+
entry.stub(:posted_at).and_return(time)
|
35
|
+
entry.stub(:content).and_return("the content")
|
36
|
+
entry.stub(:username).and_return("pzimbelman")
|
37
|
+
entry.stub(:origin).and_return("twitter")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should take the entry to json" do
|
41
|
+
JSON.parse(entry.to_json).should == expected_hash
|
42
|
+
end
|
43
|
+
end
|
26
44
|
end
|
27
45
|
end
|
data/spec/twithub_spec.rb
CHANGED
@@ -30,4 +30,39 @@ describe Twithub do
|
|
30
30
|
Twithub.entries_for(:twitter => twitter_name, :github => github_name).should == [github_entry, twitter_entry]
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
describe "when lots of entries are returned" do
|
35
|
+
let(:fake_entries) { (1..100).to_a }
|
36
|
+
|
37
|
+
before do
|
38
|
+
Twithub::Twitter.stub(:entries_for).and_return(fake_entries)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should allow the user to limit the count of the returned entries" do
|
42
|
+
Twithub.entries_for(:twitter => "stuff", :count => 7).size.should == 7
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should return all entries if no count parameter is given or if count is larger than the number of entries" do
|
46
|
+
Twithub.entries_for(:twitter => "stuff").size.should == 100
|
47
|
+
Twithub.entries_for(:twitter => "stuff", :count => 200).size.should == 100
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "from_json" do
|
52
|
+
let(:time) { Time.parse("Jan 1st 2011") }
|
53
|
+
let(:entry) { Twithub::TwitterEntry.new.with_content("foobar").with_username("thing").with_posted_at(time) }
|
54
|
+
|
55
|
+
it "should be able accept a json string for a single entry" do
|
56
|
+
new_entry = Twithub.from_json(entry.to_json)
|
57
|
+
new_entry.content.should == "foobar"
|
58
|
+
new_entry.posted_at.should == time
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should be able to accept a json string of an array of entries" do
|
62
|
+
json = [entry].to_json
|
63
|
+
new_entry = Twithub.from_json(json).first
|
64
|
+
new_entry.content.should == "foobar"
|
65
|
+
new_entry.posted_at.should == time
|
66
|
+
end
|
67
|
+
end
|
33
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twithub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70108269820160 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70108269820160
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &70108269819700 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70108269819700
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: twitter
|
38
|
-
requirement: &
|
38
|
+
requirement: &70108269819180 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.3'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70108269819180
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: feedzirra
|
49
|
-
requirement: &
|
49
|
+
requirement: &70108269818580 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 0.2.0.rc2
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70108269818580
|
58
58
|
description: A gem to aggregate your recent twitter and github activity into a single
|
59
59
|
feed. Can accept multiple logins for either service.
|
60
60
|
email:
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- README.markdown
|
69
69
|
- Rakefile
|
70
70
|
- lib/twithub.rb
|
71
|
+
- lib/twithub/entries.rb
|
71
72
|
- lib/twithub/entry_builder_methods.rb
|
72
73
|
- lib/twithub/feed_entry.rb
|
73
74
|
- lib/twithub/github.rb
|