battle-on 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in battle-on.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alekx Lang
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
+ # Battle::On
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'battle-on'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install battle-on
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 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/battle-on.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/battle_on/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alekx Lang"]
6
+ gem.email = ["alekx.lang@gmail.com"]
7
+ gem.description = %q{A gem that provides a simple API to ease interacting with the Platform45 API for their Battleship challenge: battle.platform45.com}
8
+ gem.summary = %q{A little weapon to help fight Platform45's Battleship API.}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "battle-on"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = BattleOn::VERSION
17
+ gem.add_development_dependency(%q<rspec>, [">= 2.0"])
18
+ gem.add_development_dependency(%q<webmock>, [">= 1.11.0"])
19
+ gem.add_dependency(%q<rest-client>, [">= 1.6.7"])
20
+ end
@@ -0,0 +1,35 @@
1
+ require 'json'
2
+ require 'rest_client'
3
+
4
+ module BattleOn
5
+
6
+ #Start the game
7
+ #
8
+ #mandatory parameters
9
+ #email: my@email.com
10
+ #name: My Name
11
+
12
+ class RegisterGame
13
+ attr_reader :name, :email
14
+
15
+ def self.execute(name, email)
16
+ new(name, email).execute
17
+ end
18
+
19
+ def initialize(name, email)
20
+ @name, @email = name, email
21
+ end
22
+
23
+ def execute
24
+ JSON.parse register
25
+ end
26
+
27
+ private
28
+
29
+ def register
30
+ RestClient.post "http://battle.platform45.com/register", {name: name, email: email}.to_json
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,45 @@
1
+ module BattleOn
2
+
3
+ #mandatory parameters:
4
+ #
5
+ #game_id: this relates to the id Plaform45's API
6
+ #provides when you launch your attack.
7
+ #
8
+ #and the attack the at you want to send
9
+ #x and y as keys, for example
10
+ #{:x => 4, :y => 5}
11
+
12
+ class SendAttack
13
+ attr_reader :game_id, :args, :x_axis, :y_axis
14
+
15
+ def self.execute(game_id, args)
16
+ new(game_id, args).execute
17
+ end
18
+
19
+ def initialize(game_id, args)
20
+ @game_id = game_id
21
+ @x_axis = args[:x_axis] #get_x(args)
22
+ @y_axis = args[:y_axis] #get_y(args)
23
+ end
24
+
25
+ def execute
26
+ JSON.parse attack
27
+ end
28
+
29
+ private
30
+
31
+ def attack
32
+ RestClient.post "http://battle.platform45.com/nuke", { x: x_axis,
33
+ y: y_axis,
34
+ id: game_id}.to_json
35
+ end
36
+
37
+ def get_x(args)
38
+ end
39
+
40
+ def get_y(args)
41
+ end
42
+
43
+ end
44
+
45
+ end
@@ -0,0 +1,3 @@
1
+ module BattleOn
2
+ VERSION = "0.0.2"
3
+ end
data/lib/battle_on.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "battle_on/version"
2
+
3
+ #module Battle
4
+ #module On
5
+
6
+ module BattleOn
7
+
8
+ def self.begin(name, email)
9
+ RegisterGame.execute(name: name, email: email)
10
+ end
11
+
12
+ def self.attack(game_id, attack={})
13
+ SendAttack.execute(game_id: game_id, attack: attack)
14
+ end
15
+
16
+ end
17
+
18
+ #end
19
+ #end
@@ -0,0 +1,7 @@
1
+ module RegisterGameSpecHelper
2
+
3
+ def stubbed_request
4
+ stub_request(:post, "http://battle.platform45.com/register").with(:body => "{\"name\":\"henry@thehthornton.com\",\"email\":\"henry thornton\"}", :headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'58', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => {:id => 100, :x => 3, :y => 2}.to_json, :headers => {})
5
+ end
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ module SendAttackSpecHelper
2
+
3
+ def stubbed_request
4
+ stub_request(:post, "http://battle.platform45.com/nuke").with(:body => "{\"x\":null,\"y\":null,\"id\":100}", :headers => {'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Content-Length'=>'28', 'User-Agent'=>'Ruby'}).to_return(:status => 200, :body => { :status=>"hit", :x => 0, :y => 4 }.to_json, :headers => {})
5
+ end
6
+
7
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper_base'
2
+ require 'helpers/register_game_spec_helper'
3
+
4
+ describe BattleOn::RegisterGame do
5
+
6
+ include RegisterGameSpecHelper
7
+
8
+ describe ".execute" do
9
+
10
+ let( :name ) { "henry@thehthornton.com" }
11
+ let( :email ) { "henry thornton" }
12
+ let( :begin_battle ) { BattleOn::RegisterGame }
13
+
14
+ context "returns a new game" do
15
+
16
+ it "returns a hash" do
17
+ #given
18
+ stubbed_request
19
+ #when
20
+ new_battle = begin_battle.execute(name, email)
21
+ #expect
22
+ new_battle.should be_an_instance_of(Hash)
23
+ end
24
+
25
+ it "game contains a id" do
26
+ #given
27
+ stubbed_request
28
+ #when
29
+ new_battle = begin_battle.execute(name, email)
30
+ #expect
31
+ new_battle.should include("id")
32
+ end
33
+
34
+ it "game contains an 'x'" do
35
+ #given
36
+ stubbed_request
37
+ #when
38
+ new_battle = begin_battle.execute(name, email)
39
+ #expect
40
+ new_battle.should include("x")
41
+ end
42
+
43
+ it "game contains an 'y'" do
44
+ #given
45
+ stubbed_request
46
+ #when
47
+ new_battle = begin_battle.execute(name, email)
48
+ #expect
49
+ new_battle.should include("y")
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper_base'
2
+ require 'helpers/send_attack_spec_helper'
3
+
4
+ describe BattleOn::SendAttack do
5
+
6
+ include SendAttackSpecHelper
7
+
8
+ describe ".execute" do
9
+
10
+ let(:game) {100}
11
+ let(:coordinates) { {:x => 5, :y => 9} }
12
+ let(:send_attack) { BattleOn::SendAttack }
13
+
14
+ context "responds to the attack" do
15
+
16
+ it "response is a hash" do
17
+ #given
18
+ stubbed_request
19
+ #when
20
+ response = send_attack.execute(game, coordinates)
21
+ #expect
22
+ response.should be_an_instance_of(Hash)
23
+ end
24
+
25
+ it "response contains a status" do
26
+ #given
27
+ stubbed_request
28
+ #when
29
+ response = send_attack.execute(game, coordinates)
30
+ #expect
31
+ response.should include("status")
32
+ end
33
+
34
+ it "response contains a 'x'" do
35
+ #given
36
+ stubbed_request
37
+ #when
38
+ response = send_attack.execute(game, coordinates)
39
+ #expect
40
+ response.should include("x")
41
+ end
42
+
43
+ it "response contains a 'y'" do
44
+ #given
45
+ stubbed_request
46
+ #when
47
+ response = send_attack.execute(game, coordinates)
48
+ #expect
49
+ response.should include("y")
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'webmock/rspec'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..'))
6
+
7
+ require 'lib/battle_on/register_game'
8
+ require 'lib/battle_on/send_attack'
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: battle-on
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alekx Lang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '2.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: webmock
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.11.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.11.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rest-client
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.6.7
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.7
62
+ description: ! 'A gem that provides a simple API to ease interacting with the Platform45
63
+ API for their Battleship challenge: battle.platform45.com'
64
+ email:
65
+ - alekx.lang@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE
73
+ - README.md
74
+ - Rakefile
75
+ - battle-on.gemspec
76
+ - lib/battle_on.rb
77
+ - lib/battle_on/register_game.rb
78
+ - lib/battle_on/send_attack.rb
79
+ - lib/battle_on/version.rb
80
+ - spec/helpers/register_game_spec_helper.rb
81
+ - spec/helpers/send_attack_spec_helper.rb
82
+ - spec/register_game_spec.rb
83
+ - spec/send_attack_spec.rb
84
+ - spec/spec_helper_base.rb
85
+ homepage: ''
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.23
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: A little weapon to help fight Platform45's Battleship API.
109
+ test_files:
110
+ - spec/helpers/register_game_spec_helper.rb
111
+ - spec/helpers/send_attack_spec_helper.rb
112
+ - spec/register_game_spec.rb
113
+ - spec/send_attack_spec.rb
114
+ - spec/spec_helper_base.rb