doing_stream 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in doing_stream.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 J. Andrew Marshall
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,57 @@
1
+ # DoingStream
2
+
3
+ Accumulate streams from various sites, with the intention of manipulating them
4
+ into a single stream of your activities on the internet—i.e., a stream of
5
+ things you are *doing*.
6
+
7
+ ## Installation
8
+
9
+ With Bundler, simply add this line to your application's Gemfile:
10
+
11
+ gem 'doing_stream'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install doing_stream
20
+
21
+ ## Usage
22
+
23
+ There are six built-in streams:
24
+
25
+ - GitHub
26
+ - Last.FM
27
+ - Pinboard
28
+ - StackOverflow
29
+ - Vimeo
30
+ - Twitter
31
+
32
+ Simply create each stream desired with the username, then pass a collection of
33
+ them to `DoingStream::DoingStream.new`:
34
+
35
+ streams = []
36
+ streams << DoingStream::Streams::GitHub.new('foobar')
37
+ streams << DoingStream::Streams::LastFM.new('foobar')
38
+ streams << DoingStream::Streams::Pinboard.new('foobar')
39
+ streams << DoingStream::Streams::StackOverflow.new(42)
40
+ streams << DoingStream::Streams::Vimeo.new('foobar')
41
+ entries = DoingStream::DoingStream.new(streams)
42
+ entries.latest
43
+
44
+ Keep in mind that most of the API-based streams have rate-limits, so it would
45
+ be wise to cache the results if you expect this to run frequently.
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
54
+
55
+ ## Credits
56
+
57
+ Copyright © 2012 J. Andrew Marshall. All rights reserved.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/doing_stream/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Andrew Marshall"]
6
+ gem.email = ["andrew@johnandrewmarshall.com"]
7
+ gem.description = %q{Accumulate streams from various sites}
8
+ gem.summary = %q{Accumulate streams from various sites}
9
+ gem.homepage = "http://johnandrewmarshall.com/projects/doing-stream"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "doing_stream"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = DoingStream::VERSION
17
+
18
+ gem.add_dependency 'curb'
19
+ gem.add_dependency 'feedzirra'
20
+ gem.add_dependency 'json'
21
+ end
@@ -0,0 +1,21 @@
1
+ require 'doing_stream/version'
2
+ require 'doing_stream/stream'
3
+ require 'doing_stream/streams'
4
+
5
+ class DoingStream::DoingStream
6
+ attr_accessor :streams
7
+
8
+ def initialize streams
9
+ @streams = streams
10
+ end
11
+
12
+ def latest
13
+ @latest ||= streams.map do |stream|
14
+ stream.entries.take(2)
15
+ end.flatten.sort_by(&:published).reverse.take(5)
16
+ end
17
+
18
+ def entries
19
+ @entries ||= streams.map(&:entries).flatten.sort_by(&:published).reverse
20
+ end
21
+ end
@@ -0,0 +1,4 @@
1
+ require 'doing_stream/stream/entry'
2
+ require 'doing_stream/stream/stream'
3
+ require 'doing_stream/stream/feed_stream'
4
+ require 'doing_stream/stream/json_stream'
@@ -0,0 +1,20 @@
1
+ require 'date'
2
+ require 'json'
3
+
4
+ module DoingStream::Stream
5
+ class Entry < Struct.new(:name, :data)
6
+ def published
7
+ published = data['published']
8
+ published = Time.new published unless published.is_a? Time
9
+ published
10
+ end
11
+
12
+ def to_h
13
+ { 'feed_name' => name, name => 'true', 'published' => published, 'data' => data }
14
+ end
15
+
16
+ def to_json
17
+ to_h.to_json
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'feedzirra'
2
+
3
+ module DoingStream::Stream
4
+ class FeedStream < Stream
5
+ def feed
6
+ @feed ||= Feedzirra::Feed.fetch_and_parse uri.to_s
7
+ end
8
+
9
+ def entries
10
+ @entries ||= feed.entries.map do |entry|
11
+ entry_class.new(name, Hash[entry.to_a])
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ require 'curb'
2
+ require 'json'
3
+
4
+ module DoingStream::Stream
5
+ class JSONStream < Stream
6
+ def body
7
+ @body ||= Curl::Easy.perform(uri.to_s).body_str
8
+ end
9
+
10
+ def json
11
+ JSON.parse body
12
+ end
13
+
14
+ def entries
15
+ @entries ||= json.map do |entry|
16
+ entry_class.new(name, entry)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ require 'erb'
2
+ require 'uri'
3
+
4
+ module DoingStream::Stream
5
+ class Stream
6
+ attr_accessor :entries, :uri
7
+
8
+ def initialize user
9
+ @uri = ::URI.parse(ERB.new(self.class::URI).result(binding))
10
+ end
11
+
12
+ def entry_class
13
+ if self.class.constants.include? :Entry
14
+ self.class.const_get(:Entry)
15
+ else
16
+ Entry
17
+ end
18
+ end
19
+
20
+ def name
21
+ self.class.to_s.split('::').last.downcase
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,10 @@
1
+ require 'doing_stream/stream'
2
+
3
+ module DoingStream::Streams; end
4
+
5
+ require 'doing_stream/streams/github'
6
+ require 'doing_stream/streams/last_fm'
7
+ require 'doing_stream/streams/pinboard'
8
+ require 'doing_stream/streams/stack_overflow'
9
+ require 'doing_stream/streams/twitter'
10
+ require 'doing_stream/streams/vimeo'
@@ -0,0 +1,15 @@
1
+ module DoingStream
2
+ class Streams::GitHub < Stream::JSONStream
3
+ URI = 'https://api.github.com/users/<%= user %>/events/public'
4
+
5
+ def entries
6
+ @entries ||= super.select { |entry| %w[ForkEvent PublicEvent PushEvent].include? entry.data['type'] }
7
+ end
8
+
9
+ class Entry < Stream::Entry
10
+ def published
11
+ Time.new data['created_at']
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module DoingStream
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'
4
+
5
+ def json
6
+ super['recenttracks']['track']
7
+ end
8
+
9
+ class Entry < Stream::Entry
10
+ def published
11
+ if data['@attr'] && data['@attr']['nowplaying'] == 'true'
12
+ Time.now
13
+ else
14
+ Time.at data['date']['uts'].to_i
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module DoingStream
2
+ class Streams::Pinboard < Stream::FeedStream
3
+ URI = 'http://feeds.pinboard.in/rss/u:<%= user %>/'
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ require 'open-uri'
2
+ require 'zlib'
3
+
4
+ module DoingStream
5
+ class Streams::StackOverflow < Stream::JSONStream
6
+ URI = 'https://api.stackexchange.com/2.0/users/<%= user %>/timeline?site=stackoverflow&pagesize=100'
7
+
8
+ def body
9
+ @body ||= Zlib::GzipReader.new(open(uri.to_s)).read
10
+ end
11
+
12
+ def json
13
+ super['items']
14
+ end
15
+
16
+ def entries
17
+ @entries ||= super.select { |entry| %w[answered asked badge].include? entry.data['timeline_type'] }
18
+ end
19
+
20
+ class Entry < Stream::Entry
21
+ def published
22
+ Time.at data['creation_date'].to_i
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module DoingStream
2
+ class Streams::Twitter < Stream::JSONStream
3
+ URI = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=<%= user %>'
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ module DoingStream
2
+ class Streams::Vimeo < Stream::Stream
3
+ def initialize user
4
+ @likes = Likes.new user
5
+ @videos = Videos.new user
6
+ end
7
+
8
+ def entries
9
+ @entries ||= (@likes.entries + @videos.entries).sort_by(&:published).reverse
10
+ end
11
+ end
12
+
13
+ class Streams::Vimeo::Likes < Stream::JSONStream
14
+ URI = 'http://vimeo.com/api/v2/<%= user %>/likes.json'
15
+
16
+ def name; 'vimeo'; end
17
+
18
+ class Entry < Stream::Entry
19
+ def published
20
+ Time.new data['liked_on']
21
+ end
22
+ end
23
+ end
24
+
25
+ class Streams::Vimeo::Videos < Stream::JSONStream
26
+ URI = 'http://vimeo.com/api/v2/<%= user %>/videos.json'
27
+
28
+ def name; 'vimeo'; end
29
+
30
+ class Entry < Stream::Entry
31
+ def published
32
+ Time.new data['upload_date']
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module DoingStream
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doing_stream
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrew Marshall
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: curb
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: feedzirra
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: json
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Accumulate streams from various sites
63
+ email:
64
+ - andrew@johnandrewmarshall.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - doing_stream.gemspec
75
+ - lib/doing_stream.rb
76
+ - lib/doing_stream/stream.rb
77
+ - lib/doing_stream/stream/entry.rb
78
+ - lib/doing_stream/stream/feed_stream.rb
79
+ - lib/doing_stream/stream/json_stream.rb
80
+ - lib/doing_stream/stream/stream.rb
81
+ - lib/doing_stream/streams.rb
82
+ - lib/doing_stream/streams/github.rb
83
+ - lib/doing_stream/streams/last_fm.rb
84
+ - lib/doing_stream/streams/pinboard.rb
85
+ - lib/doing_stream/streams/stack_overflow.rb
86
+ - lib/doing_stream/streams/twitter.rb
87
+ - lib/doing_stream/streams/vimeo.rb
88
+ - lib/doing_stream/version.rb
89
+ homepage: http://johnandrewmarshall.com/projects/doing-stream
90
+ licenses: []
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 1.8.24
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Accumulate streams from various sites
113
+ test_files: []
114
+ has_rdoc: