mcbans 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Gemfile +3 -0
  2. data/LICENSE +14 -0
  3. data/README.md +43 -0
  4. data/lib/mcbans.rb +69 -0
  5. data/mcbans.gemspec +13 -0
  6. metadata +82 -0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'json'
data/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2011 Scott Barron <scott@elitists.net>
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for any
4
+ purpose with or without fee is hereby granted, provided that the above
5
+ copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
+
@@ -0,0 +1,43 @@
1
+ # MCBans
2
+
3
+ A simple library for accessing the MCBans API from Ruby.
4
+
5
+ ## Install
6
+
7
+ gem install mcbans
8
+
9
+ ## Usage
10
+
11
+ ```
12
+ mcbans = MCBans.new('yourapikey')
13
+ player = mcbans.lookup('rubyist')
14
+ puts player.reputation #=> 10
15
+
16
+ mcbans.unban('foobar')
17
+ mcbans.global_ban('foobar', 'admin', 'griefing')
18
+ mcbans.local_ban('foobar', 'admin', 'griefing')
19
+ ```
20
+
21
+ ## Development
22
+
23
+ - Source hosted at [GitHub](https://github.com/rubyist/mcbans)
24
+ - Report issues and feature requests to [GitHub Issues](https://github.com/rubyist/mcbans/issues)
25
+
26
+ ## License
27
+
28
+ (The MIT License)
29
+
30
+ Copyright (c) 2011 Scott Barron
31
+
32
+ Permission to use, copy, modify, and/or distribute this software for any
33
+ purpose with or without fee is hereby granted, provided that the above
34
+ copyright notice and this permission notice appear in all copies.
35
+
36
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
37
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
38
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
39
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
40
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
41
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
42
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
43
+
@@ -0,0 +1,69 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'ostruct'
4
+
5
+
6
+ class MCBans
7
+ def initialize(api_key)
8
+ @api_key = api_key
9
+ end
10
+
11
+ def ping
12
+ request({'exec' => 'check'}) == 'up'
13
+ end
14
+
15
+ def lookup(player)
16
+ OpenStruct.new JSON.parse(request('player' => player, 'exec' => 'playerLookup'))
17
+ end
18
+
19
+ def unban(player, admin='[RUBY]')
20
+ data = {
21
+ 'player' => player,
22
+ 'admin' => admin,
23
+ 'exec' => 'unBan'
24
+ }
25
+ request(JSON.parse(data))
26
+ end
27
+
28
+ def local_ban(player, admin='[RUBY]', reason='Local Banned')
29
+ data = {
30
+ 'player' => player,
31
+ 'admin' => admin,
32
+ 'reason' => reason,
33
+ 'exec' => 'localBan'
34
+ }
35
+ request(JSON.parse(data))
36
+ end
37
+
38
+ def global_ban(player, admin='[RUBY]', reason='Global Banned')
39
+ data = {
40
+ 'player' => player,
41
+ 'admin' => admin,
42
+ 'reason' => reason,
43
+ 'exec' => 'globalBan'
44
+ }
45
+ request(JSON.parse(data))
46
+ end
47
+
48
+ def temp_ban(player, duration, measure='m', admin='[RUBY]', reason='Temp Banned')
49
+ data = {
50
+ 'player' => player,
51
+ 'duration' => duration,
52
+ 'measure' => measure,
53
+ 'admin' => admin,
54
+ 'reason' => reason,
55
+ 'exec' => 'globalBan'
56
+ }
57
+ request(JSON.parse(data))
58
+ end
59
+
60
+ private
61
+ def url
62
+ @_uri ||= URI.parse("http://api.mcbans.com/v2/#{@api_key}/")
63
+ end
64
+
65
+ def request(data)
66
+ response = Net::HTTP.post_form(url, data)
67
+ response.body
68
+ end
69
+ end
@@ -0,0 +1,13 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "mcbans"
3
+ s.version = "1.0.0"
4
+ s.date = "2011-12-28"
5
+ s.summary = "Access the MCBans API from Ruby"
6
+ s.email = "scott@elitists.net"
7
+ s.homepage = "http://github.com/rubyist/mcbans"
8
+ s.description = "Access the MCBans API from Ruby"
9
+ s.has_rdoc = false
10
+ s.authors = ["Scott Barron"]
11
+ s.files = ["Gemfile", "LICENSE", "README.md", "mcbans.gemspec"] + Dir['**/*.rb']
12
+ s.add_dependency('json')
13
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mcbans
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Scott Barron
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-12-28 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: json
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description: Access the MCBans API from Ruby
35
+ email: scott@elitists.net
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - Gemfile
44
+ - LICENSE
45
+ - README.md
46
+ - mcbans.gemspec
47
+ - lib/mcbans.rb
48
+ homepage: http://github.com/rubyist/mcbans
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 3
62
+ segments:
63
+ - 0
64
+ version: "0"
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.8.5
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Access the MCBans API from Ruby
81
+ test_files: []
82
+