This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
require ‘uri’ | |
require ‘net/http’ | |
url = URI(“https://api.hurriyet.com.tr/v1/articles?$top=20") | |
http = Net::HTTP.new(url.host, url.port) | |
http.use_ssl = true | |
http.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
request = Net::HTTP::Get.new(url) | |
request[“apikey”] = ‘kendi apikeyinizi buraya yapıştırın’ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api::V1 | |
class BooksController < ApplicationController | |
before_action :set_book, only: [:show, :update, :destroy] | |
# GET /books | |
def index | |
@books = Book.all | |
render json: @books | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Wand | |
def cast_spell | |
spell = get_new_spell | |
spell.cast! | |
end | |
def get_new_spell | |
raise "abstract method #get_new_spell must be defined" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prototype Pattern kullanmadan | |
class ProductDefinition | |
def create_product | |
@product = Product.new( | |
product_definition_name: self.name, | |
properties: self.properties, | |
active: self.active?, | |
category: self.category | |
) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RestaurantServer | |
def initialize(meal_factory) | |
@meal_factory = meal_factory | |
end | |
def serve! | |
@meal_factory.new_utensil | |
@meal_factory.new_dish | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventDirector | |
def initialize | |
@subevents = [:welcome, :intermediary,:closing] | |
end | |
def organize event | |
@subevents.each { |se| event.send(se) if event.respond_to? se } | |
end | |
end | |
class Wedding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'singleton' | |
class SingletonObject | |
include Singleton | |
attr_accessor :counter | |
def initialize | |
@counter = 0 | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/lib/json_web_token.rb | |
class JsonWebToken | |
SECRET_KEY = Rails.application.secrets.secret_key_base.to_s | |
def self.encode(payload, exp = 24.hours.from_now) | |
payload[:exp] = exp.to_i | |
JWT.encode(payload, SECRET_KEY) | |
end | |
def self.decode(token) | |
begin | |
@decoded_token = JWT.decode(token, SECRET_KEY)[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::API | |
def authorize_request | |
header = request.headers['Authorization'] | |
if !header.nil? | |
header = header.split(' ').last | |
@decoded_token ||= JsonWebToken.decode(header) | |
begin | |
@user = User.find(@decoded_token[:id]) | |
rescue Exception => e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Api::V1 | |
class UsersController < ApplicationController | |
before_action :authorize_request, except: [:create, :show, :index, :destroy, :update] | |
# GET /users | |
def index | |
@users = User.all | |
render json: @users, status: :ok | |
end |
OlderNewer