steam-id2 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1bba90f3409c8ed2fa3a29936611a9ee8f1a3ce8
4
+ data.tar.gz: bc66bac1e1595e8e8bf8c710c211949f6a2d429b
5
+ SHA512:
6
+ metadata.gz: 5702892387d37107eb996ec168f44315c4a9958eb80a6480a5e0de143251d3c0f1ef0b13463f137260c7b63cdb3da7f0be780b83b5babfd2ce3d44372cc2b8dc
7
+ data.tar.gz: 24763f1af669221b5434bd12a3efbcf4b2ecadca4ef617c119596032730ae11a1bbdb108c2a44aae17f0c818c3d7bdb16a61f2b9ad425fdfb29f7775aff794b2
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ # Change log
2
+
3
+ This document represents a high-level overview of changes made to this project.
4
+ It will not list every miniscule change, but will allow you to view - at a
5
+ glance - what to expact from upgrading to a new version.
6
+
7
+ ## [unpublished]
8
+
9
+ ### Added
10
+
11
+ ### Changed
12
+
13
+ ### Fixed
14
+
15
+ ### Security
16
+
17
+ ### Deprecated
18
+
19
+ ### Removed
20
+
21
+
22
+ ## [0.1.0] - 02.01.2017
23
+
24
+ ### Added
25
+
26
+ - Module to allow conversion of SteamIDs into account IDs suitable for e.g.
27
+ Hive 2 API calls.
28
+
29
+ Supported are:
30
+ - Steam ID
31
+ - Steam ID 3
32
+ - Steam ID 64
33
+ - Community URL
34
+ - Profile URL
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sunscout.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2016 Michael Senn
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # CHANGE ME
2
+
3
+ ## License
4
+
5
+ The gem is available as open source under the terms of the [Apache-2.0 License](http://opensource.org/licenses/Apache-2.0).
6
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hive-stalker"
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
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,88 @@
1
+ require 'steam-condenser'
2
+
3
+ module SteamID
4
+ # Module to convert various formats of Steam IDs into an account ID.
5
+ module SteamID
6
+ STEAM_ID_64_OFFSET = 61197960265728
7
+
8
+ PATTERN_STEAM_ID = /^STEAM_[0-9]:([0-9]):([0-9]+)$/i
9
+ PATTERN_STEAM_ID_3 = /^U:([0-9]{1,2}):([0-9]+)$/i
10
+ PATTERN_STEAM_ID_64 = /^765([0-9]+)$/
11
+ # Not sure what its valid range is - exists with at least 7 and 8 numbers.
12
+ PATTERN_ACCOUNT_ID = /^[0-9]+$/
13
+
14
+ PATTERN_COMMUNITY_URL = /^https?:\/\/steamcommunity\.com\/profiles\/(765[0-9]+)\/?$/
15
+ PATTERN_CUSTOM_URL = /^https?:\/\/steamcommunity\.com\/id\/([^\/]+)\/?$/
16
+
17
+ # Resolve custom URL into account ID suitable for API calls.
18
+ # @param s [String] custom URL:
19
+ # - http://steamcommunity.com/id/some-custom-url
20
+ # - some-custom-url
21
+ # @return [Fixnum] Account ID
22
+ # @raise [ArgumentError] If the supplied string was not a valid community URL.
23
+ def self.from_vanity_url(url, steam_api_key:)
24
+ WebApi.api_key = steam_api_key
25
+
26
+ PATTERN_CUSTOM_URL.match(url) do |m|
27
+ url = m[1]
28
+ end
29
+
30
+ steam_id = SteamId.resolve_vanity_url(url)
31
+ if steam_id.nil?
32
+ raise ArgumentError, "#{ url } was not a valid custom URL."
33
+ else
34
+ from_steam_id(steam_id)
35
+ end
36
+ end
37
+
38
+ # Convert community URL into account ID suitable for API calls.
39
+ # @param s [String] community URL: http://steamcommunity.com/profiles/76561198008487038
40
+ # @return [Fixnum] Account ID
41
+ # @raise [ArgumentError] If the supplied string was not a valid community URL.
42
+ def self.from_community_url(url)
43
+ PATTERN_COMMUNITY_URL.match(url) do |m|
44
+ return self.from_steam_id(m[1])
45
+ end
46
+
47
+ raise ArgumentError, "#{ url.inspect } is not a supported community URL."
48
+ end
49
+
50
+ # Convert Steam ID into account ID suitable for API calls.
51
+ # @param s [String] Steam ID, either of:
52
+ # - Steam ID: STEAM_0:0:24110655
53
+ # - Steam ID 3: U:1:48221310
54
+ # - Steam ID 64: 76561198008487038
55
+ # - Account ID: 48221310
56
+ # @return [Fixnum] Account ID
57
+ # @raise [ArgumentError] If the supplied string could not be converted to
58
+ # an account ID.
59
+ def self.from_steam_id(id)
60
+ # In case we get a fixnum.
61
+ id = id.to_s
62
+
63
+ # https://developer.valvesoftware.com/wiki/SteamID#Format
64
+ PATTERN_STEAM_ID.match(id) do |m|
65
+ return m[1].to_i + m[2].to_i * 2
66
+ end
67
+
68
+ PATTERN_STEAM_ID_3.match(id) do |m|
69
+ return m[2].to_i
70
+ end
71
+
72
+ PATTERN_STEAM_ID_64.match(id) do |m|
73
+ return m[1].to_i - STEAM_ID_64_OFFSET
74
+ end
75
+
76
+ # Matching this one last, as not to catch an ID 64 on accident.
77
+ PATTERN_ACCOUNT_ID.match(id) do |m|
78
+ return id.to_i
79
+ end
80
+
81
+ # If we get until here, we did not match any regex.
82
+ raise ArgumentError, "#{ id.inspect } is not a supported SteamID."
83
+ end
84
+
85
+ def self.from_string(s)
86
+ end
87
+ end
88
+ end
data/lib/steam_id.rb ADDED
@@ -0,0 +1,7 @@
1
+ # coding: utf-8
2
+
3
+ require 'steam-id/steam_id'
4
+
5
+ module SteamID
6
+ # Your code goes here...
7
+ end
data/steam-id2.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "steam-id2"
7
+ spec.version = '0.1.0'
8
+ spec.authors = ["Michael Senn"]
9
+ spec.email = ["michael@morrolan.ch"]
10
+
11
+ spec.summary = %q{Convert Steam IDs}
12
+ # spec.description = %q{}
13
+ spec.homepage = "https://bitbucket.org/Lavode/steamid"
14
+ spec.license = "Apache-2.0"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'steam-condenser', '~> 1.3'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "yard"
27
+ end
28
+
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steam-id2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Senn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: steam-condenser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - michael@morrolan.ch
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - CHANGELOG.md
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/steam-id/steam_id.rb
99
+ - lib/steam_id.rb
100
+ - steam-id2.gemspec
101
+ homepage: https://bitbucket.org/Lavode/steamid
102
+ licenses:
103
+ - Apache-2.0
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.5.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Convert Steam IDs
125
+ test_files: []