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.2.30 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.29 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.28 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.27 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.26 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.25 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.24 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.23 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.22 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.21 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.20 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.19 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.18 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.17 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.16 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.15 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.14 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.13 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.12 after_templates/addons/httparty/app/controllers/home_controller.rb
rails_app_generator-0.2.11 after_templates/addons/httparty/app/controllers/home_controller.rb