hatolence 0.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.
Files changed (37) hide show
  1. data/.gitignore +17 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +4 -0
  4. data/Guardfile +10 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +29 -0
  7. data/Rakefile +1 -0
  8. data/hatolence.gemspec +31 -0
  9. data/lib/hatolence.rb +21 -0
  10. data/lib/hatolence/bias.rb +25 -0
  11. data/lib/hatolence/bias_category.rb +16 -0
  12. data/lib/hatolence/http_client.rb +21 -0
  13. data/lib/hatolence/offense.rb +25 -0
  14. data/lib/hatolence/offense_category.rb +16 -0
  15. data/lib/hatolence/params_builder.rb +10 -0
  16. data/lib/hatolence/version.rb +3 -0
  17. data/lib/hatolence/victim_count.rb +45 -0
  18. data/spec/fixtures/vcr_cassettes/all_biases.yml +48 -0
  19. data/spec/fixtures/vcr_cassettes/all_offenses.yml +48 -0
  20. data/spec/fixtures/vcr_cassettes/all_victim_count.yml +48 -0
  21. data/spec/fixtures/vcr_cassettes/bias_categories.yml +48 -0
  22. data/spec/fixtures/vcr_cassettes/cat_and_turtle_bias_victim_count.yml +48 -0
  23. data/spec/fixtures/vcr_cassettes/cat_bias_victim_count.yml +48 -0
  24. data/spec/fixtures/vcr_cassettes/land_and_water_bias.yml +48 -0
  25. data/spec/fixtures/vcr_cassettes/land_bias.yml +48 -0
  26. data/spec/fixtures/vcr_cassettes/offense_categories.yml +48 -0
  27. data/spec/fixtures/vcr_cassettes/person_and_property_offense.yml +48 -0
  28. data/spec/fixtures/vcr_cassettes/person_offense.yml +48 -0
  29. data/spec/fixtures/vcr_cassettes/poked_and_dropped_offense_victim_count.yml +48 -0
  30. data/spec/fixtures/vcr_cassettes/poked_offense_victim_conut.yml +48 -0
  31. data/spec/hatolence/bias_category_spec.rb +12 -0
  32. data/spec/hatolence/bias_spec.rb +30 -0
  33. data/spec/hatolence/offense_category_spec.rb +12 -0
  34. data/spec/hatolence/offense_spec.rb +30 -0
  35. data/spec/hatolence/victim_count_spec.rb +51 -0
  36. data/spec/spec_helper.rb +28 -0
  37. metadata +251 -0
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hatolence.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ end
10
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 lalalainexd
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
+ # Hatolence
2
+
3
+ This a gem for hate-crimes api (http://hate-crimes.herokuapp.com)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'hatolence'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install hatolence
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
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/hatolence.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hatolence/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hatolence"
8
+ spec.version = Hatolence::VERSION
9
+ spec.authors = ["lalalainexd"]
10
+ spec.email = ["lalalainexd@gmail.com"]
11
+ spec.description = %q{Wrapper for hate_crimes api}
12
+ spec.summary = %q{Wrapper for hate_crimes api}
13
+ spec.homepage = "https://github.com/lalalainexd/hatolence"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "rest-client"
22
+ spec.add_runtime_dependency "activesupport"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "guard"
28
+ spec.add_development_dependency "guard-rspec"
29
+ spec.add_development_dependency "vcr"
30
+ spec.add_development_dependency "webmock"
31
+ end
data/lib/hatolence.rb ADDED
@@ -0,0 +1,21 @@
1
+ require "hatolence/version"
2
+
3
+ require "rest_client"
4
+ require "json"
5
+ require "active_support/inflector"
6
+
7
+ ActiveSupport::Inflector.inflections do |inflect|
8
+ inflect.irregular 'bias', 'biases'
9
+ end
10
+
11
+ module Hatolence
12
+
13
+ end
14
+
15
+ require "hatolence/http_client"
16
+ require "hatolence/params_builder"
17
+ require "hatolence/victim_count"
18
+ require "hatolence/bias"
19
+ require "hatolence/bias_category"
20
+ require "hatolence/offense"
21
+ require "hatolence/offense_category"
@@ -0,0 +1,25 @@
1
+ module Hatolence
2
+ class Bias
3
+ include HttpClient
4
+ include ParamsBuilder
5
+
6
+ def self.all
7
+ self.new.all
8
+ end
9
+
10
+ def self.filter_by *category
11
+ self.new.filter_by(category)
12
+ end
13
+
14
+ def all
15
+ result = get_resource
16
+ JSON.parse(result)
17
+ end
18
+
19
+ def filter_by category
20
+ result = get_resource(params("category",category))
21
+ JSON.parse(result)
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ module Hatolence
2
+ class BiasCategory
3
+ include HttpClient
4
+
5
+ def self.all
6
+ self.new.all
7
+
8
+ end
9
+
10
+ def all
11
+ response = get_resource
12
+ JSON.parse(response)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,21 @@
1
+ module Hatolence
2
+ module HttpClient
3
+
4
+ def get_resource params=nil
5
+ result = RestClient.get build_request(params)
6
+ end
7
+
8
+ def build_request params
9
+ params ? "#{root_url}?#{params}" : root_url
10
+ end
11
+
12
+ def root_url
13
+ "http://hate-crimes.herokuapp.com/api/#{resource}.json"
14
+ end
15
+
16
+ def resource
17
+ self.class.to_s.demodulize.underscore.pluralize
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ module Hatolence
2
+ class Offense
3
+ include HttpClient
4
+ include ParamsBuilder
5
+
6
+ def self.all
7
+ self.new.all
8
+ end
9
+
10
+ def self.filter_by *category
11
+ self.new.filter_by(category)
12
+ end
13
+
14
+ def all
15
+ result = get_resource
16
+ JSON.parse(result)
17
+ end
18
+
19
+ def filter_by category
20
+ result = get_resource(params("category",category))
21
+ JSON.parse(result)
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ module Hatolence
2
+ class OffenseCategory
3
+ include HttpClient
4
+
5
+ def self.all
6
+ self.new.all
7
+
8
+ end
9
+
10
+ def all
11
+ response = get_resource
12
+ JSON.parse(response)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,10 @@
1
+ module Hatolence
2
+ module ParamsBuilder
3
+
4
+ def params key, values
5
+
6
+ values.collect{|v|"#{key}[]=#{v}"}.join("&").gsub(" ", "%20")
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Hatolence
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,45 @@
1
+ module Hatolence
2
+ class VictimCount
3
+ include HttpClient
4
+ include ParamsBuilder
5
+
6
+ def self.all
7
+ count = self.new
8
+ count.all
9
+ end
10
+
11
+ def self.filter_by_bias(*bias)
12
+ count = self.new
13
+ count.filter_by_bias(bias)
14
+ end
15
+
16
+ def self.filter_by_offense(*offense)
17
+ count = self.new
18
+ count.filter_by_offense(offense)
19
+ end
20
+
21
+ def all
22
+ result = get_resource
23
+ JSON.parse(result)
24
+ end
25
+
26
+ def filter_by_bias(bias)
27
+ result = get_resource(biases(bias))
28
+ JSON.parse(result)
29
+ end
30
+
31
+ def filter_by_offense(offense)
32
+ result = get_resource(offenses(offense))
33
+ JSON.parse(result)
34
+ end
35
+
36
+ def biases bias
37
+ params("bias", bias)
38
+ end
39
+
40
+ def offenses offense
41
+ params("offense", offense)
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://hate-crimes.herokuapp.com/api/biases.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: ! 'OK '
20
+ headers:
21
+ Cache-Control:
22
+ - max-age=0, private, must-revalidate
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Date:
26
+ - Sun, 02 Jun 2013 03:12:47 GMT
27
+ Etag:
28
+ - "\"77dec0a5715ff5863ce4bb17f1af03e9\""
29
+ Server:
30
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
31
+ X-Rack-Cache:
32
+ - miss
33
+ X-Request-Id:
34
+ - b23e1b5c7dfe2fc70f245703f2830c8c
35
+ X-Runtime:
36
+ - '0.007120'
37
+ X-Ua-Compatible:
38
+ - IE=Edge,chrome=1
39
+ Content-Length:
40
+ - '69'
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: UTF-8
45
+ string: "[{\"name\":\"cat\"},{\"name\":\"turtle\"},{\"name\":\"fish\"},{\"name\":\"dolphin\"}]"
46
+ http_version:
47
+ recorded_at: Sun, 02 Jun 2013 03:12:47 GMT
48
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://hate-crimes.herokuapp.com/api/offenses.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: ! 'OK '
20
+ headers:
21
+ Cache-Control:
22
+ - max-age=0, private, must-revalidate
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Date:
26
+ - Sun, 02 Jun 2013 03:12:47 GMT
27
+ Etag:
28
+ - "\"bd4a8bb70b6cf5f97ab4a5f3335b7db8\""
29
+ Server:
30
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
31
+ X-Rack-Cache:
32
+ - miss
33
+ X-Request-Id:
34
+ - 9f773071db8375c33be82d3698c83b15
35
+ X-Runtime:
36
+ - '0.007105'
37
+ X-Ua-Compatible:
38
+ - IE=Edge,chrome=1
39
+ Content-Length:
40
+ - '75'
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: UTF-8
45
+ string: "[{\"name\":\"poked\"},{\"name\":\"dropped\"},{\"name\":\"vandalism\"},{\"name\":\"arson\"}]"
46
+ http_version:
47
+ recorded_at: Sun, 02 Jun 2013 03:12:47 GMT
48
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://hate-crimes.herokuapp.com/api/victim_counts.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: ! 'OK '
20
+ headers:
21
+ Cache-Control:
22
+ - max-age=0, private, must-revalidate
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Date:
26
+ - Sun, 02 Jun 2013 03:12:46 GMT
27
+ Etag:
28
+ - "\"dbdf1e185aa8b4670992341ae873d23d\""
29
+ Server:
30
+ - WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
31
+ X-Rack-Cache:
32
+ - miss
33
+ X-Request-Id:
34
+ - 72ed7113d7878040313e3a6d7be2362f
35
+ X-Runtime:
36
+ - '0.033883'
37
+ X-Ua-Compatible:
38
+ - IE=Edge,chrome=1
39
+ Content-Length:
40
+ - '1045'
41
+ Connection:
42
+ - keep-alive
43
+ body:
44
+ encoding: UTF-8
45
+ string: "[{\"total\":1,\"bias\":{\"name\":\"cat\"},\"offense\":{\"name\":\"poked\"}},{\"total\":2,\"bias\":{\"name\":\"cat\"},\"offense\":{\"name\":\"dropped\"}},{\"total\":3,\"bias\":{\"name\":\"cat\"},\"offense\":{\"name\":\"vandalism\"}},{\"total\":4,\"bias\":{\"name\":\"cat\"},\"offense\":{\"name\":\"arson\"}},{\"total\":11,\"bias\":{\"name\":\"turtle\"},\"offense\":{\"name\":\"poked\"}},{\"total\":12,\"bias\":{\"name\":\"turtle\"},\"offense\":{\"name\":\"dropped\"}},{\"total\":13,\"bias\":{\"name\":\"turtle\"},\"offense\":{\"name\":\"vandalism\"}},{\"total\":14,\"bias\":{\"name\":\"turtle\"},\"offense\":{\"name\":\"arson\"}},{\"total\":21,\"bias\":{\"name\":\"fish\"},\"offense\":{\"name\":\"poked\"}},{\"total\":22,\"bias\":{\"name\":\"fish\"},\"offense\":{\"name\":\"dropped\"}},{\"total\":23,\"bias\":{\"name\":\"fish\"},\"offense\":{\"name\":\"vandalism\"}},{\"total\":21,\"bias\":{\"name\":\"fish\"},\"offense\":{\"name\":\"poked\"}},{\"total\":32,\"bias\":{\"name\":\"dolphin\"},\"offense\":{\"name\":\"dropped\"}},{\"total\":33,\"bias\":{\"name\":\"dolphin\"},\"offense\":{\"name\":\"vandalism\"}},{\"total\":34,\"bias\":{\"name\":\"dolphin\"},\"offense\":{\"name\":\"arson\"}},{\"total\":34,\"bias\":{\"name\":\"dolphin\"},\"offense\":{\"name\":\"arson\"}}]"
46
+ http_version:
47
+ recorded_at: Sun, 02 Jun 2013 03:12:46 GMT
48
+ recorded_with: VCR 2.5.0