decibel_wrapper 0.0.2

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTBmYzQ2ZTI1NTRmNTg4ZGIwNzA4ZWI1ZWMwNjg3OTUzMDZhYTk1NQ==
5
+ data.tar.gz: !binary |-
6
+ Mjg1MDM1YjJhMDExYzk1ZmY0OGQ4Y2FmOGVlNDJjZDY2OTBlZTY5Zg==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ YmU0ZGVkYjYzMGI4MzVlNTRjNTFjNDk4NTVhNmVmN2FiYzBkMDc2NWZiM2Fl
10
+ MGU5OTVkMTg2NjI2NzkwNmYyMTFhNTNmZjgxYjZmZTBhZGEyZDJlNDM2NDVj
11
+ YzYxYjA5MmY2ZGU2ZDU5MWVmMzBhMjEzYmI1MGVlOGRmNDkyZDA=
12
+ data.tar.gz: !binary |-
13
+ MmYwYmJlNmVjZjc0ZGJmYzg4N2ZiNGQ3OWY2ZWY2MDMxYzA0ODQ1ZTY5NTNl
14
+ YjlmMDcyYjIzMTZkYmJiMDI2MWFlM2FiMTQ0MzczYzY5M2I4ZDg4OGE5Nzk2
15
+ MGY0MzQ5YWVlY2FjZTRmMjY0MWE5MzI3YjQwMjdmZmFjZjA1MjE=
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in decibel_wrapper.gemspec
4
+ gemspec
5
+
6
+ gem 'rspec'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 tomallen400
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # DecibelWrapper
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'decibel_wrapper'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install decibel_wrapper
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'decibel_wrapper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "decibel_wrapper"
8
+ spec.version = DecibelWrapper::VERSION
9
+ spec.authors = ["tomallen400"]
10
+ spec.email = ["tomallen4000@gmail.com"]
11
+ spec.description = "A simple wrapper for the Decibel API"
12
+ spec.summary = "Creates objects from the Decibel API"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = ">= 1.8.7"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "rspec"
25
+ end
data/lib/.DS_Store ADDED
Binary file
data/lib/decibel.rb ADDED
@@ -0,0 +1,6 @@
1
+ module Decibel
2
+
3
+ end
4
+
5
+ # Loading sequence.
6
+ require File.dirname(__FILE__) + "/wrapper/wrapper"
@@ -0,0 +1,3 @@
1
+ require "decibel_wrapper/version"
2
+ require "decibel"
3
+
@@ -0,0 +1,3 @@
1
+ module DecibelWrapper
2
+ VERSION = "0.0.2"
3
+ end
Binary file
@@ -0,0 +1,11 @@
1
+ class Decibel::Activity
2
+
3
+ attr_accessor :Name
4
+
5
+ def initialize args
6
+ args.each do |k, v|
7
+ instance_variable_set("@#{k}", v) unless v.nil?
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,33 @@
1
+ class Decibel::Album
2
+
3
+ attr_accessor :Title, :FeaturedArtistString, :IsUnofficial, :Identifiers, :Genres
4
+
5
+ def initialize args
6
+ args.each do |k, v|
7
+ instance_variable_set("@#{k}", v) unless v.nil?
8
+ end
9
+ #self.child_initializers
10
+ end
11
+
12
+ def child_initializers
13
+ self.identifiers_initialize if self.Identifiers
14
+ self.genres_initialize if self.Genres
15
+ end
16
+
17
+ def identifiers_initialize
18
+ array = []
19
+ self.Identifiers.each do |i|
20
+ array << Decibel::Identifier.new(i)
21
+ end
22
+ self.Identifiers = array
23
+ end
24
+
25
+ def genres_initialize
26
+ array = []
27
+ self.Genres.each do |i|
28
+ array << Decibel::Genre.new(i)
29
+ end
30
+ self.Genres = array
31
+ end
32
+
33
+ end
@@ -0,0 +1,11 @@
1
+ class Decibel::FeaturedArtist
2
+
3
+ attr_accessor :Id, :Name
4
+
5
+ def initialize args
6
+ args.each do |k, v|
7
+ instance_variable_set("@#{k}", v) unless v.nil?
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ class Decibel::Genre
2
+
3
+ attr_accessor :Name
4
+
5
+ def initialize args
6
+ args.each do |k, v|
7
+ instance_variable_set("@#{k}", v) unless v.nil?
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ class Decibel::Identifier
2
+
3
+ attr_accessor :IdentifierType, :Value
4
+
5
+ def initialize args
6
+ args.each do |k, v|
7
+ instance_variable_set("@#{k}", v) unless v.nil?
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,11 @@
1
+ class Decibel::MainIdentity
2
+
3
+ attr_accessor :Id, :LiteralName
4
+
5
+ def initialize args
6
+ args.each do |k, v|
7
+ instance_variable_set("@#{k}", v) unless v.nil?
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,20 @@
1
+ class Decibel::Participant
2
+
3
+ attr_accessor :Id, :Name, :StageName, :Identifiers, :Biography, :BiographySnippet, :Members
4
+
5
+ def initialize args
6
+ args.each do |k, v|
7
+ instance_variable_set("@#{k}", v) unless v.nil?
8
+ end
9
+ self.members_initialize if self.Members
10
+ end
11
+
12
+ def members_initialize
13
+ array = []
14
+ self.Members.each do |m|
15
+ array << Decibel::Participant.new(m)
16
+ end
17
+ self.Members = array
18
+ end
19
+
20
+ end
@@ -0,0 +1,60 @@
1
+ class Decibel::Recording
2
+
3
+ attr_accessor :Id, :Title, :FeaturedArtistString, :Duration, :FeaturedArtists, :Genres, :Participations, :Authors
4
+
5
+ def initialize args
6
+ args.each do |k, v|
7
+ instance_variable_set("@#{k}", v) unless v.nil?
8
+ end
9
+ self.child_initializers
10
+ end
11
+
12
+ def child_initializers
13
+ self.featured_artists_initialize if self.FeaturedArtists
14
+ self.genres_initialize if self.Genres
15
+ self.participations_initialize if self.Participations
16
+ self.authors_initialize if self.Authors
17
+ end
18
+
19
+ def featured_artists_initialize
20
+ array = []
21
+ self.FeaturedArtists.each do |a|
22
+ array << Decibel::FeaturedArtist.new(a)
23
+ end
24
+ self.FeaturedArtists = array
25
+ end
26
+
27
+ def genres_initialize
28
+ array = []
29
+ self.Genres.each do |i|
30
+ array << Decibel::Genre.new(i)
31
+ end
32
+ self.Genres = array
33
+ end
34
+
35
+ def participations_initialize
36
+ array = []
37
+ self.Participations.each do |p|
38
+ array << Decibel::Participation.new(p)
39
+ end
40
+ self.Participations = array
41
+ end
42
+
43
+ def authors_initialize
44
+ array = []
45
+ self.Authors.each do |a|
46
+ array << Decibel::Participation.new(a)
47
+ end
48
+ self.Authors = array
49
+ end
50
+
51
+ # Needs looking at for refactoring
52
+ def child_initializer(object, child_object)
53
+ array = []
54
+ object.each do |o|
55
+ array << child_object.new(o)
56
+ end
57
+ object = array
58
+ end
59
+
60
+ end
@@ -0,0 +1,33 @@
1
+ class Decibel::Participation
2
+
3
+ attr_accessor :LiteralMainIdentities, :MainIdentities, :LiteralActivity, :Activities
4
+
5
+ def initialize args
6
+ args.each do |k, v|
7
+ instance_variable_set("@#{k}", v) unless v.nil?
8
+ end
9
+ self.child_initializers
10
+ end
11
+
12
+ def child_initializers
13
+ self.main_identities_initialize
14
+ self.activities_initialize
15
+ end
16
+
17
+ def main_identities_initialize
18
+ array = []
19
+ self.MainIdentities.each do |i|
20
+ array << Decibel::MainIdentity.new(i)
21
+ end
22
+ self.MainIdentities = array
23
+ end
24
+
25
+ def activities_initialize
26
+ array = []
27
+ self.Activities.each do |a|
28
+ array << Decibel::Activity.new(a)
29
+ end
30
+ self.Activities = array
31
+ end
32
+
33
+ end
@@ -0,0 +1,20 @@
1
+ class Decibel::Work
2
+
3
+ attr_accessor :Id, :Title, :Participations, :Tracks
4
+
5
+ def initialize args
6
+ args.each do |k, v|
7
+ instance_variable_set("@#{k}", v) unless v.nil?
8
+ end
9
+ self.participations_initialize if self.Participations
10
+ end
11
+
12
+ def participations_initialize
13
+ array = []
14
+ self.Participations.each do |p|
15
+ array << Decibel::Participation.new(p)
16
+ end
17
+ self.Participations = array
18
+ end
19
+
20
+ end
@@ -0,0 +1,168 @@
1
+ class Decibel::Wrapper
2
+
3
+ require 'net/https'
4
+ require 'uri'
5
+ require 'json'
6
+
7
+ attr_accessor :decibel_app_id, :decibel_app_key
8
+
9
+ @@api_url = "http://rest.decibel.net/v2/"
10
+
11
+ Dir[File.join(File.dirname(__FILE__), "resources", "*.rb")].each { |file| require file }
12
+
13
+ def initialize args
14
+ args.each do |k, v|
15
+ instance_variable_set("@#{k}", v) unless v.nil?
16
+ end
17
+ end
18
+
19
+ def album(params)
20
+ response = self.query(Decibel::Wrapper.create_query_string('album/?', params))
21
+ Decibel::Album.new(response) if !response.nil?
22
+ end
23
+
24
+ def albums(params)
25
+ response = self.query(Decibel::Wrapper.create_query_string('albums/?', params))
26
+ if !response.nil?
27
+ array = []
28
+ response.each do |a|
29
+ array << Decibel::Album.new(response)
30
+ end
31
+ array
32
+ end
33
+ end
34
+
35
+ def disctags(params)
36
+
37
+ end
38
+
39
+ def image(params)
40
+ image_id = "0"
41
+ image_id = params[:id] if params.is_a?(Hash) && params[:id]
42
+ response = self.query("image/#{image_id}/#{Decibel::Wrapper.image_size(params)}")
43
+ end
44
+
45
+ def self.image_size(params)
46
+ image_size = "standard"
47
+ image_size = "thumbnail" if params.is_a?(Hash) && params[:thumbnail]
48
+ image_size = "full" if params.is_a?(Hash) && params[:full]
49
+ image_size
50
+ end
51
+
52
+ def participant(params)
53
+ response = self.query(Decibel::Wrapper.create_query_string('participant/?', params))
54
+ Decibel::Participant.new(response) if !response.nil?
55
+ end
56
+
57
+ def participants(params)
58
+ response = self.query(Decibel::Wrapper.create_query_string('participants/?', params))
59
+ if !response.nil?
60
+ array = []
61
+ response.each do |a|
62
+ array << Decibel::Participant.new(response)
63
+ end
64
+ array
65
+ end
66
+ end
67
+
68
+ def recording(params)
69
+ response = self.query(Decibel::Wrapper.create_query_string('recording/?', params))
70
+ Decibel::Recording.new(response) if !response.nil?
71
+ end
72
+
73
+ def recordings(params)
74
+ response = self.query(Decibel::Wrapper.create_query_string('recordings/?', params))
75
+ if !response.nil?
76
+ array = []
77
+ response.each do |a|
78
+ array << Decibel::Recording.new(response)
79
+ end
80
+ array
81
+ end
82
+ end
83
+
84
+ def return_number
85
+ self.query(Decibel::Wrapper.create_query_string('return/number', nil))
86
+ end
87
+
88
+ def work(params)
89
+ response = self.query(Decibel::Wrapper.create_query_string('work/?', params))
90
+ Decibel::Work.new(response) if !response.nil?
91
+ end
92
+
93
+ def works(params)
94
+ response = self.query(Decibel::Wrapper.create_query_string('works/?', params))
95
+ if !response.nil?
96
+ array = []
97
+ response.each do |a|
98
+ array << Decibel::Work.new(response)
99
+ end
100
+ array
101
+ end
102
+ end
103
+
104
+ # Query String
105
+ def self.create_query_string(start, params)
106
+ if params.is_a?(Hash)
107
+ start += hash_to_query_string(params).join('&')
108
+ else
109
+ start
110
+ end
111
+ end
112
+
113
+ def self.hash_to_query_string(hash)
114
+ array = []
115
+ hash.each do |k, v|
116
+ array << query_value(k, v)
117
+ end
118
+ array
119
+ end
120
+
121
+ def self.query_value(k, v)
122
+ if k.to_s.downcase != "depth" && !v.nil?
123
+ "#{k}=#{URI.encode(v, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}"
124
+ else
125
+ depth_string(v)
126
+ end
127
+ end
128
+
129
+ def self.depth_string(hash)
130
+ string = "depth="
131
+ new_array = []
132
+ hash.each do |depth_k, depth_v|
133
+ new_array << "#{depth_k}" if depth_v == true
134
+ end
135
+ string += new_array.join(';')
136
+ end
137
+
138
+ # Hit Decibel API
139
+ def query(ending)
140
+ query = @@api_url + ending
141
+ response = self.send_query(query)
142
+ Decibel::Wrapper.parse_response(response)
143
+ end
144
+
145
+ def send_query(query)
146
+ uri = URI.parse(query)
147
+ http = Net::HTTP.new(uri.host, uri.port)
148
+ request = Net::HTTP::Get.new(uri.request_uri)
149
+ request.initialize_http_header('DecibelAppID' => self.decibel_app_id,
150
+ 'DecibelAppKey' => self.decibel_app_key,
151
+ 'DecibelTimestamp' => Time.now.strftime('%Y%m%d %H:%M:%S'))
152
+ http.request(request)
153
+ end
154
+
155
+ def self.parse_response(response)
156
+ if response.is_a?(Net::HTTPOK)
157
+ json = JSON.parse(response.body) rescue {}
158
+ if json["ResultSet"]
159
+ json["ResultSet"]
160
+ elsif json["Result"]
161
+ json["Result"]
162
+ else
163
+ response.body
164
+ end
165
+ end
166
+ end
167
+
168
+ end
data/spec/.DS_Store ADDED
Binary file
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe Decibel do
4
+
5
+ end
@@ -0,0 +1,19 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
18
+
19
+ require 'decibel_wrapper'
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Decibel::Album do
4
+
5
+ let(:wrapper) { Decibel::Wrapper.new(:decibel_app_id => 'YOUR_DECIBEL_APP_ID', :decibel_app_key => 'YOUR_DECIBEL_APP_KEY') }
6
+ let(:decibal_album) { wrapper.album(:id => 'cd94ce57-533a-e311-be6d-ac220b82800d') }
7
+ let(:album) { Decibel::Album.new(:Id => 'cd94ce57-533a-e311-be6d-ac220b82800d', :Identifiers => [{:IdentifierType => "A type", :Value => "1234"}], :Genres => [{:Name => "House"}, {:Name => "Electro"}]) }
8
+ subject { album }
9
+
10
+ it { should respond_to(:Title) }
11
+ it { should respond_to(:FeaturedArtistString) }
12
+ it { should respond_to(:IsUnofficial) }
13
+ it { should respond_to(:Identifiers) }
14
+
15
+ describe "identifiers_initialize" do
16
+ before { album.identifiers_initialize }
17
+ it "should set initializers to an array" do
18
+ album.Identifiers.should be_an_instance_of Array
19
+ end
20
+ it "should set initializers to an array of Decibel::Identifier s" do
21
+ album.Identifiers[0].should be_an_instance_of Decibel::Identifier
22
+ end
23
+ end
24
+
25
+ describe "genres_intialize" do
26
+ before { album.genres_initialize }
27
+ it "should set genres to an array" do
28
+ album.Genres.should be_an_instance_of Array
29
+ end
30
+ it "should set genres to an array of Decibel::Genre s" do
31
+ album.Genres[0].should be_an_instance_of Decibel::Genre
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Decibel::Participant do
4
+
5
+ let(:wrapper) { Decibel::Wrapper.new(:decibel_app_id => 'YOUR_DECIBEL_APP_ID', :decibel_app_key => 'YOUR_DECIBEL_APP_KEY') }
6
+ let(:decibal_participant) { wrapper.participant(:id => '5e9c115a-7e00-11e3-be7b-ac220b82800d') }
7
+ let(:participant) { Decibel::Participant.new(:Id => "1fe03321-463a-e311-be6d-ac220b82800d", :Name => "The Rolling Stones", :StageName => "The Rolling Stones", :Members => [:Id => "1fe03321-463a-e311-be6d-ac220b82800d", :Name => "The Rolling Stones", :StageName => "The Rolling Stones", :Identifiers => [{:IdentifierType => "DiscogsName", :Value => "Rolling Stones, The"}, {:IdentifierType => "DiscogsID", :Value => "a20991"}]], :Identifiers => [{:IdentifierType => "DiscogsName", :Value => "Rolling Stones, The"}, {:IdentifierType => "DiscogsID", :Value => "a20991"}], :ParticipantType => 1) }
8
+ subject { participant }
9
+
10
+ it { should respond_to(:Id) }
11
+ it { should respond_to(:Name) }
12
+ it { should respond_to(:StageName) }
13
+ it { should respond_to(:Identifiers) }
14
+ it { should respond_to(:Biography) }
15
+ it { should respond_to(:BiographySnippet) }
16
+ it { should respond_to(:Members) }
17
+
18
+ it "should set Members to an array" do
19
+ participant.Members.should be_an_instance_of Array
20
+ end
21
+ it "should set Members to an array of Decibel::Participants" do
22
+ participant.Members[0].should be_an_instance_of Decibel::Participant
23
+ end
24
+
25
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Decibel::Participation do
4
+
5
+ let(:wrapper) { Decibel::Wrapper.new(:decibel_app_id => 'YOUR_DECIBEL_APP_ID', :decibel_app_key => 'YOUR_DECIBEL_APP_KEY') }
6
+ #let(:decibal_participant) { wrapper.recording(:id => '5e9c115a-7e00-11e3-be7b-ac220b82800d') }
7
+ let(:participation) { Decibel::Participation.new(:LiteralMainIdentities => "Chad Smith", :MainIdentities => [{:Id => "f8d2a321-463a-e311-be6d-ac220b82800d", :LiteralName => "Chad Smith"}], :LiteralActivity => "Drums", :Activities => [{:Name => "Drums"}]) }
8
+ subject { participation }
9
+
10
+ it { should respond_to(:LiteralMainIdentities) }
11
+ it { should respond_to(:MainIdentities) }
12
+ it { should respond_to(:LiteralActivity) }
13
+ it { should respond_to(:Activities) }
14
+
15
+ it "should set MainIdentities to an array" do
16
+ participation.MainIdentities.should be_an_instance_of Array
17
+ end
18
+ it "should set MainIdentities to an array of Decibel::FeaturedArtist s" do
19
+ participation.MainIdentities[0].should be_an_instance_of Decibel::MainIdentity
20
+ end
21
+ it "should set Activities to an array" do
22
+ participation.Activities.should be_an_instance_of Array
23
+ end
24
+ it "should set Activities to an array of Decibel::Activity s" do
25
+ participation.Activities[0].should be_an_instance_of Decibel::Activity
26
+ end
27
+
28
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Decibel::Recording do
4
+
5
+ let(:wrapper) { Decibel::Wrapper.new(:decibel_app_id => 'YOUR_DECIBEL_APP_ID', :decibel_app_key => 'YOUR_DECIBEL_APP_KEY') }
6
+ let(:decibal_recording) { wrapper.recording(:id => '5e9c115a-7e00-11e3-be7b-ac220b82800d') }
7
+ let(:recording) { Decibel::Recording.new(:Id => '5e9c115a-7e00-11e3-be7b-ac220b82800d', :Title => "Zephyr Song", :Genres => [{:Name => "House"}, {:Name => "Electro"}], :Duration => 232.0, :FeaturedArtists => [{:Id => "efcd42f6-7dff-11e3-be7b-ac220b82800d", :LiteralName => "Red Hot Chili Peppers"}], :Participations => [{:LiteralMainIdentities => "Chad Smith", :MainIdentities => [{:Id => "f8d2a321-463a-e311-be6d-ac220b82800d", :LiteralName => "Chad Smith"}], :LiteralActivity => "Drums", :Activities => [{:Name => "Drums"}]}], :Authors => [{:LiteralMainIdentities => "John Frusciante", :MainIdentities => [{:Id => "03d85421-463a-e311-be6d-ac220b82800d", :LiteralName => "John Frusciante"}], :LiteralActivity => "Written-By", :Activities => [{:Name => "Written By"}]}]) }
8
+ let(:blank_recording) { Decibel::Recording.new(:Id => "") }
9
+ subject { recording }
10
+
11
+ it { should respond_to(:Id) }
12
+ it { should respond_to(:Title) }
13
+ it { should respond_to(:FeaturedArtistString) }
14
+ it { should respond_to(:Duration) }
15
+ it { should respond_to(:FeaturedArtists) }
16
+
17
+ it "should set FeaturedArtists to an array" do
18
+ recording.FeaturedArtists.should be_an_instance_of Array
19
+ end
20
+ it "should set FeaturedArtists to an array of Decibel::FeaturedArtists" do
21
+ recording.FeaturedArtists[0].should be_an_instance_of Decibel::FeaturedArtist
22
+ end
23
+ it "should set FeaturedArtists to nil if no FeaturedArtists" do
24
+ blank_recording.FeaturedArtists.should be_nil
25
+ end
26
+ it "should set Genres to an array" do
27
+ recording.Genres.should be_an_instance_of Array
28
+ end
29
+ it "should set Genres to an array of Decibel::Genre" do
30
+ recording.Genres[0].should be_an_instance_of Decibel::Genre
31
+ end
32
+ it "should set Genres to nil if no Genres" do
33
+ blank_recording.Genres.should be_nil
34
+ end
35
+ it "should set Participations to an array" do
36
+ recording.Participations.should be_an_instance_of Array
37
+ end
38
+ it "should set Participations to an array of Decibel::RecordingParticipations" do
39
+ recording.Participations[0].should be_an_instance_of Decibel::Participation
40
+ end
41
+ it "should set Participations to nil if no Participations" do
42
+ blank_recording.Participations.should be_nil
43
+ end
44
+ it "should set Authors to an array" do
45
+ recording.Authors.should be_an_instance_of Array
46
+ end
47
+ it "should set Authors to an array of Decibel::RecordingParticipations" do
48
+ recording.Authors[0].should be_an_instance_of Decibel::Participation
49
+ end
50
+ it "should set Authors to nil if no Authors" do
51
+ blank_recording.Authors.should be_nil
52
+ end
53
+
54
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Decibel::Work do
4
+
5
+ let(:wrapper) { Decibel::Wrapper.new(:decibel_app_id => 'YOUR_DECIBEL_APP_ID', :decibel_app_key => 'YOUR_DECIBEL_APP_KEY') }
6
+ let(:decibel_work) { wrapper.work(:id => '5e9c115c-7e00-11e3-be7b-ac220b82800d') }
7
+ let(:work) { Decibel::Work.new(:Id => '5e9c115c-7e00-11e3-be7b-ac220b82800d', :Title => "Zephyr Song", :Participations => [{:LiteralMainIdentities => "John Frusciante", :MainIdentities => [{:Id => "03d85421-463a-e311-be6d-ac220b82800d", :LiteralName => "John Frusciante"}], :LiteralActivity => "Written-By", :Activities => [{:Name => "Written By"}]}]) }
8
+ let(:blank_work) { Decibel::Recording.new(:Id => "") }
9
+ subject { work }
10
+
11
+ it { should respond_to(:Id) }
12
+ it { should respond_to(:Title) }
13
+ it { should respond_to(:Participations) }
14
+ it { should respond_to(:Tracks) }
15
+
16
+ it "should set Participations to an array" do
17
+ work.Participations.should be_an_instance_of Array
18
+ end
19
+ it "should set Participations to an array of Decibel::Participations" do
20
+ work.Participations[0].should be_an_instance_of Decibel::Participation
21
+ end
22
+ it "should set Participations to nil if no Participations" do
23
+ blank_work.Participations.should be_nil
24
+ end
25
+
26
+
27
+ end
@@ -0,0 +1,278 @@
1
+ require 'spec_helper'
2
+
3
+ describe Decibel::Wrapper do
4
+
5
+ let(:wrapper) { Decibel::Wrapper.new(:decibel_app_id => 'YOUR_DECIBEL_APP_ID', :decibel_app_key => 'YOUR_DECIBEL_APP_KEY') }
6
+ let(:test_query) { "albums/?title=the%20fame%20monster&depth=Tracks;TrackAuthors" }
7
+ let(:album_query) { "album/?id=cd94ce57-533a-e311-be6d-ac220b82800d" }
8
+
9
+ # Album
10
+ describe "album" do
11
+ context "when passed a valid id" do
12
+ it "should return an instance of Decibel::Album" do
13
+ wrapper.album(:id => 'cd94ce57-533a-e311-be6d-ac220b82800d').should be_an_instance_of Decibel::Album
14
+ end
15
+ end
16
+ context "when passed an invalid id" do
17
+ it "should return nil" do
18
+ wrapper.album(:id => 'something_else').should be_nil
19
+ end
20
+ end
21
+ end
22
+
23
+ describe "albums" do
24
+ context "when finding something" do
25
+ it "should return an array" do
26
+ wrapper.albums(:title => 'the fame monster').should be_an_instance_of Array
27
+ end
28
+ it "should return an array of Decibel::Album" do
29
+ wrapper.albums(:title => 'the fame monster').first.should be_an_instance_of Decibel::Album
30
+ end
31
+ end
32
+ context "when finding nothing" do
33
+ it "should return an empty array" do
34
+ wrapper.albums(:title => 'blank title').should == []
35
+ end
36
+ end
37
+ end
38
+
39
+ describe "disctags"
40
+
41
+ describe "image" do
42
+ context "when passed a valid id" do
43
+ it "should return a string of the file" do
44
+ wrapper.image(:id => "ad4c211d-45a8-e211-9400-bcaec56d8fb5").should be_an_instance_of String
45
+ end
46
+ end
47
+ context "when passed an invalid id" do
48
+ it "should return nil" do
49
+ wrapper.image(:id => "something_else").should be_nil
50
+ end
51
+ end
52
+ context "when passed no id" do
53
+ it "should return nil" do
54
+ wrapper.image(nil).should be_nil
55
+ end
56
+ end
57
+ end
58
+
59
+ describe "image_size" do
60
+ it "should return a string" do
61
+ Decibel::Wrapper.image_size(nil).should be_an_instance_of String
62
+ end
63
+ it "should default to standard" do
64
+ Decibel::Wrapper.image_size(nil).should == "standard"
65
+ end
66
+ it "should return thumbnail if passed thumbnail in the params" do
67
+ Decibel::Wrapper.image_size(:thumbnail => true).should == "thumbnail"
68
+ end
69
+ it "should return standard if passed thumbnail as false" do
70
+ Decibel::Wrapper.image_size(:thumbnail => false).should == "standard"
71
+ end
72
+ it "should return full if passed full in the params" do
73
+ Decibel::Wrapper.image_size(:full => true).should == "full"
74
+ end
75
+ end
76
+
77
+ describe "participant" do
78
+ context "when passed a valid id" do
79
+ it "should return an instance of Decibel::Participant" do
80
+ wrapper.participant(:id => 'dd8b7421-463a-e311-be6d-ac220b82800d').should be_an_instance_of Decibel::Participant
81
+ end
82
+ end
83
+ context "when passed an invalid id" do
84
+ it "should return nil" do
85
+ wrapper.participant(:id => 'something_else').should be_nil
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "participants" do
91
+ context "when finding something" do
92
+ it "should return an array" do
93
+ wrapper.participants(:name => 'Mick Jagger').should be_an_instance_of Array
94
+ end
95
+ it "should return an array of Decibel::Participant" do
96
+ wrapper.participants(:name => 'Mick Jagger').first.should be_an_instance_of Decibel::Participant
97
+ end
98
+ end
99
+ context "when finding nothing" do
100
+ it "should return an empty array" do
101
+ wrapper.participants(:name => 'blank person').should == []
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "recording" do
107
+ context "when passed a valid id" do
108
+ it "should return an instance of Decibel::Recording" do
109
+ wrapper.recording(:id => '5e9c115a-7e00-11e3-be7b-ac220b82800d').should be_an_instance_of Decibel::Recording
110
+ end
111
+ end
112
+ context "when passed an invalid id" do
113
+ it "should return nil" do
114
+ wrapper.recording(:id => 'something_else').should be_nil
115
+ end
116
+ end
117
+ end
118
+
119
+ describe "recordings" do
120
+ context "when finding something" do
121
+ it "should return an array" do
122
+ wrapper.recordings(:artistname => 'The Rolling Stones').should be_an_instance_of Array
123
+ end
124
+ it "should return an array of Decibel::Recording" do
125
+ wrapper.recordings(:artistname => 'The Rolling Stones').first.should be_an_instance_of Decibel::Recording
126
+ end
127
+ end
128
+ context "when finding nothing" do
129
+ it "should return an empty array" do
130
+ wrapper.recordings(:artistname => 'blank person').should == []
131
+ end
132
+ end
133
+ end
134
+
135
+ describe "return_number" do
136
+ it "should return 1" do
137
+ wrapper.return_number.should == "1"
138
+ end
139
+ end
140
+
141
+ describe "work" do
142
+ context "when passed a valid id" do
143
+ it "should return an instance of Decibel::Work" do
144
+ wrapper.work(:id => '5e9c115c-7e00-11e3-be7b-ac220b82800d').should be_an_instance_of Decibel::Work
145
+ end
146
+ end
147
+ context "when passed an invalid id" do
148
+ it "should return nil" do
149
+ wrapper.work(:id => 'something_else').should be_nil
150
+ end
151
+ end
152
+ end
153
+
154
+ describe "works" do
155
+ context "when finding something" do
156
+ it "should return an array" do
157
+ wrapper.works(:workname => 'The Zephyr Song').should be_an_instance_of Array
158
+ end
159
+ it "should return an array of Decibel::Work" do
160
+ wrapper.works(:workname => 'The Zephyr Song').first.should be_an_instance_of Decibel::Work
161
+ end
162
+ end
163
+ context "when finding nothing" do
164
+ it "should return an empty array" do
165
+ wrapper.works(:authornames => 'blank person').should == []
166
+ end
167
+ end
168
+ end
169
+
170
+ # Create Query String
171
+ describe "create_query_string" do
172
+ it "should return a string" do
173
+ Decibel::Wrapper.create_query_string('albums/?', {:title => "Sticky Fingers"}).should be_an_instance_of String
174
+ end
175
+ it "should add each of the values" do
176
+ Decibel::Wrapper.create_query_string('albums/?', {:title => "Sticky Fingers"}).should == "albums/?title=Sticky%20Fingers"
177
+ end
178
+ it "should separate each key with an &" do
179
+ Decibel::Wrapper.create_query_string('albums/?', {:title => "Sticky Fingers", :mainArtist => "The Rolling Stones"}).should == "albums/?title=Sticky%20Fingers&mainArtist=The%20Rolling%20Stones"
180
+ end
181
+ it "should return first attribute if passed blank hash" do
182
+ Decibel::Wrapper.create_query_string('albums/?', {}).should == "albums/?"
183
+ end
184
+ it "should return first attribute if not passed hash" do
185
+ Decibel::Wrapper.create_query_string('albums/?', nil).should == "albums/?"
186
+ end
187
+ end
188
+
189
+ describe "hash_to_query_string" do
190
+ it "should return an array" do
191
+ Decibel::Wrapper.hash_to_query_string({:title => "Sticky Fingers"}).should be_an_instance_of Array
192
+ end
193
+ it "should call query_value for each value in hash" do
194
+ Decibel::Wrapper.should_receive(:query_value).exactly(2).times
195
+ Decibel::Wrapper.hash_to_query_string({:title => "Sticky Fingers", :mainArtist => "The Rolling Stones"})
196
+ end
197
+ end
198
+
199
+ describe "query_value" do
200
+ it "should return a string" do
201
+ Decibel::Wrapper.query_value('title', 'Sticky Fingers').should be_an_instance_of String
202
+ end
203
+ it "should escape string" do
204
+ Decibel::Wrapper.query_value('title', 'Sticky Fingers').should == 'title=Sticky%20Fingers'
205
+ end
206
+ it "should call depth_string if passed the key of depth" do
207
+ Decibel::Wrapper.should_receive(:depth_string)
208
+ Decibel::Wrapper.query_value('depth', {:TrackAuthors => true})
209
+ end
210
+ end
211
+
212
+ describe "depth_string" do
213
+ it "should return a string" do
214
+ Decibel::Wrapper.depth_string(:Genres => true).should be_an_instance_of String
215
+ end
216
+ it "should join each key where the value is true" do
217
+ Decibel::Wrapper.depth_string(:Genres => true).should == "depth=Genres"
218
+ end
219
+ it "should leave out any keys where the value is false" do
220
+ Decibel::Wrapper.depth_string(:Genres => true, :TrackAuthors => false).should == "depth=Genres"
221
+ end
222
+ it "should join each key with a semi-colon" do
223
+ Decibel::Wrapper.depth_string(:Genres => true, :TrackAuthors => true).should == "depth=Genres;TrackAuthors"
224
+ end
225
+ end
226
+
227
+ # Hit Decibel API
228
+ describe "send_query" do
229
+ it "should return json as the body" do
230
+ wrapper.send_query('http://rest.decibel.net/v2/' + test_query).body.should be_an_instance_of String
231
+ end
232
+ it "should return a Net::HTTPOK object" do
233
+ wrapper.send_query('http://rest.decibel.net/v2/' + test_query).should be_an_instance_of Net::HTTPOK
234
+ end
235
+ end
236
+
237
+ describe "query" do
238
+ context "is passed a plural object" do
239
+ it "should return an Array" do
240
+ wrapper.query(test_query).should be_an_instance_of Array
241
+ end
242
+ end
243
+ context "is passed a single object" do
244
+ it "should return a hash" do
245
+ wrapper.query(album_query).should be_an_instance_of Hash
246
+ end
247
+ end
248
+ context "is passed bad data" do
249
+ it "should return nil" do
250
+ wrapper.query('album/?id=c').should be_nil
251
+ end
252
+ end
253
+ end
254
+
255
+ describe "parse_response" do
256
+ context "is passed a good response" do
257
+ context "for a single object" do
258
+ it "should return a hash" do
259
+ response = wrapper.send_query('http://rest.decibel.net/v2/' + album_query)
260
+ Decibel::Wrapper.parse_response(response).should be_an_instance_of Hash
261
+ end
262
+ end
263
+ context "form multiple objects" do
264
+ it "should return an array" do
265
+ response = wrapper.send_query('http://rest.decibel.net/v2/' + test_query)
266
+ Decibel::Wrapper.parse_response(response).should be_an_instance_of Array
267
+ end
268
+ end
269
+ end
270
+ context "is passed a bad response" do
271
+ it "should return nil" do
272
+ response = wrapper.send_query('http://rest.decibel.net/v2/album/?id=c')
273
+ Decibel::Wrapper.parse_response(response).should be_nil
274
+ end
275
+ end
276
+ end
277
+
278
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decibel_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - tomallen400
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A simple wrapper for the Decibel API
56
+ email:
57
+ - tomallen4000@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .DS_Store
63
+ - .gitignore
64
+ - .rspec
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - decibel_wrapper.gemspec
70
+ - lib/.DS_Store
71
+ - lib/decibel.rb
72
+ - lib/decibel_wrapper.rb
73
+ - lib/decibel_wrapper/version.rb
74
+ - lib/wrapper/.DS_Store
75
+ - lib/wrapper/resources/activity.rb
76
+ - lib/wrapper/resources/album.rb
77
+ - lib/wrapper/resources/featured_artist.rb
78
+ - lib/wrapper/resources/genre.rb
79
+ - lib/wrapper/resources/indetifier.rb
80
+ - lib/wrapper/resources/main_indentity.rb
81
+ - lib/wrapper/resources/participant.rb
82
+ - lib/wrapper/resources/recording.rb
83
+ - lib/wrapper/resources/recording_participation.rb
84
+ - lib/wrapper/resources/work.rb
85
+ - lib/wrapper/wrapper.rb
86
+ - spec/.DS_Store
87
+ - spec/decibel_wrapper_spec.rb
88
+ - spec/spec_helper.rb
89
+ - spec/wrapper/album_spec.rb
90
+ - spec/wrapper/participant_spec.rb
91
+ - spec/wrapper/recording_participation_spec.rb
92
+ - spec/wrapper/recording_spec.rb
93
+ - spec/wrapper/work_spec.rb
94
+ - spec/wrapper/wrapper_spec.rb
95
+ homepage: ''
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: 1.8.7
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.0.3
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Creates objects from the Decibel API
119
+ test_files:
120
+ - spec/.DS_Store
121
+ - spec/decibel_wrapper_spec.rb
122
+ - spec/spec_helper.rb
123
+ - spec/wrapper/album_spec.rb
124
+ - spec/wrapper/participant_spec.rb
125
+ - spec/wrapper/recording_participation_spec.rb
126
+ - spec/wrapper/recording_spec.rb
127
+ - spec/wrapper/work_spec.rb
128
+ - spec/wrapper/wrapper_spec.rb