musicgraph 0.0.1

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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 565669d2c3f1a4398efe5d9741cc59efc52ac894
4
+ data.tar.gz: 5001572c0cdc89a8fc4c9aeac31cb7d9a8057133
5
+ SHA512:
6
+ metadata.gz: 709e4b6c88456e6a17e698e87ca7088ff80495451ace2804decdca9a3d8ba3a47e00cb48576aaa49f0bf716689fc0fd634f6822c66255da5bc8accafe9167236
7
+ data.tar.gz: 9dbe24da0a606226ca9e85f701cece956a3b219774d1fce028bf44fcf886799182fce56f5eaad495efc7f006f4f25dd8cde51f01fc1b33f85c3a4059f3bea6d7
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in musicgraph.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Dave Powers
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,82 @@
1
+ # MusicGraph
2
+
3
+ A Ruby gem to access the [MusicGraph API](https://developer.musicgraph.com/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'musicgraph'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install musicgraph
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+
25
+ MusicGraph.api_key = "[api key]"
26
+
27
+ artist = MusicGraph::Artist.search('kaiser chiefs').first
28
+ artist.name # => "Kaiser Chiefs"
29
+ artist.main_genre # => "rock"
30
+ artist.decade # => "2000s / 2010s"
31
+
32
+ artists = MusicGraph::Artist.search({similar_to: "Pink Floyd"})
33
+ artists.first.name # => "David Gilmour"
34
+ artists.last.name # => "Eric Clapton"
35
+
36
+ artists = MusicGraph::Artist.search({decade: "1990s"})
37
+ artists.first.name # => "Lil Wayne"
38
+
39
+ artists = MusicGraph::Artist.search({genre: "Soul/R&B"})
40
+ artists.last.name # => "Amy Winehouse"
41
+
42
+ artists = MusicGraph::Artist.search({gender: "female"})
43
+ artists.last.name # => "Shakira"
44
+
45
+ artists = MusicGraph::Artist.search({country: "wales"})
46
+ artists.last.name # => "Tom Jones"
47
+
48
+ artists = MusicGraph::Artist.search({limit: 5})
49
+ artists.length # => 5
50
+
51
+ artist = MusicGraph::Artist.suggest("king").last
52
+ artist.name # => "King James"
53
+
54
+ artist = MusicGraph::Artist.find("e4de0d41-a6b5-11e0-b446-00251188dd67")
55
+ artist.name # => "Beck"
56
+
57
+ artist.edges # => ["albums", "similar", "tracks"]
58
+
59
+ artist.metadata # => returns all available metadata
60
+
61
+ artist.similar.first # => "Bob Forrest"
62
+
63
+ artist.albums # => returns array of albums belonging to artist
64
+
65
+ artist.tracks # => returns array of tracks belonging to artist
66
+
67
+ artist = MusicGraph::Artist.find("e4de0d41-a6b5-11e0-b446-00251188dd67", ["id", "name"])
68
+ artist.name # => "Beck"
69
+ artist.gender # => nil
70
+ ```
71
+
72
+ ## Testing
73
+
74
+ To configure the gem for testing, add the following to `.env`: `MUSICGRAPH_API_KEY=xyz` (where "xyz" is your MusicGraph API key)
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it ( https://github.com/[djpowers]/musicgraph/fork )
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,7 @@
1
+ module MusicGraph
2
+ class Album
3
+
4
+ def initialize(attributes)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,84 @@
1
+ require "faraday"
2
+ require "json"
3
+ require "uri"
4
+
5
+ API_URL = "http://api.musicgraph.com/api/v2/artist/"
6
+
7
+ module MusicGraph
8
+ class Artist
9
+ attr_reader :seven_digital_id, :main_genre, :country_of_origin, :entity_type, :artist_ref_id, :vevo_id, :sort_name, :gender, :rhapsody_id, :id, :decade, :name
10
+
11
+ def initialize(attributes)
12
+ @seven_digital_id = attributes["7digital_id"]
13
+ @main_genre = attributes["main_genre"]
14
+ @country_of_origin = attributes["country_of_origin"]
15
+ @entity_type = attributes["entity_type"]
16
+ @artist_ref_id = attributes["artist_ref_id"]
17
+ @vevo_id = attributes["vevo_id"]
18
+ @sort_name = attributes["sort_name"]
19
+ @gender = attributes["gender"]
20
+ @rhapsody_id = attributes["rhapsody_id"]
21
+ @id = attributes["id"]
22
+ @decade = attributes["decade"]
23
+ @name = attributes["name"]
24
+ end
25
+
26
+ def self.search(params)
27
+ if params.is_a? String
28
+ response = Faraday.get("#{API_URL}search?#{MusicGraph.key_param}&name=#{params}")
29
+ elsif params.is_a? Hash
30
+ encoded_params = URI.encode_www_form(params)
31
+ response = Faraday.get("#{API_URL}search?#{MusicGraph.key_param}&#{encoded_params}")
32
+ end
33
+ artists = JSON.parse(response.body)["data"]
34
+ artists.map { |attributes| new(attributes) }
35
+ end
36
+
37
+ def self.suggest(params)
38
+ if params.is_a? String
39
+ response = Faraday.get("#{API_URL}suggest?#{MusicGraph.key_param}&prefix=#{params}")
40
+ elsif params.is_a? Hash
41
+ encoded_params = URI.encode_www_form(params)
42
+ response = Faraday.get("#{API_URL}suggest?#{MusicGraph.key_param}&#{encoded_params}")
43
+ end
44
+ artists = JSON.parse(response.body)["data"]
45
+ artists.map { |attributes| new(attributes) }
46
+ end
47
+
48
+ def self.find(id, filters = nil)
49
+ request = "#{API_URL}#{id}?#{MusicGraph.key_param}"
50
+ request += "&fields=#{filters.join(",")}" if filters
51
+ response = Faraday.get(request)
52
+ attributes = JSON.parse(response.body)
53
+ new(attributes["data"])
54
+ end
55
+
56
+ def edges
57
+ response = Faraday.get("#{API_URL}#{id}/edges?#{MusicGraph.key_param}")
58
+ JSON.parse(response.body)["data"]
59
+ end
60
+
61
+ def metadata
62
+ response = Faraday.get("#{API_URL}#{id}?#{MusicGraph.key_param}")
63
+ JSON.parse(response.body)["data"]
64
+ end
65
+
66
+ def similar
67
+ response = Faraday.get("#{API_URL}#{id}/similar?#{MusicGraph.key_param}")
68
+ artists = JSON.parse(response.body)["data"]
69
+ artists.map { |attributes| Artist.new(attributes) }
70
+ end
71
+
72
+ def albums
73
+ response = Faraday.get("#{API_URL}#{id}/albums?#{MusicGraph.key_param}")
74
+ albums = JSON.parse(response.body)["data"]
75
+ albums.map { |attributes| Album.new(attributes) }
76
+ end
77
+
78
+ def tracks
79
+ response = Faraday.get("#{API_URL}#{id}/albums?#{MusicGraph.key_param}")
80
+ albums = JSON.parse(response.body)["data"]
81
+ albums.map { |attributes| Track.new(attributes) }
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,7 @@
1
+ module MusicGraph
2
+ class Track
3
+
4
+ def initialize(attributes)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module MusicGraph
2
+ VERSION = "0.0.1"
3
+ end
data/lib/musicgraph.rb ADDED
@@ -0,0 +1,29 @@
1
+ require "musicgraph/version"
2
+ require "musicgraph/artist"
3
+ require "musicgraph/album"
4
+ require "musicgraph/track"
5
+
6
+ begin
7
+ require "pry"
8
+ rescue LoadError
9
+ end
10
+
11
+ module MusicGraph
12
+
13
+ def self.api_key=(key)
14
+ @api_key = key
15
+ end
16
+
17
+ def self.api_key
18
+ @api_key
19
+ end
20
+
21
+ protected
22
+ def self.key_param
23
+ begin
24
+ "api_key=" + MusicGraph.api_key
25
+ rescue
26
+ raise "No MusicGraph API key present (MusicGraph.api_key='xyz')"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'musicgraph/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "musicgraph"
8
+ spec.version = MusicGraph::VERSION
9
+ spec.authors = ["Dave Powers"]
10
+ spec.email = ["djpowers89@gmail.com"]
11
+ spec.summary = %q{Web service wrapper for MusicGraph API}
12
+ spec.description = %q{Web service wrapper for MusicGraph API}
13
+ spec.homepage = "https://github.com/djpowers/musicgraph"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "vcr"
25
+ spec.add_development_dependency "webmock"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "dotenv"
28
+
29
+ spec.add_dependency "faraday"
30
+ spec.add_dependency "json"
31
+ end