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.



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

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.



3
4
5
# File 'lib/kanye/page.rb', line 3

def html
  @html
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/kanye/page.rb', line 3

def response
  @response
end

#tracksObject (readonly)

Returns the value of attribute tracks.



3
4
5
# File 'lib/kanye/page.rb', line 3

def tracks
  @tracks
end

Instance Method Details

#download_all!Object



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

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
        print e.message
      end
        
      history.insert(current_track)
      puts "\tInserted song into db" if Kanye.config["debug"]
    end
  end
end

#url(path, page = 1) ⇒ Object



30
31
32
# File 'lib/kanye/page.rb', line 30

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