Class: Kanye::Page

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, page = 1) ⇒ Page

Returns a new instance of Page.



8
9
10
11
12
13
14
# File 'lib/kanye/page.rb', line 8

def initialize(path, page=1)
  @response = HTTParty.get url(path, page)
  @tracks   = []
  @cookie   = @response.headers['set-cookie']
  @html     = @response.parsed_response    
  parse_response
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



5
6
7
# File 'lib/kanye/page.rb', line 5

def html
  @html
end

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/kanye/page.rb', line 5

def response
  @response
end

#tracksObject (readonly)

Returns the value of attribute tracks.



5
6
7
# File 'lib/kanye/page.rb', line 5

def tracks
  @tracks
end

Instance Method Details

#download_all!Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kanye/page.rb', line 16

def download_all!
  tracks.each do |current_track|
    history = History.new(DEFAULT_DB_PATH)
    unless history.exists?(current_track)
      begin
        current_track.download! 
      rescue Mp3InfoError => e
        puts e.message if Kanye.config["debug"]
      end

      history.insert(current_track)
      puts "\tInserted song into db" if Kanye.config["debug"]
    end
  end
end

#url(path, page = 1) ⇒ Object



32
33
34
# File 'lib/kanye/page.rb', line 32

def url(path, page=1)
  "http://#{BASE_URL}/"+path+"/"+page.to_s+"?ax=1&ts="+timestamp
end