musicbrainz-ruby 0.2.0 → 0.3.0

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.
Files changed (3) hide show
  1. data/README.markdown +7 -5
  2. data/lib/musicbrainz.rb +44 -12
  3. metadata +7 -7
data/README.markdown CHANGED
@@ -1,11 +1,11 @@
1
1
  MusicBrainz-ruby
2
2
  ================
3
3
 
4
- O hai, I [HTTParty][1]'d with ur [web service][2].
4
+ O hai, I [HTTParty][1]'d with ur [web service][2]. No offence, RBrainz gem.
5
5
 
6
- No offence, RBrainz gem.
6
+ This gem supports authentication, all the GET calls and basic POSTing (not batch POSTs) provided you read the web service documentation and provide the correct parameters.
7
7
 
8
- I have only done the artist call so far. Returns [Mashes][3] of the metadata tag.
8
+ Returns [Mashes][3] of the metadata tag.
9
9
 
10
10
  [1]: https://github.com/jnunemaker/httparty
11
11
  [2]: http://wiki.musicbrainz.org/XMLWebService
@@ -20,17 +20,19 @@ Examples
20
20
  --------
21
21
 
22
22
  require 'musicbrainz-ruby'
23
- brainz = MusicBrainz::Client.new
23
+ brainz = MusicBrainz::Client.new('username', 'password')
24
24
 
25
25
  # Find an artist by id, include artist relations
26
26
  brainz.artist('45d15468-2918-4da4-870b-d6b880504f77', :inc => 'artist-rels')
27
27
  # Search for artists with the term 'Diplo'
28
28
  brainz.artist(nil, :query => 'Diplo')
29
+ # Tag an Artist
30
+ brainz.post('tag', :id => '45d15468-2918-4da4-870b-d6b880504f77', :entity => 'artist', :tags => 'post-everything')
29
31
 
30
32
  MIT License
31
33
  ===========
32
34
 
33
- (c) Robin Tweedie 2010
35
+ (c) Robin Tweedie 2011
34
36
 
35
37
  Permission is hereby granted, free of charge, to any person obtaining a copy
36
38
  of this software and associated documentation files (the "Software"), to deal
data/lib/musicbrainz.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
 
3
- gem 'httparty', '~> 0.6.1'
3
+ gem 'httparty', '~> 0.7.3'
4
4
  require 'httparty'
5
5
 
6
6
  gem 'hashie', '~> 0.4.0'
@@ -13,17 +13,9 @@ module MusicBrainz
13
13
 
14
14
  base_uri 'musicbrainz.org/ws/1'
15
15
 
16
- def request(path, params)
17
- options = {:query => {:type => 'xml'}}
18
- options[:query].merge!(params)
19
-
20
- response = self.class.get(path, options)
21
-
22
- if response.response.is_a? Net::HTTPBadRequest
23
- raise ArgumentError, response.parsed_response
24
- end
25
-
26
- Mash.new(response).metadata
16
+ # Provide your username and password if you need to make authenticated calls
17
+ def initialize(username = nil, password = nil)
18
+ self.class.digest_auth username, password
27
19
  end
28
20
 
29
21
  def artist(musicbrainz_id = nil, params = {})
@@ -45,5 +37,45 @@ module MusicBrainz
45
37
  def label(musicbrainz_id = nil, params = {})
46
38
  request("/label/#{musicbrainz_id}", params)
47
39
  end
40
+
41
+ def rating(params = {})
42
+ request('/rating/', params)
43
+ end
44
+
45
+ def tag(params = {})
46
+ request('/tag/', params)
47
+ end
48
+
49
+ def collection(params = {})
50
+ request('/collection/', params)
51
+ end
52
+
53
+ # provide a resource you want to post to, and the appropriate parameters
54
+ def post(resource, params = {})
55
+ response = self.class.post("/#{resource}/", :body => params)
56
+ if response.response.is_a? Net::HTTPOK
57
+ return true
58
+ else
59
+ raise response.response.message
60
+ end
61
+ end
62
+
63
+ private
64
+ def request(path, params)
65
+ options = {:query => {:type => 'xml'}}
66
+ options[:query].merge!(params)
67
+
68
+ response = self.class.get(path, options)
69
+
70
+ if response.response.is_a? Net::HTTPBadRequest
71
+ raise ArgumentError, response.parsed_response
72
+ end
73
+
74
+ if response.response.is_a? Net::HTTPUnauthorized
75
+ raise response.response.message
76
+ end
77
+
78
+ Mash.new(response).metadata
79
+ end
48
80
  end
49
81
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musicbrainz-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
8
+ - 3
9
9
  - 0
10
- version: 0.2.0
10
+ version: 0.3.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robin Tweedie
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-17 00:00:00 +00:00
18
+ date: 2011-01-23 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -29,9 +29,9 @@ dependencies:
29
29
  hash: 5
30
30
  segments:
31
31
  - 0
32
- - 6
33
- - 1
34
- version: 0.6.1
32
+ - 7
33
+ - 3
34
+ version: 0.7.3
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency