openkit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +63 -0
- data/Rakefile +7 -0
- data/lib/openkit.rb +15 -0
- data/lib/openkit/request.rb +17 -0
- data/lib/openkit/request/base.rb +72 -0
- data/lib/openkit/request/base_delegate.rb +37 -0
- data/lib/openkit/request/delete.rb +31 -0
- data/lib/openkit/request/get.rb +43 -0
- data/lib/openkit/request/post.rb +33 -0
- data/lib/openkit/request/post_multipart.rb +63 -0
- data/lib/openkit/request/put.rb +33 -0
- data/lib/openkit/request/upload.rb +21 -0
- data/lib/openkit/version.rb +3 -0
- data/openkit.gemspec +46 -0
- data/test/api/score_api_test.rb +22 -0
- data/test/api/user_api_test.rb +16 -0
- data/test/test_helper.rb +19 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3d0b4f00b8e5a5a3a6ce085a3738719f3ac02265
|
4
|
+
data.tar.gz: d1b034360fe320cdf1ad7e538d5ccd29698fc01f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2367135097d83e600d8f254d0ab7ae35916e11ad6223f03b3fb58134327cada781850c72898c350415159b38000933b6c87e3a000c96463fdf2149be5c76705
|
7
|
+
data.tar.gz: 9c325267738058087290d47b9f16030c1316f57e6fa631867baa6f32b43e477f2db20c105b85169b2989866247aca759b9e3cc380c34c07713e9086fc4c5d11b
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Lou Zell
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Openkit
|
2
|
+
|
3
|
+
The ruby client for OpenKit's gaming backend.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'openkit'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install openkit
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Get your app_key and secret_key from [https://developer.openkit.io](https://developer.openkit.io).
|
22
|
+
|
23
|
+
Set credentials:
|
24
|
+
|
25
|
+
OpenKit::Config.app_key = "<your-app-key>"
|
26
|
+
OpenKit::Config.secret_key = "<your-secret-key>"
|
27
|
+
OpenKit::Config.skip_https = true # required unless you're using the beta-api endpoint
|
28
|
+
|
29
|
+
Request examples:
|
30
|
+
|
31
|
+
include OpenKit::Request
|
32
|
+
|
33
|
+
# Get
|
34
|
+
response = Get.new('/v1/leaderboards').perform
|
35
|
+
|
36
|
+
# Post
|
37
|
+
response = Post.new('/v1/users', {:nick => 'lou'}).perform
|
38
|
+
|
39
|
+
# Put
|
40
|
+
response = Put.new('/v1/users/:id', {:nick => 'lou z'}).perform
|
41
|
+
|
42
|
+
# Multipart Post
|
43
|
+
upload = Upload.new('<param-name-of-upload>', '<path-to-file>')
|
44
|
+
req = OpenKit::PostMultipart.new('/v1/scores', {:score => {:value => 100}}, upload)
|
45
|
+
response = req.perform
|
46
|
+
|
47
|
+
Parse the response:
|
48
|
+
|
49
|
+
json = JSON.parse(response.body)
|
50
|
+
|
51
|
+
Check the response headers:
|
52
|
+
|
53
|
+
puts response.code
|
54
|
+
response.header.each { |h, v| puts "#{h}: #{v}" }
|
55
|
+
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Fork it
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/openkit.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module OpenKit
|
2
|
+
|
3
|
+
class Config
|
4
|
+
@host = 'api.openkit.io' # default
|
5
|
+
class << self
|
6
|
+
attr_accessor :app_key, :secret_key
|
7
|
+
attr_accessor :host
|
8
|
+
attr_accessor :skip_https
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require_relative 'openkit/request'
|
14
|
+
require_relative "openkit/version"
|
15
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/http/post/multipart'
|
4
|
+
require 'digest/hmac'
|
5
|
+
require 'base64'
|
6
|
+
require 'cgi'
|
7
|
+
require 'json'
|
8
|
+
require 'pp'
|
9
|
+
|
10
|
+
require_relative 'request/base'
|
11
|
+
require_relative 'request/base_delegate'
|
12
|
+
require_relative 'request/get'
|
13
|
+
require_relative 'request/put'
|
14
|
+
require_relative 'request/delete'
|
15
|
+
require_relative 'request/post'
|
16
|
+
require_relative 'request/post_multipart'
|
17
|
+
require_relative 'request/upload'
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module OpenKit
|
2
|
+
module Request
|
3
|
+
|
4
|
+
class Base
|
5
|
+
def initialize(verb, the_delegate)
|
6
|
+
raise "Don't instantiate me!" if abstract_class?
|
7
|
+
|
8
|
+
@delegate = the_delegate
|
9
|
+
@nonce = SecureRandom.uuid
|
10
|
+
@oauth_version = '1.0'
|
11
|
+
@signature_method = 'HMAC-SHA1'
|
12
|
+
@timestamp = Time.now.to_i
|
13
|
+
@verb = verb
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform
|
17
|
+
http = Net::HTTP.new(@delegate.uri.host, @delegate.uri.port)
|
18
|
+
http.use_ssl = (@delegate.scheme == 'https')
|
19
|
+
http.start do
|
20
|
+
response = http.request(self.net_request)
|
21
|
+
response
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def net_request
|
26
|
+
net_request = @delegate.net_request()
|
27
|
+
net_request['Authorization'] = authorization_header
|
28
|
+
net_request
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def authorization_header
|
33
|
+
%|OAuth oauth_consumer_key="#{@delegate.app_key}", oauth_nonce="#{@nonce}", oauth_signature="#{escape(signature)}", oauth_signature_method="#{@signature_method}", oauth_timestamp="#{@timestamp}", oauth_version="#{@oauth_version}"|
|
34
|
+
end
|
35
|
+
|
36
|
+
def signature
|
37
|
+
k = @delegate.secret_key + "&"
|
38
|
+
hmac = Digest::HMAC.digest(signature_base_string, k, Digest::SHA1)
|
39
|
+
Base64.encode64(hmac).chomp
|
40
|
+
end
|
41
|
+
|
42
|
+
def signature_base_string
|
43
|
+
[ @verb.to_s.upcase,
|
44
|
+
escape(@delegate.base_uri + @delegate.uri.path),
|
45
|
+
escape(params_string_for_signature)
|
46
|
+
].join('&')
|
47
|
+
end
|
48
|
+
|
49
|
+
def params_string_for_signature
|
50
|
+
params_in_signature.sort_by{|k, _| k}.collect{ |k,v| k.to_s + '=' + v.to_s }.join("&")
|
51
|
+
end
|
52
|
+
|
53
|
+
def params_in_signature
|
54
|
+
{
|
55
|
+
oauth_consumer_key: @delegate.app_key,
|
56
|
+
oauth_nonce: @nonce,
|
57
|
+
oauth_signature_method: @signature_method,
|
58
|
+
oauth_timestamp: @timestamp,
|
59
|
+
oauth_version: @oauth_version,
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def escape(s)
|
64
|
+
CGI.escape(s)
|
65
|
+
end
|
66
|
+
|
67
|
+
def abstract_class?
|
68
|
+
self.class == Base
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module OpenKit
|
2
|
+
module Request
|
3
|
+
|
4
|
+
class BaseDelegate
|
5
|
+
attr_reader :scheme, :host, :app_key, :secret_key
|
6
|
+
attr_reader :path
|
7
|
+
|
8
|
+
def initialize(path)
|
9
|
+
raise "Don't instantiate me!" if abstract_class?
|
10
|
+
|
11
|
+
raise "OpenKit::Config.host is not set." unless Config.host
|
12
|
+
raise "OpenKit::Config.app_key is not set." unless Config.app_key
|
13
|
+
raise "OpenKit::Config.secret_key is not set." unless Config.secret_key
|
14
|
+
|
15
|
+
@scheme = Config.skip_https ? "http" : "https"
|
16
|
+
@host = Config.host
|
17
|
+
@app_key = Config.app_key
|
18
|
+
@secret_key = Config.secret_key
|
19
|
+
|
20
|
+
@path = path
|
21
|
+
end
|
22
|
+
|
23
|
+
def base_uri
|
24
|
+
@scheme + "://" + @host
|
25
|
+
end
|
26
|
+
|
27
|
+
def uri
|
28
|
+
@uri ||= URI(base_uri + @path)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def abstract_class?
|
33
|
+
self.class == BaseDelegate
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Delete.from('/path')
|
2
|
+
module OpenKit
|
3
|
+
module Request
|
4
|
+
|
5
|
+
class Delete < Base
|
6
|
+
|
7
|
+
def self.from(path)
|
8
|
+
new(path).perform
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(path)
|
12
|
+
super :delete, DeleteDelegate.new(path)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
class DeleteDelegate < BaseDelegate
|
18
|
+
|
19
|
+
def initialize(path)
|
20
|
+
super(path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def net_request
|
24
|
+
req = Net::HTTP::Delete.new(uri.request_uri)
|
25
|
+
req['Content-Type'] = "application/json; charset=utf-8"
|
26
|
+
req['Accept'] = "application/json"
|
27
|
+
req
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# Get.from('/path', {query_param1: 'foo'})
|
2
|
+
module OpenKit
|
3
|
+
module Request
|
4
|
+
|
5
|
+
class Get < Base
|
6
|
+
|
7
|
+
def self.from(path, query_params = {})
|
8
|
+
new(path, query_params).perform
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(path, query_params = {})
|
12
|
+
super :get, GetDelegate.new(path, query_params)
|
13
|
+
@query_params = query_params
|
14
|
+
end
|
15
|
+
|
16
|
+
def params_in_signature
|
17
|
+
super.merge(@query_params)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
class GetDelegate < BaseDelegate
|
23
|
+
attr_accessor :query_params
|
24
|
+
|
25
|
+
def initialize(path, query_params)
|
26
|
+
super(path)
|
27
|
+
@query_params = query_params
|
28
|
+
end
|
29
|
+
|
30
|
+
def net_request
|
31
|
+
req = Net::HTTP::Get.new(uri.request_uri + "?" + params_to_query(@query_params))
|
32
|
+
req['Content-Type'] = "application/json; charset=utf-8"
|
33
|
+
req['Accept'] = "application/json"
|
34
|
+
req
|
35
|
+
end
|
36
|
+
|
37
|
+
def params_to_query(h)
|
38
|
+
return '' if h.empty?
|
39
|
+
h.collect { |k, v| "#{k.to_s}=#{v.to_s}" }.join('&')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Post.to('/path', {param1: 'foo'})
|
2
|
+
module OpenKit
|
3
|
+
module Request
|
4
|
+
|
5
|
+
class Post < Base
|
6
|
+
|
7
|
+
def self.to(path, req_params)
|
8
|
+
new(path, req_params).perform
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(path, req_params)
|
12
|
+
super :post, PostDelegate.new(path, req_params)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
class PostDelegate < BaseDelegate
|
18
|
+
|
19
|
+
def initialize(path, req_params)
|
20
|
+
super(path)
|
21
|
+
@req_params = req_params
|
22
|
+
end
|
23
|
+
|
24
|
+
def net_request
|
25
|
+
req = Net::HTTP::Post.new(uri.request_uri)
|
26
|
+
req.set_body_internal(@req_params.to_json)
|
27
|
+
req['Content-Type'] = "application/json; charset=utf-8"
|
28
|
+
req['Accept'] = "application/json"
|
29
|
+
req
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# upload = Upload.new('score[meta_doc]', 'path-to-file')
|
2
|
+
# PostMultipart.to('/path', {param1: 'foo'}, upload)
|
3
|
+
module OpenKit
|
4
|
+
module Request
|
5
|
+
|
6
|
+
|
7
|
+
class PostMultipart < Base
|
8
|
+
attr_reader :upload
|
9
|
+
|
10
|
+
def self.to(path, req_params, upload)
|
11
|
+
new(path, req_params, upload).perform
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(path, req_params, upload)
|
15
|
+
super :post, PostMultipartDelegate.new(path, req_params, upload)
|
16
|
+
@upload = upload
|
17
|
+
end
|
18
|
+
|
19
|
+
def perform
|
20
|
+
response = super
|
21
|
+
@upload.close
|
22
|
+
response
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
class PostMultipartDelegate < BaseDelegate
|
28
|
+
|
29
|
+
def initialize(path, req_params, upload)
|
30
|
+
super(path)
|
31
|
+
@req_params = req_params
|
32
|
+
@upload = upload
|
33
|
+
end
|
34
|
+
|
35
|
+
def net_request
|
36
|
+
up_io = UploadIO.new(@upload.file, "application/octet-stream", "upload")
|
37
|
+
flat_params = flatten_params(@req_params)
|
38
|
+
req = Net::HTTP::Post::Multipart.new(uri.request_uri, flat_params.merge(@upload.param_name => up_io))
|
39
|
+
req['Accept'] = "application/json"
|
40
|
+
req
|
41
|
+
end
|
42
|
+
|
43
|
+
def flatten_params(parameters)
|
44
|
+
flattened = {}
|
45
|
+
flat_names(parameters, '') do |name,v|
|
46
|
+
flattened[name] = v
|
47
|
+
end
|
48
|
+
flattened
|
49
|
+
end
|
50
|
+
|
51
|
+
def flat_names(parameters, running = '', &block)
|
52
|
+
parameters.each do |k,v|
|
53
|
+
name = (running.length == 0) ? k.to_s : running + "[#{k}]"
|
54
|
+
if v.is_a?(Hash)
|
55
|
+
flat_names(v, name, &block)
|
56
|
+
else
|
57
|
+
yield name, v
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Put.to('/path', {param1: 'foo'})
|
2
|
+
module OpenKit
|
3
|
+
module Request
|
4
|
+
|
5
|
+
class Put < Base
|
6
|
+
|
7
|
+
def self.to(path, req_params)
|
8
|
+
new(path, req_params).perform
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(path, req_params)
|
12
|
+
super :put, PutDelegate.new(path, req_params)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
class PutDelegate < BaseDelegate
|
18
|
+
|
19
|
+
def initialize(path, req_params)
|
20
|
+
super(path)
|
21
|
+
@req_params = req_params
|
22
|
+
end
|
23
|
+
|
24
|
+
def net_request
|
25
|
+
req = Net::HTTP::Put.new(uri.request_uri)
|
26
|
+
req.set_body_internal(@req_params.to_json)
|
27
|
+
req['Content-Type'] = "application/json; charset=utf-8"
|
28
|
+
req['Accept'] = "application/json"
|
29
|
+
req
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module OpenKit
|
2
|
+
module Request
|
3
|
+
|
4
|
+
class Upload
|
5
|
+
attr_accessor :param_name, :filepath
|
6
|
+
|
7
|
+
def initialize(param_name, filepath)
|
8
|
+
@param_name = param_name
|
9
|
+
@filepath = filepath
|
10
|
+
end
|
11
|
+
|
12
|
+
def file
|
13
|
+
@file ||= File.open(@filepath)
|
14
|
+
end
|
15
|
+
|
16
|
+
def close
|
17
|
+
@file.close if @file # Use ivar directly, not the #file method.
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/openkit.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'openkit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "openkit"
|
8
|
+
spec.version = Openkit::VERSION
|
9
|
+
spec.authors = ["Lou Zell"]
|
10
|
+
spec.email = ["lou@openkit.io"]
|
11
|
+
spec.description = %q{List leaderboards, post scores, etc.}
|
12
|
+
spec.summary = %q{Client for OpenKit's gaming backend}
|
13
|
+
spec.homepage = "https://github.com/OpenKit/openkit-server/tree/development/clients/ruby"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.files = %w[
|
16
|
+
Gemfile
|
17
|
+
LICENSE.txt
|
18
|
+
README.md
|
19
|
+
Rakefile
|
20
|
+
lib/openkit.rb
|
21
|
+
lib/openkit/request/base.rb
|
22
|
+
lib/openkit/request/base_delegate.rb
|
23
|
+
lib/openkit/request/delete.rb
|
24
|
+
lib/openkit/request/get.rb
|
25
|
+
lib/openkit/request/post.rb
|
26
|
+
lib/openkit/request/post_multipart.rb
|
27
|
+
lib/openkit/request/put.rb
|
28
|
+
lib/openkit/request/upload.rb
|
29
|
+
lib/openkit/request.rb
|
30
|
+
lib/openkit/version.rb
|
31
|
+
test/api/score_api_test.rb
|
32
|
+
test/api/user_api_test.rb
|
33
|
+
test/test_helper.rb
|
34
|
+
openkit.gemspec
|
35
|
+
]
|
36
|
+
spec.executables = []
|
37
|
+
spec.test_files = spec.files.grep(%r{^(test)/})
|
38
|
+
spec.require_paths = ["lib"]
|
39
|
+
|
40
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
41
|
+
spec.add_development_dependency "rake"
|
42
|
+
spec.add_development_dependency "minitest", "~> 4.7"
|
43
|
+
spec.add_development_dependency "turn"
|
44
|
+
|
45
|
+
spec.add_dependency 'multipart-post'
|
46
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'test_helper.rb'
|
2
|
+
|
3
|
+
class ScoreApiTest < ApiTest
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@leaderboard_id = 831
|
7
|
+
@user_id = 237492
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_create
|
11
|
+
custom_id = random_alphanumeric(7)
|
12
|
+
nick = "guest-#{custom_id}"
|
13
|
+
|
14
|
+
request = Post.new '/v1/scores', {score: {user_id: @user_id, leaderboard_id: @leaderboard_id, value: 100}}
|
15
|
+
response = request.perform
|
16
|
+
assert response.code =~ /^20\d/, "Got a return code of #{response.code}"
|
17
|
+
|
18
|
+
score = JSON.parse(response.body)
|
19
|
+
assert score['id']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper.rb'
|
2
|
+
|
3
|
+
class UserApiTest < ApiTest
|
4
|
+
def test_create
|
5
|
+
custom_id = random_alphanumeric(7)
|
6
|
+
nick = "guest-#{custom_id}"
|
7
|
+
|
8
|
+
request = Post.new '/v1/users', {user: {custom_id: custom_id, nick: nick}}
|
9
|
+
response = request.perform
|
10
|
+
assert response.code =~ /^20\d/
|
11
|
+
|
12
|
+
user = JSON.parse(response.body)
|
13
|
+
assert user['id']
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'openkit'
|
2
|
+
gem "minitest", '~>4.7'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'turn'
|
5
|
+
#require 'debugger'
|
6
|
+
|
7
|
+
class ApiTest < MiniTest::Unit::TestCase
|
8
|
+
include OpenKit::Request
|
9
|
+
|
10
|
+
def setup
|
11
|
+
OpenKit::Config.skip_https = true
|
12
|
+
OpenKit::Config.app_key = '9c7FMNznXbQC4Pr4FHi5'
|
13
|
+
OpenKit::Config.secret_key = 'o2HdzSZg99jdmP4oi0LdiJwFPYG06gXvCGqNHeXG'
|
14
|
+
end
|
15
|
+
|
16
|
+
def random_alphanumeric(n)
|
17
|
+
Array.new(n){[*'0'..'9', *'a'..'z', *'A'..'Z'].sample}.join
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openkit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lou Zell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
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: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: turn
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: multipart-post
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: List leaderboards, post scores, etc.
|
84
|
+
email:
|
85
|
+
- lou@openkit.io
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- Gemfile
|
91
|
+
- LICENSE.txt
|
92
|
+
- README.md
|
93
|
+
- Rakefile
|
94
|
+
- lib/openkit.rb
|
95
|
+
- lib/openkit/request/base.rb
|
96
|
+
- lib/openkit/request/base_delegate.rb
|
97
|
+
- lib/openkit/request/delete.rb
|
98
|
+
- lib/openkit/request/get.rb
|
99
|
+
- lib/openkit/request/post.rb
|
100
|
+
- lib/openkit/request/post_multipart.rb
|
101
|
+
- lib/openkit/request/put.rb
|
102
|
+
- lib/openkit/request/upload.rb
|
103
|
+
- lib/openkit/request.rb
|
104
|
+
- lib/openkit/version.rb
|
105
|
+
- test/api/score_api_test.rb
|
106
|
+
- test/api/user_api_test.rb
|
107
|
+
- test/test_helper.rb
|
108
|
+
- openkit.gemspec
|
109
|
+
homepage: https://github.com/OpenKit/openkit-server/tree/development/clients/ruby
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.1.11
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Client for OpenKit's gaming backend
|
133
|
+
test_files:
|
134
|
+
- test/api/score_api_test.rb
|
135
|
+
- test/api/user_api_test.rb
|
136
|
+
- test/test_helper.rb
|