musicbrainz_wrapper 0.0.5 → 0.0.6
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.
- checksums.yaml +8 -8
- data/lib/musicbrainz_wrapper/version.rb +1 -1
- data/lib/wrapper/wrapper.rb +12 -2
- data/spec/wrapper/wrapper_spec.rb +27 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MGE2NzQxZmUzMDI5ZGI0MzY5MTY3Nzk4N2UxM2M5OTRlYTZjNWYzYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Y2MxODc4NzI5MzlhZjUwZDc2YzI0MDFmOGM4MDRhZmZjODY5ZTgzOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTZkNzFkNTc0NjY4MDM4ZGNiNjg2ZTAzMWY4ZDAyNzA3ZjU4NGU2YzRhYmVh
|
10
|
+
NWZjNTNhODU5YzUyNTFlZGFjZWZjZjJkNzI2ZjE3MDdlMGJhODZlMDc2MzVh
|
11
|
+
NGI0MjdjNmU0NWZmZWFmYTYwZmNjZmJjZjQ1ZmUxNmMwZDRlMjA=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZWIxYjUzM2U4ZjcxMjM3ZDU4OTA1MGVlNzU2OTFlMTFkNDZlMDc1ZTljYWRk
|
14
|
+
ZjkzNWQ1YTE1MWUwZjZlMWQwMjA1MDNmMjRmMDdkOWIzYTVhMzBjYmE4Njc3
|
15
|
+
ZjljZDZkNmNiMjkxOTFkOWY3OWU5NjExYjUzYWI1NzhlN2U1NWM=
|
data/lib/wrapper/wrapper.rb
CHANGED
@@ -127,7 +127,7 @@ class Musicbrainz::Wrapper
|
|
127
127
|
def self.create_query_string(start, params)
|
128
128
|
if params.is_a?(Hash) && params.count > 0
|
129
129
|
ending = hash_to_query_string(params)
|
130
|
-
"#{start}/#{ending}#{question_mark_or_ampersand(ending)}fmt=json"
|
130
|
+
"#{start}/#{ending}#{question_mark_or_ampersand(ending)}fmt=json&limit=#{value_or_default(params[:limit], 25)}&offset=#{value_or_default(params[:offset], 0)}"
|
131
131
|
else
|
132
132
|
"#{start}/"
|
133
133
|
end
|
@@ -146,7 +146,9 @@ class Musicbrainz::Wrapper
|
|
146
146
|
def self.query_array(hash)
|
147
147
|
array = []
|
148
148
|
hash.each do |k, v|
|
149
|
-
|
149
|
+
if k != :inc && k != :limit && k != :offset
|
150
|
+
array << "#{k}:#{URI.encode(v, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"
|
151
|
+
end
|
150
152
|
end
|
151
153
|
array
|
152
154
|
end
|
@@ -174,6 +176,14 @@ class Musicbrainz::Wrapper
|
|
174
176
|
'?'
|
175
177
|
end
|
176
178
|
end
|
179
|
+
|
180
|
+
def self.value_or_default(value, default)
|
181
|
+
if value
|
182
|
+
value
|
183
|
+
else
|
184
|
+
default
|
185
|
+
end
|
186
|
+
end
|
177
187
|
|
178
188
|
# Hit Musicbrainz API
|
179
189
|
def query(ending, type)
|
@@ -28,6 +28,18 @@ describe Musicbrainz::Wrapper do
|
|
28
28
|
it "should add &fmt=json to end of string" do
|
29
29
|
should include('&fmt=json')
|
30
30
|
end
|
31
|
+
it "should contain &limit=25 if limit not passed" do
|
32
|
+
should include('&limit=25')
|
33
|
+
end
|
34
|
+
it "should set limit if passed" do
|
35
|
+
Musicbrainz::Wrapper.create_query_string('release', {:limit => 100}).should include('&limit=100')
|
36
|
+
end
|
37
|
+
it "should contain &offset=0 if offset not passed" do
|
38
|
+
should include('&offset=0')
|
39
|
+
end
|
40
|
+
it "should set offset if passed" do
|
41
|
+
Musicbrainz::Wrapper.create_query_string('release', {:offset => 100}).should include('&offset=100')
|
42
|
+
end
|
31
43
|
it "should return the start if passed blank hash" do
|
32
44
|
Musicbrainz::Wrapper.create_query_string('release', {}).should == 'release/'
|
33
45
|
end
|
@@ -98,21 +110,30 @@ describe Musicbrainz::Wrapper do
|
|
98
110
|
end
|
99
111
|
end
|
100
112
|
|
113
|
+
describe "value_or_default" do
|
114
|
+
it "should return value if it is not nil" do
|
115
|
+
Musicbrainz::Wrapper.value_or_default(1, 2).should == 1
|
116
|
+
end
|
117
|
+
it "should return default if value is nil" do
|
118
|
+
Musicbrainz::Wrapper.value_or_default(nil, 2).should == 2
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
101
122
|
# Hit Musicbrainz API
|
102
123
|
describe "query", :slow => true do
|
103
124
|
context "is passed a plural object" do
|
104
125
|
it "should return an array" do
|
105
|
-
wrapper.query(albums_query).should be_an_instance_of Array
|
126
|
+
wrapper.query(albums_query, :multiple).should be_an_instance_of Array
|
106
127
|
end
|
107
128
|
end
|
108
129
|
context "is passed a single object" do
|
109
130
|
it "should return a hash" do
|
110
|
-
wrapper.query(album_query).should be_an_instance_of Hash
|
131
|
+
wrapper.query(album_query, :single).should be_an_instance_of Hash
|
111
132
|
end
|
112
133
|
end
|
113
134
|
context "is passed bad data" do
|
114
135
|
it "should return nil" do
|
115
|
-
wrapper.query("something_else").should be_nil
|
136
|
+
wrapper.query("something_else", :single).should be_nil
|
116
137
|
end
|
117
138
|
end
|
118
139
|
end
|
@@ -143,20 +164,20 @@ describe Musicbrainz::Wrapper do
|
|
143
164
|
context "for a single object" do
|
144
165
|
it "should return a hash" do
|
145
166
|
response = wrapper.send_query(api_point + album_query)
|
146
|
-
Musicbrainz::Wrapper.parse_response(response).should be_an_instance_of Hash
|
167
|
+
Musicbrainz::Wrapper.parse_response(response, :single).should be_an_instance_of Hash
|
147
168
|
end
|
148
169
|
end
|
149
170
|
context "for multiple objects" do
|
150
171
|
it "should return an array" do
|
151
172
|
response = wrapper.send_query(api_point + albums_query)
|
152
|
-
Musicbrainz::Wrapper.parse_response(response).should be_an_instance_of Array
|
173
|
+
Musicbrainz::Wrapper.parse_response(response, :multiple).should be_an_instance_of Array
|
153
174
|
end
|
154
175
|
end
|
155
176
|
end
|
156
177
|
context "when passed a bad response" do
|
157
178
|
it "should return nil" do
|
158
179
|
response = wrapper.send_query(api_point + 'release/d8')
|
159
|
-
Musicbrainz::Wrapper.parse_response(response).should be_nil
|
180
|
+
Musicbrainz::Wrapper.parse_response(response, :single).should be_nil
|
160
181
|
end
|
161
182
|
end
|
162
183
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: musicbrainz_wrapper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tomallen400
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|