Sha256: 48afffdaaf936303f2b0b36f4e748a7bb54950e5420467d37abe38f986d36ba8

Contents?: true

Size: 751 Bytes

Versions: 55

Compression:

Stored size: 751 Bytes

Contents

class HomeController < ApplicationController
  def index
  end

  def questions
    @questions = StackExchange.new("stackoverflow", 1).questions
    @questions = clean_data(@questions)
  end

  def users
    @users = StackExchange.new("stackoverflow", 1).users
    @users = clean_data(@users)
  end

  def clean_data(data)
    encode_utf8 = data.to_json.encode('UTF-8', invalid: :replace, undef: :replace)
    JSON.parse(encode_utf8)
  end
end

class StackExchange
  include HTTParty
  base_uri 'api.stackexchange.com'

  def initialize(service, page)
    @options = { query: { site: service, page: page } }
  end

  def questions
    self.class.get("/2.2/questions", @options)
  end

  def users
    self.class.get("/2.2/users", @options)
  end
end

Version data entries

55 entries across 55 versions & 1 rubygems

Version Path
rails_app_generator-0.3.6 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.3.5 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.3.4 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.3.3 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.3.2 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.3.1 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.3.0 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.43 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.42 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.41 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.40 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.39 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.38 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.37 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.36 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.35 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.34 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.33 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.32 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.31 after_templates/addons/httparty/app/controllers/home_controller.rb