alacrity_client 0.0.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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in alacrity_client.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ Alacrity Client
2
+ ===============
3
+
4
+ What is it ?
5
+ -------------
6
+
7
+ A ruby gem for accessing an alacrity server.
8
+
9
+ provides async and sync calls for updating a players rank and for querying a players rank.
10
+
11
+ Very much unstable at the moment, so use at your own risk
12
+
13
+ author: Sean Reilly
14
+ email: reillyse@gmail.com
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "alacrity_client/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "alacrity_client"
7
+ s.version = AlacrityClient::VERSION
8
+ s.authors = ["Sean Reilly"]
9
+ s.email = ["reillyse@gmail.com"]
10
+ s.homepage = "http://github.com/reillyse/alacrity_client"
11
+ s.summary = %q{This gem provides access to an alacrity server}
12
+ s.description = %q{Gem provides synch and async calls for getting a players rank and updating a players rank}
13
+
14
+ s.rubyforge_project = "alacrity_client"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ s.add_development_dependency "rspec", "~> 2.6"
21
+ s.add_dependency "em-http-request"
22
+ s.add_dependency "json"
23
+ end
@@ -0,0 +1,5 @@
1
+ require "alacrity_client/version"
2
+
3
+ module AlacrityClient
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,46 @@
1
+ require 'net/http'
2
+ require 'net/https'
3
+ require 'em-http-request'
4
+ require 'json'
5
+ class AlacrityClient::Connection
6
+
7
+ def initialize(server = "localhost",port = 8888)
8
+ @server = server
9
+ @port = port
10
+ end
11
+
12
+ def get_player_ranking(player)
13
+ @http ||= Net::HTTP.new(@server, @port)
14
+ path = "/getPlayerRanking?playerNum=#{player}"
15
+ resp, data = @http.get(path, nil)
16
+ return JSON(data)
17
+
18
+ end
19
+
20
+ def update_player_ranking(player,rank,type)
21
+ @http = Net::HTTP.new(@server, @port)
22
+ path = '/updatePlayerRanking'
23
+ data = "playerNum=#{player}&rank=#{rank}&type=#{type}"
24
+ headers = {
25
+ 'Content-Type' => 'application/x-www-form-urlencoded'
26
+ }
27
+ resp, data = @http.post(path, data, headers)
28
+ return JSON(data)
29
+ end
30
+
31
+ # using this method only makes sense if you are running event machine
32
+ def get_player_ranking_async(player,callback_success,callback_err )
33
+ http = EventMachine::HttpRequest.new("http://#{@server}:#{@port}/getPlayerRanking").get :query => {'playerNum' => player}
34
+ http.errback { callback_err.call(http)}
35
+ http.callback { callback_success.call(http)}
36
+ end
37
+
38
+ # using this method only makes sense if you are running event machine
39
+ def update_player_ranking_async(player,rank,type,callback_success ,callback_err )
40
+
41
+ http = EventMachine::HttpRequest.new("http://#{@server}:#{@port}/updatePlayerRanking").post :body => {'playerNum' => player,'type' => type,'rank'=>rank}
42
+ http.errback { callback_err.call(http)}
43
+ http.callback { callback_success.call(http)}
44
+ end
45
+ end
46
+
@@ -0,0 +1,3 @@
1
+ module AlacrityClient
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,53 @@
1
+ require 'alacrity_client/connection'
2
+ describe AlacrityClient::Connection do
3
+
4
+
5
+ # this really isn't much use as a general test file, it very much relies
6
+ # on what is currently defined on the server side of things and can really
7
+ # only be used with a correctly configured server (i.e. the aggragator)
8
+ # for example the "kills" and "eats" are very much game specific
9
+ # that said, it should still connect if you have the server running in the
10
+ # right place (localhost:8888 at the moment) and the tests should still pass
11
+ # so it does test the structure of the api
12
+
13
+ it "should connect and get correctly async" do
14
+
15
+ EventMachine.run {
16
+ client = AlacrityClient::Connection.new
17
+ client.get_player_ranking_async(1,lambda { |http| p JSON(http.response) ;EM.stop},lambda { |http| p "Error.. #{http.error}" ;EM.stop})
18
+
19
+ }
20
+ end
21
+
22
+ it "it should connect and post correctly async" do
23
+ client = AlacrityClient::Connection.new
24
+ EventMachine.run {
25
+ client.update_player_ranking_async(1,100,"kills",lambda { |http| p JSON(http.response) ;EM.stop},lambda { |http| p "Error.. #{http.error}" ;EM.stop })
26
+ }
27
+ EventMachine.run {
28
+ client.update_player_ranking_async(1,100,"eats",lambda { |http| p JSON(http.response) ;EM.stop},lambda { |http| p "Error.. #{http.error}" ;EM.stop })
29
+ }
30
+ EventMachine.run {
31
+ client.get_player_ranking_async(1,lambda { |http| p JSON(http.response) ;EM.stop },lambda { |http| p "Error.. #{http.error}" ;EM.stop })
32
+ }
33
+ end
34
+
35
+ it "should connect and get ranking synchronously too" do
36
+ client = AlacrityClient::Connection.new
37
+ client.get_player_ranking(1)
38
+ end
39
+
40
+
41
+ it "should connect and update synchronously too" do
42
+ client = AlacrityClient::Connection.new
43
+ client.update_player_ranking(1,100,"kills")
44
+ end
45
+
46
+ it "should be able to operate asynchronously" do
47
+ client = AlacrityClient::Connection.new
48
+ EventMachine.run {
49
+ client.update_player_ranking_async(1,100,"kills",lambda { |http| puts "working" ; puts JSON(http.response) ;EM.stop}, lambda{ |http| puts "error" ; puts http.error ; EM.stop})
50
+ puts "should happen first or in between not after"
51
+ }
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alacrity_client
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Sean Reilly
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-01 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 2
31
+ - 6
32
+ version: "2.6"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: em-http-request
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: json
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :runtime
62
+ version_requirements: *id003
63
+ description: Gem provides synch and async calls for getting a players rank and updating a players rank
64
+ email:
65
+ - reillyse@gmail.com
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - .gitignore
74
+ - Gemfile
75
+ - README.md
76
+ - Rakefile
77
+ - alacrity_client.gemspec
78
+ - lib/alacrity_client.rb
79
+ - lib/alacrity_client/connection.rb
80
+ - lib/alacrity_client/version.rb
81
+ - spec/alacrity_client_spec.rb
82
+ homepage: http://github.com/reillyse/alacrity_client
83
+ licenses: []
84
+
85
+ post_install_message:
86
+ rdoc_options: []
87
+
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
98
+ version: "0"
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
107
+ version: "0"
108
+ requirements: []
109
+
110
+ rubyforge_project: alacrity_client
111
+ rubygems_version: 1.8.10
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: This gem provides access to an alacrity server
115
+ test_files: []
116
+