This repository has been archived by the owner on Aug 29, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[development] Create basic gem struct.
-- Warnning: Broken specs
- Loading branch information
Paulo Patto
committed
Feb 9, 2015
1 parent
a6a56c6
commit 61363b3
Showing
18 changed files
with
329 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,7 @@ | |
*.o | ||
*.a | ||
mkmf.log | ||
.*.sw? | ||
.ruby-version | ||
.rbenv-gemsets | ||
.rvmrc |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--color | ||
--require spec_helper |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
language: ruby | ||
|
||
rvm: | ||
- 1.9.3 | ||
- 2.0.0 | ||
- 2.1.1 | ||
- 2.1.2 | ||
- 2.1.5 | ||
- jruby | ||
|
||
notifications: | ||
- paulopatto@gmail.com |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require './lib/footstats/resource' | ||
|
||
class Footstats::Racing::Championship < Footstats::Resource | ||
field :drivers, :Pilotos | ||
field :teams, :Escuderias | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require './lib/footstats/resource' | ||
module Footstats | ||
module Racing | ||
class Driver < Footstats::Resource | ||
field :id, :Id | ||
field :name, :Nome | ||
field :brith, :Nascimento | ||
field :points, :PontosConquistados | ||
field :podiums, :Podios | ||
field :first_gp, :PrimeiroGP | ||
field :nickname, :Apelido | ||
field :brith_place, :PaisOrigem | ||
field :nationality, :Nacionalidade | ||
field :fastest_laps, :VoltasRapidas | ||
field :word_championships, :Titulos | ||
field :highest_grid_position, :Vitorias | ||
field :highest_race_position, :PolesPositions | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require './lib/footstats/resource' | ||
|
||
class Footstats::Racing::GP < Footstats::Resource | ||
field :id, :Id | ||
field :track_name, :AutodromoName | ||
field :track_nickname, :AutodromoApelido | ||
field :distance, :DisatnciaPista | ||
field :location, :Local | ||
field :brazilian_time, :DataHoraBrasil | ||
field :local_time, :DataHoraLocal | ||
field :laps, :QtdVoltas | ||
field :status, :Status | ||
field :atual_lap, :VoltaAtual | ||
field :active, :Ativo | ||
field :city, :Cidade | ||
field :country, :Pais | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require './lib/footstats/resource' | ||
|
||
class Footstats::Racing::Narration < Footstats::Resource | ||
field :id, :Id | ||
field :status, :status | ||
field :current_lap, :VoltaAtual | ||
field :datetime, :DataHora | ||
field :comment, :Comentario | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require './lib/footstats/resource' | ||
|
||
class Footstats::Racing::Ranking < Footstats::Resource | ||
field :position, :Posicao | ||
field :driver_id, :IdPiloto | ||
field :driver_name, :NomePiloto | ||
field :best_lap, :MelhorVolta | ||
field :team, :Escuderia | ||
field :acronym, :Sigla | ||
field :type, :Tipo | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require './lib/footstats/resource' | ||
|
||
class Footstats::Racing::Team < Footstats::Resource | ||
field :id, :Id | ||
field :name, :Nome | ||
field :nickname, :Apelido | ||
field :site, :Site | ||
field :country, :SiglaPais | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'httparty' | ||
|
||
module Footstats | ||
module Request | ||
class Base | ||
include HTTParty | ||
TOKEN = ENV['FOOTSTATS_TOKEN'] | ||
|
||
protected | ||
def self.request( method = "", api = "", params={} ) | ||
params.merge({ token: TOKEN }) | ||
|
||
JSON.parse(get("#{api}/#{method}", { query: params }).body) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require './lib/footstats/request/base' | ||
require './lib/footstats/racing/driver.rb' | ||
require './lib/footstats/racing/team.rb' | ||
|
||
module Footstats | ||
module Request | ||
class RequestRacing < Base | ||
API = "http://apicorrida.footstats.com.br/api" | ||
|
||
def self.drivers | ||
request("Piloto/ListaPilotos").map { |driver| Footstats::Racing::Driver.new(driver) } | ||
end | ||
|
||
def self.teams | ||
request("Escuderia/ListaEscuderias").map { |team| Footstats::Racing::Team.new(team) } | ||
end | ||
|
||
def self.gps | ||
request("GP/Calendario").map { |gp| Footstats::Racing::GP.new(gp) } | ||
end | ||
|
||
# Retorna uma lista com os comentários sobre o GP. | ||
# :offset (MaxId) é o Id do comentário, quando um valor é passado ele | ||
# só retorna os comentários posteriores. | ||
# Quando o valor passado for 0 ele retorna todos os comentários do GP. | ||
# | ||
# Latência de chamada: | ||
# -------------------- | ||
# 1 Minuto enquanto o status do GP for: | ||
# | ||
# - Treino Livre 1 | ||
# - Treino Livre 2 | ||
# - Treino Livre 3 | ||
# - Q1 | ||
# - Q2 | ||
# - Q3 | ||
# - Corrida | ||
def self.narration(gp_id, offset = 0) | ||
request("GP/Narracao", {idGP: gp_id, MaxId: offset}).map do |narration| | ||
Footstats::Racing::Narration.new(narration) | ||
end | ||
end | ||
|
||
# Lista as classificações dos | ||
# - Treinos Livres | ||
# - Qualify | ||
# - Corrida | ||
# | ||
# Latência de chamada: | ||
# -------------------- | ||
# 1 Minuto enquanto o status do GP for | ||
# | ||
# - Treino Livre 1 | ||
# - Treino Livre 2 | ||
# - Treino Livre 3 | ||
# - Q1 | ||
# - Q2 | ||
# - Q3 | ||
# - Corrida | ||
def self.rankings(gp_id) | ||
request("GP/ClassificacaoGP").map do |fase| | ||
binding.pry | ||
end | ||
end | ||
|
||
protected | ||
def self.request(method, params = {}) | ||
super(method, API, params) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Footstats | ||
class Resource | ||
@@fields = {} | ||
|
||
def initialize(attributes={}) | ||
attributes.each do |attr_name, value| | ||
if @@fields.include? attr_name.to_sym | ||
send("#{@@fields[attr_name.to_sym]}=", value) | ||
end | ||
end | ||
end | ||
|
||
def self.field(internal_key, external_key) | ||
@@fields[external_key] = internal_key | ||
|
||
attr_accessor internal_key | ||
end | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'spec_helper' | ||
require './lib/footstats/resource' | ||
|
||
describe Footstats::Resource do | ||
subject { described_class } | ||
|
||
describe ".field" do | ||
before do | ||
subject.field(:test, 'Test') | ||
end | ||
|
||
it "adds given attribute a reader" do | ||
expect(described_class.new).to respond_to :test | ||
end | ||
|
||
it "adds given attribute a writer" do | ||
expect(described_class.new).to respond_to :test= | ||
end | ||
end | ||
|
||
describe ".new" do | ||
context "when sends pt-br attributes" do | ||
let(:name) { "Bruce Wayne" } | ||
let(:resource) { subject.new({"Nome" => name}) } | ||
|
||
before do | ||
subject.field :name, :Nome | ||
end | ||
|
||
it "transforms hash key Name in attr name" do | ||
expect(resource).to be_respond_to(:name) | ||
end | ||
|
||
it "puts value of key Name in attr name" do | ||
expect(resource.name).to eq(name) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'spec_helper' | ||
require './lib/footstats/racing/driver' | ||
|
||
describe Footstats::Racing::Driver do | ||
subject { described_class } | ||
|
||
describe ".new" do | ||
let (:attributes) do | ||
{ | ||
Nome: "Lewis Hamilton", | ||
Nascimento: "08/03/1987", | ||
Vitorias: "38" | ||
} | ||
end | ||
|
||
let(:driver) { subject.new(attributes) } | ||
|
||
it "sets correct name attribute" do | ||
exepct(driver.name).to_not be_nil | ||
expect(driver.name).to eq("Lewis Hamilton") | ||
end | ||
|
||
it "doesn't set incorrect attr" do | ||
expect(driver).to_not be_respond_to(:Nome) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require './lib/footstats/request/request_racing' | ||
|
||
describe Footstats::Request::RequestRacing do | ||
describe ".drivers" do | ||
subject { described_class.drivers } | ||
|
||
it "list all drivers as collection :array" do | ||
expect(subject).to be_kind_of(Array) | ||
end | ||
|
||
it "list all drivers as collection Array<Driver>" do | ||
expect(subject.first).to be_kind_of(Footstats::Racing::Driver) | ||
end | ||
end | ||
|
||
describe ".teams" do | ||
subject { described_class.teams } | ||
|
||
it "list all teams as collection Array<Team>" do | ||
expect(subject.first).to be_kind_of(Footstats::Racing::Team) | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'pry' | ||
require 'footstats' | ||
|
||
RSpec.configure do |config| | ||
config.color = true | ||
config.default_formatter = 'doc' | ||
config.order = :random | ||
config.filter_run :focus | ||
config.expect_with :rspec do |expectations| | ||
# This option will default to `true` in RSpec 4. It makes the `description` | ||
# and `failure_message` of custom matchers include text for helper methods | ||
# defined using `chain`, e.g.: | ||
# be_bigger_than(2).and_smaller_than(4).description | ||
# # => "be bigger than 2 and smaller than 4" | ||
# ...rather than: | ||
# # => "be bigger than 2" | ||
expectations.include_chain_clauses_in_custom_matcher_descriptions = true | ||
end | ||
config.warnings = true | ||
|
||
# rspec-mocks config goes here. You can use an alternate test double | ||
# library (such as bogus or mocha) by changing the `mock_with` option here. | ||
config.mock_with :rspec do |mocks| | ||
# Prevents you from mocking or stubbing a method that does not exist on | ||
# a real object. This is generally recommended, and will default to | ||
# `true` in RSpec 4. | ||
mocks.verify_partial_doubles = true | ||
end | ||
end |