Class: Discogs::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/base.rb

Direct Known Subclasses

Artist, Label, Release, Search, Util

Constant Summary collapse

DISCOGS_BASE_URL =
'http://www.discogs.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_string = nil, request_type = :artist) ⇒ Base

Returns a new instance of Base.



14
15
16
17
18
# File 'lib/base.rb', line 14

def initialize(request_string = nil, request_type = :artist)
  @api_key = load_api_key
  @request_string = request_string
  @request_type = request_type.to_s
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



10
11
12
# File 'lib/base.rb', line 10

def api_key
  @api_key
end

#request_stringObject

Returns the value of attribute request_string.



10
11
12
# File 'lib/base.rb', line 10

def request_string
  @request_string
end

#request_typeObject

Returns the value of attribute request_type.



10
11
12
# File 'lib/base.rb', line 10

def request_type
  @request_type
end

Instance Method Details

#fetchedObject

:nodoc:



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/base.rb', line 25

def fetched #:nodoc:
  @fetched ||= begin
    begin
    gz = Zlib::GzipReader.new(open(request_url, 'Accept-encoding' => 'gzip, deflate'))
    fetched = gz.read
    gz.close
    rescue
      fetched = open(request_url).read
    end
    fetched
  end
end

#parsedObject

Hpricot parsed XML



21
22
23
# File 'lib/base.rb', line 21

def parsed
  @parsed ||= Hpricot.XML(fetched)
end