doing_stream 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -34,7 +34,7 @@ them to `DoingStream::DoingStream.new`:
34
34
 
35
35
  streams = []
36
36
  streams << DoingStream::Streams::GitHub.new('foobar')
37
- streams << DoingStream::Streams::LastFM.new('foobar')
37
+ streams << DoingStream::Streams::LastFM.new('foobar', api_key: 'my_awesome_api_key')
38
38
  streams << DoingStream::Streams::Pinboard.new('foobar')
39
39
  streams << DoingStream::Streams::StackOverflow.new(42)
40
40
  streams << DoingStream::Streams::Vimeo.new('foobar')
@@ -16,6 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.version = DoingStream::VERSION
17
17
 
18
18
  gem.add_dependency 'curb'
19
- gem.add_dependency 'feedzirra'
19
+ gem.add_dependency 'feedzirra', '~> 0.1.3'
20
20
  gem.add_dependency 'json'
21
21
  end
@@ -9,10 +9,10 @@ class DoingStream::DoingStream
9
9
  @streams = streams
10
10
  end
11
11
 
12
- def latest
13
- @latest ||= streams.map do |stream|
14
- stream.entries.take(2)
15
- end.flatten.sort_by(&:published).reverse.take(5)
12
+ def latest n = 5, m = 2
13
+ streams.map do |stream|
14
+ stream.entries.take((m.respond_to? :call) ? m.call(stream) : m)
15
+ end.flatten.sort_by(&:published).reverse.take(n)
16
16
  end
17
17
 
18
18
  def entries
@@ -3,10 +3,11 @@ require 'uri'
3
3
 
4
4
  module DoingStream::Stream
5
5
  class Stream
6
- attr_accessor :entries, :uri
6
+ attr_accessor :entries, :user
7
7
 
8
- def initialize user
9
- @uri = ::URI.parse(ERB.new(self.class::URI).result(binding))
8
+ def initialize user, options = {}
9
+ @user = user
10
+ @options = options
10
11
  end
11
12
 
12
13
  def entry_class
@@ -20,5 +21,9 @@ module DoingStream::Stream
20
21
  def name
21
22
  self.class.to_s.split('::').last.downcase
22
23
  end
24
+
25
+ def uri
26
+ ::URI.parse(ERB.new(self.class::URI).result(binding))
27
+ end
23
28
  end
24
29
  end
@@ -1,6 +1,13 @@
1
1
  module DoingStream
2
2
  class Streams::LastFM < Stream::JSONStream
3
- URI = 'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=<%= user %>&format=json&limit=5&api_key=b25b959554ed76058ac220b7b2e0a026'
3
+ URI = 'http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=<%= user %>&format=json&limit=5&api_key=<%= api_key %>'
4
+
5
+ attr_accessor :api_key
6
+
7
+ def initialize user, options = {}
8
+ super
9
+ @api_key = options[:api_key]
10
+ end
4
11
 
5
12
  def json
6
13
  super['recenttracks']['track']
@@ -6,7 +6,13 @@ module DoingStream
6
6
  end
7
7
 
8
8
  def entries
9
- @entries ||= (@likes.entries + @videos.entries).sort_by(&:published).reverse
9
+ @entries ||= begin
10
+ (@likes.entries + @videos.entries).sort_by(&:published).reverse.each do |entry|
11
+ class << entry; alias_method :type, :name; end
12
+ entry.define_singleton_method(:name) { "vimeo" }
13
+ def entry.to_h; super.tap { |h| h['data']['type'] = type }; end
14
+ end
15
+ end
10
16
  end
11
17
  end
12
18
 
@@ -1,3 +1,3 @@
1
1
  module DoingStream
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: doing_stream
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
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-05-14 00:00:00.000000000 Z
12
+ date: 2012-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: curb
@@ -32,17 +32,17 @@ dependencies:
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
- - - ! '>='
35
+ - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: 0.1.3
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
- - - ! '>='
43
+ - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: 0.1.3
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: json
48
48
  requirement: !ruby/object:Gem::Requirement