stream_grabber 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +11 -4
- data/lib/stream_grabber.rb +7 -4
- data/lib/stream_grabber/github.rb +2 -2
- data/lib/stream_grabber/last_fm.rb +3 -3
- data/lib/stream_grabber/twitter.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -10,9 +10,16 @@ you'll need to give it your username for these sites. Create
|
|
10
10
|
`#{RAILS_ROOT}/config/stream_grabber.yml` so that it looks like the
|
11
11
|
following
|
12
12
|
|
13
|
-
:twitter:
|
14
|
-
|
15
|
-
|
13
|
+
:twitter:
|
14
|
+
username: username
|
15
|
+
|
16
|
+
:last_fm:
|
17
|
+
username: username
|
18
|
+
api_key: api_key
|
19
|
+
|
20
|
+
:github:
|
21
|
+
username: username
|
22
|
+
api_key: api_key
|
16
23
|
|
17
24
|
And then you can include the plugin in your Gemfile like so
|
18
25
|
|
@@ -47,7 +54,7 @@ following interface
|
|
47
54
|
|
48
55
|
module StreamGrabber
|
49
56
|
class Twitter
|
50
|
-
def initialize(user_name)
|
57
|
+
def initialize(user_name, api_key)
|
51
58
|
# do your setup in here to grab and parse the stream
|
52
59
|
end
|
53
60
|
|
data/lib/stream_grabber.rb
CHANGED
@@ -13,8 +13,10 @@ module StreamGrabber
|
|
13
13
|
class Engine < Rails::Engine; end
|
14
14
|
|
15
15
|
class << self
|
16
|
-
def
|
17
|
-
|
16
|
+
def set_config
|
17
|
+
raw_config = File.read(Rails.root.to_s + "/config/stream_grabber.yml")
|
18
|
+
@app_config ||= YAML.load(raw_config)
|
19
|
+
@app_config
|
18
20
|
end
|
19
21
|
|
20
22
|
def mux_stream
|
@@ -23,8 +25,9 @@ module StreamGrabber
|
|
23
25
|
k = StreamGrabber.const_get(klass)
|
24
26
|
if k.instance_of?(Class) and k.method_defined?('last_five')
|
25
27
|
name = k.name.partition('::').last.underscore.downcase
|
26
|
-
user_name =
|
27
|
-
|
28
|
+
user_name = set_config[name.to_sym]["username"]
|
29
|
+
api_key = set_config[name.to_sym]["api_key"]
|
30
|
+
messages.merge!(k.new(user_name, api_key).send(:last_five))
|
28
31
|
end
|
29
32
|
end
|
30
33
|
arr = messages.sort.reverse
|
@@ -4,8 +4,8 @@ require 'pp'
|
|
4
4
|
|
5
5
|
module StreamGrabber
|
6
6
|
class Github
|
7
|
-
def initialize(user_name)
|
8
|
-
@doc = SimpleRSS.parse(open("https://github.com/#{user_name}.private.actor.atom?token
|
7
|
+
def initialize(user_name, api_key)
|
8
|
+
@doc = SimpleRSS.parse(open("https://github.com/#{user_name}.private.actor.atom?token=#{api_key}"))
|
9
9
|
end
|
10
10
|
|
11
11
|
def last_five
|
@@ -3,9 +3,9 @@ require 'open-uri'
|
|
3
3
|
|
4
4
|
module StreamGrabber
|
5
5
|
class LastFm
|
6
|
-
def initialize(user_name)
|
6
|
+
def initialize(user_name, api_key)
|
7
7
|
@user_name = user_name
|
8
|
-
@doc ||= Nokogiri::XML(open("http://ws.audioscrobbler.com/2.0/?method=user.getlovedtracks&user=#{user_name}&api_key
|
8
|
+
@doc ||= Nokogiri::XML(open("http://ws.audioscrobbler.com/2.0/?method=user.getlovedtracks&user=#{user_name}&api_key=#{api_key}"))
|
9
9
|
end
|
10
10
|
|
11
11
|
def last_five
|
@@ -22,7 +22,7 @@ module StreamGrabber
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def message_for(artist, title, url)
|
25
|
-
%Q{ #{@user_name} loved the track
|
25
|
+
%Q{ <a href="#{url}">#{@user_name} loved the track #{title} by #{artist} on Last.fm</a> }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -3,7 +3,7 @@ require 'open-uri'
|
|
3
3
|
|
4
4
|
module StreamGrabber
|
5
5
|
class Twitter
|
6
|
-
def initialize(user_name)
|
6
|
+
def initialize(user_name, api_key=nil)
|
7
7
|
@user_name = user_name
|
8
8
|
@doc = JSON.load(open("http://api.twitter.com/1/statuses/user_timeline.json?count=6&screen_name=#{user_name}"))
|
9
9
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stream_grabber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt House
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-25 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|