koa 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f0a36d7a479927aedae831cc52ea4666a6459eb
4
- data.tar.gz: 7b2715f889d044cffb30d99817c8af4c214aad55
3
+ metadata.gz: 4527672e44d188f950838b2ffb7cf0c4fab99519
4
+ data.tar.gz: a24329ff70bb83b6c1a38c545bb2b4e8a88914e2
5
5
  SHA512:
6
- metadata.gz: 8fade97f37ecf8561faf373260090983c7a4e7b0225ea9d515012ac515ac5ae2cc7c9ffc7a507c93557747f7423cba5351b3775cd0d18381930358c78e6de529
7
- data.tar.gz: 2c00d131a8c09746da4ed3312f8815188fa3e7f6c1db732f47a7fe16ab3010dc0f6474538f9a4a9206e72ff151e3d3ae4c0d06f2834797cdb16f238087db2b58
6
+ metadata.gz: 7694ae4f33a88a267786303ce3ece54457988c228652432444f160232225b2978f8a9883e015a1b1eaac13732e8533f7c4bac9378704ca1a9b5998b6a9d57e8c
7
+ data.tar.gz: c91060f60942fd40c8838312c2284e49c2a1944adc191a96bc1532ca497e3ac5af6ab6bbd3dad8f145a6fe5239be03a7ce5eb4ef09e7929e0ff8ea638317405e
@@ -2,9 +2,12 @@ require 'json'
2
2
  require 'net/http'
3
3
  require 'timeout'
4
4
 
5
- module Koa::Kik
6
- def self.purchase(signedData, username, host)
7
- Koa::Logger.measure_block("kikpurchase") do
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
- end
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
- end
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
- end
48
-
49
- def self.request_with_retry(url, body, tries, seconds = 2)
50
- tries.times do
51
- begin
52
- Timeout::timeout(seconds) do
53
- return request(url, body)
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
- end
61
-
62
- def self.request(url, body)
63
- uri = URI.parse(url)
64
- http = Net::HTTP.new(uri.host, uri.port)
65
- http.use_ssl = true
66
- request = Net::HTTP::Post.new(uri.request_uri)
67
- request.add_field('Content-Type', 'application/json')
68
- request.add_field('Content-Length', body.size)
69
-
70
- request.body = body
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
- def bad_token?
84
- @response and @response.code.to_i == 403
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
- Logger.measure_block("leaderboard-client.get-leaderboards") do
11
- response = Koa::Request.make(
12
- type: :get,
13
- url: URL + "/boards",
14
- data: {limit: limit, game_id: GAME_ID}
15
- )
16
- if response.successful?
17
- JSON.parse(response.body)
18
- else
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
- Logger.measure_block("leaderboard-client.get-user-scores") do
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
- 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
- Logger.measure_block("leaderboard-client.add-score") do
39
- Koa::Request.make(
40
- type: :put,
41
- url: URL + "/score",
42
- data: {
43
- user_id: user_id,
44
- score: score,
45
- request_id: SecureRandom.uuid,
46
- game_id: GAME_ID
47
- },
48
- tries: 3,
49
- timeout: 5
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.6
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-01-02 00:00:00.000000000 Z
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