Skip to content

Instantly share code, notes, and snippets.

View ARamy23's full-sized avatar
👋
Hello, there!

Ahmed Ramy ARamy23

👋
Hello, there!
View GitHub Profile
@ARamy23
ARamy23 / TowerOfHanoi_.idea_description.html
Created October 17, 2017 23:04
Making the famous Tower of Hanoi game , will feature those ISA , num of moves done , optimum no. of moves , return to last move played
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
@ARamy23
ARamy23 / Constants.swift
Last active June 12, 2018 14:14
Constants
enum Constants: String
{
case mainURLString = "https://dev.wifimetropolis.com:8060/api/"
case voucherEndPoint = "getVouchers?user_id=AHP100-7605-1"
case threadsEndPoint = "messaging/threads"
}
@ARamy23
ARamy23 / getData.swift
Last active June 12, 2018 14:24
a generic network call function
func getData<T: Codable>(endpoint: String, method: HTTPMethod?, params: [String: Any]?, headers: [String: String]?, model: T.Type, completion: @escaping (T?, URLResponse?, Error?) -> Void)
{
//1
guard let url = URL(string: Constants.mainURLString.rawValue + endpoint) else {print("error with creating url"); return;}
var request = URLRequest(url: url)
//2
request.httpMethod = method?.rawValue ?? "GET"
//3
enum HTTPMethod: String
{
case get = "GET"
case post = "POST"
case delete = "DELETE"
}
//1
enum TodoRouter: URLRequestConvertible {
//2
static let baseURLString = "https://jsonplaceholder.typicode.com/"
//3
case get(Int)
case create([String: Any])
case delete(Int)
func asURLRequest() throws -> URLRequest {
import Foundation
import Alamofire
protocol URLRequestBuilder: URLRequestConvertible {
var mainURL: URL { get }
var requestURL: URL { get }
// MARK: - Path
var path: ServerPaths { get }
enum ServerPaths: String {
case login
case register
case phoneActivation = "phone_activation"
case resendPhoneActivation = "resend_phone_activation_code"
case resendEmailLink = "send_reset_link_email"
case resetPassword = "reset_password"
case userInfo = "get_account_info"
case updateInfo = "update_account_info"
case userBalance = "get_user_internal_balance"
enum UserRequest: URLRequestBuilder {
case login(email: String, password: String)
case register(name: String, email: String, password: String, phone: String)
case userInfo
// MARK: - Path
internal var path: ServerPaths {
switch self {
case .login:
enum UserRequest: URLRequestBuilder {
// 1
case login(email: String, password: String)
case register(name: String, email: String, password: String, phone: String)
case userInfo
// MARK: - Path
internal var path: ServerPaths {
// 2
/// Response completion handler beautified.
typealias CallResponse<T> = ((ServerResponse<T>) -> Void)?
/// API protocol, The alamofire wrapper
protocol APIRequestHandler: HandleAlamoResponse {
/// Calling network layer via (Alamofire), this implementation can be replaced anytime in one place which is the protocol itself, applied anywhere.