diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 8272487..6dceb8d 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -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 diff --git a/lib/warframe/models/vallis_cycle.rb b/lib/warframe/models/vallis_cycle.rb new file mode 100644 index 0000000..df03a0d --- /dev/null +++ b/lib/warframe/models/vallis_cycle.rb @@ -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 diff --git a/lib/warframe/rest/api.rb b/lib/warframe/rest/api.rb index 9a5acdb..2c4891e 100644 --- a/lib/warframe/rest/api.rb +++ b/lib/warframe/rest/api.rb @@ -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. # @@ -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 diff --git a/lib/warframe/rest/api/vallis_cycle.rb b/lib/warframe/rest/api/vallis_cycle.rb new file mode 100644 index 0000000..5a4b380 --- /dev/null +++ b/lib/warframe/rest/api/vallis_cycle.rb @@ -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 diff --git a/spec/fixtures/vallis_cycle.json b/spec/fixtures/vallis_cycle.json new file mode 100644 index 0000000..1124773 --- /dev/null +++ b/spec/fixtures/vallis_cycle.json @@ -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" +} diff --git a/spec/models/vallis_cycle_spec.rb b/spec/models/vallis_cycle_spec.rb new file mode 100644 index 0000000..ca65bcf --- /dev/null +++ b/spec/models/vallis_cycle_spec.rb @@ -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 diff --git a/spec/rest/rest_spec.rb b/spec/rest/rest_spec.rb index ac0157d..161fced 100644 --- a/spec/rest/rest_spec.rb +++ b/spec/rest/rest_spec.rb @@ -48,6 +48,18 @@ 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 } @@ -55,4 +67,5 @@ def nightwave cetus cambion nightwave + vallis_cycle end