mixcloud-rb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mixcloud/artist.rb +26 -0
- data/lib/mixcloud/category.rb +31 -0
- data/lib/mixcloud/cloudcast.rb +0 -0
- data/lib/mixcloud/search.rb +0 -0
- data/lib/mixcloud/tag.rb +39 -0
- data/lib/mixcloud/track.rb +7 -0
- data/lib/mixcloud/user.rb +56 -0
- data/lib/mixcloud.rb +17 -0
- data/test/unit/mixcloud_artist_test.rb +28 -0
- data/test/unit/mixcloud_tag_test.rb +36 -0
- data/test/unit/mixcloud_user_test.rb +91 -0
- metadata +112 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hashie'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module MixCloud
|
6
|
+
|
7
|
+
class Artist < Hashie::Dash
|
8
|
+
include HTTParty
|
9
|
+
format :json
|
10
|
+
base_uri MixCloud::BASE_URL
|
11
|
+
|
12
|
+
property :url
|
13
|
+
property :name
|
14
|
+
property :key
|
15
|
+
property :slug
|
16
|
+
property :type
|
17
|
+
property :metadata, :default => {}
|
18
|
+
|
19
|
+
def self.find(artist)
|
20
|
+
res = self.get("/artist/#{artist}?metadata=1")
|
21
|
+
self.new res
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hashie'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module MixCloud
|
6
|
+
|
7
|
+
class Category < Hashie::Dash
|
8
|
+
include HTTParty
|
9
|
+
format :json
|
10
|
+
base_uri MixCloud.base_uri
|
11
|
+
|
12
|
+
property :name
|
13
|
+
property :url
|
14
|
+
property :key
|
15
|
+
property :slug
|
16
|
+
property :type
|
17
|
+
property :format
|
18
|
+
property :pictures, :default => {}
|
19
|
+
property :metadata, :default => {}
|
20
|
+
|
21
|
+
def self.find(category)
|
22
|
+
res = self.get("/categories/#{category}?metadata=1")
|
23
|
+
self.new res
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
category = MixCloud::Category.find("ambient")
|
31
|
+
puts category
|
File without changes
|
File without changes
|
data/lib/mixcloud/tag.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hashie'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module MixCloud
|
6
|
+
class Tag < Hashie::Dash
|
7
|
+
include HTTParty
|
8
|
+
attr_writer :options
|
9
|
+
|
10
|
+
format :json
|
11
|
+
base_uri MixCloud::BASE_URL
|
12
|
+
|
13
|
+
property :url
|
14
|
+
property :type
|
15
|
+
property :name
|
16
|
+
property :key
|
17
|
+
property :metadata, :default => {}
|
18
|
+
property :data, :default => {}
|
19
|
+
property :popular, :default => {}
|
20
|
+
|
21
|
+
def initialize(tag_name, options={})
|
22
|
+
@options = options
|
23
|
+
@tag = self.class.get("/tag/#{tag_name}", :query => @options)
|
24
|
+
|
25
|
+
@tag['metadata']['connections'].each do |k,v|
|
26
|
+
@tag['metadata'][k.to_sym] = v
|
27
|
+
end
|
28
|
+
@tag['metadata'].delete('connections')
|
29
|
+
|
30
|
+
super @tag
|
31
|
+
end
|
32
|
+
|
33
|
+
def popular(options=nil)
|
34
|
+
options = options ||= @options
|
35
|
+
self.popular = self.class.get("#{self[:key]}popular/", :query => options)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hashie'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module MixCloud
|
6
|
+
class User < Hashie::Dash
|
7
|
+
include HTTParty
|
8
|
+
attr_writer :options
|
9
|
+
|
10
|
+
format :json
|
11
|
+
base_uri MixCloud::BASE_URL
|
12
|
+
|
13
|
+
property :username
|
14
|
+
property :city
|
15
|
+
property :cloudcast_count
|
16
|
+
property :following_count
|
17
|
+
property :url
|
18
|
+
property :pictures, :defaul => {}
|
19
|
+
property :listen_count
|
20
|
+
property :updated_time
|
21
|
+
property :created_time
|
22
|
+
property :biog
|
23
|
+
property :key
|
24
|
+
property :country
|
25
|
+
property :follower_count
|
26
|
+
property :favorite_count
|
27
|
+
property :country
|
28
|
+
property :name
|
29
|
+
property :type
|
30
|
+
property :metadata, :default => {}
|
31
|
+
|
32
|
+
def initialize(user_name, options={})
|
33
|
+
@options = options
|
34
|
+
@user = self.class.get("/#{user_name}?metadata=1", :query => @options)
|
35
|
+
|
36
|
+
@user['metadata']['connections'].each do |k,v|
|
37
|
+
@user['metadata'][k.to_sym] = v
|
38
|
+
end
|
39
|
+
@user['metadata'].delete('connections')
|
40
|
+
|
41
|
+
@user['metadata'].each do |k,v|
|
42
|
+
self.class.send(:define_method, "#{k}".downcase) do |options|
|
43
|
+
options = options ||= @options
|
44
|
+
self.class.get("#{self.metadata[k.to_sym]}", :query => @options)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
super @user
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.find(user_name, options={})
|
52
|
+
self.new user_name, options
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
data/lib/mixcloud.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hashie'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
6
|
+
|
7
|
+
module MixCloud
|
8
|
+
|
9
|
+
VERSION = '0.0.1'
|
10
|
+
BASE_URL = 'http://api.mixcloud.com'
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
require File.join(directory, 'mixcloud', 'artist')
|
15
|
+
require File.join(directory, 'mixcloud', 'user')
|
16
|
+
require File.join(directory, 'mixcloud', 'tag')
|
17
|
+
require File.join(directory, 'mixcloud', 'track')
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "mixcloud"
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
class TestMixCloudArtist < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
artist_name = "aphex-twin"
|
8
|
+
@artist = MixCloud::Artist.find("aphex-twin");
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_artist_properties
|
12
|
+
assert_equal(@artist.name, "Aphex Twin")
|
13
|
+
assert_equal(@artist.key, "/artist/aphex-twin/")
|
14
|
+
assert_equal(@artist.slug,"aphex-twin")
|
15
|
+
assert_equal(@artist.url, "http://www.mixcloud.com/artist/aphex-twin/")
|
16
|
+
assert_equal(@artist.type, "artist")
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_artist_has_metadata
|
20
|
+
assert_equal(@artist.metadata.size, 1 )
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_artist_metadata_properties
|
24
|
+
assert_equal(@artist.metadata["connections"]["popular"], MixCloud::BASE_URL + "/artist/aphex-twin/popular/")
|
25
|
+
assert_equal(@artist.metadata["connections"]["new"], MixCloud::BASE_URL + "/artist/aphex-twin/new/")
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "mixcloud"
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
class TestMixCloudTag < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@tag = MixCloud::Tag.new("funk", {:limit => 1, :offset=> 1, :metadata => 1})
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_tag_properties
|
11
|
+
assert_equal(@tag.url, 'http://www.mixcloud.com/tag/funk/')
|
12
|
+
assert_equal(@tag.type, 'tag')
|
13
|
+
assert_equal(@tag.name, 'Funk')
|
14
|
+
assert_equal(@tag.key, '/tag/funk/')
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_tag_has_metadata
|
18
|
+
assert_equal(@tag.metadata.size, 3 )
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_tag_metadata_properties
|
22
|
+
assert_equal(@tag.metadata[:popular], MixCloud::BASE_URL + '/tag/funk/popular/' )
|
23
|
+
assert_equal(@tag.metadata[:new], MixCloud::BASE_URL + '/tag/funk/new/' )
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def test_tag_popular
|
28
|
+
assert_equal(@tag.popular.length, 3)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_tags_pagination
|
32
|
+
assert_equal(@tag.popular['paging']['previous'], MixCloud::BASE_URL + '/tag/funk/popular/?metadata=1&limit=1&offset=0' )
|
33
|
+
assert_equal(@tag.popular['paging']['next'], MixCloud::BASE_URL + '/tag/funk/popular/?metadata=1&limit=1&offset=2' )
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require "mixcloud"
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
class TestMixCloudUser < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@user = MixCloud::User.find("spartacus", { :limit => 1, :offset => 1, :metadata => 1 } )
|
8
|
+
@user_feed = @user.feed
|
9
|
+
@user_comments = @user.comments
|
10
|
+
@user_followers = @user.followers
|
11
|
+
@user_following = @user.following
|
12
|
+
@user_favorites = @user.favorites
|
13
|
+
@user_cloudcasts = @user.cloudcasts
|
14
|
+
@user_listens = @user.listens
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_user_properties
|
18
|
+
assert_equal(@user.username, "spartacus")
|
19
|
+
assert_equal(@user.city, 'London')
|
20
|
+
assert_equal(@user.cloudcast_count, 3)
|
21
|
+
assert_equal(@user.following_count, 26)
|
22
|
+
assert_equal(@user.url, 'http://www.mixcloud.com/spartacus/')
|
23
|
+
assert_equal(@user.pictures.length, 6)
|
24
|
+
assert_equal(@user.listen_count, 373)
|
25
|
+
assert_equal(@user.biog, "Part of the Mixcloud team - since Mixcloud was just a good idea.")
|
26
|
+
assert_equal(@user.key, '/spartacus/')
|
27
|
+
assert_equal(@user.country, "United Kingdom")
|
28
|
+
assert_equal(@user.type, 'user')
|
29
|
+
assert_equal(@user.name, 'Spartacus')
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_user_has_metadata
|
33
|
+
assert_equal(@user.metadata.size, 7)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_user_metadata_properties
|
37
|
+
assert_equal(@user.metadata[:feed], MixCloud::BASE_URL + '/spartacus/feed/' )
|
38
|
+
assert_equal(@user.metadata[:comments], MixCloud::BASE_URL + '/spartacus/comments/' )
|
39
|
+
assert_equal(@user.metadata[:followers], MixCloud::BASE_URL + '/spartacus/followers/' )
|
40
|
+
assert_equal(@user.metadata[:favorites], MixCloud::BASE_URL + '/spartacus/favorites/' )
|
41
|
+
assert_equal(@user.metadata[:following], MixCloud::BASE_URL + '/spartacus/following/' )
|
42
|
+
assert_equal(@user.metadata[:listens], MixCloud::BASE_URL + '/spartacus/listens/' )
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_user_feed_properties
|
46
|
+
assert_equal(@user_feed['data'].length, 1)
|
47
|
+
assert_equal(@user_feed['data'][0]['from']['url'], 'http://www.mixcloud.com/spartacus/')
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_user_comments_properties
|
51
|
+
assert_equal(@user_comments['paging']['previous'],'http://api.mixcloud.com/spartacus/comments/?metadata=1&limit=1&offset=0')
|
52
|
+
assert_equal(@user_comments['paging']['next'],'http://api.mixcloud.com/spartacus/comments/?metadata=1&limit=1&offset=2')
|
53
|
+
|
54
|
+
assert_equal(@user_comments['data'].nil?, false)
|
55
|
+
assert_equal(@user_comments['name'],'Comments on Spartacus\'s profile')
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_user_followers_properties
|
59
|
+
assert_equal(@user_followers['paging']['previous'],'http://api.mixcloud.com/spartacus/followers/?metadata=1&limit=1&offset=0')
|
60
|
+
assert_equal(@user_followers['paging']['next'],'http://api.mixcloud.com/spartacus/followers/?metadata=1&limit=1&offset=2')
|
61
|
+
assert_equal(@user_followers['data'].nil?, false)
|
62
|
+
assert_equal(@user_followers['name'],'Spartacus\'s followers')
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_user_favorites_properties
|
66
|
+
assert_equal(@user_favorites['paging']['previous'],'http://api.mixcloud.com/spartacus/favorites/?metadata=1&limit=1&offset=0')
|
67
|
+
assert_equal(@user_favorites['paging']['next'],'http://api.mixcloud.com/spartacus/favorites/?metadata=1&limit=1&offset=2')
|
68
|
+
assert_equal(@user_favorites['data'].nil?, false)
|
69
|
+
assert_equal(@user_favorites['name'],'Spartacus\'s favorites')
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_user_following_properties
|
73
|
+
assert_equal(@user_following['paging']['previous'],'http://api.mixcloud.com/spartacus/following/?metadata=1&limit=1&offset=0')
|
74
|
+
assert_equal(@user_following['paging']['next'],'http://api.mixcloud.com/spartacus/following/?metadata=1&limit=1&offset=2')
|
75
|
+
assert_equal(@user_following['data'].nil?, false)
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_user_cloudcasts_properties
|
79
|
+
assert_equal(@user_cloudcasts['paging']['previous'],'http://api.mixcloud.com/spartacus/cloudcasts/?metadata=1&limit=1&offset=0')
|
80
|
+
assert_equal(@user_cloudcasts['data'].nil?, false)
|
81
|
+
assert_equal(@user_cloudcasts['name'],'Spartacus\'s Cloudcasts')
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_user_listens_properties
|
85
|
+
assert_equal(@user_listens['paging']['previous'],'http://api.mixcloud.com/spartacus/listens/?metadata=1&limit=1&offset=0')
|
86
|
+
assert_equal(@user_listens['paging']['next'],'http://api.mixcloud.com/spartacus/listens/?metadata=1&limit=1&offset=2')
|
87
|
+
assert_equal(@user_listens['data'].nil?, false)
|
88
|
+
assert_equal(@user_listens['name'],'Spartacus\'s listens')
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mixcloud-rb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Joao Da Silva
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-29 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 23
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 2
|
31
|
+
- 0
|
32
|
+
version: 0.2.0
|
33
|
+
name: hashie
|
34
|
+
prerelease: false
|
35
|
+
requirement: *id001
|
36
|
+
type: :runtime
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 15
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 5
|
47
|
+
- 2
|
48
|
+
version: 0.5.2
|
49
|
+
name: httparty
|
50
|
+
prerelease: false
|
51
|
+
requirement: *id002
|
52
|
+
type: :runtime
|
53
|
+
description: Ruby wrapper for the mixcloud.com API
|
54
|
+
email: joao@codedefinition.com
|
55
|
+
executables: []
|
56
|
+
|
57
|
+
extensions: []
|
58
|
+
|
59
|
+
extra_rdoc_files: []
|
60
|
+
|
61
|
+
files:
|
62
|
+
- lib/mixcloud/artist.rb
|
63
|
+
- lib/mixcloud/category.rb
|
64
|
+
- lib/mixcloud/cloudcast.rb
|
65
|
+
- lib/mixcloud/search.rb
|
66
|
+
- lib/mixcloud/tag.rb
|
67
|
+
- lib/mixcloud/track.rb
|
68
|
+
- lib/mixcloud/user.rb
|
69
|
+
- lib/mixcloud.rb
|
70
|
+
- test/unit/mixcloud_artist_test.rb
|
71
|
+
- test/unit/mixcloud_tag_test.rb
|
72
|
+
- test/unit/mixcloud_user_test.rb
|
73
|
+
has_rdoc: true
|
74
|
+
homepage: http://github.com/jsilva/mixcloud-rb/
|
75
|
+
licenses: []
|
76
|
+
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 23
|
97
|
+
segments:
|
98
|
+
- 1
|
99
|
+
- 3
|
100
|
+
- 6
|
101
|
+
version: 1.3.6
|
102
|
+
requirements: []
|
103
|
+
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 1.3.7
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: Ruby wrapper for the mixcloud.com API
|
109
|
+
test_files:
|
110
|
+
- test/unit/mixcloud_artist_test.rb
|
111
|
+
- test/unit/mixcloud_tag_test.rb
|
112
|
+
- test/unit/mixcloud_user_test.rb
|