memphis 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1334d1c816707816d461d6214ba5eef61b24c3ff
4
- data.tar.gz: 7c28d8fe5a9401119454975e1cfaa0fa824cb1c0
3
+ metadata.gz: fee7a70029c417fcb7d7b4b8748e2a1a35147b97
4
+ data.tar.gz: 41fa03cf0e65bd71f387d359a4838077add0e86e
5
5
  SHA512:
6
- metadata.gz: f31fd08d8a6d6d77bac86a1b896c41199b2366f9f46070ca0da74eeedbb364e02d55c2dedb8c5e14e07625f4148f8e6f87980fd6e18fa9d5c092470b63b4b73f
7
- data.tar.gz: 5e787ecb1ba5f7f3dfb5c135599ea94ab4252d9a744405ea139c793ac8d8945078af7424c6c23cc382bd81542b7dfdeca9dd63b5f08b6ad27eac7c84e416e234
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
- memphis = Memphis::Memphis.new ECHONEST_API_KEY
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 = memphis.search "ARH6W4X1187B99274F"
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/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
@@ -0,0 +1,14 @@
1
+ module Memphis
2
+ class Artist < Client
3
+
4
+ ARTIST_URI = File.join(::Memphis::Configuration.base_uri, '/artist/profile?')
5
+
6
+ def initialize
7
+ super
8
+ end
9
+
10
+ def search id
11
+ client_search ARTIST_URI, id
12
+ end
13
+ end
14
+ end
@@ -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
- BASE_URI = 'http://developer.echonest.com/api/v4/artist/profile?'
26
+ def initialize
27
+ raise DirectClientUserError, "You cannot instantiate Client class directly" if self.class == Memphis::Client
26
28
 
27
- def initialize api_key=nil
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 search id
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 = BASE_URI
52
- uri += "api_key=#{@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
@@ -1,3 +1,3 @@
1
1
  module Memphis
2
- VERSION = "0.0.4"
2
+ VERSION = "0.1.0"
3
3
  end
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 'invalid API key' do
6
- context 'empty API key' do
7
- it 'throws EmptyAPIKeyException' do
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
- context 'valid API key' do
34
+ context 'valid API key' do
14
35
 
36
+ end
15
37
  end
16
- end
17
38
 
18
- describe '#search' do
19
- context 'invalid search ID' do
20
- let(:client) { Memphis::Client.new "fake_API_key" }
21
- context 'empty search ID' do
22
- it 'throws EmptySearchIDException' do
23
- expect{client.search "" }.to raise_exception Memphis::Client::EmptySearchIDError
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
- end
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
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: 2013-12-12 00:00:00.000000000 Z
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/memphis.rb
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.0.5
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
@@ -1,14 +0,0 @@
1
- module Memphis
2
- class Memphis
3
- attr_accessor :result
4
-
5
- def initialize api_key=nil
6
- @client = Client.new api_key
7
- end
8
-
9
- def search id
10
- @result = @client.search id
11
- end
12
-
13
- end
14
- end