Problem getting JSON with API KEY
Added by Chan Kim over 9 years ago
I'm creating a plugin and i'm finding trouble with the REST API
When I use this code:
class PollsController < ApplicationController
unloadable
before_filter :check_if_login_required
before_filter :verify_authenticity_token
before_filter :find_project, :authorize, :only => [:index, :vote]#, :print]
accept_api_auth :index, :vote, :print
def index
@project = Project.find(params[:project_id])
@polls = Poll.all # @project.polls
end
def print
require 'odf-report'
require 'open-uri'
@apiKey = User.current.api_key
url = 'http://redmine.lab.ic.unicamp.br:8080/users.json?key=' + @apiKey
#url = 'http://www.json-generator.com/api/json/get/cuLKyfYKOG'
@result = JSON.parse(open(url).read)
report = ODFReport::Report.new(Rails.root.join('plugins', 'polls', 'ODT', 'test_users.odt')) do |r|
r.add_section("USUARIO", @result['users']) do |s|
s.add_field(:firstname)
s.add_field(:lastname)
end
end
send_data report.generate,
type: 'application/vnd.oasis.opendocument.text',
disposition: 'attachment',
filename: 'relatorio_usuarios.odt'
end
#private
def find_project
@project = Project.find(params[:project_id])
end
end
I get error 500 internal (TIMEOUT)
and when accessing the same JSON, but outside the server, using this json:url = 'http://redmine.lab.ic.unicamp.br:8080/users.json?key=' + @apiKey
url = 'http://www.json-generator.com/api/json/get/cuLKyfYKOG'
it works.
Im using ruby 1.9.3p484, Rails 4.2.3 and redmine 3.0.4
How can I fix it?