gs2-ruby-sdk-core 0.1.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41ce097411dd94f6d8315b17d5e6a7b4715459d7
4
+ data.tar.gz: 84a19816b2bc1c0d90bdc7690f2b85289fb6a261
5
+ SHA512:
6
+ metadata.gz: 321971da1af890b08166ce892d165811b33ee69dbe740ce86acd40f30ab60b928a3c37226e6e3e5970521666c89adafb33c21556aa2a84e7ae664c0926308ef1
7
+ data.tar.gz: 22989a1fcb10c1fbe5796c36ecbf7379962fd05898a5d1556b04336b3a66a6f78f99144509fe9bc9068455beaed79c2548beb1238de2294285997bf96fee5a5e
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .buildpath
11
+ .project
12
+ .DS_Store
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+ gem 'httpclient', '~> 2'
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ gs2-ruby-sdk-core
2
+ ===============
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gs2-sdk"
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
data/circle.yml ADDED
@@ -0,0 +1,19 @@
1
+ ## Customize the test machine
2
+ machine:
3
+ ruby:
4
+ version: ruby-2.3.1
5
+
6
+ checkout:
7
+ post:
8
+ - aws s3 cp s3://gs2-repos/python/publish/${PUBLISH_VERSION}/publish-${PUBLISH_VERSION}.tar.gz ~/ && tar -zxvf ~/publish-${PUBLISH_VERSION}.tar.gz -C ~/
9
+
10
+ test:
11
+ override:
12
+ - echo "test"
13
+
14
+ deployment:
15
+ maven:
16
+ branch: master
17
+ commands:
18
+ - bash ~/publish-${PUBLISH_VERSION}/ruby/publish_rubygems.sh ~/publish-${PUBLISH_VERSION}/
19
+ - bundle exec rake release
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gs2/core/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gs2-ruby-sdk-core"
8
+ spec.version = Gs2::Core::VERSION
9
+ spec.authors = ["Game Server Services, Inc."]
10
+ spec.email = ["contact@gs2.io"]
11
+ spec.licenses = "Apache-2.0"
12
+
13
+ spec.summary = %q{Game Server Services Core Library}
14
+ spec.homepage = "https://gs2.io/"
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_dependency "httpclient", "~> 2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
data/lib/gs2-sdk.rb ADDED
@@ -0,0 +1,10 @@
1
+ begin; require 'gs2-auth'; rescue LoadError; end
2
+ begin; require 'gs2-identifier'; rescue LoadError; end
3
+ begin; require 'gs2-inbox'; rescue LoadError; end
4
+ begin; require 'gs2-matchmaking'; rescue LoadError; end
5
+ begin; require 'gs2-notification'; rescue LoadError; end
6
+ begin; require 'gs2-ranking'; rescue LoadError; end
7
+ begin; require 'gs2-realtime'; rescue LoadError; end
8
+ begin; require 'gs2-stamina'; rescue LoadError; end
9
+ begin; require 'gs2-timer'; rescue LoadError; end
10
+ begin; require 'gs2-watch'; rescue LoadError; end
@@ -0,0 +1,111 @@
1
+ require 'gs2-sdk'
2
+ require 'openssl'
3
+ require 'base64'
4
+ require 'httpclient'
5
+ require 'json'
6
+
7
+ require 'gs2/core/BadRequestException.rb'
8
+ require 'gs2/core/BadGatewayException.rb'
9
+ require 'gs2/core/InternalServerErrorException.rb'
10
+ require 'gs2/core/NotFoundException.rb'
11
+ require 'gs2/core/QuotaExceedException.rb'
12
+ require 'gs2/core/RequestTimeoutException.rb'
13
+ require 'gs2/core/ServiceUnavailableException.rb'
14
+ require 'gs2/core/UnauthorizedException.rb'
15
+ require 'gs2/core/ConflictException.rb'
16
+
17
+ module Gs2 module Core
18
+ class AbstractClient
19
+
20
+ @@ENDPOINT_BASE = 'https://{service}.{region}.gs2.io'
21
+
22
+ def initialize(region, gs2_client_id, gs2_client_secret)
23
+ @region = region
24
+ @gs2_client_id = gs2_client_id
25
+ @gs2_client_secret = gs2_client_secret
26
+ end
27
+
28
+ def create_sign(_module, function, timestamp)
29
+ message = _module + ':' + function + ':' + timestamp.to_s
30
+ return Base64.strict_encode64(OpenSSL::HMAC::digest(OpenSSL::Digest::SHA256.new, Base64.strict_decode64(@gs2_client_secret), message))
31
+ end
32
+
33
+ def get(_module, function, endpoint, url, query = {}, extheader = {})
34
+ url = (@@ENDPOINT_BASE + url).gsub(/{service}/, endpoint).gsub(/{region}/, @region)
35
+ client = HTTPClient.new
36
+ timestamp = Time.now.to_i
37
+ header = {
38
+ 'X-GS2-CLIENT-ID' => @gs2_client_id,
39
+ 'X-GS2-REQUEST-TIMESTAMP' => timestamp,
40
+ 'X-GS2-REQUEST-SIGN' => create_sign(_module,function,timestamp),
41
+ 'Content-Type' => 'application/json'
42
+ }
43
+ header.merge!(extheader)
44
+ return handling(client.get(url, query: query, header: header))
45
+ end
46
+
47
+ def post(_module, function, endpoint, url, body, query = {}, extheader = {})
48
+ url = (@@ENDPOINT_BASE + url).gsub(/{service}/, endpoint).gsub(/{region}/, @region)
49
+ client = HTTPClient.new
50
+ timestamp = Time.now.to_i
51
+ header = {
52
+ 'X-GS2-CLIENT-ID' => @gs2_client_id,
53
+ 'X-GS2-REQUEST-TIMESTAMP' => timestamp,
54
+ 'X-GS2-REQUEST-SIGN' => create_sign(_module,function,timestamp),
55
+ 'Content-Type' => 'application/json'
56
+ }
57
+ header.merge!(extheader)
58
+ return handling(client.post(url, query: query, header: header, body: body.to_json))
59
+ end
60
+
61
+ def put(_module, function, endpoint, url, body, query = {}, extheader = {})
62
+ url = (@@ENDPOINT_BASE + url).gsub(/{service}/, endpoint).gsub(/{region}/, @region)
63
+ client = HTTPClient.new
64
+ timestamp = Time.now.to_i
65
+ header = {
66
+ 'X-GS2-CLIENT-ID' => @gs2_client_id,
67
+ 'X-GS2-REQUEST-TIMESTAMP' => timestamp,
68
+ 'X-GS2-REQUEST-SIGN' => create_sign(_module,function,timestamp),
69
+ 'Content-Type' => 'application/json'
70
+ }
71
+ header.merge!(extheader)
72
+ return handling(client.put(url, query: query, header: header, body: body.to_json))
73
+ end
74
+
75
+ def delete(_module, function, endpoint, url, query = {}, extheader = {})
76
+ url = (@@ENDPOINT_BASE + url).gsub(/{service}/, endpoint).gsub(/{region}/, @region)
77
+ client = HTTPClient.new
78
+ timestamp = Time.now.to_i
79
+ header = {
80
+ 'X-GS2-CLIENT-ID' => @gs2_client_id,
81
+ 'X-GS2-REQUEST-TIMESTAMP' => timestamp,
82
+ 'X-GS2-REQUEST-SIGN' => create_sign(_module,function,timestamp),
83
+ 'Content-Type' => 'application/json'
84
+ }
85
+ header.merge!(extheader)
86
+ return handling(client.delete(url, query: query, header: header))
87
+ end
88
+
89
+ def handling(response)
90
+ case response.status
91
+ when 200
92
+ begin
93
+ return JSON.parse(response.body)
94
+ rescue JSON::ParserError
95
+ return nil
96
+ end
97
+ when 400; raise Gs2::Core::BadRequestException.new(JSON.parse(JSON.parse(response.body)['message']))
98
+ when 401; raise Gs2::Core::UnauthorizedException.new(JSON.parse(JSON.parse(response.body)['message']))
99
+ when 402; raise Gs2::Core::QuotaExceedException.new(JSON.parse(JSON.parse(response.body)['message']))
100
+ when 404; raise Gs2::Core::NotFoundException.new(JSON.parse(JSON.parse(response.body)['message']))
101
+ when 409; raise Gs2::Core::ConflictException.new(JSON.parse(JSON.parse(response.body)['message']))
102
+ when 500; raise Gs2::Core::InternalServerErrorException.new(JSON.parse(JSON.parse(response.body)['message']))
103
+ when 502; raise Gs2::Core::BadGatewayException.new(JSON.parse(JSON.parse(response.body)['message']))
104
+ when 503; raise Gs2::Core::ServiceUnavailableException.new(JSON.parse(JSON.parse(response.body)['message']))
105
+ when 504; raise Gs2::Core::RequestTimeoutException.new(JSON.parse(JSON.parse(response.body)['message']))
106
+ end
107
+ puts response.status
108
+ puts response.body
109
+ end
110
+ end
111
+ end end
@@ -0,0 +1,14 @@
1
+ module Gs2 module Core
2
+ class BadGatewayException < Exception
3
+
4
+ def initialize(errors)
5
+ super(errors)
6
+ @errors = errors
7
+ end
8
+
9
+ def errors()
10
+ return @errors
11
+ end
12
+
13
+ end
14
+ end end
@@ -0,0 +1,14 @@
1
+ module Gs2 module Core
2
+ class BadRequestException < Exception
3
+
4
+ def initialize(errors)
5
+ super(errors)
6
+ @errors = errors
7
+ end
8
+
9
+ def errors()
10
+ return @errors
11
+ end
12
+
13
+ end
14
+ end end
@@ -0,0 +1,14 @@
1
+ module Gs2 module Core
2
+ class ConflictException < Exception
3
+
4
+ def initialize(errors)
5
+ super(errors)
6
+ @errors = errors
7
+ end
8
+
9
+ def errors()
10
+ return @errors
11
+ end
12
+
13
+ end
14
+ end end
@@ -0,0 +1,14 @@
1
+ module Gs2 module Core
2
+ class InternalServerErrorException < Exception
3
+
4
+ def initialize(errors)
5
+ super(errors)
6
+ @errors = errors
7
+ end
8
+
9
+ def errors()
10
+ return @errors
11
+ end
12
+
13
+ end
14
+ end end
@@ -0,0 +1,14 @@
1
+ module Gs2 module Core
2
+ class NotFoundException < Exception
3
+
4
+ def initialize(errors)
5
+ super(errors)
6
+ @errors = errors
7
+ end
8
+
9
+ def errors()
10
+ return @errors
11
+ end
12
+
13
+ end
14
+ end end
@@ -0,0 +1,14 @@
1
+ module Gs2 module Core
2
+ class QuotaExceedException < Exception
3
+
4
+ def initialize(errors)
5
+ super(errors)
6
+ @errors = errors
7
+ end
8
+
9
+ def errors()
10
+ return @errors
11
+ end
12
+
13
+ end
14
+ end end
@@ -0,0 +1,14 @@
1
+ module Gs2 module Core
2
+ class RequestTimeoutException < Exception
3
+
4
+ def initialize(errors)
5
+ super(errors)
6
+ @errors = errors
7
+ end
8
+
9
+ def errors()
10
+ return @errors
11
+ end
12
+
13
+ end
14
+ end end
@@ -0,0 +1,14 @@
1
+ module Gs2 module Core
2
+ class ServiceUnavailableException < Exception
3
+
4
+ def initialize(errors)
5
+ super(errors)
6
+ @errors = errors
7
+ end
8
+
9
+ def errors()
10
+ return @errors
11
+ end
12
+
13
+ end
14
+ end end
@@ -0,0 +1,14 @@
1
+ module Gs2 module Core
2
+ class UnauthorizedException < Exception
3
+
4
+ def initialize(errors)
5
+ super(errors)
6
+ @errors = errors
7
+ end
8
+
9
+ def errors()
10
+ return @errors
11
+ end
12
+
13
+ end
14
+ end end
@@ -0,0 +1,5 @@
1
+ module Gs2
2
+ module Core
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gs2-ruby-sdk-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Game Server Services, Inc.
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
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
+ description:
56
+ email:
57
+ - contact@gs2.io
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".ruby-version"
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - circle.yml
70
+ - gs2-ruby-sdk-core.gemspec
71
+ - lib/.DS_Store
72
+ - lib/gs2-sdk.rb
73
+ - lib/gs2/.DS_Store
74
+ - lib/gs2/core/.DS_Store
75
+ - lib/gs2/core/AbstractClient.rb
76
+ - lib/gs2/core/BadGatewayException.rb
77
+ - lib/gs2/core/BadRequestException.rb
78
+ - lib/gs2/core/ConflictException.rb
79
+ - lib/gs2/core/InternalServerErrorException.rb
80
+ - lib/gs2/core/NotFoundException.rb
81
+ - lib/gs2/core/QuotaExceedException.rb
82
+ - lib/gs2/core/RequestTimeoutException.rb
83
+ - lib/gs2/core/ServiceUnavailableException.rb
84
+ - lib/gs2/core/UnauthorizedException.rb
85
+ - lib/gs2/core/version.rb
86
+ homepage: https://gs2.io/
87
+ licenses:
88
+ - Apache-2.0
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.5.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Game Server Services Core Library
110
+ test_files: []