stratify-rhapsody 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .bundle
3
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.2-p180@stratify
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in stratify-rhapsody.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,94 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ stratify-rhapsody (0.1.0)
5
+ railties (~> 3.1.0.rc1)
6
+ stratify-base (~> 0.1.0)
7
+ thoughtafter-simple-rss (~> 1.2.3)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ actionpack (3.1.0.rc1)
13
+ activemodel (= 3.1.0.rc1)
14
+ activesupport (= 3.1.0.rc1)
15
+ builder (~> 3.0.0)
16
+ erubis (~> 2.7.0)
17
+ i18n (~> 0.6.0beta1)
18
+ rack (~> 1.3.0.beta2)
19
+ rack-cache (~> 1.0.1)
20
+ rack-mount (~> 0.8.1)
21
+ rack-test (~> 0.6.0)
22
+ sprockets (~> 2.0.0.beta.5)
23
+ tzinfo (~> 0.3.27)
24
+ activemodel (3.1.0.rc1)
25
+ activesupport (= 3.1.0.rc1)
26
+ bcrypt-ruby (~> 2.1.4)
27
+ builder (~> 3.0.0)
28
+ i18n (~> 0.6.0beta1)
29
+ activesupport (3.1.0.rc1)
30
+ multi_json (~> 1.0)
31
+ bcrypt-ruby (2.1.4)
32
+ bson (1.3.1)
33
+ bson_ext (1.3.1)
34
+ builder (3.0.0)
35
+ database_cleaner (0.6.7)
36
+ diff-lcs (1.1.2)
37
+ erubis (2.7.0)
38
+ fakeweb (1.3.0)
39
+ hike (1.0.0)
40
+ i18n (0.6.0)
41
+ mongo (1.3.1)
42
+ bson (>= 1.3.1)
43
+ mongoid (2.0.2)
44
+ activemodel (~> 3.0)
45
+ mongo (~> 1.3)
46
+ tzinfo (~> 0.3.22)
47
+ multi_json (1.0.3)
48
+ rack (1.3.0)
49
+ rack-cache (1.0.2)
50
+ rack (>= 0.4)
51
+ rack-mount (0.8.1)
52
+ rack (>= 1.0.0)
53
+ rack-ssl (1.3.2)
54
+ rack
55
+ rack-test (0.6.0)
56
+ rack (>= 1.0)
57
+ railties (3.1.0.rc1)
58
+ actionpack (= 3.1.0.rc1)
59
+ activesupport (= 3.1.0.rc1)
60
+ rack-ssl (~> 1.3.2)
61
+ rake (>= 0.8.7)
62
+ thor (~> 0.14.6)
63
+ rake (0.9.2)
64
+ rspec (2.6.0)
65
+ rspec-core (~> 2.6.0)
66
+ rspec-expectations (~> 2.6.0)
67
+ rspec-mocks (~> 2.6.0)
68
+ rspec-core (2.6.3)
69
+ rspec-expectations (2.6.0)
70
+ diff-lcs (~> 1.1.2)
71
+ rspec-mocks (2.6.0)
72
+ sprockets (2.0.0.beta.10)
73
+ hike (~> 1.0)
74
+ rack (~> 1.0)
75
+ tilt (!= 1.3.0, ~> 1.1)
76
+ stratify-base (0.1.0)
77
+ bson_ext (~> 1.3.1)
78
+ mongoid (~> 2.0.2)
79
+ tilt (~> 1.3.2)
80
+ thor (0.14.6)
81
+ thoughtafter-simple-rss (1.2.3.3)
82
+ tilt (1.3.2)
83
+ tzinfo (0.3.27)
84
+ vcr (1.10.0)
85
+
86
+ PLATFORMS
87
+ ruby
88
+
89
+ DEPENDENCIES
90
+ database_cleaner (~> 0.6.7)
91
+ fakeweb (~> 1.3.0)
92
+ rspec (~> 2.6.0)
93
+ stratify-rhapsody!
94
+ vcr (~> 1.10.0)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jason Rudolph (http://jasonrudolph.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # stratify-rhapsody
2
+
3
+ ## Dependencies
4
+
5
+ Stratify is developed and tested with the following dependencies.
6
+
7
+ * Ruby 1.9.2 (See `.rvmrc` for the specific version.)
8
+ * MongoDB 1.8
9
+
10
+ ## Development
11
+
12
+ To get set up for development on stratify-rhapsody, clone the repo, and ...
13
+
14
+ cd stratify/stratify-rhapsody
15
+ gem install bundler
16
+ bundle
17
+ rake
18
+
19
+ ## License
20
+
21
+ Copyright 2011 Jason Rudolph ([jasonrudolph.com](http://jasonrudolph.com)). Released under the MIT license. See the LICENSE file for further details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,26 @@
1
+ module Stratify
2
+ module Rhapsody
3
+ class Activity < Stratify::Activity
4
+ field :track_id # Rhapsody Track GUID / "RCID" (e.g., tra.39893452)
5
+ field :track_title
6
+ field :artist_id # Rhapsody Artist GUID / "RCID" (e.g., art.32992347)
7
+ field :artist_name
8
+ field :album_id # Rhapsody Album GUID / "RCID" (e.g., alb.39893441)
9
+ field :album_title
10
+ field :genre
11
+
12
+ natural_key :track_id, :created_at
13
+
14
+ validates_presence_of :track_id, :track_title, :artist_id, :artist_name, :album_id, :album_title
15
+
16
+ template %q[
17
+ <p class="summary"><%= track_title %> &bull; <%= artist_name %></p>
18
+ <p class="details"><%= album_title %> &bull; <%= genre %></p>
19
+ ]
20
+
21
+ def permalink
22
+ "http://www.rhapsody.com/goto?rcid=#{track_id}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ require 'stratify-rhapsody/query'
2
+
3
+ module Stratify
4
+ module Rhapsody
5
+ class Collector < Stratify::Collector
6
+ source "Rhapsody"
7
+
8
+ configuration_fields :rss_url => {:type => :string, :label => "RSS URL"}
9
+
10
+ configuration_instructions %q[
11
+ <p>To collect your Rhapsody listening history, the Rhapsody collector needs the RSS feed for your "recently played tracks."</p>
12
+
13
+ <p>To find the URL for your personal RSS feed, go to the <a href="http://www.rhapsody.com/myrhapsody/feeds.html" target="_blank">RSS Feeds</a> page for your Rhapsody account. Look for the RSS feed link labeled "Recently Played Tracks." The URL will look something like this:</p>
14
+
15
+ <p><code>http://feeds.rhapsody.com/member/ABCDEF0123456789ABCDEF0123456789/track-history.rss</code></p>
16
+
17
+ <p>Grab the RSS feed URL for your account and paste it into the field below.</p>
18
+ ]
19
+
20
+ def activities
21
+ query.activities
22
+ end
23
+
24
+ def query
25
+ Stratify::Rhapsody::Query.new(rss_url)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails'
2
+
3
+ module Stratify
4
+ module Rhapsody
5
+ class Engine < Rails::Engine
6
+ engine_name :stratify_rhapsody
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,43 @@
1
+ require 'open-uri'
2
+ require 'simple-rss'
3
+
4
+ module Stratify
5
+ module Rhapsody
6
+ class Query
7
+ attr_reader :rss_url
8
+
9
+ def initialize(rss_url)
10
+ @rss_url = rss_url
11
+ end
12
+
13
+ def activities
14
+ raw_activities.map {|raw_activity| build_activity_from_raw_data(raw_activity)}
15
+ end
16
+
17
+ private
18
+
19
+ def raw_activities
20
+ initialize_simple_rss_to_import_rhapsody_tags
21
+ rss = SimpleRSS.parse open(rss_url)
22
+ rss.items
23
+ end
24
+
25
+ def build_activity_from_raw_data(raw_activity)
26
+ Stratify::Rhapsody::Activity.new({
27
+ :track_id => raw_activity[:"rhap_track-rcid"],
28
+ :track_title => raw_activity[:rhap_track],
29
+ :artist_id => raw_activity[:"rhap_artist-rcid"],
30
+ :artist_name => raw_activity[:rhap_artist],
31
+ :album_id => raw_activity[:"rhap_album-rcid"],
32
+ :album_title => raw_activity[:rhap_album],
33
+ :genre => raw_activity[:category],
34
+ :created_at => raw_activity[:pubDate]
35
+ })
36
+ end
37
+
38
+ def initialize_simple_rss_to_import_rhapsody_tags
39
+ SimpleRSS.item_tags << :"rhap:track-rcid" << :"rhap:track" << :"rhap:artist-rcid" << :"rhap:artist"<< :"rhap:album-rcid" << :"rhap:album"
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ module Stratify
2
+ module Rhapsody
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require 'stratify-base'
2
+
3
+ require 'stratify-rhapsody/activity'
4
+ require 'stratify-rhapsody/collector'
5
+ require 'stratify-rhapsody/engine'
6
+ require 'stratify-rhapsody/version'
data/spec/mongoid.yml ADDED
@@ -0,0 +1,3 @@
1
+ persist_in_safe_mode: true
2
+ host: localhost
3
+ database: stratify_rhapsody_test
@@ -0,0 +1,38 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'stratify-rhapsody'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ require 'database_cleaner'
11
+
12
+ RSpec.configure do |config|
13
+ config.color_enabled = true
14
+ config.formatter = :progress
15
+
16
+ # Configure RSpec to run focused specs, and also respect the alias 'fit' for focused specs
17
+ config.filter_run :focused => true
18
+ config.run_all_when_everything_filtered = true
19
+ config.alias_example_to :fit, :focused => true
20
+
21
+ config.extend VCR::RSpec::Macros
22
+
23
+ # Configure RSpec to truncate the database before any spec tagged with ":database => true"
24
+ DatabaseCleaner.strategy = :truncation
25
+ DatabaseCleaner.orm = "mongoid"
26
+ config.before(:each, :database => true) do
27
+ DatabaseCleaner.clean
28
+ end
29
+
30
+ config.before(:suite) do
31
+ initialize_mongoid_configuration
32
+ end
33
+ end
34
+
35
+ def initialize_mongoid_configuration
36
+ mongoid_config = YAML::load_file(File.join(File.dirname(__FILE__), "mongoid.yml"))
37
+ Mongoid.from_hash(mongoid_config)
38
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stratify::Rhapsody::Activity do
4
+ describe "#permalink" do
5
+ it "returns the URL of the track on Rhapsody" do
6
+ listening = Stratify::Rhapsody::Activity.new(:track_id => "tra.1956646")
7
+ listening.permalink.should == "http://www.rhapsody.com/goto?rcid=tra.1956646"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "stratify-rhapsody" do
4
+ use_vcr_cassette "rhapsody"
5
+
6
+ it "collects and stores data from Rhapsody", :database => true do
7
+ collector = Stratify::Rhapsody::Collector.create!(:rss_url => "http://feeds.rhapsody.com/member/ABCDEFGHIJKLMNOPQRSTUVWXYZ123456/track-history.rss")
8
+ collector.run
9
+
10
+ Stratify::Rhapsody::Activity.where(
11
+ :track_id => "tra.1956653",
12
+ :track_title => "Drain You",
13
+ :artist_id => "art.69299",
14
+ :artist_name => "Nirvana",
15
+ :album_id => "alb.238528",
16
+ :album_title => "Nevermind",
17
+ :genre => "'90s Alternative",
18
+ :created_at => Time.parse("Tue, 22 Feb 2011 03:28:00 -0800")
19
+ ).should exist
20
+
21
+ Stratify::Rhapsody::Activity.where(
22
+ :track_id => "tra.43710797",
23
+ :track_title => "From A Table Away",
24
+ :artist_id => "art.13689488",
25
+ :artist_name => "Sunny Sweeney",
26
+ :album_id => "alb.43710792",
27
+ :album_title => "Sunny Sweeney EP",
28
+ :genre => "Honky-Tonk",
29
+ :created_at => Time.parse("Sat, 19 Feb 2011 05:40:00 -0800")
30
+ ).should exist
31
+ end
32
+ end
@@ -0,0 +1,7 @@
1
+ require 'vcr'
2
+
3
+ VCR.config do |c|
4
+ c.cassette_library_dir = 'vcr_cassettes'
5
+ c.stub_with :fakeweb
6
+ c.default_cassette_options = { :record => :once }
7
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "stratify-rhapsody/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "stratify-rhapsody"
7
+ s.version = Stratify::Rhapsody::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Jason Rudolph"]
10
+ s.email = ["jason@jasonrudolph.com"]
11
+ s.homepage = "http://github.com/jasonrudolph/stratify/"
12
+ s.summary = "Rhapsody plugin for Stratify"
13
+ s.description = s.summary
14
+
15
+ s.rubyforge_project = "stratify-rhapsody"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_runtime_dependency "railties", "~> 3.1.0.rc1"
23
+ s.add_runtime_dependency "stratify-base", "~> 0.1.0"
24
+ s.add_runtime_dependency "thoughtafter-simple-rss", "~> 1.2.3"
25
+
26
+ s.add_development_dependency "database_cleaner", "~> 0.6.7"
27
+ s.add_development_dependency "fakeweb", "~> 1.3.0"
28
+ s.add_development_dependency "rspec", "~> 2.6.0"
29
+ s.add_development_dependency "vcr", "~> 1.10.0"
30
+ end