Skip to content

Commit

Permalink
feat(REST): add vallisCycle route. (#61)
Browse files Browse the repository at this point in the history
* feat(REST): add `vallisCycle` route.

* ci(rspec): use `head` for latest ruby version
  • Loading branch information
aj-rom committed Jan 1, 2022
1 parent 07148e2 commit f81577f
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
ruby: [ '2.5', '2.6', '3.0', '3.1' ]
ruby: [ '2.5', '2.6', '3.0', head ]
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
Expand Down
35 changes: 35 additions & 0 deletions lib/warframe/models/vallis_cycle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

require_relative './base'
require_relative './attributes/id'
require_relative './attributes/active'
require_relative './attributes/expiry'

module Warframe
module Models
# Model for VallisCycle data.
# {https://api.warframestat.us/pc/vallisCycle /:platform/vallisCycle}
class VallisCycle < Warframe::Models::Base
include Warframe::Models::Attributes::ID
include Warframe::Models::Attributes::Expiry
include Warframe::Models::Attributes::Activation

# @!attribute time_left
# @return [String] time left until next cycle.
attr_reader :time_left

# @!attribute is_warm?
# @return [Boolean] whether or not it currently is warm.
attr_reader :is_warm
alias is_warm? is_warm

# @!attribute state
# @return [String] the current world state (Cold or Warm)
attr_reader :state

# @!attribute short_string
# @return [String] the time remaining until state change. Ex: `5m to Warm`.
attr_reader :short_string
end
end
end
4 changes: 3 additions & 1 deletion lib/warframe/rest/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
require_relative 'api/sortie'
require_relative 'api/steel_path'
require_relative 'api/syndicate_missions'
require_relative 'api/vallis_cycle'

module Warframe
# A REST-ful API service, provided by https://api.warframestat.us.
# A REST-ful API service, provided by https://api.warframestat.us
module REST
# The API Router for getting live data.
#
Expand All @@ -32,6 +33,7 @@ module API
include Warframe::REST::API::Sortie
include Warframe::REST::API::SteelPath
include Warframe::REST::API::SyndicateMissions
include Warframe::REST::API::VallisCycle
end
end
end
23 changes: 23 additions & 0 deletions lib/warframe/rest/api/vallis_cycle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'warframe/models/vallis_cycle'
require_relative '../utils'

module Warframe
module REST
module API
# API endpoint for getting information on current VallisCycle data.
#
# {https://api.warframestat.us/pc/vallisCycle Example Response}
module VallisCycle
include Warframe::REST::Utils

# Gets the current vallisCycle Data.
# @return [Warframe::Models::VallisCycle]
def vallis_cycle
get('/vallisCycle', Warframe::Models::VallisCycle)
end
end
end
end
end
9 changes: 9 additions & 0 deletions spec/fixtures/vallis_cycle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "vallisCycle1641060420000",
"expiry": "2022-01-01T18:27:08.000Z",
"isWarm": false,
"state": "cold",
"activation": "2022-01-01T18:07:00.000Z",
"timeLeft": "5m 32s",
"shortString": "5m to Warm"
}
16 changes: 16 additions & 0 deletions spec/models/vallis_cycle_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

RSpec.describe Warframe::Models::VallisCycle do
let(:json) { load_json_file 'vallis_cycle' }

it 'can be instantiated from JSON' do
expect { Warframe::Models::VallisCycle.new(json) }.to_not raise_error
end

let(:cycle) { Warframe::Models::VallisCycle.new(json) }

it 'can read VallisCycle data' do
expect(cycle.state).to eq 'cold'
expect(cycle.is_warm?).to eq false
end
end
13 changes: 13 additions & 0 deletions spec/rest/rest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,24 @@ def nightwave
end
end

def vallis_cycle
context '#vallis_cycle' do
it 'does not raise error on call' do
expect { client.vallis_cycle }.to_not raise_error
end

it 'properly loads data into model' do
expect(client.vallis_cycle).to be_a Warframe::Models::VallisCycle
end
end
end

RSpec.describe Warframe::REST::API do
let(:client) { Warframe::REST::Client.new }

alerts
cetus
cambion
nightwave
vallis_cycle
end

0 comments on commit f81577f

Please sign in to comment.