warframe 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +45 -0
  3. data/README.md +39 -34
  4. data/lib/warframe/api/alerts.rb +14 -0
  5. data/lib/warframe/api/cambion_drift.rb +16 -0
  6. data/lib/warframe/api/cetus.rb +16 -0
  7. data/lib/warframe/api/conclave_challenges.rb +16 -0
  8. data/lib/warframe/api/global_upgrades.rb +16 -0
  9. data/lib/warframe/api/invasions.rb +16 -0
  10. data/lib/warframe/api/news.rb +16 -0
  11. data/lib/warframe/api/nightwave.rb +16 -0
  12. data/lib/warframe/api/sortie.rb +16 -0
  13. data/lib/warframe/api/steel_path.rb +16 -0
  14. data/lib/warframe/api/syndicate_missions.rb +16 -0
  15. data/lib/warframe/api/vallis_cycle.rb +16 -0
  16. data/lib/warframe/api.rb +24 -0
  17. data/lib/warframe/cache.rb +3 -3
  18. data/lib/warframe/client.rb +98 -0
  19. data/lib/warframe/models/alert.rb +16 -23
  20. data/lib/warframe/models/attributes/active.rb +2 -2
  21. data/lib/warframe/models/attributes/description.rb +12 -16
  22. data/lib/warframe/models/attributes/eta.rb +6 -10
  23. data/lib/warframe/models/attributes/expiry.rb +20 -24
  24. data/lib/warframe/models/attributes/id.rb +6 -10
  25. data/lib/warframe/models/attributes/reward_types.rb +6 -10
  26. data/lib/warframe/models/attributes/start_string.rb +6 -10
  27. data/lib/warframe/models/attributes/translations.rb +9 -13
  28. data/lib/warframe/models/base.rb +5 -30
  29. data/lib/warframe/models/cambion_drift.rb +14 -19
  30. data/lib/warframe/models/cetus.rb +25 -30
  31. data/lib/warframe/models/conclave_challenge.rb +43 -50
  32. data/lib/warframe/models/global_upgrade.rb +33 -37
  33. data/lib/warframe/models/invasion.rb +58 -67
  34. data/lib/warframe/models/news.rb +45 -50
  35. data/lib/warframe/models/nightwave.rb +24 -30
  36. data/lib/warframe/models/objectified_hash.rb +74 -0
  37. data/lib/warframe/models/sortie.rb +21 -27
  38. data/lib/warframe/models/steel_path.rb +22 -24
  39. data/lib/warframe/models/syndicate_mission.rb +18 -24
  40. data/lib/warframe/models/vallis_cycle.rb +30 -0
  41. data/lib/warframe/models.rb +6 -0
  42. data/lib/warframe/version.rb +1 -1
  43. data/lib/warframe.rb +4 -2
  44. data/warframe.gemspec +41 -0
  45. metadata +42 -106
  46. data/lib/warframe/client_wrapper.rb +0 -39
  47. data/lib/warframe/rest/api/alerts.rb +0 -23
  48. data/lib/warframe/rest/api/cambion_drift.rb +0 -23
  49. data/lib/warframe/rest/api/cetus.rb +0 -23
  50. data/lib/warframe/rest/api/conclave_challenges.rb +0 -23
  51. data/lib/warframe/rest/api/global_upgrades.rb +0 -23
  52. data/lib/warframe/rest/api/invasions.rb +0 -23
  53. data/lib/warframe/rest/api/news.rb +0 -23
  54. data/lib/warframe/rest/api/nightwave.rb +0 -23
  55. data/lib/warframe/rest/api/sortie.rb +0 -23
  56. data/lib/warframe/rest/api/steel_path.rb +0 -23
  57. data/lib/warframe/rest/api/syndicate_missions.rb +0 -23
  58. data/lib/warframe/rest/api.rb +0 -37
  59. data/lib/warframe/rest/client.rb +0 -42
  60. data/lib/warframe/rest/request.rb +0 -61
  61. data/lib/warframe/rest/utils.rb +0 -23
@@ -1,54 +1,49 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './base'
4
- require_relative './attributes/translations'
5
- require_relative './attributes/eta'
6
- require_relative './attributes/id'
7
-
8
- module Warframe
9
- module Models
10
- # News data model.
11
- # {https://api.warframestat.us/pc/news /:platform/news}
12
- class News < Warframe::Models::Base
13
- include Warframe::Models::Attributes::Translations
14
- include Warframe::Models::Attributes::ETA
15
- include Warframe::Models::Attributes::ID
16
-
17
- # The date the news was released.
18
- # @return [String]
19
- attr_reader :date
20
-
21
- # The image link from the news page.
22
- # @return [String]
23
- attr_reader :image_link
24
-
25
- # Link for more information on this news.
26
- # @return [String]
27
- attr_reader :link
28
-
29
- # Whether or not the news has to do with Prime Access.
30
- # @return [Boolean]
31
- attr_reader :prime_access
32
- alias prime_access? prime_access
33
-
34
- # Whether or not a DEV stream is available.
35
- # @return [Boolean]
36
- attr_reader :stream
37
- alias stream? stream
38
-
39
- # Whether or not this news is regarding an update.
40
- # @return [Boolean]
41
- attr_reader :update
42
- alias update? update
43
-
44
- # Whether or not this news is of priority.
45
- # @return [Boolean]
46
- attr_reader :priority
47
- alias priority? priority
48
-
49
- # The entire response as a long string.
50
- # @return [String]
51
- attr_reader :as_string
52
- end
3
+ require_rel 'base'
4
+
5
+ module Warframe::Models
6
+ # News data model.
7
+ # {https://api.warframestat.us/pc/news /:platform/news}
8
+ class News < Base
9
+ include Attributes::Translations
10
+ include Attributes::ETA
11
+ include Attributes::ID
12
+
13
+ # The date the news was released.
14
+ # @return [String]
15
+ attr_reader :date
16
+
17
+ # The image link from the news page.
18
+ # @return [String]
19
+ attr_reader :image_link
20
+
21
+ # Link for more information on this news.
22
+ # @return [String]
23
+ attr_reader :link
24
+
25
+ # Whether or not the news has to do with Prime Access.
26
+ # @return [Boolean]
27
+ attr_reader :prime_access
28
+ alias prime_access? prime_access
29
+
30
+ # Whether or not a DEV stream is available.
31
+ # @return [Boolean]
32
+ attr_reader :stream
33
+ alias stream? stream
34
+
35
+ # Whether or not this news is regarding an update.
36
+ # @return [Boolean]
37
+ attr_reader :update
38
+ alias update? update
39
+
40
+ # Whether or not this news is of priority.
41
+ # @return [Boolean]
42
+ attr_reader :priority
43
+ alias priority? priority
44
+
45
+ # The entire response as a long string.
46
+ # @return [String]
47
+ attr_reader :as_string
53
48
  end
54
49
  end
@@ -1,40 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './base'
4
- require_relative './attributes/active'
5
- require_relative './attributes/id'
6
- require_relative './attributes/expiry'
7
- require_relative './attributes/reward_types'
3
+ require_rel 'base'
8
4
 
9
- module Warframe
10
- module Models
11
- # Nightwave data model.
12
- # {https://api.warframestat.us/pc/nightwave /:platform/nightwave}
13
- class Nightwave < Warframe::Models::Base
14
- include Warframe::Models::Attributes::Activation
15
- include Warframe::Models::Attributes::ID
16
- include Warframe::Models::Attributes::Expiry
17
- include Warframe::Models::Attributes::RewardTypes
5
+ module Warframe::Models
6
+ # Nightwave data model.
7
+ # {https://api.warframestat.us/pc/nightwave /:platform/nightwave}
8
+ class Nightwave < Base
9
+ include Attributes::Activation
10
+ include Attributes::ID
11
+ include Attributes::Expiry
12
+ include Attributes::RewardTypes
18
13
 
19
- # The current phase of this event.
20
- # @return [Integer]
21
- attr_reader :phase
14
+ # The current phase of this event.
15
+ # @return [Integer]
16
+ attr_reader :phase
22
17
 
23
- # The current Nightwave Tag
24
- # @return [String]
25
- attr_reader :tag
18
+ # The current Nightwave Tag
19
+ # @return [String]
20
+ attr_reader :tag
26
21
 
27
- # The current Nightwave Season
28
- # @return [Integer]
29
- attr_reader :season
22
+ # The current Nightwave Season
23
+ # @return [Integer]
24
+ attr_reader :season
30
25
 
31
- # List of all possible challenges.
32
- # @return [Array<OpenStruct>]
33
- attr_reader :possible_challenges
26
+ # List of all possible challenges.
27
+ # @return [Array<OpenStruct>]
28
+ attr_reader :possible_challenges
34
29
 
35
- # Active Challenges for this event.
36
- # @return [Array<OpenStruct>]
37
- attr_reader :active_challenges
38
- end
30
+ # Active Challenges for this event.
31
+ # @return [Array<OpenStruct>]
32
+ attr_reader :active_challenges
39
33
  end
40
34
  end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Warframe::Models
4
+ # An objectified hash response. Used for turning raw JSON objects into a ruby friendly object.
5
+ # This can be accessed in multiple formats, ie: JSON `obj['String']` access, Ruby hash `obj[:symbol]`,
6
+ # Ruby object `obj.method`.
7
+ # This also handles serialization of nested hashes or arrays of hashes, which in turn will become
8
+ # a Waframe::Models::ObjectifiedHash.
9
+ class ObjectifiedHash
10
+ def initialize(data)
11
+ @data = transform_to_hash(data)
12
+ populate_object
13
+ end
14
+
15
+ def [](key)
16
+ @data[key] || @data[string_to_symbol(key)]
17
+ end
18
+
19
+ def to_hash # rubocop:todo Metrics/CyclomaticComplexity
20
+ @to_hash ||= @data.each_with_object({}) do |(k, v), hash|
21
+ v = v.to_h if v.is_a?(Warframe::Models::ObjectifiedHash) && !v.empty?
22
+ v = v.map(&:to_h) if v.is_a?(Array) && v.first.is_a?(Warframe::Models::ObjectifiedHash)
23
+ hash[k] = v
24
+ end
25
+ end
26
+ alias to_h to_hash
27
+ alias hash to_hash
28
+
29
+ def to_s
30
+ @to_s ||= hash.to_s
31
+ end
32
+
33
+ def self.from_array(arr)
34
+ arr.map { |data| new(data) if data.is_a?(Hash) }.compact
35
+ end
36
+
37
+ # @return [String] Formatted string with the class name, object id and original hash.
38
+ def inspect
39
+ "#<#{self.class}:#{object_id} { data: #{data.inspect} }".gsub('\"', '')
40
+ end
41
+
42
+ def size
43
+ @data.size
44
+ end
45
+
46
+ private
47
+
48
+ attr_reader :data
49
+
50
+ def populate_object # rubocop:todo Metrics/AbcSize
51
+ data.each do |k, v|
52
+ if v.is_a?(Hash) && v.size.positive?
53
+ v = ObjectifiedHash.new(v)
54
+ elsif v.is_a?(Array) && v.first.is_a?(Hash) && v.first.size.positive?
55
+ v = ObjectifiedHash.from_array(v)
56
+ end
57
+
58
+ self.class.send(:attr_reader, k)
59
+ instance_variable_set("@#{k}", v)
60
+ @data[k] = v
61
+ end
62
+ end
63
+
64
+ def transform_to_hash(hash)
65
+ hash.transform_keys { |data| string_to_symbol(data) }
66
+ rescue NoMethodError
67
+ pp "Error decoding: #{hash}"
68
+ end
69
+
70
+ def string_to_symbol(string)
71
+ string.split(/(?=[A-Z])/).map(&:downcase).join('_').to_sym
72
+ end
73
+ end
74
+ end
@@ -1,36 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './base'
4
- require_relative 'attributes/id'
5
- require_relative 'attributes/expiry'
6
- require_relative 'attributes/active'
7
- require_relative 'attributes/eta'
3
+ require_rel 'base'
8
4
 
9
- module Warframe
10
- module Models
11
- # Sortie data model.
12
- # {https://api.warframestat.us/pc/sortie /:platform/sortie}
13
- class Sortie < Warframe::Models::Base
14
- include Warframe::Models::Attributes::ID
15
- include Warframe::Models::Attributes::ActiveBoth
16
- include Warframe::Models::Attributes::Expiration
17
- include Warframe::Models::Attributes::ETA
5
+ # Sortie data model.
6
+ # {https://api.warframestat.us/pc/sortie /:platform/sortie}
7
+ module Warframe::Models
8
+ class Sortie < Base
9
+ include Attributes::ID
10
+ include Attributes::ActiveBoth
11
+ include Attributes::Expiration
12
+ include Attributes::ETA
18
13
 
19
- # The boss for this part of the sortie.
20
- # @return [String]
21
- attr_reader :boss
14
+ # The boss for this part of the sortie.
15
+ # @return [String]
16
+ attr_reader :boss
22
17
 
23
- # The faction fighting you in this mission.
24
- # @return [String]
25
- attr_reader :faction
18
+ # The faction fighting you in this mission.
19
+ # @return [String]
20
+ attr_reader :faction
26
21
 
27
- # Modifiers active for this challenge.
28
- # @return [Array<OpenStruct>]
29
- attr_reader :variants
22
+ # Modifiers active for this challenge.
23
+ # @return [Array<OpenStruct>]
24
+ attr_reader :variants
30
25
 
31
- # The reward pool which this is pulling from.
32
- # @return [String]
33
- attr_reader :reward_pool
34
- end
26
+ # The reward pool which this is pulling from.
27
+ # @return [String]
28
+ attr_reader :reward_pool
35
29
  end
36
30
  end
@@ -1,34 +1,32 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './base'
3
+ require_rel 'base'
4
4
 
5
- module Warframe
6
- module Models
7
- # SteelPath data model.
8
- # {https://api.warframestat.us/pc/steelPath /:platform/steelPath}
9
- class SteelPath < Warframe::Models::Base
10
- include Warframe::Models::Attributes::Active
11
- include Warframe::Models::Attributes::Expiry
5
+ # SteelPath data model.
6
+ # {https://api.warframestat.us/pc/steelPath /:platform/steelPath}
7
+ module Warframe::Models
8
+ class SteelPath < Base
9
+ include Attributes::Active
10
+ include Attributes::Expiry
12
11
 
13
- # The currently available item from Teshin.
14
- # @return [OpenStruct]
15
- attr_reader :current_reward
12
+ # The currently available item from Teshin.
13
+ # @return [OpenStruct]
14
+ attr_reader :current_reward
16
15
 
17
- # The time remaining of the current reward.
18
- # @return [String]
19
- attr_reader :remaining
16
+ # The time remaining of the current reward.
17
+ # @return [String]
18
+ attr_reader :remaining
20
19
 
21
- # Current rotation of items the Arbiters have to offer.
22
- # @return [Array<OpenStruct>]
23
- attr_reader :rotation
20
+ # Current rotation of items the Arbiters have to offer.
21
+ # @return [Array<OpenStruct>]
22
+ attr_reader :rotation
24
23
 
25
- # Current rotation of items Teshin has to offer.
26
- # @return [Array<OpenStruct>]
27
- attr_reader :evergreens
24
+ # Current rotation of items Teshin has to offer.
25
+ # @return [Array<OpenStruct>]
26
+ attr_reader :evergreens
28
27
 
29
- # Current incursion data
30
- # @return [OpenStruct]
31
- attr_reader :incursions
32
- end
28
+ # Current incursion data
29
+ # @return [OpenStruct]
30
+ attr_reader :incursions
33
31
  end
34
32
  end
@@ -1,32 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative './base'
4
- require_relative 'attributes/eta'
5
- require_relative 'attributes/id'
6
- require_relative 'attributes/active'
7
- require_relative 'attributes/start_string'
3
+ require_rel 'base'
8
4
 
9
- module Warframe
10
- module Models
11
- # SyndicateMission data model.
12
- # {https://api.warframestat.us/pc/syndicateMissions /:platform/syndicateMissions}
13
- class SyndicateMission < Warframe::Models::Base
14
- include Warframe::Models::Attributes::ETA
15
- include Warframe::Models::Attributes::ID
16
- include Warframe::Models::Attributes::ActiveBoth
17
- include Warframe::Models::Attributes::StartString
5
+ # SyndicateMission data model.
6
+ # {https://api.warframestat.us/pc/syndicateMissions /:platform/syndicateMissions}
7
+ module Warframe::Models
8
+ class SyndicateMission < Base
9
+ include Attributes::ETA
10
+ include Attributes::ID
11
+ include Attributes::ActiveBoth
12
+ include Attributes::StartString
18
13
 
19
- # 'Jobs' or challenges currently available.
20
- # @return [Array<OpenStruct>]
21
- attr_reader :jobs
14
+ # 'Jobs' or challenges currently available.
15
+ # @return [Array<OpenStruct>]
16
+ attr_reader :jobs
22
17
 
23
- # The syndicate you will be fighting.
24
- # @return [String]
25
- attr_reader :syndicate
18
+ # The syndicate you will be fighting.
19
+ # @return [String]
20
+ attr_reader :syndicate
26
21
 
27
- # The nodes that this mission is available on.
28
- # @return [Array]
29
- attr_reader :nodes
30
- end
22
+ # The nodes that this mission is available on.
23
+ # @return [Array]
24
+ attr_reader :nodes
31
25
  end
32
26
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_rel 'base'
4
+
5
+ module Warframe::Models
6
+ # Model for VallisCycle data.
7
+ # {https://api.warframestat.us/pc/vallisCycle /:platform/vallisCycle}
8
+ class VallisCycle < Base
9
+ include Attributes::ID
10
+ include Attributes::Expiry
11
+ include Attributes::Activation
12
+
13
+ # @!attribute time_left
14
+ # @return [String] time left until next cycle.
15
+ attr_reader :time_left
16
+
17
+ # @!attribute is_warm?
18
+ # @return [Boolean] whether or not it currently is warm.
19
+ attr_reader :is_warm
20
+ alias is_warm? is_warm
21
+
22
+ # @!attribute state
23
+ # @return [String] the current world state (Cold or Warm)
24
+ attr_reader :state
25
+
26
+ # @!attribute short_string
27
+ # @return [String] the time remaining until state change. Ex: `5m to Warm`.
28
+ attr_reader :short_string
29
+ end
30
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_rel 'models'
4
+
5
+ # Currently supported models.
6
+ module Warframe::Models; end
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Warframe
4
4
  # The current version of this gem.
5
- VERSION = '0.3.1'
5
+ VERSION = '1.0.0'
6
6
  end
data/lib/warframe.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'warframe/version'
4
- require 'warframe/rest/client'
3
+ require 'require_all'
4
+ require 'rest-client'
5
+ require 'json'
6
+ require_rel 'warframe'
5
7
 
6
8
  # Warframe Stat Ruby Client main module
7
9
  module Warframe; end
data/warframe.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/warframe/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ # Required
7
+ spec.name = 'warframe'
8
+ spec.version = Warframe::VERSION
9
+ spec.authors = ['A.J. Romaniello', 'Warframe Community Developers']
10
+
11
+ # Descriptive
12
+ spec.summary = 'A Ruby interface to the WarframeStat API.'
13
+ spec.description = spec.summary
14
+ spec.license = 'MIT'
15
+ spec.homepage = 'https://gitlab.com/aj-rom/warframe-ruby'
16
+
17
+ # MetaData
18
+ spec.metadata['source_code_uri'] = "#{spec.homepage}/-/tree/v#{spec.version}"
19
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/-/tree/v#{spec.version}/CHANGELOG.md"
20
+ spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/-/issues"
21
+ spec.metadata['documentation_uri'] = "https://rubydoc.info/gems/#{spec.name}/#{spec.version}"
22
+
23
+ # Executables / Files
24
+ spec.bindir = 'exe'
25
+ spec.require_paths = ['lib']
26
+
27
+ # Specify which files should be added to the gem when it is released.
28
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
+ `git ls-files -z lib *.gemspec README.md CHANGELOG.md *.txt .yardopts`.split("\x0")
31
+ end
32
+
33
+ # Dependencies
34
+ spec.required_ruby_version = '>= 2.3' # rubocop:disable Gemspec/RequiredRubyVersion
35
+ spec.add_dependency 'fast_underscore', '~> 0.3'
36
+ spec.add_dependency 'require_all', '~> 3.0'
37
+ spec.add_dependency 'rest-client', '~> 2.1'
38
+
39
+ # Development Dependencies
40
+ spec.add_development_dependency 'bundler', '~> 2.3'
41
+ end