akagi 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 +18 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +8 -0
- data/akagi.gemspec +19 -0
- data/lib/akagi.rb +5 -0
- data/lib/akagi/base.rb +60 -0
- data/lib/akagi/version.rb +3 -0
- data/spec/akagi/base_spec.rb +57 -0
- data/spec/akagi_spec.rb +11 -0
- data/spec/spec_helper.rb +8 -0
- metadata +63 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 JakubOboza
|
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,29 @@
|
|
1
|
+
# Akagi
|
2
|
+
|
3
|
+
Akagi was super ''uber'' pro Japan made aircraft carrier made from cruiser.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'akagi'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install akagi
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/akagi.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'akagi/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "akagi"
|
8
|
+
gem.version = Akagi::VERSION
|
9
|
+
gem.authors = ["JakubOboza"]
|
10
|
+
gem.email = ["jakub.oboza@gmail.com"]
|
11
|
+
gem.description = %q{Simple Midway game-server client library}
|
12
|
+
gem.summary = %q{Simple battleships "Midway" server client that can be used to prototype fast your own game without handling billions of random stuff}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/lib/akagi.rb
ADDED
data/lib/akagi/base.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Akagi
|
5
|
+
|
6
|
+
class Base
|
7
|
+
|
8
|
+
attr_accessor :base_url, :team_id, :key
|
9
|
+
|
10
|
+
def initialize(base_url, team_id, key)
|
11
|
+
@base_url = base_url.to_s
|
12
|
+
@key = key.to_s
|
13
|
+
@team_id = team_id.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(url)
|
17
|
+
RestClient.get url, "HTTP_MIDWAY_API_KEY" => @key, :content_type => "application/json"
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(url)
|
21
|
+
RestClient.delete url, "HTTP_MIDWAY_API_KEY" => @key, :content_type => "application/json"
|
22
|
+
end
|
23
|
+
|
24
|
+
def post(url, payload = {})
|
25
|
+
RestClient.post url, payload.to_json, "HTTP_MIDWAY_API_KEY" => @key, :content_type => "application/json"
|
26
|
+
end
|
27
|
+
|
28
|
+
def maps_url(extra_bit_of_url = "")
|
29
|
+
extra_bit_of_url ||= ""
|
30
|
+
File.join([@base_url, "teams", @team_id, "maps", extra_bit_of_url.to_s])
|
31
|
+
end
|
32
|
+
|
33
|
+
def game_url
|
34
|
+
File.join(@base_url, "teams", @team_id, "game")
|
35
|
+
end
|
36
|
+
|
37
|
+
def maps
|
38
|
+
self.get(self.maps_url())
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_map(map_id)
|
42
|
+
self.delete(self.maps_url(map_id))
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_map(map)
|
46
|
+
self.post(self.maps_url(), {"grid" => map})
|
47
|
+
end
|
48
|
+
|
49
|
+
def game_status
|
50
|
+
self.get(self.game_url)
|
51
|
+
end
|
52
|
+
|
53
|
+
def game_move(move = [])
|
54
|
+
self.post(self.game_url, {"move" => move})
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Akagi::Base do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@base_url = "http://localhost:3000"
|
7
|
+
@team_id = "13"
|
8
|
+
@key = "f94a8505949317a54c96c3d21de2007da2a3f139"
|
9
|
+
@client = Akagi::Base.new(@base_url, @team_id, @key)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "maps" do
|
13
|
+
|
14
|
+
it "can get maps list" do
|
15
|
+
stub_request(:get, "http://localhost:3000/teams/13/maps/")
|
16
|
+
@client.maps
|
17
|
+
WebMock.should have_requested(:get, "http://localhost:3000/teams/13/maps/").with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json', 'Http-Midway-Api-Key'=>'f94a8505949317a54c96c3d21de2007da2a3f139', 'User-Agent'=>'Ruby'})
|
18
|
+
end
|
19
|
+
|
20
|
+
it "can delete map" do
|
21
|
+
stub_request(:delete, "http://localhost:3000/teams/13/maps/1")
|
22
|
+
@client.delete_map(1)
|
23
|
+
WebMock.should have_requested(:delete, "http://localhost:3000/teams/13/maps/1").
|
24
|
+
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json', 'Http-Midway-Api-Key'=>'f94a8505949317a54c96c3d21de2007da2a3f139', 'User-Agent'=>'Ruby'})
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can add map" do
|
28
|
+
stub_request(:post, "http://localhost:3000/teams/13/maps/")
|
29
|
+
@client.add_map([[2, 1, 5, "across"], [0, 3, 4, "down"], [2, 6, 3, "across"], [6, 4, 3, "across"], [3, 4, 2, "down"]])
|
30
|
+
WebMock.should have_requested(:post, "http://localhost:3000/teams/13/maps/").
|
31
|
+
with(:body => "{\"grid\":[[2,1,5,\"across\"],[0,3,4,\"down\"],[2,6,3,\"across\"],[6,4,3,\"across\"],[3,4,2,\"down\"]]}",
|
32
|
+
:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'91', 'Content-Type'=>'application/json', 'Http-Midway-Api-Key'=>'f94a8505949317a54c96c3d21de2007da2a3f139', 'User-Agent'=>'Ruby'})
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "game" do
|
39
|
+
|
40
|
+
it "can check game status" do
|
41
|
+
stub_request(:get, "http://localhost:3000/teams/13/game")
|
42
|
+
@client.game_status
|
43
|
+
WebMock.should have_requested(:get, "http://localhost:3000/teams/13/game").
|
44
|
+
with(:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Type'=>'application/json', 'Http-Midway-Api-Key'=>'f94a8505949317a54c96c3d21de2007da2a3f139', 'User-Agent'=>'Ruby'})
|
45
|
+
end
|
46
|
+
|
47
|
+
it "can make game move" do
|
48
|
+
stub_request(:post, "http://localhost:3000/teams/13/game")
|
49
|
+
@client.game_move([2,1])
|
50
|
+
WebMock.should have_requested(:post, "http://localhost:3000/teams/13/game").
|
51
|
+
with(:body => "{\"move\":[2,1]}",
|
52
|
+
:headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'14', 'Content-Type'=>'application/json', 'Http-Midway-Api-Key'=>'f94a8505949317a54c96c3d21de2007da2a3f139', 'User-Agent'=>'Ruby'})
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/spec/akagi_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: akagi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- JakubOboza
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-21 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Simple Midway game-server client library
|
15
|
+
email:
|
16
|
+
- jakub.oboza@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rspec
|
23
|
+
- .travis.yml
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- akagi.gemspec
|
29
|
+
- lib/akagi.rb
|
30
|
+
- lib/akagi/base.rb
|
31
|
+
- lib/akagi/version.rb
|
32
|
+
- spec/akagi/base_spec.rb
|
33
|
+
- spec/akagi_spec.rb
|
34
|
+
- spec/spec_helper.rb
|
35
|
+
homepage: ''
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.8.24
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: Simple battleships "Midway" server client that can be used to prototype fast
|
59
|
+
your own game without handling billions of random stuff
|
60
|
+
test_files:
|
61
|
+
- spec/akagi/base_spec.rb
|
62
|
+
- spec/akagi_spec.rb
|
63
|
+
- spec/spec_helper.rb
|