lapis-minecraft-versioning 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +18 -0
  3. data/.gitignore +151 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +1156 -0
  6. data/.travis.yml +4 -0
  7. data/Gemfile +4 -0
  8. data/LICENSE.md +16 -0
  9. data/README.md +83 -0
  10. data/Rakefile +28 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +7 -0
  13. data/lapis-minecraft-versioning.gemspec +35 -0
  14. data/lib/lapis/minecraft/version.rb +89 -0
  15. data/lib/lapis/minecraft/versioning.rb +26 -0
  16. data/lib/lapis/minecraft/versioning/asset.rb +44 -0
  17. data/lib/lapis/minecraft/versioning/asset_index.rb +61 -0
  18. data/lib/lapis/minecraft/versioning/basic.rb +56 -0
  19. data/lib/lapis/minecraft/versioning/detailed.rb +69 -0
  20. data/lib/lapis/minecraft/versioning/launcher_properties.rb +48 -0
  21. data/lib/lapis/minecraft/versioning/library.rb +51 -0
  22. data/lib/lapis/minecraft/versioning/manifest.rb +49 -0
  23. data/lib/lapis/minecraft/versioning/marshalling.rb +15 -0
  24. data/lib/lapis/minecraft/versioning/marshalling/asset_index_parser.rb +41 -0
  25. data/lib/lapis/minecraft/versioning/marshalling/manifest_parser.rb +66 -0
  26. data/lib/lapis/minecraft/versioning/marshalling/version_parser.rb +204 -0
  27. data/lib/lapis/minecraft/versioning/meta_server.rb +52 -0
  28. data/lib/lapis/minecraft/versioning/os_rule.rb +45 -0
  29. data/lib/lapis/minecraft/versioning/resource.rb +44 -0
  30. data/lib/lapis/minecraft/versioning/resource_set.rb +61 -0
  31. data/lib/lapis/minecraft/versioning/rule.rb +32 -0
  32. data/lib/lapis/minecraft/versioning/version.rb +7 -0
  33. data/lib/lapis/minecraft/versioning/version_list.rb +64 -0
  34. data/spec/factories/asset_factory.rb +11 -0
  35. data/spec/factories/asset_index_document_factory.rb +25 -0
  36. data/spec/factories/asset_index_factory.rb +15 -0
  37. data/spec/factories/basic_factory.rb +28 -0
  38. data/spec/factories/detailed_factory.rb +16 -0
  39. data/spec/factories/launcher_properties_factory.rb +11 -0
  40. data/spec/factories/library_factory.rb +21 -0
  41. data/spec/factories/manifest_document_factory.rb +48 -0
  42. data/spec/factories/manifest_factory.rb +12 -0
  43. data/spec/factories/meta_server_mock_factory.rb +33 -0
  44. data/spec/factories/os_rule_factory.rb +30 -0
  45. data/spec/factories/resource_factory.rb +32 -0
  46. data/spec/factories/resource_set_factory.rb +16 -0
  47. data/spec/factories/rule_factory.rb +17 -0
  48. data/spec/factories/version_document_factory.rb +176 -0
  49. data/spec/factories/version_factory.rb +18 -0
  50. data/spec/lapis/minecraft/version_spec.rb +181 -0
  51. data/spec/lapis/minecraft/versioning/asset_index_spec.rb +89 -0
  52. data/spec/lapis/minecraft/versioning/asset_spec.rb +65 -0
  53. data/spec/lapis/minecraft/versioning/basic_spec.rb +75 -0
  54. data/spec/lapis/minecraft/versioning/detailed_spec.rb +175 -0
  55. data/spec/lapis/minecraft/versioning/launcher_properties_spec.rb +73 -0
  56. data/spec/lapis/minecraft/versioning/library_spec.rb +91 -0
  57. data/spec/lapis/minecraft/versioning/manifest_spec.rb +71 -0
  58. data/spec/lapis/minecraft/versioning/marshalling/asset_index_parser_spec.rb +27 -0
  59. data/spec/lapis/minecraft/versioning/marshalling/manifest_parser_spec.rb +74 -0
  60. data/spec/lapis/minecraft/versioning/marshalling/version_parser_spec.rb +101 -0
  61. data/spec/lapis/minecraft/versioning/meta_server_spec.rb +59 -0
  62. data/spec/lapis/minecraft/versioning/os_rule_spec.rb +73 -0
  63. data/spec/lapis/minecraft/versioning/resource_set_spec.rb +87 -0
  64. data/spec/lapis/minecraft/versioning/resource_spec.rb +55 -0
  65. data/spec/lapis/minecraft/versioning/rule_spec.rb +36 -0
  66. data/spec/lapis/minecraft/versioning/version_list_spec.rb +66 -0
  67. data/spec/spec_helper.rb +90 -0
  68. data/spec/time_helper.rb +39 -0
  69. metadata +289 -0
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Gem dependencies and information defined in lapis-minecraft-versioning.gemspec
4
+ gemspec
@@ -0,0 +1,16 @@
1
+ The MIT License (MIT)
2
+ =====================
3
+
4
+ *Copyright (c) 2016 Lapis MC*
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
8
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
9
+ persons to whom the Software is furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,83 @@
1
+ Minecraft Version Info
2
+ ======================
3
+
4
+ [![Travis CI](https://travis-ci.org/lapis-mc/minecraft-versioning.svg)](https://travis-ci.org/lapis-mc/minecraft-versioning)
5
+ [![Code Climate](https://codeclimate.com/github/lapis-mc/minecraft-versioning/badges/gpa.svg)](https://codeclimate.com/github/lapis-mc/minecraft-versioning)
6
+ [![Test Coverage](https://codeclimate.com/github/lapis-mc/minecraft-versioning/badges/coverage.svg)](https://codeclimate.com/github/lapis-mc/minecraft-versioning/coverage)
7
+ [![Issue Count](https://codeclimate.com/github/lapis-mc/minecraft-versioning/badges/issue_count.svg)](https://codeclimate.com/github/lapis-mc/minecraft-versioning)
8
+
9
+ Retrieves and processes information about versions of Minecraft.
10
+ Small library for getting version information from Mojang about Minecraft.
11
+ Includes a command-line utility as well.
12
+
13
+ Installation
14
+ ------------
15
+
16
+ Add this line to your application's Gemfile:
17
+
18
+ ```ruby
19
+ gem 'lapis-minecraft-versioning'
20
+ ```
21
+
22
+ Or to your gemspec:
23
+
24
+ ```ruby
25
+ spec.add_dependency 'lapis-minecraft-versioning'
26
+ ```
27
+
28
+ And then execute:
29
+
30
+ $ bundle
31
+
32
+ Or install it yourself as:
33
+
34
+ $ gem install lapis-minecraft-versioning
35
+
36
+ Usage
37
+ -----
38
+
39
+ Include the gem by adding this to your scripts:
40
+
41
+ ```ruby
42
+ require 'lapis/minecraft/versioning'
43
+ ```
44
+
45
+ ### Accessing Minecraft version data
46
+
47
+ Retrieve the official Minecraft version list:
48
+
49
+ ```ruby
50
+ list = Lapis::Minecraft::Versioning::VersionList.official
51
+ ```
52
+
53
+ Display a list of all versions:
54
+
55
+ ```ruby
56
+ list.each do |version|
57
+ puts version.id
58
+ end
59
+ ```
60
+
61
+ Get the client URL for the latest release:
62
+
63
+ ```ruby
64
+ list.latest_release.client_download.url
65
+ ```
66
+
67
+ Development
68
+ -----------
69
+
70
+ After checking out the repo, run `bin/setup` to install dependencies.
71
+ Then, run `bundle exec rake test` to run the tests.
72
+ It's recommended that you run `bundle exec rake inspect` to run inspections.
73
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+ `bundle exec rake doc` will generate documentation.
75
+
76
+ To install this gem onto your local machine, run `bundle exec rake install`.
77
+ To release a new version, update the version number in `versioning/version.rb`, and then run `bundle exec rake release`.
78
+ This will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
79
+
80
+ Contributing
81
+ ------------
82
+
83
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/lapis-mc/minecraft-versioning).
@@ -0,0 +1,28 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'reek/rake/task'
3
+ require 'rubocop/rake_task'
4
+ require 'rubocop'
5
+ require 'rspec/core/rake_task'
6
+ require 'yard'
7
+
8
+ task :default => [:build, :test]
9
+ task :inspect => [:reek, :rubocop]
10
+
11
+ RSpec::Core::RakeTask.new(:spec)
12
+ task :test => :spec
13
+
14
+ Reek::Rake::Task.new do |task| # :reek
15
+ task.name = :reek
16
+ task.source_files = 'lib/**/*.rb'
17
+ task.fail_on_error = false
18
+ end
19
+
20
+ RuboCop::RakeTask.new(:rubocop) do |task|
21
+ task.patterns = ['lib/**/*.rb']
22
+ task.fail_on_error = false
23
+ end
24
+
25
+ YARD::Rake::YardocTask.new do |task| # :yard
26
+ task.files = %w(lib/**/*.rb - *.md)
27
+ end
28
+ task :doc => :yard
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'lapis/minecraft/versioning'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install --path=vendor/bundle
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lapis/minecraft/versioning/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'lapis-minecraft-versioning'
8
+ spec.version = Lapis::Minecraft::Versioning::VERSION
9
+ spec.authors = ['Michael Miller']
10
+ spec.email = ['bluepixelmike@gmail.com']
11
+
12
+ spec.summary = %q{Retrieves and processes information about versions of Minecraft.}
13
+ spec.description = %q{Small library for getting version information from Mojang about Minecraft.
14
+ Includes a command-line utility as well.}
15
+ spec.homepage = 'https://github.com/lapis-mc/minecraft-versioning'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.bindir = 'bin'
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.executables = spec.files.grep(%r{^bin/(lapis|minecraft)-}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.add_dependency 'httpclient', '~> 2.1'
25
+
26
+ spec.add_development_dependency 'bundler'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
+ spec.add_development_dependency 'factory_girl', '~> 4.0'
30
+ spec.add_development_dependency 'webmock', '~> 2.0'
31
+ spec.add_development_dependency 'reek', '~> 3.0'
32
+ spec.add_development_dependency 'rubocop', '~> 0.38.0'
33
+ spec.add_development_dependency 'codeclimate-test-reporter'
34
+ spec.add_development_dependency 'yard'
35
+ end
@@ -0,0 +1,89 @@
1
+ require_relative 'versioning/basic'
2
+
3
+ module Lapis
4
+ module Minecraft
5
+
6
+ # Complete information about a Minecraft version.
7
+ # @note This class uses lazy-loading to retrieve additional information only when it is needed.
8
+ class Version < Versioning::Basic
9
+
10
+ # Creates version information.
11
+ # @param basic_info [Versioning::Basic] Minimal information to extend from.
12
+ # @param meta_server [Versioning::MetaServer] Connection used to retrieve version information.
13
+ def initialize(basic_info, meta_server)
14
+ super(basic_info.id, basic_info.type, basic_info.time, basic_info.url)
15
+ @meta_server = meta_server
16
+ end
17
+
18
+ # List of assets needed for this version.
19
+ # @return [Array<Versioning::Asset>] Asset list.
20
+ def assets
21
+ @assets ||= @meta_server.get_assets(asset_index.url)
22
+ end
23
+
24
+ # Overview of assets included in this version.
25
+ # @return [Versioning::AssetIndex] Asset overview.
26
+ def asset_index
27
+ details.asset_index
28
+ end
29
+
30
+ # List of downloads available for this version.
31
+ # @return [Array<Versioning::Resource>] Download list.
32
+ def downloads
33
+ details.downloads
34
+ end
35
+
36
+ # Retrieves the client jar information for this version.
37
+ # @return [Versioning::Resource] Download information for the client.
38
+ # @return [nil] There is no client for this version.
39
+ def client_download
40
+ details.client_download
41
+ end
42
+
43
+ # Retrieves the server jar information for this version.
44
+ # @return [Versioning::Resource] Download information for the server.
45
+ # @return [nil] There is no server for this version.
46
+ def server_download
47
+ details.server_download
48
+ end
49
+
50
+ # List of libraries needed to run this version.
51
+ # @return [Array<Versioning::Library>] Library list.
52
+ def libraries
53
+ details.libraries
54
+ end
55
+
56
+ # Information about how to start the client in a launcher.
57
+ # @return [Versioning::LauncherProperties] Client launcher information.
58
+ def launcher_properties
59
+ details.launcher_properties
60
+ end
61
+
62
+ # Compares one version to another.
63
+ # @param other [Version] Version to compare against.
64
+ # @return [true] The versions are the same.
65
+ # @return [false] The versions are different.
66
+ def ==(other)
67
+ # Ordered by least expensive to most expensive.
68
+ super(other) &&
69
+ other.asset_index == asset_index &&
70
+ other.launcher_properties == launcher_properties &&
71
+ other.client_download == client_download &&
72
+ other.server_download == server_download &&
73
+ other.downloads == downloads &&
74
+ other.libraries == libraries &&
75
+ other.assets == assets
76
+ end
77
+
78
+ private
79
+
80
+ # Retrieves and caches detailed version information.
81
+ # @return [Versioning::Detailed] Detailed version information.
82
+ def details
83
+ @detailed ||= @meta_server.get_details(url)
84
+ end
85
+
86
+ end
87
+
88
+ end
89
+ end
@@ -0,0 +1,26 @@
1
+ module Lapis
2
+ module Minecraft
3
+
4
+ # Brings in information for Minecraft versions.
5
+ module Versioning
6
+ end
7
+
8
+ end
9
+ end
10
+
11
+ require_relative 'versioning/version'
12
+ require_relative 'versioning/basic'
13
+ require_relative 'versioning/asset'
14
+ require_relative 'versioning/asset_index'
15
+ require_relative 'versioning/resource'
16
+ require_relative 'versioning/resource_set'
17
+ require_relative 'versioning/rule'
18
+ require_relative 'versioning/os_rule'
19
+ require_relative 'versioning/library'
20
+ require_relative 'versioning/launcher_properties'
21
+ require_relative 'versioning/detailed'
22
+ require_relative 'version'
23
+ require_relative 'versioning/manifest'
24
+ require_relative 'versioning/meta_server'
25
+ require_relative 'versioning/marshalling'
26
+ require_relative 'versioning/version_list'
@@ -0,0 +1,44 @@
1
+ module Lapis
2
+ module Minecraft
3
+ module Versioning
4
+
5
+ # Information about a content file needed for the client.
6
+ class Asset
7
+
8
+ # Size of the asset in bytes.
9
+ # @return [Fixnum]
10
+ attr_reader :size
11
+
12
+ # SHA1 hash of the asset's contents in hexadecimal.
13
+ # @return [String]
14
+ attr_reader :sha1
15
+
16
+ # Path, relative to the installation directory, to store the asset.
17
+ # @return [String, nil] Relative path or +nil+ if the asset can be placed anywhere.
18
+ attr_reader :path
19
+
20
+ # Creates information about an asset.
21
+ # @param size [Fixnum] Size of the asset in bytes.
22
+ # @param sha1 [String] SHA1 hash of the asset's contents in hexadecimal.
23
+ # @param path [String, nil] Path, relative to the installation directory, to store the asset.
24
+ def initialize(size, sha1, path)
25
+ @size = size
26
+ @sha1 = sha1.dup.freeze
27
+ @path = path ? path.dup.freeze : nil
28
+ end
29
+
30
+ # Compares one asset to another.
31
+ # @param other [Asset] Asset to compare against.
32
+ # @return [true] The assets are the same.
33
+ # @return [false] The assets are different.
34
+ def ==(other)
35
+ other.size == @size &&
36
+ other.sha1 == @sha1 &&
37
+ other.path == @path
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,61 @@
1
+ module Lapis
2
+ module Minecraft
3
+ module Versioning
4
+
5
+ # Container for tracking information about assets.
6
+ # @note This class isn't used directly for accessing asset instances.
7
+ # It is used for retrieving information about assets.
8
+ # @see Asset
9
+ class AssetIndex
10
+
11
+ # Unique name of the collection of assets.
12
+ # @return [String]
13
+ attr_reader :id
14
+
15
+ # SHA1 hash of the asset list document in hexadecimal.
16
+ # @return [String]
17
+ attr_reader :sha1
18
+
19
+ # Size of the asset list document in bytes.
20
+ # @return [Fixnum]
21
+ attr_reader :size
22
+
23
+ # Location of where the asset list document can be found.
24
+ # @return [String]
25
+ attr_reader :url
26
+
27
+ # Total size of all the assets combined.
28
+ # @return [Fixnum]
29
+ attr_reader :total_size
30
+
31
+ # Creates an asset index.
32
+ # @param id [String] Unique name of the collection of assets.
33
+ # @param sha1 [String] SHA1 hash of the asset list document in hexadecimal.
34
+ # @param size [Fixnum] Size of the asset list document in bytes.
35
+ # @param url [String] Location of where the asset list document can be found.
36
+ # @param total_size [Fixnum] Total size of all the assets combined.
37
+ def initialize(id, sha1, size, url, total_size)
38
+ @id = id.dup.freeze
39
+ @sha1 = sha1.dup.freeze
40
+ @size = size
41
+ @url = url.dup.freeze
42
+ @total_size = total_size
43
+ end
44
+
45
+ # Compares one asset index to another.
46
+ # @param other [AssetIndex] Asset index to compare against.
47
+ # @return [true] The asset indices are the same.
48
+ # @return [false] The asset indices are different.
49
+ def ==(other)
50
+ other.id == @id &&
51
+ other.sha1 == @sha1 &&
52
+ other.size == @size &&
53
+ other.url == @url &&
54
+ other.total_size == @total_size
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,56 @@
1
+ module Lapis
2
+ module Minecraft
3
+ module Versioning
4
+
5
+ # Minimal information about a Minecraft version.
6
+ class Basic
7
+
8
+ # Unique identifier used to reference the version.
9
+ # @return [String] Unique identifier.
10
+ attr_reader :id
11
+
12
+ # Type of version.
13
+ # This can be one of:
14
+ # - +:release+ - Official release.
15
+ # - +:snapshot+ - Unstable, in development.
16
+ # - +:beta+ - Old beta.
17
+ # - +:alpha+ - Old alpha.
18
+ # @return [Symbol] +:release+, +:snapshot+, +:beta+, or +:alpha+.
19
+ attr_reader :type
20
+
21
+ # Date and time the version was made available to the public.
22
+ # @return [Time]
23
+ attr_reader :time
24
+
25
+ # URL pointing to detailed information about the version.
26
+ # @return [String] Version URL.
27
+ attr_reader :url
28
+
29
+ # Creates the basic information for a Minecraft version.
30
+ # @param id [String] Unique identifier used to reference the version.
31
+ # @param type [Symbol] +:release+, +:snapshot+, +:beta+, or +:alpha+.
32
+ # @param time [Time] Date and time the version was made available to the public.
33
+ # @param url [String] URL pointing to detailed information about the version.
34
+ def initialize(id, type, time, url)
35
+ @id = id.dup.freeze
36
+ @type = type
37
+ @time = time
38
+ @url = url.dup.freeze
39
+ end
40
+
41
+ # Compares one version to another.
42
+ # @param other [Basic] Version to compare against.
43
+ # @return [true] The versions are the same.
44
+ # @return [false] The versions are different.
45
+ def ==(other)
46
+ other.id == @id &&
47
+ other.type == @type &&
48
+ other.time == @time &&
49
+ other.url == @url
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
56
+ end