bomberman 1.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,19 @@
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
+ .idea/
19
+ *.sublime-*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3@narya-client --create
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bomberman.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 LupineDev
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,114 @@
1
+ # Bomberman
2
+
3
+ This is a ruby client gem for the Bomberman HTTP API. It has been built
4
+ and tested against Ruby 1.9.3.
5
+
6
+ [Bomberman](http://addons.heroku.com/bomberman): shelter from profanity bombing, is an [add-on](http://addons.heroku.com) for Heroku
7
+ applications. If you would like to be part of the alpha or early beta
8
+ testing process please email <bomberman-support@ikayzo.com>.
9
+
10
+ For detailed instructions on installing the addon to your Heroku
11
+ application please see our [add-on documentation page](http://bomberman.ikayzo.com/)
12
+
13
+ ## Using with Rails 3.x
14
+
15
+ We developed a ruby client gem for making requests to the
16
+ Bomberman API.
17
+
18
+ Ruby on Rails applications will need to add the following entry into their `Gemfile` specifying the Bomberman client library.
19
+
20
+ ```ruby
21
+ gem 'bomberman'
22
+ ```
23
+
24
+ Update application dependencies with bundler.
25
+
26
+ ```term
27
+ $ bundle install
28
+ ```
29
+
30
+ Now create an initializer file `config/initializers/bomberman.rb` with
31
+ your `BOMBERMAN_API_KEY`
32
+
33
+ ```ruby
34
+ Bomberman.configure do |config|
35
+ config.api_key = ENV['BOMBERMAN_API_KEY']
36
+ end
37
+ ```
38
+ From here you can call the Bomberman::Profanity functionality within
39
+ your application.
40
+
41
+ ### Checking if Text Contains Profanity
42
+
43
+ To check if a piece of text or *corpus* contains profanity use the
44
+ `.profane?(corpus)` method. This will return a boolean value as the
45
+ result
46
+
47
+ ```ruby
48
+ non_profane_text = "The quick brown fox jumped over the lazy dog."
49
+ Bomberman::Profanity.profane?(non_profane_text)
50
+ #=> false
51
+ profane_text = "The quick brown fox jumped over the F-BOMBing lazy dog."
52
+ Bomberman::Profanity.profane?(profane_text)
53
+ #=> true
54
+ ```
55
+
56
+ ### Censoring Profane Words & Phrases
57
+
58
+ If you would like to save or display text where the profane words (if
59
+ any) are obfuscated the `.censor(corpus, replacement_text)` method is
60
+ what you are looking for.
61
+
62
+ ```ruby
63
+ non_profane_text = "The quick brown fox jumped over the lazy dog."
64
+ Bomberman::Profanity.censor(non_profane_text, "####")
65
+ #=> "The quick brown fox jumped over the lazy dog."
66
+ profane_text = "The quick brown fox jumped over the F-BOMBing lazy dog."
67
+ Bomberman::Profanity.censor(profane_text, "####")
68
+ #=> "The quick brown fox jumped over the ### lazy dog."
69
+ ```
70
+
71
+ The `replacement_text` parameter is a string and optional. `"***"` is
72
+ suppled by default.
73
+
74
+ ### Highlighting Profane Words & Phrases
75
+
76
+ Sometimes it is useful to leave the original profane word/phrase intact
77
+ but wrap it in some sort of tag to make it stand out. This can be
78
+ accomplished with the `.highlight(corpus, start_tag, end_tag)` method.
79
+
80
+ ```ruby
81
+ non_profane_text = "The quick brown fox jumped over the lazy dog."
82
+ BomberMan::Profanity.highlight(non_profane_text, "<blink>", "</blink>")
83
+ #=> "The quick brown fox jumped over the lazy dog."
84
+ profane_text = "The quick brown fox jumped over the F-BOMBing lazy dog."
85
+ BomberMan::Profanity.highlight(profane_text, "<blink>", "</blink>")
86
+ #=> "The quick brown fox jumped over the <blink>F-BOMBing</blink> lazy dog."
87
+ ```
88
+
89
+ The `start_tag` & `end_tag` parameters are strings and optional. A pair
90
+ of opening and closing `<span>` tags are used if none are provided.
91
+
92
+
93
+ ### Checking Japanese Text for Profanity.
94
+
95
+ Bomberman supports for checking Japanese text for profanity.
96
+ To do this pass an optional language argument with the value `:ja` as the
97
+ last parameter to any of the `Bomberman::Profanity` methods
98
+
99
+ ```ruby
100
+ non_profane_text = "聖パトリックの日"
101
+ Bomberman::Profanity.profane?(non_profane_text, :ja)
102
+ #=> false
103
+ ```
104
+
105
+ For more info on customizing Bomberman please refer to the [add-on documentation](http://bomberman.ikayzo.com/).
106
+ ## Troubleshooting
107
+
108
+ We are just starting out. If you experience trouble please contact us
109
+ at <bomberman-support@ikayzo.com>.
110
+
111
+ ## Contributing
112
+
113
+ Given the early stage of this project we are open to comments &
114
+ suggestions for this library please send them to <bomberman-support@ikayzo.com>.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bomberman.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bomberman/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "bomberman"
8
+ gem.version = Bomberman::VERSION
9
+ gem.authors = ["Ikayzo"]
10
+ gem.email = ["chris@ikayzo.com"]
11
+ gem.summary = %q{Shelter from profanity bombing}
12
+ gem.description = %q{Client for interacting with Bomberman HTTP API. For more information visit http://bomberman.ikayzo.com/}
13
+ gem.homepage = "https://github.com/ikayzo/bomberman-ruby"
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
+ gem.add_runtime_dependency "faraday", ["~>0.8.5"]
20
+ gem.add_runtime_dependency "json", [">=1.7.7"]
21
+ gem.add_development_dependency "rspec", ["~>2.12.0"]
22
+ end
data/lib/bomberman.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'bomberman/configuration'
2
+ require 'bomberman/connection'
3
+ require 'bomberman/error'
4
+ require 'bomberman/profanity'
5
+ require 'bomberman/string_utils'
6
+ require 'bomberman/version'
7
+
8
+ module Bomberman
9
+ class << self
10
+ include Bomberman::Configuration
11
+ #include Bomberman::Connection
12
+ attr_reader :connection
13
+
14
+ def connection
15
+ @connection ||= Connection.new
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ module Bomberman
2
+ module Configuration
3
+ VALID_OPTIONS = [:api_key, :api_version, :include_string_utils, :url].freeze
4
+ DEFAULT_VALUES = {
5
+ api_key: 'change me',
6
+ api_version: 1,
7
+ use_https: true,
8
+ include_string_utils: false,
9
+ url: 'bomberman-prod.herokuapp.com'
10
+ }.freeze
11
+ attr_accessor(*VALID_OPTIONS)
12
+ class << self
13
+
14
+ end
15
+
16
+ def configure
17
+ reset
18
+ yield self
19
+ self
20
+ end
21
+
22
+ def reset
23
+ VALID_OPTIONS.each do |key|
24
+ instance_variable_set(:"@#{key}", DEFAULT_VALUES[key])
25
+ end
26
+ self
27
+ end
28
+ alias setup reset
29
+ end
30
+ end
@@ -0,0 +1,12 @@
1
+ require 'faraday'
2
+
3
+ module Bomberman
4
+ class Connection < Faraday::Connection
5
+ def initialize
6
+ super('https://' + Bomberman.url)
7
+ self.headers['Content-Type'] = 'application/json; charset=utf-8'
8
+ self.headers['Authorization'] = "Token token=#{Bomberman.api_key}"
9
+ self
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,25 @@
1
+ module Bomberman
2
+ class Error < StandardError; end
3
+
4
+ class BadRequest < Error; end
5
+
6
+ class Unauthorized < Error; end
7
+
8
+ class Forbidden < Error; end
9
+
10
+ class NotFound < Error; end
11
+
12
+ class NotAcceptable < Error; end
13
+
14
+ class UnprocessableEntity < Error; end
15
+
16
+ class InternalServerError < Error; end
17
+
18
+ class NotImplemented < Error; end
19
+
20
+ class BadGateway < Error; end
21
+
22
+ class ServiceUnavailable < Error; end
23
+
24
+ class LanguageNotSupported < Error; end
25
+ end
@@ -0,0 +1,62 @@
1
+ require 'json'
2
+ module Bomberman
3
+ module Profanity
4
+ def self.profane?(corpus=nil, language=:en)
5
+ request = Bomberman.connection.get do |req|
6
+ req.url "#{lang_api_version(language)}/profanity/check", corpus: corpus
7
+ end
8
+
9
+ validate_status(request)
10
+
11
+ if request.status == 200
12
+ request.body.eql?("1") ? true : false
13
+ end
14
+ end
15
+
16
+ def self.censor(corpus=nil, replacement_text=nil, language=:en)
17
+ request = Bomberman.connection.get do |req|
18
+ req.url "#{lang_api_version(language)}/profanity/censor", corpus: corpus, replacement_text: replacement_text
19
+ end
20
+
21
+ validate_status(request)
22
+
23
+ if request.status == 200
24
+ JSON.parse(request.body)['censored_text']
25
+ end
26
+ end
27
+
28
+ def self.highlight(corpus=nil, start_tag=nil, end_tag=nil, language=:en)
29
+ request = Bomberman.connection.get do |req|
30
+ req.url "#{lang_api_version(language)}/profanity/highlight", corpus: corpus, start_tag: start_tag, end_tag: end_tag
31
+ end
32
+
33
+ validate_status(request)
34
+
35
+ if request.status == 200
36
+ JSON.parse(request.body)['highlighted_text']
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def self.lang_api_version(language=:en)
43
+ if language == :en
44
+ "v#{Bomberman.api_version}"
45
+ elsif language == :ja
46
+ "#{language}/v#{Bomberman.api_version}"
47
+ else
48
+ raise Bomberman::LanguageNotSupported
49
+ end
50
+ end
51
+
52
+ def self.validate_status(request)
53
+ if request.status == 400
54
+ raise Bomberman::BadRequest
55
+ elsif request.status == 401
56
+ raise Bomberman::Unauthorized
57
+ elsif request.status == 500
58
+ raise Bomberman::InternalServerError
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,9 @@
1
+ module Bomberman
2
+ module StringUtils
3
+ String.class_eval do
4
+ def profane?
5
+ Bomberman::Profanity.profane?(self) if Bomberman.include_string_utils
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Bomberman
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Bomberman::Configuration do
4
+ it 'should have default values' do
5
+ config = Bomberman.configure {}
6
+ config.api_key.should eq('change me')
7
+ config.api_version.should eq(1)
8
+ config.include_string_utils.should eq(false)
9
+ config.url.should eq('bomberman-prod.herokuapp.com')
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Bomberman::Connection do
5
+ before :all do
6
+ Bomberman.configure {}
7
+ end
8
+
9
+ it 'should inherit from Faraday::Connection' do
10
+ Bomberman::Connection.new.should be_a(Faraday::Connection)
11
+ end
12
+
13
+ describe "constructor" do
14
+ before :all do
15
+ @connection = Bomberman::Connection.new
16
+ end
17
+
18
+ it "should initialize with url based on config values" do
19
+ @connection.host.should eq(Bomberman.url)
20
+ end
21
+
22
+ it "should set the headers with application/json content type" do
23
+ @connection.headers['Content-Type'].should eq('application/json; charset=utf-8')
24
+ end
25
+
26
+ it "should set the headers correct api authorization params" do
27
+ auth_headers = "Token token=#{Bomberman.api_key}"
28
+ @connection.headers['Authorization'].should eq(auth_headers)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe Bomberman::Profanity do
5
+ before :all do
6
+ Bomberman.configure {}
7
+ end
8
+
9
+ it 'should do a get request' do
10
+ pending "need webmock tests"
11
+ Bomberman.connection.should_receive(:get)
12
+ Bomberman::Profanity.profane?("alkjsdf")
13
+ end
14
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe Bomberman::StringUtils do
4
+ describe "String extension" do
5
+ it "should give strings the #profane? method" do
6
+ "str".public_methods.should include(:profane?)
7
+ end
8
+ context "When include_string_utils is set to true" do
9
+ before :all do
10
+ Bomberman.configure do |config|
11
+ config.include_string_utils = true
12
+ end
13
+ end
14
+
15
+ it "should check the string to see if it's profane" do
16
+ string = "my str"
17
+ Bomberman::Profanity.should_receive(:profane?).with(string)
18
+ string.profane?
19
+ end
20
+
21
+ end
22
+
23
+ context "When include_string_utils is set to false" do
24
+ before :all do
25
+ Bomberman.configure {}
26
+ end
27
+
28
+ it "should NOT check the string to see if it's profane" do
29
+ string = "my str"
30
+ Bomberman::Profanity.should_not_receive(:profane?).with(string)
31
+ string.profane?
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'bomberman'
5
+
6
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
7
+
8
+ RSpec.configure do |config|
9
+ # some (optional) config here
10
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bomberman
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ikayzo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.5
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.5
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.7.7
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.7.7
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.12.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.12.0
62
+ description: Client for interacting with Bomberman HTTP API. For more information
63
+ visit http://bomberman.ikayzo.com/
64
+ email:
65
+ - chris@ikayzo.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rspec
72
+ - .rvmrc
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - bomberman.gemspec
78
+ - lib/bomberman.rb
79
+ - lib/bomberman/configuration.rb
80
+ - lib/bomberman/connection.rb
81
+ - lib/bomberman/error.rb
82
+ - lib/bomberman/profanity.rb
83
+ - lib/bomberman/string_utils.rb
84
+ - lib/bomberman/version.rb
85
+ - spec/lib/bomberman/configuration_spec.rb
86
+ - spec/lib/bomberman/connection_spec.rb
87
+ - spec/lib/bomberman/profanity_spec.rb
88
+ - spec/lib/bomberman/string_utils_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: https://github.com/ikayzo/bomberman-ruby
91
+ licenses: []
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.25
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Shelter from profanity bombing
114
+ test_files:
115
+ - spec/lib/bomberman/configuration_spec.rb
116
+ - spec/lib/bomberman/connection_spec.rb
117
+ - spec/lib/bomberman/profanity_spec.rb
118
+ - spec/lib/bomberman/string_utils_spec.rb
119
+ - spec/spec_helper.rb