gracenote-rb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1ff142be64295e04fc90a1d074c5ae20961b7e9a
4
+ data.tar.gz: 9a08354c78f8f318fc0ddaed49ecbdccbf7328d3
5
+ SHA512:
6
+ metadata.gz: 2e7a2ad729e4ad6dc16e329d060f18cfe45f850839bfb9bd8fd291f96f43be902b4df21058275409515bc0febead352b45b44bb728fdad647fd8394c8c2adbf9
7
+ data.tar.gz: 8458aab6e5ab45cd46547a7cfb4e134cbba72fb54842452ab31e77a2b2dc3ca1e3e2c8711e827ce53276f2fc050e721e3cc489e3be8f7363c6eeed1cbe30267f
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ log/
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.2
3
+
4
+ Documentation:
5
+ Enabled: false
6
+
7
+ Metrics/LineLength:
8
+ Max: 120
9
+
10
+ StringLiterals:
11
+ EnforcedStyle: double_quotes
12
+
13
+ Style/NumericLiterals:
14
+ MinDigits: 7
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.11.2
6
+ script: bundle exec rake test
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at tomoya@cookpad.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in gracenote-rb.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Tomoya Hirano
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Gracenote-Rb
2
+
3
+ [![Build Status](https://travis-ci.org/tomoya55/gracenote-rb.svg?branch=master)](https://travis-ci.org/tomoya55/gracenote-rb)
4
+
5
+ Gracenote client for modern Ruby
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'gracenote-rb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install gracenote-rb
22
+
23
+ ## Usage
24
+
25
+ ### Registration
26
+
27
+ Run this snippet only once and your keep your user_id somewhere.
28
+
29
+ ```
30
+ > require 'gracenote-rb'
31
+ > Gracenote::Client.new(client_id: 'XXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').register
32
+ > F3180SG7792B09ZPN7-UFC6XA8FV3RQ80K0RO7FURV76GQSDM16
33
+ ```
34
+
35
+ ### Search
36
+
37
+ _Search_
38
+
39
+ ```
40
+ > require 'gracenote-rb'
41
+ > client = Gracenote::Client.new(client_id: 'XXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', user_id: 'F3180SG7792B09ZPN7-UFC6XA8FV3RQ80K0RO7FURV76GQSDM16')
42
+ > response = client.search(artist: "Suchmos")
43
+ > response.albums.map(&:title)
44
+ => ["THE BAY",
45
+ "Essence",
46
+ "ROOKIES!!! Campaign Special Sampler CD",
47
+ "STAY TUNE",
48
+ "LOVE&VICE"]
49
+ ```
50
+
51
+ _Pagination_
52
+
53
+ ```
54
+ > response = client.search(artist: "Suchmos")
55
+ > response.range.end
56
+ 10
57
+ > response = client.search(artist: "Suchmos", range: {start: 11})
58
+ > response.range.to_h
59
+ {"count"=>4460, "start"=>11, "end"=>29}
60
+ ```
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gracenote-rb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
71
+
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gracenote-rb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gracenote/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gracenote-rb"
8
+ spec.version = Gracenote::VERSION
9
+ spec.authors = ["Tomoya Hirano"]
10
+ spec.email = ["hiranotomoya@gmail.com"]
11
+
12
+ spec.summary = "Gracenote Client for modern Ruby"
13
+ spec.description = "Gracenote Client for modern Ruby"
14
+ spec.homepage = "https://github.com/tomoya55/gracenote-rb"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "faraday"
23
+ spec.add_dependency "faraday_middleware"
24
+ spec.add_dependency "nokogiri"
25
+ spec.add_dependency "multi_xml"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.11"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "minitest", "~> 5.0"
30
+ spec.add_development_dependency "minitest-reporters"
31
+ spec.add_development_dependency "minitest-power_assert"
32
+ spec.add_development_dependency "rspec-mocks"
33
+ spec.add_development_dependency "faraday-conductivity"
34
+ spec.add_development_dependency "webmock"
35
+ spec.add_development_dependency "pry"
36
+ end
@@ -0,0 +1,42 @@
1
+ require "gracenote/http"
2
+ require "gracenote/query_builder"
3
+ require "gracenote/errors"
4
+ require "gracenote/request/register"
5
+ require "gracenote/request/search"
6
+ require "gracenote/request/fetch"
7
+ require "gracenote/response"
8
+
9
+ module Gracenote
10
+ class Client
11
+ attr_reader :client_id, :user_id
12
+ attr_accessor :lang, :country
13
+
14
+ include Http
15
+ include QueryBuilder
16
+ include Request::Register
17
+ include Request::Search
18
+ include Request::Fetch
19
+
20
+ def initialize(client_id:, user_id: nil, lang: nil, country: nil)
21
+ @client_id = client_id
22
+ @user_id = user_id
23
+ @lang = lang || "eng"
24
+ @country = country || "usa"
25
+ end
26
+
27
+ def short_client_id
28
+ client_id.split("-", 2)[0]
29
+ end
30
+
31
+ def auth
32
+ raise "user_id is empty" unless user_id
33
+ { client: client_id, user: user_id }
34
+ end
35
+
36
+ def query(cmd, options = {}, &block)
37
+ request = build_query(cmd, options, &block).to_xml
38
+ response = post(request)
39
+ Response.new(response)
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,6 @@
1
+ module Gracenote
2
+ module Errors
3
+ class RequestError < StandardError
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,35 @@
1
+ module Gracenote
2
+ module Helper
3
+ def wrap_array(object)
4
+ case object
5
+ when NilClass
6
+ []
7
+ when Array
8
+ object
9
+ else
10
+ [object]
11
+ end
12
+ end
13
+
14
+ def recursive_downcase_keys(object, numerify_values: false)
15
+ case object
16
+ when Hash
17
+ object.each_with_object({}) do |(k,v), memo|
18
+ memo[k.downcase] = recursive_downcase_keys(v, numerify_values: numerify_values)
19
+ end
20
+ when Array
21
+ object.map { |e| recursive_downcase_keys(e, numerify_values: numerify_values) }
22
+ else
23
+ numerify_values ? numerify_value(object) : object
24
+ end
25
+ end
26
+
27
+ def numerify_value(v)
28
+ if v =~ /^\d+$/
29
+ v.to_i
30
+ else
31
+ v
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "faraday/conductivity"
4
+ require "logger"
5
+
6
+ module Gracenote
7
+ module Http
8
+
9
+ def post(body)
10
+ agent.post do |req|
11
+ req.url path
12
+ req.headers["Content-Type"] = "application/xml"
13
+ req.body = body
14
+ end
15
+ end
16
+
17
+ def host
18
+ "https://c#{short_client_id}.web.cddbp.net"
19
+ end
20
+
21
+ def path
22
+ "/webapi/xml/1.0/"
23
+ end
24
+
25
+ def agent
26
+ @agent ||= begin
27
+ Faraday.new(url: host) do |conn|
28
+ conn.response :xml, :content_type => /\bxml$/
29
+ conn.use Faraday::Conductivity::ExtendedLogging, logger: ::Logger.new("faraday.log") if log_enabled?
30
+ conn.adapter Faraday.default_adapter
31
+ end
32
+ end
33
+ end
34
+
35
+ def log_enabled?
36
+ ENV["LOGGING"] == "1"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,21 @@
1
+ module Gracenote
2
+ module QueryBuilder
3
+ def build_query(cmd, auth: nil, lang: nil, country: nil)
4
+ Nokogiri::XML::Builder.new do |xml|
5
+ xml.QUERIES {
6
+ if auth
7
+ xml.AUTH {
8
+ xml.CLIENT auth[:client]
9
+ xml.USER auth[:user]
10
+ }
11
+ end
12
+ xml.LANG lang if lang
13
+ xml.COUNTRY country if country
14
+ xml.QUERY(CMD: cmd) {
15
+ yield(xml)
16
+ }
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,14 @@
1
+ require "gracenote/request/option"
2
+
3
+ module Gracenote
4
+ module Request
5
+ module Fetch
6
+ def fetch(gn_id:)
7
+ query("album_fetch", auth: auth, lang: lang, country: country) do |xml|
8
+ xml.GN_ID gn_id
9
+ Option.new(xml).render
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,46 @@
1
+ module Gracenote
2
+ module Request
3
+ class Option
4
+ include Helper
5
+
6
+ DEFAULT_OPTIONS = {
7
+ "SELECT_EXTENDED" => %w(
8
+ COVER
9
+ REVIEW
10
+ ARTIST_OET
11
+ MOOD
12
+ TEMPO
13
+ ARTIST_BIOGRAPHY
14
+ ARTIST_IMAGE
15
+ CONTENT
16
+ LINK
17
+ ),
18
+ "SELECT_DETAIL" => %w(
19
+ GENRE:3LEVEL
20
+ MOOD:2LEVEL
21
+ TEMPO:3LEVEL
22
+ ARTIST_ORIGIN:4LEVEL
23
+ ARTIST_ERA:2LEVEL
24
+ ARTIST_TYPE:2LEVEL
25
+ )
26
+ }
27
+
28
+ def initialize(xml, options = {})
29
+ @xml = xml
30
+
31
+ @options = DEFAULT_OPTIONS.merge(options)
32
+ end
33
+
34
+ def render
35
+ @options.each { |k, v| render_option(k, v) }
36
+ end
37
+
38
+ def render_option(key, value)
39
+ @xml.OPTION {
40
+ @xml.PARAMETER key
41
+ @xml.VALUE wrap_array(value).join(",")
42
+ }
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,14 @@
1
+ module Gracenote
2
+ module Request
3
+ module Register
4
+ def register
5
+ response = query("register") do |xml|
6
+ xml.CLIENT client_id
7
+ end
8
+
9
+ raise Gracenote::Errors::RequestError, response.message unless response.ok?
10
+ @user_id = response.params["user"]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ require "gracenote/request/option"
2
+
3
+ module Gracenote
4
+ module Request
5
+ module Search
6
+ # @params mode [String] 'SINGLE_BEST' or 'SINGLE_BEST_COVER'
7
+ # @params range [Hash] { start: 1, end: 10 }
8
+ #
9
+ def search(artist: nil, album: nil, track: nil, mode: nil, range: nil)
10
+ query("album_search", auth: auth, lang: lang, country: country) do |xml|
11
+ xml.MODE { xml.text mode } if mode
12
+ if range
13
+ xml.RANGE {
14
+ xml.START range[:start]
15
+ xml.END range[:end] if range[:end]
16
+ }
17
+ end
18
+ xml.TEXT(TYPE: "ARTIST") { xml.text artist } if artist
19
+ xml.TEXT(TYPE: "ALBUM_TITLE") { xml.text album } if album
20
+ xml.TEXT(TYPE: "TRACK_TITLE") { xml.text track } if track
21
+
22
+ options = {}
23
+ options = { "PREFER_XID" => "applealbumid" } if mode == "SINGLE_BEST"
24
+ Option.new(xml, options).render
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,50 @@
1
+ require "gracenote/response/base"
2
+ require "gracenote/response/artist"
3
+ require "gracenote/response/track"
4
+ require "gracenote/response/cover_art"
5
+
6
+ module Gracenote
7
+ class Response
8
+ class Album < Base
9
+ self.attributes = %w(
10
+ gn_id
11
+ pkg_lang
12
+ title
13
+ date
14
+ matched_track_num
15
+ track_count
16
+ )
17
+
18
+ def artist
19
+ Artist.new(self)
20
+ end
21
+
22
+ def track_count
23
+ self["track_count"].to_i
24
+ end
25
+
26
+ def tracks
27
+ wrap_array(self["track"]).map do |track_attrs|
28
+ Track.new(track_attrs)
29
+ end
30
+ end
31
+
32
+ def track
33
+ tracks[0]
34
+ end
35
+
36
+ def genres
37
+ self["genre"]
38
+ end
39
+
40
+ def genre
41
+ wrap_array(genres)[0]
42
+ end
43
+
44
+ def cover_art
45
+ url = @response["url"]
46
+ CoverArt.new(url) if url && url["type"] == "COVERART"
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,39 @@
1
+ require "gracenote/response/base"
2
+
3
+ module Gracenote
4
+ class Response
5
+ class Artist < Base
6
+ def name
7
+ self["artist"]
8
+ end
9
+
10
+ def origins
11
+ self["artist_origin"]
12
+ end
13
+
14
+ def origin
15
+ wrap_array(origins)[0]
16
+ end
17
+
18
+ def types
19
+ self["artist_type"]
20
+ end
21
+
22
+ def type
23
+ wrap_array(types)[0]
24
+ end
25
+
26
+ def eras
27
+ self["artist_era"]
28
+ end
29
+
30
+ def era
31
+ wrap_array(eras)[0]
32
+ end
33
+
34
+ def to_h
35
+ { "name" => name, "origins" => origins, "types" => types, "eras" => eras }
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,34 @@
1
+ module Gracenote
2
+ class Response
3
+ class Base
4
+ include Helper
5
+
6
+ def self.attributes=(attrs)
7
+ attrs.each do |attr|
8
+ define_method(attr) do
9
+ self[attr]
10
+ end
11
+ end
12
+ end
13
+
14
+ def initialize(response)
15
+ @response = response
16
+ end
17
+
18
+ def [](attr)
19
+ values = wrap_array(@response[attr]).map do |value|
20
+ if value.is_a?(Hash) && value.key?("__content__")
21
+ value["__content__"]
22
+ else
23
+ value
24
+ end
25
+ end
26
+ values.size == 1 ? values[0] : values
27
+ end
28
+
29
+ def to_h
30
+ @response
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,21 @@
1
+ require "gracenote/response/base"
2
+
3
+ module Gracenote
4
+ class Response
5
+ class CoverArt < Base
6
+ self.attributes = %w(type size width height)
7
+
8
+ def href
9
+ self["__content__"]
10
+ end
11
+
12
+ def width
13
+ self["width"].to_i
14
+ end
15
+
16
+ def height
17
+ self["height"].to_i
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require "gracenote/response/base"
2
+
3
+ module Gracenote
4
+ class Response
5
+ class Range < Base
6
+ self.attributes = %w(count start end)
7
+
8
+ def next
9
+ self["end"].succ
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ require "gracenote/response/base"
2
+
3
+ module Gracenote
4
+ class Response
5
+ class Track < Base
6
+ self.attributes = %w(gn_id track_num title)
7
+
8
+ def track_num
9
+ self["track_num"].to_i
10
+ end
11
+
12
+ def moods
13
+ self["mood"]
14
+ end
15
+
16
+ def mood
17
+ wrap_array(moods)[0]
18
+ end
19
+
20
+ def tempos
21
+ self["tempo"]
22
+ end
23
+
24
+ def tempo
25
+ wrap_array(tempos)[0]
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,60 @@
1
+ require "faraday"
2
+ require "forwardable"
3
+ require "gracenote/response/album"
4
+ require "gracenote/response/range"
5
+
6
+ module Gracenote
7
+ class Response
8
+ extend Forwardable
9
+ include Helper
10
+ attr_reader :response
11
+
12
+ def_delegators :@response, :success?
13
+
14
+ def initialize(response)
15
+ @response = response
16
+ end
17
+
18
+ def body
19
+ response.body
20
+ end
21
+
22
+ def range
23
+ Range.new(range_body) if range_body
24
+ end
25
+
26
+ def params
27
+ recursive_downcase_keys body["RESPONSES"]["RESPONSE"].reject { |k,v| k == "STATUS" }
28
+ end
29
+
30
+ def albums
31
+ ok? ? wrap_array(params["album"]).map { |attrs| Album.new(attrs) } : []
32
+ end
33
+
34
+ def album
35
+ albums[0]
36
+ end
37
+
38
+ def ok?
39
+ body["RESPONSES"]["RESPONSE"]["STATUS"] == "OK"
40
+ end
41
+
42
+ def no_match?
43
+ body["RESPONSES"]["RESPONSE"]["STATUS"] == "NO_MATCH"
44
+ end
45
+
46
+ def error?
47
+ body["RESPONSES"]["RESPONSE"]["STATUS"] == "ERROR"
48
+ end
49
+
50
+ def message
51
+ error? && body["RESPONSES"]["MESSAGE"]
52
+ end
53
+
54
+ private
55
+
56
+ def range_body
57
+ recursive_downcase_keys body["RESPONSES"]["RESPONSE"]["RANGE"], numerify_values: true
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,3 @@
1
+ module Gracenote
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "nokogiri"
2
+ require "multi_xml"
3
+ require "gracenote/helper"
4
+ require "gracenote/client"
metadata ADDED
@@ -0,0 +1,255 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gracenote-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomoya Hirano
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: multi_xml
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.11'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest-reporters
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: minitest-power_assert
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec-mocks
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: faraday-conductivity
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: webmock
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: pry
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description: Gracenote Client for modern Ruby
196
+ email:
197
+ - hiranotomoya@gmail.com
198
+ executables: []
199
+ extensions: []
200
+ extra_rdoc_files: []
201
+ files:
202
+ - ".gitignore"
203
+ - ".rubocop.yml"
204
+ - ".travis.yml"
205
+ - CODE_OF_CONDUCT.md
206
+ - Gemfile
207
+ - LICENSE.txt
208
+ - README.md
209
+ - Rakefile
210
+ - bin/console
211
+ - bin/setup
212
+ - gracenote-rb.gemspec
213
+ - lib/gracenote-rb.rb
214
+ - lib/gracenote/client.rb
215
+ - lib/gracenote/errors.rb
216
+ - lib/gracenote/helper.rb
217
+ - lib/gracenote/http.rb
218
+ - lib/gracenote/query_builder.rb
219
+ - lib/gracenote/request/fetch.rb
220
+ - lib/gracenote/request/option.rb
221
+ - lib/gracenote/request/register.rb
222
+ - lib/gracenote/request/search.rb
223
+ - lib/gracenote/response.rb
224
+ - lib/gracenote/response/album.rb
225
+ - lib/gracenote/response/artist.rb
226
+ - lib/gracenote/response/base.rb
227
+ - lib/gracenote/response/cover_art.rb
228
+ - lib/gracenote/response/range.rb
229
+ - lib/gracenote/response/track.rb
230
+ - lib/gracenote/version.rb
231
+ homepage: https://github.com/tomoya55/gracenote-rb
232
+ licenses:
233
+ - MIT
234
+ metadata: {}
235
+ post_install_message:
236
+ rdoc_options: []
237
+ require_paths:
238
+ - lib
239
+ required_ruby_version: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ required_rubygems_version: !ruby/object:Gem::Requirement
245
+ requirements:
246
+ - - ">="
247
+ - !ruby/object:Gem::Version
248
+ version: '0'
249
+ requirements: []
250
+ rubyforge_project:
251
+ rubygems_version: 2.4.5
252
+ signing_key:
253
+ specification_version: 4
254
+ summary: Gracenote Client for modern Ruby
255
+ test_files: []