bomberman 1.0.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjRjYjlkZThhZjgxMjQ3NDdhOWNjYjc1MDA3YTkxNzYxOWM0ZWRmZQ==
5
+ data.tar.gz: !binary |-
6
+ M2ZlNjViMDY5MDM2MjE0YWUyZTg5ZWUyNDE5ZWFhMzY5NjQyYWY1NA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZjMwNjA3NTNiYjQwNDAwOWJhOWI4YWNjMzE4YWViMDk4MGE1NjQyNTZlMDI1
10
+ ZWVmZTFiNGNlY2UxMGE2ZGJiY2QzZTUxYjE5NzA5ZDZmODM0NDMxYzdiMzJl
11
+ MzI2NzVlYmYyMTNhY2ZiZjQyM2Y2YTRiMWFkMzEwMWY1YWZiZGQ=
12
+ data.tar.gz: !binary |-
13
+ YjhhMDExMTdmMGUzYTBiZmZkM2FlNjU5MmY5Nzk4Y2I2MzMxZjlmMzFmNWNj
14
+ ZGExY2JiYjZiNzMxMWIzYTM3MjJmZGJjMmRhNmUzMjRmMWRlM2YyMmQ5ZjFi
15
+ M2I4YjFlOTMyYTNmNDZiNTgxNTFjMjM0ZGU3MjM1NDg0YmJhODI=
data/.gitignore CHANGED
@@ -1,19 +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/
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
19
  *.sublime-*
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm use 1.9.3@narya-client --create
1
+ rvm use 1.9.3@narya-client --create
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in bomberman.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bomberman.gemspec
4
+ gemspec
@@ -1,22 +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
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
22
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,114 +1,117 @@
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>.
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
+
39
+ If you are using the Bomberman Heroku addon, please uncomment line 12 in ```lib/bomberman/configuration.rb```.
40
+
41
+ From here you can call the Bomberman::Profanity functionality within
42
+ your application.
43
+
44
+ ### Checking if Text Contains Profanity
45
+
46
+ To check if a piece of text or *corpus* contains profanity use the
47
+ `.profane?(corpus)` method. This will return a boolean value as the
48
+ result
49
+
50
+ ```ruby
51
+ non_profane_text = "The quick brown fox jumped over the lazy dog."
52
+ Bomberman::Profanity.profane?(non_profane_text)
53
+ #=> false
54
+ profane_text = "The quick brown fox jumped over the F-BOMBing lazy dog."
55
+ Bomberman::Profanity.profane?(profane_text)
56
+ #=> true
57
+ ```
58
+
59
+ ### Censoring Profane Words & Phrases
60
+
61
+ If you would like to save or display text where the profane words (if
62
+ any) are obfuscated the `.censor(corpus, replacement_text)` method is
63
+ what you are looking for.
64
+
65
+ ```ruby
66
+ non_profane_text = "The quick brown fox jumped over the lazy dog."
67
+ Bomberman::Profanity.censor(non_profane_text, "####")
68
+ #=> "The quick brown fox jumped over the lazy dog."
69
+ profane_text = "The quick brown fox jumped over the F-BOMBing lazy dog."
70
+ Bomberman::Profanity.censor(profane_text, "####")
71
+ #=> "The quick brown fox jumped over the ### lazy dog."
72
+ ```
73
+
74
+ The `replacement_text` parameter is a string and optional. `"***"` is
75
+ suppled by default.
76
+
77
+ ### Highlighting Profane Words & Phrases
78
+
79
+ Sometimes it is useful to leave the original profane word/phrase intact
80
+ but wrap it in some sort of tag to make it stand out. This can be
81
+ accomplished with the `.highlight(corpus, start_tag, end_tag)` method.
82
+
83
+ ```ruby
84
+ non_profane_text = "The quick brown fox jumped over the lazy dog."
85
+ BomberMan::Profanity.highlight(non_profane_text, "<blink>", "</blink>")
86
+ #=> "The quick brown fox jumped over the lazy dog."
87
+ profane_text = "The quick brown fox jumped over the F-BOMBing lazy dog."
88
+ BomberMan::Profanity.highlight(profane_text, "<blink>", "</blink>")
89
+ #=> "The quick brown fox jumped over the <blink>F-BOMBing</blink> lazy dog."
90
+ ```
91
+
92
+ The `start_tag` & `end_tag` parameters are strings and optional. A pair
93
+ of opening and closing `<span>` tags are used if none are provided.
94
+
95
+
96
+ ### Checking Japanese Text for Profanity.
97
+
98
+ Bomberman supports for checking Japanese text for profanity.
99
+ To do this pass an optional language argument with the value `:ja` as the
100
+ last parameter to any of the `Bomberman::Profanity` methods
101
+
102
+ ```ruby
103
+ non_profane_text = "聖パトリックの日"
104
+ Bomberman::Profanity.profane?(non_profane_text, :ja)
105
+ #=> false
106
+ ```
107
+
108
+ For more info on customizing Bomberman please refer to the [add-on documentation](http://bomberman.ikayzo.com/).
109
+ ## Troubleshooting
110
+
111
+ We are just starting out. If you experience trouble please contact us
112
+ at <bomberman-support@ikayzo.com>.
113
+
114
+ ## Contributing
115
+
116
+ Given the early stage of this project we are open to comments &
117
+ suggestions for this library please send them to <bomberman-support@ikayzo.com>.
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require "bundler/gem_tasks"
@@ -1,23 +1,23 @@
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
- gem.add_development_dependency "webmock"
23
- end
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
+ gem.add_development_dependency "webmock"
23
+ end
@@ -1,18 +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
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
@@ -1,30 +1,33 @@
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
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.ikayzo.com'
10
+
11
+ # Uncomment the following line if you are using the Bomberman Heroku addon
12
+ # url: 'bomberman-prod.herokuapp.com'
13
+ }.freeze
14
+ attr_accessor(*VALID_OPTIONS)
15
+ class << self
16
+
17
+ end
18
+
19
+ def configure
20
+ reset
21
+ yield self
22
+ self
23
+ end
24
+
25
+ def reset
26
+ VALID_OPTIONS.each do |key|
27
+ instance_variable_set(:"@#{key}", DEFAULT_VALUES[key])
28
+ end
29
+ self
30
+ end
31
+ alias setup reset
32
+ end
33
+ end
@@ -1,12 +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
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
@@ -1,27 +1,27 @@
1
- module Bomberman
2
- class Error < StandardError; end
3
-
4
- class BadRequest < Error; end
5
-
6
- class Unauthorized < Error; end
7
-
8
- class RateLimitExceeded < Error; end
9
-
10
- class Forbidden < Error; end
11
-
12
- class NotFound < Error; end
13
-
14
- class NotAcceptable < Error; end
15
-
16
- class UnprocessableEntity < Error; end
17
-
18
- class InternalServerError < Error; end
19
-
20
- class NotImplemented < Error; end
21
-
22
- class BadGateway < Error; end
23
-
24
- class ServiceUnavailable < Error; end
25
-
26
- class LanguageNotSupported < Error; end
27
- end
1
+ module Bomberman
2
+ class Error < StandardError; end
3
+
4
+ class BadRequest < Error; end
5
+
6
+ class Unauthorized < Error; end
7
+
8
+ class RateLimitExceeded < Error; end
9
+
10
+ class Forbidden < Error; end
11
+
12
+ class NotFound < Error; end
13
+
14
+ class NotAcceptable < Error; end
15
+
16
+ class UnprocessableEntity < Error; end
17
+
18
+ class InternalServerError < Error; end
19
+
20
+ class NotImplemented < Error; end
21
+
22
+ class BadGateway < Error; end
23
+
24
+ class ServiceUnavailable < Error; end
25
+
26
+ class LanguageNotSupported < Error; end
27
+ end
@@ -1,64 +1,64 @@
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
- "api/v#{Bomberman.api_version}"
45
- elsif language == :ja
46
- "api/#{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 == 403
58
- raise Bomberman::RateLimitExceeded
59
- elsif request.status == 500
60
- raise Bomberman::InternalServerError
61
- end
62
- end
63
- end
64
- end
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
+ "api/v#{Bomberman.api_version}"
45
+ elsif language == :ja
46
+ "api/#{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 == 403
58
+ raise Bomberman::RateLimitExceeded
59
+ elsif request.status == 500
60
+ raise Bomberman::InternalServerError
61
+ end
62
+ end
63
+ end
64
+ end
@@ -1,9 +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
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
9
  end
@@ -1,3 +1,3 @@
1
- module Bomberman
2
- VERSION = "1.0.4"
3
- end
1
+ module Bomberman
2
+ VERSION = "2.0.0"
3
+ end
@@ -1,11 +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
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
@@ -1,31 +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
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
@@ -1,45 +1,45 @@
1
- require 'spec_helper'
2
-
3
- describe Bomberman::Profanity do
4
- before :all do
5
- Bomberman.configure {}
6
- end
7
-
8
- describe "profantity" do
9
- it 'returns true if Bomber server returns 1 as profantity result' do
10
- stub_request(:get, "https://bomberman-prod.herokuapp.com/api/v1/profanity/check?corpus=profanity_text").
11
- with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Token token=change me', 'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>'Faraday v0.8.7'}).
12
- to_return(:status => 200, :body => "1", :headers => {'Content-Type'=>'application/json; charset=utf-8'})
13
- Bomberman::Profanity.profane?("profanity_text").should == true
14
- end
15
-
16
- it "returns false if Bomberman server returns something other than 1 as profanity result" do
17
- stub_request(:get, "https://bomberman-prod.herokuapp.com/api/v1/profanity/check?corpus=nonprofanity_text").
18
- with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Token token=change me', 'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>'Faraday v0.8.7'}).
19
- to_return(:status => 200, :body => "something_else", :headers => {'Content-Type'=>'application/json; charset=utf-8'})
20
- Bomberman::Profanity.profane?("nonprofanity_text").should == false
21
- end
22
- end
23
-
24
- describe "censor" do
25
- it "substitutes censored texts with replacement text" do
26
- stub_request(:get, "https://bomberman-prod.herokuapp.com/api/v1/profanity/censor?corpus=The%20quick%20brown%20fox%20jumped%20over%20the%20F-BOMBing%20lazy%20dog.&replacement_text=%23%23%23%23").
27
- with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Token token=change me', 'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>'Faraday v0.8.7'}).
28
- to_return(:status => 200, :body => "{\"censored_text\":\"The quick brown fox jumped over the ### lazy dog.\"}", :headers => {'Content-Type'=>'application/json; charset=utf-8'})
29
-
30
- profane_text = "The quick brown fox jumped over the F-BOMBing lazy dog."
31
- Bomberman::Profanity.censor(profane_text, "####").should == "The quick brown fox jumped over the ### lazy dog."
32
- end
33
- end
34
-
35
- describe "highlight" do
36
- it "highlights captured string" do
37
- stub_request(:get, "https://bomberman-prod.herokuapp.com/api/v1/profanity/highlight?corpus=The%20quick%20brown%20fox%20jumped%20over%20the%20F-BOMBing%20lazy%20dog.&end_tag=%3C/blink%3E&start_tag=%3Cblink%3E").
38
- with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Token token=change me', 'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>'Faraday v0.8.7'}).
39
- to_return(:status => 200, :body => "{\"highlighted_text\":\"The quick brown fox jumped over the <blink>F-BOMBing</blink> lazy dog.\"}", :headers => {'Content-Type'=>'application/json; charset=utf-8'})
40
-
41
- profane_text = "The quick brown fox jumped over the F-BOMBing lazy dog."
42
- Bomberman::Profanity.highlight(profane_text, "<blink>", "</blink>").should == "The quick brown fox jumped over the <blink>F-BOMBing</blink> lazy dog."
43
- end
44
- end
1
+ require 'spec_helper'
2
+
3
+ describe Bomberman::Profanity do
4
+ before :all do
5
+ Bomberman.configure {}
6
+ end
7
+
8
+ describe "profantity" do
9
+ it 'returns true if Bomber server returns 1 as profantity result' do
10
+ stub_request(:get, "https://bomberman-prod.herokuapp.com/api/v1/profanity/check?corpus=profanity_text").
11
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Token token=change me', 'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>'Faraday v0.8.7'}).
12
+ to_return(:status => 200, :body => "1", :headers => {'Content-Type'=>'application/json; charset=utf-8'})
13
+ Bomberman::Profanity.profane?("profanity_text").should == true
14
+ end
15
+
16
+ it "returns false if Bomberman server returns something other than 1 as profanity result" do
17
+ stub_request(:get, "https://bomberman-prod.herokuapp.com/api/v1/profanity/check?corpus=nonprofanity_text").
18
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Token token=change me', 'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>'Faraday v0.8.7'}).
19
+ to_return(:status => 200, :body => "something_else", :headers => {'Content-Type'=>'application/json; charset=utf-8'})
20
+ Bomberman::Profanity.profane?("nonprofanity_text").should == false
21
+ end
22
+ end
23
+
24
+ describe "censor" do
25
+ it "substitutes censored texts with replacement text" do
26
+ stub_request(:get, "https://bomberman-prod.herokuapp.com/api/v1/profanity/censor?corpus=The%20quick%20brown%20fox%20jumped%20over%20the%20F-BOMBing%20lazy%20dog.&replacement_text=%23%23%23%23").
27
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Token token=change me', 'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>'Faraday v0.8.7'}).
28
+ to_return(:status => 200, :body => "{\"censored_text\":\"The quick brown fox jumped over the ### lazy dog.\"}", :headers => {'Content-Type'=>'application/json; charset=utf-8'})
29
+
30
+ profane_text = "The quick brown fox jumped over the F-BOMBing lazy dog."
31
+ Bomberman::Profanity.censor(profane_text, "####").should == "The quick brown fox jumped over the ### lazy dog."
32
+ end
33
+ end
34
+
35
+ describe "highlight" do
36
+ it "highlights captured string" do
37
+ stub_request(:get, "https://bomberman-prod.herokuapp.com/api/v1/profanity/highlight?corpus=The%20quick%20brown%20fox%20jumped%20over%20the%20F-BOMBing%20lazy%20dog.&end_tag=%3C/blink%3E&start_tag=%3Cblink%3E").
38
+ with(:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Token token=change me', 'Content-Type'=>'application/json; charset=utf-8', 'User-Agent'=>'Faraday v0.8.7'}).
39
+ to_return(:status => 200, :body => "{\"highlighted_text\":\"The quick brown fox jumped over the <blink>F-BOMBing</blink> lazy dog.\"}", :headers => {'Content-Type'=>'application/json; charset=utf-8'})
40
+
41
+ profane_text = "The quick brown fox jumped over the F-BOMBing lazy dog."
42
+ Bomberman::Profanity.highlight(profane_text, "<blink>", "</blink>").should == "The quick brown fox jumped over the <blink>F-BOMBing</blink> lazy dog."
43
+ end
44
+ end
45
45
  end
@@ -1,35 +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
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
@@ -1,11 +1,11 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
-
4
- require 'bomberman'
5
- require 'webmock/rspec'
6
-
7
- Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
8
-
9
- RSpec.configure do |config|
10
- config.color_enabled = true
11
- end
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'bomberman'
5
+ require 'webmock/rspec'
6
+
7
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
8
+
9
+ RSpec.configure do |config|
10
+ config.color_enabled = true
11
+ end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bomberman
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
5
- prerelease:
4
+ version: 2.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ikayzo
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-26 00:00:00.000000000 Z
11
+ date: 2014-06-06 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: faraday
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: json
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ~>
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: webmock
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -104,27 +95,26 @@ files:
104
95
  - spec/spec_helper.rb
105
96
  homepage: https://github.com/ikayzo/bomberman-ruby
106
97
  licenses: []
98
+ metadata: {}
107
99
  post_install_message:
108
100
  rdoc_options: []
109
101
  require_paths:
110
102
  - lib
111
103
  required_ruby_version: !ruby/object:Gem::Requirement
112
- none: false
113
104
  requirements:
114
105
  - - ! '>='
115
106
  - !ruby/object:Gem::Version
116
107
  version: '0'
117
108
  required_rubygems_version: !ruby/object:Gem::Requirement
118
- none: false
119
109
  requirements:
120
110
  - - ! '>='
121
111
  - !ruby/object:Gem::Version
122
112
  version: '0'
123
113
  requirements: []
124
114
  rubyforge_project:
125
- rubygems_version: 1.8.25
115
+ rubygems_version: 2.2.2
126
116
  signing_key:
127
- specification_version: 3
117
+ specification_version: 4
128
118
  summary: Shelter from profanity bombing
129
119
  test_files:
130
120
  - spec/lib/bomberman/configuration_spec.rb