Fixed display of Ubuntu reviews
This commit is contained in:
parent
dd91412671
commit
527bc7cd07
1 changed files with 6 additions and 3 deletions
|
|
@ -200,7 +200,7 @@ class PackagesController < ApplicationController
|
||||||
def reviews
|
def reviews
|
||||||
expires_in 1.day, public: true
|
expires_in 1.day, public: true
|
||||||
# @reviews = Package.find_by_name!(params[:name]).ubuntu_reviews
|
# @reviews = Package.find_by_name!(params[:name]).ubuntu_reviews
|
||||||
@reviews = get_ubuntu_reviews :name
|
@reviews = get_ubuntu_reviews params[:name]
|
||||||
render '_reviews', layout: false
|
render '_reviews', layout: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -261,9 +261,12 @@ class PackagesController < ApplicationController
|
||||||
# Get reviews of this package from the Ubuntu API
|
# Get reviews of this package from the Ubuntu API
|
||||||
def get_ubuntu_reviews(packagename)
|
def get_ubuntu_reviews(packagename)
|
||||||
# Use the URL defined in the configuration to get a JSON string
|
# Use the URL defined in the configuration to get a JSON string
|
||||||
json = open(Rails.configuration.ubuntu_reviews_api_url % packagename).read
|
url = Rails.configuration.ubuntu_reviews_api_url % packagename
|
||||||
|
logger.debug "Loading Ubuntu reviews for package #{packagename} from #{url}"
|
||||||
|
|
||||||
|
body = open(url).read
|
||||||
# Turn JSON into a Ruby data structure
|
# Turn JSON into a Ruby data structure
|
||||||
json = JSON.parse(json)
|
json = JSON.parse(body)
|
||||||
# Only show english reviews
|
# Only show english reviews
|
||||||
# TODO: Support further languages
|
# TODO: Support further languages
|
||||||
json = json.select {|x| x['language']=='en'}
|
json = json.select {|x| x['language']=='en'}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue