koa 0.0.6 → 0.0.7
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 +4 -4
- data/lib/koa/kik.rb +44 -45
- data/lib/koa/leaderboard-client.rb +31 -35
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4527672e44d188f950838b2ffb7cf0c4fab99519
|
4
|
+
data.tar.gz: a24329ff70bb83b6c1a38c545bb2b4e8a88914e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7694ae4f33a88a267786303ce3ece54457988c228652432444f160232225b2978f8a9883e015a1b1eaac13732e8533f7c4bac9378704ca1a9b5998b6a9d57e8c
|
7
|
+
data.tar.gz: c91060f60942fd40c8838312c2284e49c2a1944adc191a96bc1532ca497e3ac5af6ab6bbd3dad8f145a6fe5239be03a7ce5eb4ef09e7929e0ff8ea638317405e
|
data/lib/koa/kik.rb
CHANGED
@@ -2,9 +2,12 @@ require 'json'
|
|
2
2
|
require 'net/http'
|
3
3
|
require 'timeout'
|
4
4
|
|
5
|
-
module Koa
|
6
|
-
|
7
|
-
|
5
|
+
module Koa
|
6
|
+
module Kik
|
7
|
+
include Measurement
|
8
|
+
measure_methods :purchase, :push, :verify
|
9
|
+
|
10
|
+
def self.purchase(signedData, username, host)
|
8
11
|
url = "https://purchase.kik.com/verification/v1/check?u=#{username}&d=#{host}"
|
9
12
|
response = request_with_retry(url, signedData, 5)
|
10
13
|
if response.nil? or response.code.to_i != 200
|
@@ -16,10 +19,8 @@ module Koa::Kik
|
|
16
19
|
end
|
17
20
|
JSON.parse(response.body)
|
18
21
|
end
|
19
|
-
|
20
|
-
|
21
|
-
def self.push(token, message, data)
|
22
|
-
Koa::Logger.measure_block("kikpush") do
|
22
|
+
|
23
|
+
def self.push(token, message, data)
|
23
24
|
url = "https://api.kik.com/push/v1/send"
|
24
25
|
body = {
|
25
26
|
token: token,
|
@@ -37,51 +38,49 @@ module Koa::Kik
|
|
37
38
|
end
|
38
39
|
end
|
39
40
|
end
|
40
|
-
|
41
|
-
|
42
|
-
def self.verify(signedData, username, host)
|
43
|
-
Koa::Logger.measure_block("kikverify") do
|
41
|
+
|
42
|
+
def self.verify(signedData, username, host)
|
44
43
|
url = "https://auth.kik.com/verification/v1/check?u=#{username}&d=#{host}"
|
45
44
|
request_with_retry(url, signedData, 5).body
|
46
45
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
46
|
+
|
47
|
+
def self.request_with_retry(url, body, tries, seconds = 2)
|
48
|
+
tries.times do
|
49
|
+
begin
|
50
|
+
Timeout::timeout(seconds) do
|
51
|
+
return request(url, body)
|
52
|
+
end
|
53
|
+
rescue Timeout::Error
|
54
|
+
Koa::Logger.count("kiktimeout", 1)
|
55
|
+
nil
|
54
56
|
end
|
55
|
-
rescue Timeout::Error
|
56
|
-
Koa::Logger.count("kiktimeout", 1)
|
57
|
-
nil
|
58
57
|
end
|
59
58
|
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
http.request(request)
|
72
|
-
end
|
73
|
-
|
74
|
-
class PushResponse
|
75
|
-
def initialize(response)
|
76
|
-
@response = response
|
77
|
-
end
|
78
|
-
|
79
|
-
def success?
|
80
|
-
@response and @response.code.to_i == 200
|
59
|
+
|
60
|
+
def self.request(url, body)
|
61
|
+
uri = URI.parse(url)
|
62
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
63
|
+
http.use_ssl = true
|
64
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
65
|
+
request.add_field('Content-Type', 'application/json')
|
66
|
+
request.add_field('Content-Length', body.size)
|
67
|
+
|
68
|
+
request.body = body
|
69
|
+
http.request(request)
|
81
70
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
71
|
+
|
72
|
+
class PushResponse
|
73
|
+
def initialize(response)
|
74
|
+
@response = response
|
75
|
+
end
|
76
|
+
|
77
|
+
def success?
|
78
|
+
@response and @response.code.to_i == 200
|
79
|
+
end
|
80
|
+
|
81
|
+
def bad_token?
|
82
|
+
@response and @response.code.to_i == 403
|
83
|
+
end
|
85
84
|
end
|
86
85
|
end
|
87
86
|
end
|
@@ -6,49 +6,45 @@ module Koa
|
|
6
6
|
URL = Conf.env!('LEADERBOARD_URL')
|
7
7
|
GAME_ID = Conf.env!('KOA_GAME_ID')
|
8
8
|
|
9
|
+
include Measurement
|
10
|
+
measure_methods :get_leaderboards, :get_user_scores, :add_score
|
11
|
+
|
9
12
|
def self.get_leaderboards(limit)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
{}
|
20
|
-
end
|
13
|
+
response = Koa::Request.make(
|
14
|
+
type: :get,
|
15
|
+
url: URL + "/boards",
|
16
|
+
data: {limit: limit, game_id: GAME_ID}
|
17
|
+
)
|
18
|
+
if response.successful?
|
19
|
+
JSON.parse(response.body)
|
20
|
+
else
|
21
|
+
{}
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
def self.get_user_scores(user_id)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
if response.successful?
|
32
|
-
user_scores = JSON.parse(response.body)
|
33
|
-
end
|
34
|
-
end
|
26
|
+
response = Koa::Request.make(
|
27
|
+
type: :get,
|
28
|
+
url: URL + "/user_scores",
|
29
|
+
data: {game_id: GAME_ID, user_id: user_id}
|
30
|
+
)
|
31
|
+
JSON.parse(response.body) if response.successful?
|
35
32
|
end
|
36
33
|
|
37
34
|
def self.add_score(user_id, score)
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
35
|
+
response = Koa::Request.make(
|
36
|
+
type: :put,
|
37
|
+
url: URL + "/score",
|
38
|
+
data: {
|
39
|
+
user_id: user_id,
|
40
|
+
score: score,
|
41
|
+
request_id: SecureRandom.uuid,
|
42
|
+
game_id: GAME_ID
|
43
|
+
},
|
44
|
+
tries: 3,
|
45
|
+
timeout: 5
|
46
|
+
)
|
47
|
+
JSON.parse(response.body)["scores"] if response.successful?
|
52
48
|
end
|
53
49
|
|
54
50
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: koa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Rykwalder
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Gem of tools for Koala
|
15
15
|
email: eric@koa.la
|