social_current 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/lib/social_current/github.rb +7 -7
- data/lib/social_current/service.rb +8 -3
- data/lib/social_current/twitter.rb +3 -3
- data/lib/social_current/version.rb +1 -1
- metadata +1 -1
data/README.md
CHANGED
@@ -23,7 +23,7 @@ Or install it yourself as:
|
|
23
23
|
You may use Social Current directly within your view like.
|
24
24
|
|
25
25
|
```ruby
|
26
|
-
<% SocialCurrent::Stream.new({ :twitter => "tristanoneil", :github => "tristanoneil" }).each do |item| %>
|
26
|
+
<% SocialCurrent::Stream.new({ :twitter => "tristanoneil", :github => "tristanoneil" }).build.each do |item| %>
|
27
27
|
<%= item[:message] >
|
28
28
|
<% end %>
|
29
29
|
```
|
@@ -33,7 +33,7 @@ Though it's probably a better idea to add a method to a class or model like.
|
|
33
33
|
```ruby
|
34
34
|
class User < ActiveRecord::Base
|
35
35
|
def stream
|
36
|
-
SocialCurrent::Stream.new({ :twitter => twitter_username, :github => github_username })
|
36
|
+
SocialCurrent::Stream.new({ :twitter => twitter_username, :github => github_username }).build
|
37
37
|
end
|
38
38
|
end
|
39
39
|
```
|
@@ -4,15 +4,15 @@ module SocialCurrent
|
|
4
4
|
base_uri "https://api.github.com"
|
5
5
|
|
6
6
|
def raw_user
|
7
|
-
|
7
|
+
fetch("/users/#{@user}", "#{@user}_github_raw_user.json")
|
8
8
|
end
|
9
9
|
|
10
10
|
def raw_stream
|
11
|
-
|
11
|
+
fetch("/users/#{@user}/events", "#{@user}_github_raw_stream.json")
|
12
12
|
end
|
13
13
|
|
14
14
|
def stream
|
15
|
-
|
15
|
+
raw_stream.collect do |s|
|
16
16
|
{ :message => format_message(s), :created_at => Time.parse(s["created_at"]).utc, :service => "github" }
|
17
17
|
end
|
18
18
|
end
|
@@ -22,13 +22,13 @@ module SocialCurrent
|
|
22
22
|
def format_message(event)
|
23
23
|
case event["type"]
|
24
24
|
when "PushEvent"
|
25
|
-
|
25
|
+
"#{self.raw_user["name"]} pushed to <a href='http://github.com/#{event["repo"]["name"]}'>#{event["repo"]["name"]}</a>."
|
26
26
|
when "FollowEvent"
|
27
|
-
|
27
|
+
"#{self.raw_user["name"]} followed <a href='#{event["payload"]["target"]["html_url"]}'>#{event["payload"]["target"]["name"]}</a>."
|
28
28
|
when "CreateEvent"
|
29
|
-
|
29
|
+
"#{self.raw_user["name"]} created <a href='http://github.com/#{event["repo"]["name"]}'>#{event["repo"]["name"]}</a>."
|
30
30
|
when "WatchEvent"
|
31
|
-
|
31
|
+
"#{self.raw_user["name"]} started watching <a href='http://github.com/#{event["repo"]["name"]}'>#{event["repo"]["name"]}</a>."
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -5,10 +5,16 @@ module SocialCurrent
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def fetch(remote, local)
|
8
|
-
|
8
|
+
if cache_valid?("#{Dir.tmpdir}/#{local}")
|
9
9
|
JSON.parse(File.read("#{Dir.tmpdir}/#{local}"))
|
10
10
|
else
|
11
|
-
|
11
|
+
response = self.class.get(remote)
|
12
|
+
if response.header.code == "404"
|
13
|
+
[]
|
14
|
+
else
|
15
|
+
write_cache(local, JSON.parse(response.body))
|
16
|
+
JSON.parse(response.body)
|
17
|
+
end
|
12
18
|
end
|
13
19
|
end
|
14
20
|
|
@@ -18,7 +24,6 @@ module SocialCurrent
|
|
18
24
|
File.open("#{Dir.tmpdir}/#{local}", "w") do |f|
|
19
25
|
f.write(contents.to_json)
|
20
26
|
end
|
21
|
-
contents
|
22
27
|
end
|
23
28
|
|
24
29
|
def cache_valid?(cache)
|
@@ -4,15 +4,15 @@ module SocialCurrent
|
|
4
4
|
base_uri "https://api.twitter.com/1"
|
5
5
|
|
6
6
|
def raw_user
|
7
|
-
|
7
|
+
fetch("/users/show.json?screen_name=#{@user}", "#{@user}_twitter_raw_user.json")
|
8
8
|
end
|
9
9
|
|
10
10
|
def raw_stream
|
11
|
-
|
11
|
+
fetch("/statuses/user_timeline.json?&screen_name=#{@user}", "#{@user}_twitter_raw_stream.json")
|
12
12
|
end
|
13
13
|
|
14
14
|
def stream
|
15
|
-
|
15
|
+
raw_stream.collect do |s|
|
16
16
|
{ :message => format_message(s), :created_at => Time.parse(s["created_at"]).utc, :service => "twitter" }
|
17
17
|
end
|
18
18
|
end
|