7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/shopify_appstore.rb', line 7
def self.top(sort_by = :newest)
raise "Unknown sort value" unless [ :newest, :popular, :highest_rated ].include?(sort_by)
sort_by = sort_by.to_s.gsub('_', '+')
values = []
page = 1
begin
begin
url = "http://apps.shopify.com/shopify_applications/filter?sortby=#{sort_by}&page=#{page}"
page += 1
doc = Nokogiri::HTML(open(url))
apps = doc.css('li.app')
apps.each do |app|
handle = app.css('a').first[:href].sub('/shopify_applications/', '').gsub('/', '')
value = {
:handle => handle,
:name => app.css('div.app-info strong').first.text,
:rank => values.size + 1,
:url => "http://apps.shopify.com/#{handle}/",
:image => app.css('img').first[:src],
:description => app.css('p.description').first.text.strip,
}
values.push(value)
end
end while apps.size == 15
rescue
end
values
end
|