Class: Discog
- Inherits:
-
Object
- Object
- Discog
- Defined in:
- lib/discog.rb
Constant Summary collapse
- API_KEY =
'd63ff5c461'
Instance Attribute Summary collapse
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#realname ⇒ Object
readonly
Returns the value of attribute realname.
Instance Method Summary collapse
- #get_members(artist) ⇒ Object
- #get_name(artist) ⇒ Object
- #get_profile(artist) ⇒ Object
- #get_realname(artist) ⇒ Object
- #get_xml(artist) ⇒ Object
-
#initialize(rawartist) ⇒ Discog
constructor
A new instance of Discog.
Constructor Details
#initialize(rawartist) ⇒ Discog
Returns a new instance of Discog.
10 11 12 13 14 15 16 17 |
# File 'lib/discog.rb', line 10 def initialize(rawartist) artist = rawartist.downcase.gsub(" ", "+") @xml = get_xml(artist) @name = get_name(artist) @realname = get_realname(artist) @members = get_members(artist) @profile = get_profile(artist) end |
Instance Attribute Details
#members ⇒ Object (readonly)
Returns the value of attribute members.
8 9 10 |
# File 'lib/discog.rb', line 8 def members @members end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/discog.rb', line 8 def name @name end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
8 9 10 |
# File 'lib/discog.rb', line 8 def profile @profile end |
#realname ⇒ Object (readonly)
Returns the value of attribute realname.
8 9 10 |
# File 'lib/discog.rb', line 8 def realname @realname end |
Instance Method Details
#get_members(artist) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/discog.rb', line 40 def get_members(artist) members = [] @xml.xpath("/resp/artist/members/name").each do |n| members << n.inner_text end return members end |
#get_name(artist) ⇒ Object
32 33 34 |
# File 'lib/discog.rb', line 32 def get_name(artist) @xml.xpath("/resp/artist/name").inner_text end |
#get_profile(artist) ⇒ Object
48 49 50 |
# File 'lib/discog.rb', line 48 def get_profile(artist) @xml.xpath("/resp/artist/profile").inner_text end |
#get_realname(artist) ⇒ Object
36 37 38 |
# File 'lib/discog.rb', line 36 def get_realname(artist) @xml.xpath("/resp/artist/realname").inner_text end |
#get_xml(artist) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/discog.rb', line 19 def get_xml(artist) begin rawfile = open("http://www.discogs.com/artist/#{artist}?f=xml&api_key=#{API_KEY}", 'Accept-encoding' => 'gzip, deflate') rescue OpenURI::HTTPError return Nokogiri::XML("") end begin return Nokogiri::XML(Zlib::GzipReader.new(rawfile).read) rescue Zlib::GzipFile::Error return Nokogiri::XML(open("http://www.discogs.com/artist/#{artist}?f=xml&api_key=#{API_KEY}")) end end |