memphis 0.0.4 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +7 -2
- data/lib/memphis.rb +3 -2
- data/lib/memphis/artist.rb +14 -0
- data/lib/memphis/client.rb +9 -10
- data/lib/memphis/configuration.rb +24 -0
- data/lib/memphis/version.rb +1 -1
- data/spec/client_spec.rb +46 -15
- data/spec/configuration_spec.rb +23 -0
- metadata +7 -4
- data/lib/memphis/memphis.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fee7a70029c417fcb7d7b4b8748e2a1a35147b97
|
4
|
+
data.tar.gz: 41fa03cf0e65bd71f387d359a4838077add0e86e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cbe955af034bbf59a6836fecbdbaf410edf6df29174a923f1c926105a35e7402d975ebd6d34264b815f4212360be19d4819c7611ec2930c6c2361ec1aac8c1f
|
7
|
+
data.tar.gz: 8b8dad01426a4c8acb489154beb130dcd936f486f6b7c366884f8815f8ce24584e41f99be1d9250a31ba4422c1692ab2d888c8056f7c9c2694266a83178ed398
|
data/README.md
CHANGED
@@ -23,10 +23,15 @@ Or install it yourself as:
|
|
23
23
|
```ruby
|
24
24
|
require 'memphis'
|
25
25
|
|
26
|
-
|
26
|
+
Memphis.configure do |config|
|
27
|
+
config.api_key = ECHONEST_API_KEY
|
28
|
+
end
|
29
|
+
|
30
|
+
# Artist Search
|
31
|
+
memphis_artist = Memphis::Artist.new
|
27
32
|
|
28
33
|
# Search using The Echo Nest ID for Radiohead
|
29
|
-
search_result =
|
34
|
+
search_result = memphis_artist.search "ARH6W4X1187B99274F"
|
30
35
|
|
31
36
|
# Show providers includeding in results
|
32
37
|
|
data/lib/memphis.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
require_relative 'memphis/
|
1
|
+
require_relative 'memphis/configuration'
|
2
2
|
require_relative 'memphis/client'
|
3
|
+
require_relative 'memphis/artist'
|
3
4
|
require_relative 'memphis/result'
|
4
5
|
require_relative 'memphis/version'
|
5
6
|
|
@@ -7,5 +8,5 @@ require 'httparty'
|
|
7
8
|
require 'multi_json'
|
8
9
|
|
9
10
|
module Memphis
|
10
|
-
|
11
|
+
extend Configuration
|
11
12
|
end
|
data/lib/memphis/client.rb
CHANGED
@@ -3,6 +3,7 @@ module Memphis
|
|
3
3
|
class ConnectionError < Exception; end
|
4
4
|
class EmptyAPIKeyError < Exception; end
|
5
5
|
class EmptySearchIDError < Exception; end
|
6
|
+
class DirectClientUserError < Exception; end
|
6
7
|
|
7
8
|
FOREIGN_PROVIDERS = {
|
8
9
|
'7digital-US' => '7digital',
|
@@ -22,23 +23,21 @@ module Memphis
|
|
22
23
|
'whosampled' => 'who_sampled'
|
23
24
|
}
|
24
25
|
|
25
|
-
|
26
|
+
def initialize
|
27
|
+
raise DirectClientUserError, "You cannot instantiate Client class directly" if self.class == Memphis::Client
|
26
28
|
|
27
|
-
|
28
|
-
if api_key.to_s == ""
|
29
|
+
if Memphis.api_key.nil?
|
29
30
|
raise EmptyAPIKeyError, "If you don't already have an an account, register here: https://developer.echonest.com/account/register"
|
30
31
|
end
|
31
|
-
|
32
|
-
@api_key = api_key
|
33
32
|
end
|
34
33
|
|
35
|
-
def
|
34
|
+
def client_search search_base_uri, id
|
36
35
|
if id.to_s == ""
|
37
36
|
raise EmptySearchIDError, "need to pass in an The Echo Nest artist ID, such as: \"ARH6W4X1187B99274F\""
|
38
37
|
end
|
39
38
|
|
40
39
|
@id = id
|
41
|
-
results_hash = get_foreign_id_hash
|
40
|
+
results_hash = get_foreign_id_hash search_base_uri
|
42
41
|
|
43
42
|
result = Result.new(results_hash)
|
44
43
|
|
@@ -47,9 +46,9 @@ module Memphis
|
|
47
46
|
|
48
47
|
private
|
49
48
|
|
50
|
-
def get_foreign_id_hash
|
51
|
-
uri =
|
52
|
-
uri += "api_key=#{
|
49
|
+
def get_foreign_id_hash search_base_uri
|
50
|
+
uri = search_base_uri
|
51
|
+
uri += "api_key=#{Memphis.api_key}"
|
53
52
|
uri += "&id=#{@id}"
|
54
53
|
uri += provider_params
|
55
54
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Memphis
|
2
|
+
module Configuration
|
3
|
+
DEFAULT_API_KEY = nil
|
4
|
+
BASE_URI = 'http://developer.echonest.com/api/v4/'
|
5
|
+
|
6
|
+
attr_accessor :api_key
|
7
|
+
|
8
|
+
def self.extended(base)
|
9
|
+
base.reset
|
10
|
+
end
|
11
|
+
|
12
|
+
def reset
|
13
|
+
self.api_key = DEFAULT_API_KEY
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.base_uri
|
17
|
+
BASE_URI
|
18
|
+
end
|
19
|
+
|
20
|
+
def configure
|
21
|
+
yield self
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/memphis/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -1,30 +1,61 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
module Memphis
|
4
|
+
class TestSearch < Memphis::Client
|
5
|
+
URI = 'http://www.example.com'
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def search id
|
12
|
+
client_search URI, id
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
3
17
|
describe Memphis::Client do
|
4
18
|
describe '#initialize' do
|
5
|
-
context '
|
6
|
-
|
7
|
-
|
8
|
-
expect{Memphis::Client.new "" }.to raise_exception Memphis::Client::EmptyAPIKeyError
|
9
|
-
end
|
19
|
+
context 'instantiated directly' do
|
20
|
+
it 'raises DirectClientUserError' do
|
21
|
+
expect{Memphis::Client.new}.to raise_exception Memphis::Client::DirectClientUserError
|
10
22
|
end
|
11
23
|
end
|
24
|
+
context 'not instantiated directly' do
|
25
|
+
context 'invalid API key' do
|
26
|
+
context 'empty API key' do
|
27
|
+
it 'throws EmptyAPIKeyException' do
|
28
|
+
Memphis.api_key = nil
|
29
|
+
expect{Memphis::TestSearch.new}.to raise_exception Memphis::TestSearch::EmptyAPIKeyError
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
12
33
|
|
13
|
-
|
34
|
+
context 'valid API key' do
|
14
35
|
|
36
|
+
end
|
15
37
|
end
|
16
|
-
end
|
17
38
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
39
|
+
describe '#search' do
|
40
|
+
let(:client) { Memphis::TestSearch.new}
|
41
|
+
|
42
|
+
before(:each) do
|
43
|
+
Memphis.configure do |config|
|
44
|
+
config.api_key = 'FAKEKEY'
|
24
45
|
end
|
25
46
|
end
|
26
|
-
end
|
27
47
|
|
28
|
-
|
48
|
+
after(:each) do
|
49
|
+
Memphis.reset
|
50
|
+
end
|
29
51
|
|
52
|
+
context 'invalid search ID' do
|
53
|
+
context 'empty search ID' do
|
54
|
+
it 'throws EmptySearchIDException' do
|
55
|
+
expect{client.search "" }.to raise_exception Memphis::Client::EmptySearchIDError
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
30
61
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Memphis::Configuration do
|
4
|
+
describe '#api_key' do
|
5
|
+
it 'should return default key' do
|
6
|
+
Memphis.api_key.should eq Memphis::Configuration::DEFAULT_API_KEY
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
Memphis.reset
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#configure' do
|
15
|
+
it "should set the api_key" do
|
16
|
+
Memphis.configure do |config|
|
17
|
+
test_key = 'test_key'
|
18
|
+
config.api_key = test_key
|
19
|
+
Memphis.api_key.should eq test_key
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: memphis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Messick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -124,12 +124,14 @@ files:
|
|
124
124
|
- README.md
|
125
125
|
- Rakefile
|
126
126
|
- lib/memphis.rb
|
127
|
+
- lib/memphis/artist.rb
|
127
128
|
- lib/memphis/client.rb
|
128
|
-
- lib/memphis/
|
129
|
+
- lib/memphis/configuration.rb
|
129
130
|
- lib/memphis/result.rb
|
130
131
|
- lib/memphis/version.rb
|
131
132
|
- memphis.gemspec
|
132
133
|
- spec/client_spec.rb
|
134
|
+
- spec/configuration_spec.rb
|
133
135
|
- spec/spec_helper.rb
|
134
136
|
homepage: ''
|
135
137
|
licenses:
|
@@ -151,11 +153,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
153
|
version: '0'
|
152
154
|
requirements: []
|
153
155
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.1.11
|
155
157
|
signing_key:
|
156
158
|
specification_version: 4
|
157
159
|
summary: Use The Echo Nest's Rosetta Stone project to look up IDs for various other
|
158
160
|
services.
|
159
161
|
test_files:
|
160
162
|
- spec/client_spec.rb
|
163
|
+
- spec/configuration_spec.rb
|
161
164
|
- spec/spec_helper.rb
|