Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

# Created by https://www.gitignore.io/api/node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless


# End of https://www.gitignore.io/api/node
57 changes: 57 additions & 0 deletions node/controllers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
var clients = require('restify-clients');
var cache = require('memory-cache');
var client = clients.createJsonClient({
url: "https://olinda.bcb.gov.br"
});


module.exports = {
hello: (req, res) => {
res.send('Test Hot Milhas');
},

cotar: (req, res) => {
let cotacao = cache.get('cotacao');
if (cotacao) {
res.send(cotacao);
} else {
client.get(`/olinda/servico/PTAX/versao/v1/odata/CotacaoDolarDia(dataCotacao=@dataCotacao)?@dataCotacao='07-20-2018'&$top=100&$format=json`, (error, reqx, resx, retornox) => {
cache.put('cotacao', retornox, 14400000);
res.send(retornox);
});
}
},

addOrder: (req, res) => {
let items = req.body.items;
let total = 0.0;

items.forEach(item => {
total += item;
})

let orders = cache.get('orders');
let id = 1;
if (orders) {
id = orders[orders.length - 1].id + 1;
} else {
orders = [];
}

item = {
id: id,
createdAt: '30/07/2018',
totalBRL: total,
totalUSD: total * 3.73
}

orders.push(item);
cache.put('orders', orders);
res.send(item);
},

orders: (req, res) => {
let orders = cache.get('orders');
res.send(orders ? orders : []);
}
}
30 changes: 30 additions & 0 deletions node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var express = require('express');
var app = express();
var bodyParser = require('body-parser');

app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));


// routes
controllers = require('./controllers.js');

app.get('/', controllers.hello);

app.get('/api/brl-usd', controllers.cotar);

app.post('/api/orders', controllers.addOrder);

app.get('/api/orders', controllers.orders);

const porta = 3000;

app.listen(3000, function () {
console.log(`Aplicação radando na porta ${porta}`);
});
17 changes: 17 additions & 0 deletions node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "node",
"version": "1.0.0",
"description": "Teste Node Hot Milhas",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jonathan Veloso",
"license": "ISC",
"dependencies": {
"express": "^4.16.3",
"memory-cache": "^0.2.0",
"restify": "^7.2.1",
"restify-clients": "^2.5.0"
}
}
13 changes: 13 additions & 0 deletions node/service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = function () {
var clients = require('restify-clients');
var client = clients.createJsonClient({
url: "https://olinda.bcb.gov.br"
});

var requisicoes = {}

requisicoes.cotacaoDolar = function(res, callback){
client.get('/emitir-seguros/v0/additional-info/benefits', callback);
}
return requisicoes;
}
26 changes: 26 additions & 0 deletions php/CurlClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

class CurlClient{
public static function get($url){
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://olinda.bcb.gov.br/olinda/servico/PTAX/versao/v1/odata/CotacaoDolarDia(dataCotacao=@dataCotacao)?@dataCotacao='07-20-2018'",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
return $response;
}
}
}

?>
15 changes: 15 additions & 0 deletions php/brl-usd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

header('Content-Type: application/json');
require('CurlClient.php');


if(!isset($_COOKIE['cotacao'])){
$url = "https://olinda.bcb.gov.br/olinda/servico/PTAX/versao/v1/odata/CotacaoDolarDia(dataCotacao=@dataCotacao)?@dataCotacao='07-20-2018'";
$cotacao = CurlClient::get($url);
setcookie('cotacao', $cotacao, 14400);
echo $cotacao;
}else{
echo $_COOKIE['cotacao'];
}
?>
16 changes: 16 additions & 0 deletions php/oop/Estaciona.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace Estacionamento{
class Estaciona{
private $veiculo;
private $vaga;
private $dataHoraEntrada;
private $dataHoraSaida;

function __construct($veiculo, $vaga){
$this->veiculo = $veiculo;
$this->vaga = $vaga;
$this->dataHoraEntrada = date();
}
}
}
?>
9 changes: 9 additions & 0 deletions php/oop/Estacionamento.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Estacionamento{
class Vaga{
private $horaAbertura;
private $horaFechamento;
private $precoPorHora;
}
}
?>
14 changes: 14 additions & 0 deletions php/oop/Pagamento.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace Estacionamento{
class Pagamento{
private $estaciona;
private $dataHora;
private $valor;

function __construct($estaciona){
$this->estaciona = $estaciona;
$this->dataHora = date();
}
}
}
?>
8 changes: 8 additions & 0 deletions php/oop/Vaga.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Estacionamento{
class Vaga{
private $localizacao;
private $statusDisponibilidade;
}
}
?>
9 changes: 9 additions & 0 deletions php/oop/Veiculo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Estacionamento{
class Veiculo{
private $placa;
private $modelo;
private $cnhCondutor;
}
}
?>
34 changes: 34 additions & 0 deletions php/orders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

header('Content-Type: application/json');

class Pedido{
public $total_brl = 0.0;
public $total_usd = 0.0;

function __construct($id){
$this->id = $id;
$this->created_at = date('d/m/Y');
}

public function addItems($items){
foreach($items as $item){
$this->total_brl += $item;
}
$this->total_usd = $this->total_brl * 3.78;
}
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$items = $_POST['items'];
$pedido = new Pedido(1);
$pedido->addItems($items);
echo json_encode((array)$pedido);
}else if($_SERVER['REQUEST_METHOD'] === 'GET'){
$pedido = new Pedido(1);
$pedido->addItems([100,200,300]);
$pedido2 = new Pedido(2);
$pedido2->addItems([100,200,300]);
echo json_encode([$pedido, $pedido2]);
}

Loading