ratings_aggregator 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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +40 -0
- data/LICENSE +21 -0
- data/README.md +23 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/ratings_aggregator +8 -0
- data/bin/setup +8 -0
- data/lib/ratings_aggregator/api.rb +19 -0
- data/lib/ratings_aggregator/base.rb +35 -0
- data/lib/ratings_aggregator/version.rb +3 -0
- data/lib/ratings_aggregator.rb +6 -0
- data/ratings_aggregator.gemspec +36 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7c2ca9cc0a9671068a69db61578c0943cd499b55
|
4
|
+
data.tar.gz: 66fd58914adfc56b6d21f1a58c947b1e3d94b009
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 70c7deb4618c270b4229437a4b7dac132b7b1177c564b98ec9db64fb72a5994081db996c213fd16be152af64c46aebab715f584bc93d01cceead9bb3f79619b9
|
7
|
+
data.tar.gz: 166844d28e9908181bfdcf637ff535e6af8b237bbcba43f500378d4d8aaf8f8e039bae3df3977a6b72244f654973a198091ea05bcc65ee3cd68776ec4e28a291
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ratings_aggregator (0.0.1)
|
5
|
+
json
|
6
|
+
rest-client
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
domain_name (0.5.20170404)
|
12
|
+
unf (>= 0.0.5, < 1.0.0)
|
13
|
+
http-cookie (1.0.3)
|
14
|
+
domain_name (~> 0.5)
|
15
|
+
json (2.1.0)
|
16
|
+
mime-types (3.1)
|
17
|
+
mime-types-data (~> 3.2015)
|
18
|
+
mime-types-data (3.2016.0521)
|
19
|
+
minitest (5.11.3)
|
20
|
+
netrc (0.11.0)
|
21
|
+
rake (10.5.0)
|
22
|
+
rest-client (2.0.2)
|
23
|
+
http-cookie (>= 1.0.2, < 2.0)
|
24
|
+
mime-types (>= 1.16, < 4.0)
|
25
|
+
netrc (~> 0.8)
|
26
|
+
unf (0.1.4)
|
27
|
+
unf_ext
|
28
|
+
unf_ext (0.0.7.5)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (~> 1.16)
|
35
|
+
minitest (~> 5.0)
|
36
|
+
rake (~> 10.0)
|
37
|
+
ratings_aggregator!
|
38
|
+
|
39
|
+
BUNDLED WITH
|
40
|
+
1.16.0
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 William Lu
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# ratings_aggregator
|
2
|
+
A ruby gem that aggregates the rating of a movie via OMDB
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
$ gem build ratings_aggregator.gemspec
|
7
|
+
|
8
|
+
$ [sudo] install ./ratings_aggregator-[VERSION].gem
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
[You must get your own OMDB key to use this gem](http://www.omdbapi.com/)
|
13
|
+
|
14
|
+
### Create a new aggregator object
|
15
|
+
`aggregator = RatingsAggregator::Base.new`
|
16
|
+
|
17
|
+
### Give it a valid OMDB key
|
18
|
+
`aggregator.set_key('YOUR_KEY')`
|
19
|
+
|
20
|
+
### Get the aggregated score of a rating
|
21
|
+
`aggregator.search('MOVIE_TITLE')`
|
22
|
+
|
23
|
+
Note that if your search query returns multiple results, you will only get the data of the first movie in the query.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ratings_aggregator"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'rest-client'
|
4
|
+
require_relative 'base'
|
5
|
+
|
6
|
+
module RatingsAggregator
|
7
|
+
class Api
|
8
|
+
API_URL = "http://www.omdbapi.com/"
|
9
|
+
|
10
|
+
attr_accessor :response
|
11
|
+
def call(params)
|
12
|
+
response = RestClient.get API_URL, params: params
|
13
|
+
{
|
14
|
+
code: response.code,
|
15
|
+
data: JSON.parse(response.body)
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require_relative 'api'
|
4
|
+
|
5
|
+
module RatingsAggregator
|
6
|
+
class Base
|
7
|
+
def search(search_title)
|
8
|
+
response = api.call(t: search_title, apikey: @key)
|
9
|
+
# puts response
|
10
|
+
if response[:data]["Response"] == "False"
|
11
|
+
nil
|
12
|
+
else
|
13
|
+
# pulls out the strings that represent the rating scores
|
14
|
+
rating_scores = response[:data]["Ratings"].map {|x| x["Value"]}
|
15
|
+
|
16
|
+
sum = 0.0
|
17
|
+
rating_scores.each do |score|
|
18
|
+
to_add = score.to_f
|
19
|
+
if /.+\/10$/.match score
|
20
|
+
to_add *= 10
|
21
|
+
end
|
22
|
+
sum += to_add
|
23
|
+
end
|
24
|
+
aggregate_score = (sum/rating_scores.length).round
|
25
|
+
end
|
26
|
+
end
|
27
|
+
def api
|
28
|
+
@api ||= RatingsAggregator::Api.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_key(key)
|
32
|
+
@key = key
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "ratings_aggregator/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ratings_aggregator"
|
7
|
+
spec.version = RatingsAggregator::VERSION
|
8
|
+
spec.authors = ["William Lu"]
|
9
|
+
spec.email = ["william.lu@shopify.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Provides an aggregate rating for a given movie}
|
12
|
+
spec.description = %q{Searches for a movie using OMDB, then computes an aggregate critic rating for it. Users must provide their own key}
|
13
|
+
|
14
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
15
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
16
|
+
# if spec.respond_to?(:metadata)
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
18
|
+
# else
|
19
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
20
|
+
# "public gem pushes."
|
21
|
+
# end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
f.match(%r{^(test|spec|features)/})
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
33
|
+
|
34
|
+
spec.add_dependency "json"
|
35
|
+
spec.add_dependency "rest-client"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ratings_aggregator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- William Lu
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Searches for a movie using OMDB, then computes an aggregate critic rating
|
84
|
+
for it. Users must provide their own key
|
85
|
+
email:
|
86
|
+
- william.lu@shopify.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/ratings_aggregator
|
100
|
+
- bin/setup
|
101
|
+
- lib/ratings_aggregator.rb
|
102
|
+
- lib/ratings_aggregator/api.rb
|
103
|
+
- lib/ratings_aggregator/base.rb
|
104
|
+
- lib/ratings_aggregator/version.rb
|
105
|
+
- ratings_aggregator.gemspec
|
106
|
+
homepage:
|
107
|
+
licenses: []
|
108
|
+
metadata: {}
|
109
|
+
post_install_message:
|
110
|
+
rdoc_options: []
|
111
|
+
require_paths:
|
112
|
+
- lib
|
113
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
requirements: []
|
124
|
+
rubyforge_project:
|
125
|
+
rubygems_version: 2.5.2
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Provides an aggregate rating for a given movie
|
129
|
+
test_files: []
|