akagi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *~
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 1.9.2
5
+ - 1.8.7
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rest-client'
4
+
5
+ # Specify your gem's dependencies in akagi.gemspec
6
+ gemspec
7
+
8
+ gem 'rspec', '~> 2.11.0'
9
+ gem 'webmock', '~> 1.8.11'
@@ -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.
@@ -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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new('spec')
7
+
8
+ task :default => :spec
@@ -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
@@ -0,0 +1,5 @@
1
+ require "akagi/version"
2
+ require "akagi/base"
3
+
4
+ module Akagi
5
+ end
@@ -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,3 @@
1
+ module Akagi
2
+ VERSION = "0.0.1"
3
+ end
@@ -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
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Akagi do
4
+
5
+ it "has version" do
6
+ lambda do
7
+ Akagi::VERSION.should_not be_nil
8
+ end.should_not raise_error
9
+ end
10
+
11
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'webmock/rspec'
4
+ require 'akagi'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
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