soundcloud-plus 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/.rvmrc ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.2-p290@soundcloud-plus"
8
+
9
+ #
10
+ # Uncomment following line if you want options to be set only for given project.
11
+ #
12
+ # PROJECT_JRUBY_OPTS=( --1.9 )
13
+
14
+ #
15
+ # First we attempt to load the desired environment directly from the environment
16
+ # file. This is very fast and efficient compared to running through the entire
17
+ # CLI and selector. If you want feedback on which environment was used then
18
+ # insert the word 'use' after --create as this triggers verbose mode.
19
+ #
20
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
21
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
22
+ then
23
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
24
+
25
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
26
+ then
27
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
28
+ fi
29
+ else
30
+ # If the environment file has not yet been created, use the RVM CLI to select.
31
+ if ! rvm --create "$environment_id"
32
+ then
33
+ echo "Failed to create RVM environment '${environment_id}'."
34
+ exit 1
35
+ fi
36
+ fi
37
+
38
+ #
39
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
40
+ # it be automatically loaded. Uncomment the following and adjust the filename if
41
+ # necessary.
42
+ #
43
+ # filename=".gems"
44
+ # if [[ -s "$filename" ]]
45
+ # then
46
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
47
+ # fi
48
+
49
+ # If you use bundler, this might be useful to you:
50
+ # if command -v bundle && [[ -s Gemfile ]]
51
+ # then
52
+ # bundle install
53
+ # fi
54
+
55
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in soundcloud-plus.gemspec
4
+ gemspec
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ soundcloud-plus (0.0.1)
5
+ active_support
6
+ soundcloud (~> 0.2.9)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ active_support (3.0.0)
12
+ activesupport (= 3.0.0)
13
+ activesupport (3.0.0)
14
+ crack (0.1.8)
15
+ diff-lcs (1.1.3)
16
+ ffi (1.0.11)
17
+ guard (0.10.0)
18
+ ffi (>= 0.5.0)
19
+ thor (~> 0.14.6)
20
+ guard-rspec (0.6.0)
21
+ guard (>= 0.10.0)
22
+ hashie (1.2.0)
23
+ httmultiparty (0.3.6)
24
+ httparty (>= 0.7.3)
25
+ multipart-post
26
+ httparty (0.7.8)
27
+ crack (= 0.1.8)
28
+ multipart-post (1.1.4)
29
+ rspec (2.8.0)
30
+ rspec-core (~> 2.8.0)
31
+ rspec-expectations (~> 2.8.0)
32
+ rspec-mocks (~> 2.8.0)
33
+ rspec-core (2.8.0)
34
+ rspec-expectations (2.8.0)
35
+ diff-lcs (~> 1.1.2)
36
+ rspec-mocks (2.8.0)
37
+ soundcloud (0.2.9)
38
+ hashie
39
+ httmultiparty (~> 0.3.0)
40
+ httparty (~> 0.7.3)
41
+ thor (0.14.6)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ guard
48
+ guard-rspec
49
+ rspec
50
+ soundcloud-plus!
@@ -0,0 +1,22 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2, :cli => "--drb", :all_on_start => false, :all_after_pass => false do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^spec/.+_spec\.rb$})
11
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
12
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
13
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
14
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
15
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
16
+ watch('spec/spec_helper.rb') { "spec" }
17
+ watch('config/routes.rb') { "spec/routing" }
18
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
19
+ # Capybara request specs
20
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
21
+ end
22
+
@@ -0,0 +1,51 @@
1
+ About
2
+ =====
3
+
4
+ SoundcloudPlus is a lightweight wrapper for a lightweight wrapper for the Soundcloud web API.
5
+
6
+ The official soundcloud gem is pretty bare bones. This builds on top of the the soundclout gem and makes things a little more ruby. It doesn't do much that the soundcloud gem won't do, but it does it in a slightly nicer way.
7
+
8
+ Instead of
9
+
10
+ client = Soundcloud.new(:client_id => "123456789")
11
+ client.get("/users/1234/comments", :limit => 5)
12
+
13
+ You can do
14
+
15
+ client = SoundcloudPlus.new(:client_id => "123456789")
16
+ client.user(1234).comment.limit(5)
17
+ or
18
+ client.user(1234).comments(:limit => 5)
19
+
20
+ Like all abstractions this one is a little leaky so it helps to know what is going on under the hood. If nothing else, remember that the plurality of the method count.
21
+
22
+ ## Singular methods add resources to the api fetch path
23
+
24
+ For example:
25
+
26
+ client = SoundcloudPlus.new(:client_id => "123456789")
27
+ client.track(1234).shared_to.email
28
+ client.path # => "/tracks/1234/shared-to/emails"
29
+
30
+ This path must match the soundcloud web api. You can't do something like
31
+
32
+ client.user(1234).comment(4321).track(2345) # Won't work
33
+
34
+ ## Plural methods add resources to the api path and then fetch
35
+
36
+ For example
37
+
38
+ client = SoundcloudPlus.new(:client_id => "123456789")
39
+ client.user(1234).favorites # => Array of user 1234's favorites
40
+ or
41
+ client.users(1234) # => Hashie with user 1234's information
42
+
43
+ ## Calls to resource properties will also result in a one time fetch
44
+
45
+ For example
46
+
47
+ client = SoundcloudPlus.new(:client_id => "123456789")
48
+ track = client.track(1234) # => SoundcloudPlus object with path = "/tracks/1234"
49
+ track.id # Makes fetch to "/tracks/1234", returns "1234"
50
+ # Subsequent property calls don't result in a fetch.
51
+
@@ -0,0 +1,11 @@
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 :test => :spec
11
+ task :default => :spec
@@ -0,0 +1,127 @@
1
+
2
+ require 'soundcloud'
3
+ require 'soundcloud-plus/functions'
4
+ require 'uri'
5
+
6
+ class SoundcloudPlus < Soundcloud
7
+
8
+ attr_accessor :path , :options
9
+
10
+ PLURAL_CALLS = %w(user track playlist group comment connection activity app following follower favorite favoriter email)
11
+ SINGULAR_CALLS = %w(shared-to secret-token all own affiliated exclusive)
12
+ PARAMETERS = %w(limit order)
13
+
14
+ def initialize(options={})
15
+ super options
16
+ @path = ""
17
+ end
18
+
19
+ # Call method on fetched results
20
+ def method_missing(method, *args, &block)
21
+ @results ||= self.fetch!
22
+ @results.send(method)
23
+ end
24
+
25
+ def me
26
+ @path = "/me"
27
+ end
28
+
29
+ # Tally look up methods
30
+ SINGULAR_CALLS.each do |call|
31
+ class_eval <<-METHOD
32
+ def #{call.gsub('-','_')}(value, options = {})
33
+ attach("#{call}",value, options)
34
+ end
35
+ METHOD
36
+ end
37
+
38
+ PLURAL_CALLS.each do |call|
39
+ class_eval <<-METHOD
40
+ def #{call.pluralize}(value = nil, options = {})
41
+ attach("#{call.pluralize}", value, options).fetch!
42
+ end
43
+
44
+ def #{call}(value = nil, options = {})
45
+ attach("#{call.pluralize}", value, options)
46
+ end
47
+ METHOD
48
+ end
49
+
50
+ PARAMETERS.each do |call|
51
+ class_eval <<-METHOD
52
+ def #{call}(value)
53
+ if value
54
+ @options[:#{call}] = value
55
+ self
56
+ else
57
+ @options[:#{call}]
58
+ end
59
+ end
60
+ METHOD
61
+ end
62
+
63
+ # Add parameters to the query options
64
+ #
65
+ # @example Adding limit to number of user returned
66
+ # client = SoundcloudPlus.new(:client_id => "client_id")
67
+ # client.user.where(:limit => 5)
68
+ #
69
+ # @return [SoundcloudPlus] self
70
+ #
71
+ def where(params = {})
72
+ @options.merge!(params)
73
+ self
74
+ end
75
+
76
+ # Attaches resource and resource id path
77
+ #
78
+ # @example Attach user resource to path
79
+ # client = SoundcloudPlus.new(:client_id => "client_id")
80
+ # client.attach("users", "bob")
81
+ # client.path # => /users/1234
82
+ #
83
+ # @return [ SoundcloudPlus ] self
84
+ #
85
+ def attach(resource, value = nil, options = {})
86
+ @path << "/#{resource}"
87
+ @options.merge!(options)
88
+ if value
89
+ @path << (value.class == Fixnum ? "/#{value}" : "/#{resolve(value).id}" )
90
+ end
91
+ self
92
+ end
93
+
94
+ # Fetches resources from current path with current options
95
+ #
96
+ # @example Fetching user
97
+ # client = SoundcloudPlus.new(:client_id => "client_id")
98
+ # user = client.user(1234).fetch!
99
+ # user.permalink # => "bob"
100
+ #
101
+ # @return [Hashie] Hashie containing resource from path
102
+ #
103
+ def fetch!
104
+ old_path = path
105
+ if old_path && path.length > 0
106
+ path = ""
107
+ @results = get(old_path, @options)
108
+ end
109
+ end
110
+ alias :get! :fetch!
111
+
112
+ # Finds the soundcloud id for a soundcloud link or path
113
+ #
114
+ # @example Getting id of song with link
115
+ # client = SoundcloudPlus.new(:client_id => "client_id")
116
+ # track = client.resolve("http://soundcloud.com/poopyman/poopy-pants-song")
117
+ # track.name # => "Poopy Pants Song"
118
+ #
119
+ # @example Getting id of song with
120
+ #
121
+ def resolve(path)
122
+ path = URI.parse(path).path.sub(/\A\/+/,'')
123
+ url = "http://#{site}/#{path}"
124
+ @results = get("/resolve", :url => url)
125
+ end
126
+
127
+ end
@@ -0,0 +1,15 @@
1
+ require 'active_support/inflector'
2
+
3
+ class String
4
+
5
+ # Uses active_support/infectors to determine if a string is singular or plural
6
+ #
7
+ # @example Determining if word is singular
8
+ # "poop".singular? # => true
9
+ # "farts".singular? # => false
10
+ #
11
+ def singular?
12
+ self.pluralize != self and self.singularize == self
13
+ end
14
+
15
+ end
@@ -0,0 +1,3 @@
1
+ module SCPlus
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "soundcloud-plus/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "soundcloud-plus"
7
+ s.version = SCPlus::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Benjamin Guest"]
10
+ s.email = ["benguest@gmaill.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Lightweight wrapper for a lightweight wrapper for the soundcloud api}
13
+ s.description = %q{makes calling soundcloud api simpler from ruby}
14
+
15
+ s.rubyforge_project = "soundcloud-plus"
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
+ # specify any dependencies here; for example:
23
+
24
+ # General Dependency's
25
+ s.add_dependency "soundcloud", "~> 0.2.9"
26
+ s.add_dependency "active_support"
27
+
28
+ #Testing
29
+ s.add_development_dependency "rspec"
30
+
31
+ #Automated Testing
32
+ s.add_development_dependency "guard"
33
+ s.add_development_dependency "guard-rspec"
34
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+ describe "#singular?" do
5
+ it { "poop".singular?.should == true }
6
+ it {"farts".singular?.should == false}
7
+ end
8
+ end
@@ -0,0 +1,106 @@
1
+ require 'spec_helper'
2
+
3
+ describe SoundcloudPlus do
4
+ PARAMS = {:client_id => "client_id", :site => "example.com", :on_exchange_token => "token"}
5
+
6
+ let(:client){SoundcloudPlus.new(PARAMS)}
7
+ describe "#attach" do
8
+ it "should be able attach random to path" do
9
+ client.attach("poopsticks", 1234)
10
+ client.path.should == "/poopsticks/1234"
11
+ end
12
+ end
13
+
14
+ describe "#resolve" do
15
+ before(:each){client.should_receive(:get).with("/resolve",:url => "http://example.com/poopman/poopy-track")}
16
+ it{ client.resolve("http://example.com/poopman/poopy-track")}
17
+ it{ client.resolve("poopman/poopy-track")}
18
+ it{ client.resolve("/poopman/poopy-track")}
19
+ end
20
+
21
+ describe "#fetch! (and alias)" do
22
+ before(:each){client.should_receive(:get).with("/tracks/1234",PARAMS)}
23
+ it{ client.track(1234).fetch!}
24
+ it{ client.tracks(1234)}
25
+ it{ client.track(1234).get!}
26
+ end
27
+
28
+ describe "#me" do
29
+ it "should add /me to path" do
30
+ client.me
31
+ client.path.should == "/me"
32
+ end
33
+ it "should remove other stuff from path when called" do
34
+ client.track(1234).me
35
+ client.path.should == "/me"
36
+ end
37
+ end
38
+
39
+ describe "#user" do
40
+ it "should add user with id" do
41
+ client.user(1234)
42
+ client.path.should == "/users/1234"
43
+ end
44
+ it "should add user with permalink only" do
45
+ client.stub!(:resolve).and_return(client)
46
+ client.stub!(:id).and_return(1234)
47
+ client.user("bob")
48
+ client.path.should == "/users/1234"
49
+ end
50
+ end
51
+
52
+ describe "#users" do
53
+ it "should request users" do
54
+ client.should_receive(:get).with("/users", PARAMS)
55
+ client.users
56
+ end
57
+ end
58
+
59
+ %w(user track playlist group comment app).each do |method|
60
+ describe "##{method}(1234)" do
61
+ it "should add correct thing to path" do
62
+ client.send(method, 1234)
63
+ client.path.should == "/#{method.pluralize}/1234"
64
+ end
65
+ end
66
+
67
+ describe "##{method.pluralize}" do
68
+ it "should add list to end of path and fetch" do
69
+ client.should_receive(:get).with("/#{method.pluralize}", PARAMS)
70
+ client.send(method.pluralize)
71
+ end
72
+ end
73
+ end
74
+
75
+ %w(shared_to secret_token all own exclusive).each do |method|
76
+ describe "##{method}" do
77
+ it "should add correct thing to path" do
78
+ client.send(method, 1234)
79
+ client.path.should == "/#{method.gsub('_','-')}/1234"
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "s ability to chain calls together" do
85
+ it "should chain track and comment together" do
86
+ client.track(1234).comment(5678)
87
+ client.path.should == "/tracks/1234/comments/5678"
88
+ end
89
+
90
+ end
91
+
92
+ %w(limit order).each do |method|
93
+ it "should add parameter to options" do
94
+ client.send(method,"param")
95
+ client.options[method.to_sym].should == "param"
96
+ end
97
+ end
98
+
99
+ describe "#where" do
100
+ it "should add hash to parameters" do
101
+ client.where(:thing => "sweet")
102
+ client.options.should == PARAMS.merge({:thing => "sweet"})
103
+ end
104
+ end
105
+
106
+ end
@@ -0,0 +1,21 @@
1
+ # spec_helper
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ # Bundler.setup
6
+
7
+ require 'soundcloud-plus'
8
+
9
+ require 'rspec'
10
+
11
+ RSpec.configure do |config| # :nodoc: all
12
+ # == Mock Framework
13
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
14
+ config.mock_with :rspec
15
+
16
+ #Focus on one test with :focus
17
+ config.treat_symbols_as_metadata_keys_with_true_values = true
18
+ config.filter_run :focus => true
19
+ config.run_all_when_everything_filtered = true
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soundcloud-plus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Benjamin Guest
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: soundcloud
16
+ requirement: &70212389140440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.9
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70212389140440
25
+ - !ruby/object:Gem::Dependency
26
+ name: active_support
27
+ requirement: &70212389139660 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70212389139660
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70212389138920 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70212389138920
47
+ - !ruby/object:Gem::Dependency
48
+ name: guard
49
+ requirement: &70212389138160 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70212389138160
58
+ - !ruby/object:Gem::Dependency
59
+ name: guard-rspec
60
+ requirement: &70212389137140 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70212389137140
69
+ description: makes calling soundcloud api simpler from ruby
70
+ email:
71
+ - benguest@gmaill.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rvmrc
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - Guardfile
81
+ - README.md
82
+ - Rakefile
83
+ - lib/soundcloud-plus.rb
84
+ - lib/soundcloud-plus/functions.rb
85
+ - lib/soundcloud-plus/version.rb
86
+ - soundcloud-plus.gemspec
87
+ - spec/soundcloud-plus/functions_spec.rb
88
+ - spec/soundcloud-plus_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: ''
91
+ licenses: []
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project: soundcloud-plus
110
+ rubygems_version: 1.8.10
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Lightweight wrapper for a lightweight wrapper for the soundcloud api
114
+ test_files:
115
+ - spec/soundcloud-plus/functions_spec.rb
116
+ - spec/soundcloud-plus_spec.rb
117
+ - spec/spec_helper.rb