omdb_gateway 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +79 -0
- data/LICENSE.txt +21 -0
- data/README.md +103 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/generators/omdb_gateway/install_generator.rb +14 -0
- data/lib/generators/omdb_gateway/templates/config/initializers/omdb.yml +2 -0
- data/lib/omdb_gateway/collection_response.rb +13 -0
- data/lib/omdb_gateway/movie.rb +26 -0
- data/lib/omdb_gateway/movie_request.rb +34 -0
- data/lib/omdb_gateway/request.rb +36 -0
- data/lib/omdb_gateway/response.rb +13 -0
- data/lib/omdb_gateway/search.rb +10 -0
- data/lib/omdb_gateway/search_request.rb +32 -0
- data/lib/omdb_gateway/version.rb +3 -0
- data/lib/omdb_gateway.rb +20 -0
- data/omdbapi.gemspec +36 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 10aa39b61cf6bd1915c2534dedee43d0f782b5f9e2a893fead2a9204ee0f50cb
|
4
|
+
data.tar.gz: 6fcfb7b6f133d0130781b81697587f99bd3ecf1da43af2a1e8409f07993a01f1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '09ab6d032b29e15dd69fc51cec498f02291c4b5f23bd8b6ea9566f55b25d11b06502bf443c4ee18683e7c1a6786e445b004f6eb8cbfe037f29233a212903a01c'
|
7
|
+
data.tar.gz: 247d9aa167e87cd8559f37a75dea46c3711d9fe6033a3386125ebc3ecede5f2e9f946b2be32487f50eae2f5c535b08146ef3f147841255789c3cec04b7e46f16
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at neeraj.kumar@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gem 'rest-client'
|
4
|
+
gem 'activesupport'
|
5
|
+
gem 'rspec'
|
6
|
+
gem 'vcr'
|
7
|
+
gem 'webmock'
|
8
|
+
|
9
|
+
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
|
10
|
+
|
11
|
+
# Specify your gem's dependencies in omdb_gateway.gemspec
|
12
|
+
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
omdb_gateway (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activesupport (5.2.0)
|
10
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
+
i18n (>= 0.7, < 2)
|
12
|
+
minitest (~> 5.1)
|
13
|
+
tzinfo (~> 1.1)
|
14
|
+
addressable (2.5.2)
|
15
|
+
public_suffix (>= 2.0.2, < 4.0)
|
16
|
+
concurrent-ruby (1.0.5)
|
17
|
+
crack (0.4.3)
|
18
|
+
safe_yaml (~> 1.0.0)
|
19
|
+
diff-lcs (1.3)
|
20
|
+
domain_name (0.5.20180417)
|
21
|
+
unf (>= 0.0.5, < 1.0.0)
|
22
|
+
hashdiff (0.3.7)
|
23
|
+
http-cookie (1.0.3)
|
24
|
+
domain_name (~> 0.5)
|
25
|
+
i18n (1.0.1)
|
26
|
+
concurrent-ruby (~> 1.0)
|
27
|
+
mime-types (3.1)
|
28
|
+
mime-types-data (~> 3.2015)
|
29
|
+
mime-types-data (3.2016.0521)
|
30
|
+
minitest (5.11.3)
|
31
|
+
netrc (0.11.0)
|
32
|
+
public_suffix (3.0.2)
|
33
|
+
rake (10.4.2)
|
34
|
+
rest-client (2.0.2)
|
35
|
+
http-cookie (>= 1.0.2, < 2.0)
|
36
|
+
mime-types (>= 1.16, < 4.0)
|
37
|
+
netrc (~> 0.8)
|
38
|
+
rspec (3.7.0)
|
39
|
+
rspec-core (~> 3.7.0)
|
40
|
+
rspec-expectations (~> 3.7.0)
|
41
|
+
rspec-mocks (~> 3.7.0)
|
42
|
+
rspec-core (3.7.1)
|
43
|
+
rspec-support (~> 3.7.0)
|
44
|
+
rspec-expectations (3.7.0)
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
46
|
+
rspec-support (~> 3.7.0)
|
47
|
+
rspec-mocks (3.7.0)
|
48
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
+
rspec-support (~> 3.7.0)
|
50
|
+
rspec-support (3.7.1)
|
51
|
+
safe_yaml (1.0.4)
|
52
|
+
thread_safe (0.3.6)
|
53
|
+
tzinfo (1.2.5)
|
54
|
+
thread_safe (~> 0.1)
|
55
|
+
unf (0.1.4)
|
56
|
+
unf_ext
|
57
|
+
unf_ext (0.0.7.5)
|
58
|
+
vcr (4.0.0)
|
59
|
+
webmock (3.4.2)
|
60
|
+
addressable (>= 2.3.6)
|
61
|
+
crack (>= 0.3.2)
|
62
|
+
hashdiff
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
activesupport
|
69
|
+
bundler (~> 1.16)
|
70
|
+
minitest (~> 5.0)
|
71
|
+
omdb_gateway!
|
72
|
+
rake (~> 10.0)
|
73
|
+
rest-client
|
74
|
+
rspec
|
75
|
+
vcr
|
76
|
+
webmock
|
77
|
+
|
78
|
+
BUNDLED WITH
|
79
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Neeraj Kumar
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# OmdbGateway
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/neerajkumar/omdb_gateway.svg?branch=master)](https://travis-ci.org/neerajkumar/omdb_gateway)
|
4
|
+
|
5
|
+
Omdb_gateway is a rubygem to fetch the movie information, all content and images on the IMDB site (http://www.omdbapi.com) which are contributed and maintained by IMDB users.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'omdb_gateway'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install omdb_gateway
|
22
|
+
|
23
|
+
Next, you need to run the generator:
|
24
|
+
|
25
|
+
$ rails generate omdb_gateway:install
|
26
|
+
|
27
|
+
Generator will create a ```config/initializers/omdb.yml``` file where you can provide your api key or token (generated from omdb).
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
Omdb_Gateway provides different methods to fetch the data from OMDB. For example, ```find_by_id, find_by_title, find_by```.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'omdb_gateway'
|
35
|
+
|
36
|
+
OmdbGateway::Movie.find_by_id('tt7363076')
|
37
|
+
|
38
|
+
OmdbGateway::Movie.find_by_title('Raid')
|
39
|
+
|
40
|
+
OmdbGateway::Movie.find_by(id: 'tt7363076')
|
41
|
+
|
42
|
+
OmdbGateway::Movie.find_by(title: 'Raid')
|
43
|
+
|
44
|
+
=> <OmdbGateway::Response:0x00007fa51293f6c0 @title="Raid", @year="2018", @rated="NOT ...
|
45
|
+
|
46
|
+
OmdbGateway::Movie.find_by_id('tt7363076', format: :json)
|
47
|
+
|
48
|
+
OmdbGateway::Movie.find_by_title('Raid', format: :json)
|
49
|
+
|
50
|
+
OmdbGateway::Movie.find_by(id: 'tt7363076', format: :json)
|
51
|
+
|
52
|
+
=> {"Title"=>"Raid", "Year"=>"2018", "Rated"=>"NOT RATED", "Released"=>"16 Mar ...
|
53
|
+
```
|
54
|
+
|
55
|
+
OmdbGateway takes other parameters too. For example, ```year, plot, format```. Default values are plot: 'short', format: 'json'.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
OmdbGateway::Movie.find_by_id('tt7363076', year: 2018, plot: :full, format: :xml)
|
59
|
+
|
60
|
+
OmdbGateway::Movie.find_by_title('Raid', year: 2018, plot: :full, format: :xml)
|
61
|
+
|
62
|
+
OmdbGateway::Movie.find_by(id: 'tt7363076', year: 2018, plot: :full, format: :xml)
|
63
|
+
|
64
|
+
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root response=\"True\"><movie title=\..."
|
65
|
+
```
|
66
|
+
|
67
|
+
OmdbGateway also provides search to query.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
OmdbGateway::Search.query('Batman')
|
71
|
+
|
72
|
+
OmdbGateway::Search.query('Batman', page: 2)
|
73
|
+
|
74
|
+
OmdbGateway::Search.query('Batman', page: 1, year: 2018, plot: :full, api_version: 1)
|
75
|
+
|
76
|
+
=> <OmdbGateway::CollectionResponse:0x00007feb56f7e0b0 @result=[#<OmdbGateway::Response:0x00007feb56f7e038 @title="Batman: The Killing Joke" ...
|
77
|
+
|
78
|
+
OmdbGateway::Search.query('Batman', page: 1, format: :xml)
|
79
|
+
|
80
|
+
=> "<root totalResults=\"338\" response=\"True\"><result title=\"Batman: The Killing ...
|
81
|
+
|
82
|
+
OmdbGateway::Search.query('Batman', page: 2, format: :json)
|
83
|
+
|
84
|
+
=> {"Search"=>[{"Title"=>"Batman: The Killing Joke", "Year"=>"2016", "imdbID"=> ...
|
85
|
+
```
|
86
|
+
|
87
|
+
## Development
|
88
|
+
|
89
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
90
|
+
|
91
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
92
|
+
|
93
|
+
## Contributing
|
94
|
+
|
95
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/neerajkumar/omdb_gateway. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
96
|
+
|
97
|
+
## License
|
98
|
+
|
99
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
100
|
+
|
101
|
+
## Code of Conduct
|
102
|
+
|
103
|
+
Everyone interacting in the Omdb_gateway project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/neerajkumar/omdb_gateway/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "omdb_gateway"
|
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,14 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
class OmdbGateway::InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
desc "copy omdb.yml file into config directory"
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
@source_root ||= File.join(File.dirname(__FILE__), 'templates')
|
9
|
+
end
|
10
|
+
|
11
|
+
def copy_config_file
|
12
|
+
template 'config/initializers/omdb.yml', 'config/initializers/omdb.yml'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module OmdbGateway
|
2
|
+
class CollectionResponse
|
3
|
+
|
4
|
+
attr_reader :result, :total_results, :response
|
5
|
+
|
6
|
+
def initialize(response_hash)
|
7
|
+
@result = []
|
8
|
+
response_hash['Search'].collect { |hash| @result << Response.new(hash) } if response_hash['Search'].present?
|
9
|
+
@total_results = response_hash['totalResults']
|
10
|
+
@response = response_hash['Response']
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module OmdbGateway
|
2
|
+
class Movie
|
3
|
+
|
4
|
+
class << self
|
5
|
+
%w(find_by_id find_by_title find_by).each do |method_name|
|
6
|
+
define_method(method_name) do |*args|
|
7
|
+
request(args, method_name).fetch
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def self.request(args, method_name)
|
15
|
+
if args[0].is_a?(Hash)
|
16
|
+
params = args[0]
|
17
|
+
elsif args[0].is_a?(String)
|
18
|
+
params = args[1] || {}
|
19
|
+
params.merge!({ method_name.gsub('find_by_', '') => args[0] }.symbolize_keys)
|
20
|
+
end
|
21
|
+
|
22
|
+
return MovieRequest.new(params)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module OmdbGateway
|
2
|
+
class MovieRequest < Request
|
3
|
+
|
4
|
+
attr_reader :id, :title
|
5
|
+
|
6
|
+
def initialize(params)
|
7
|
+
@id = params[:id]
|
8
|
+
@title = params[:title]
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def fetch
|
13
|
+
@response ||= RestClient.get(url)
|
14
|
+
if @format.present? && @format.to_sym == :json
|
15
|
+
return JSON.parse(@response.body).with_indifferent_access
|
16
|
+
elsif @format.present? && @format.to_sym == :xml
|
17
|
+
@response.body
|
18
|
+
else
|
19
|
+
response_hash = JSON.parse(@response.body)
|
20
|
+
Response.new(response_hash)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def url
|
27
|
+
raise InvalidIMDBParams.new('IMDB ID/Title not present') if !@id.present? && !@title.present?
|
28
|
+
url_string = super
|
29
|
+
url_string += @id.present? ? "&i=#{@id}" : "&t=#{@title}"
|
30
|
+
|
31
|
+
url_string
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module OmdbGateway
|
2
|
+
class Request
|
3
|
+
|
4
|
+
BASE_URI = 'https://www.omdbapi.com'.freeze
|
5
|
+
|
6
|
+
attr_reader :year, :plot, :return_type, :api_version
|
7
|
+
|
8
|
+
def initialize(params)
|
9
|
+
@year = params[:year]
|
10
|
+
@plot = params[:plot] || :short
|
11
|
+
@format = params[:format]
|
12
|
+
@api_version = params[:api_version] || 1
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def url
|
18
|
+
url_string = "#{BASE_URI}/?apikey=#{api_key}"
|
19
|
+
url_string += "&y=#{@year}" if @year.present?
|
20
|
+
url_string += "&plot=#{@plot}" if @plot.present?
|
21
|
+
url_string += "&r=#{@format}" if @format.present?
|
22
|
+
url_string += "&v=#{@api_version}"
|
23
|
+
url_string
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def api_key
|
29
|
+
raise InvalidConfiguration.new('omdb.yml file not present') unless File.exists?('config/initializers/omdb.yml')
|
30
|
+
omdb_config = YAML::load(File.open('config/initializers/omdb.yml'))
|
31
|
+
raise Unauthorized.new('Unauthorized - Provide a valid API key') unless omdb_config['apikey'].present?
|
32
|
+
|
33
|
+
omdb_config['apikey']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module OmdbGateway
|
2
|
+
class Response
|
3
|
+
|
4
|
+
def initialize(response_hash)
|
5
|
+
response_hash.each_pair do |key, value|
|
6
|
+
attribute = key.parameterize(separator: '_')
|
7
|
+
singleton_class.class_eval { attr_reader attribute }
|
8
|
+
instance_variable_set("@#{attribute}", value)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module OmdbGateway
|
2
|
+
class SearchRequest < Request
|
3
|
+
|
4
|
+
attr_reader :keyword, :page
|
5
|
+
|
6
|
+
def initialize(params)
|
7
|
+
@keyword = params[:keyword]
|
8
|
+
@page = params[:page] || 1
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def fetch
|
13
|
+
@response ||= RestClient.get(url)
|
14
|
+
if @format.present? && @format.to_sym == :json
|
15
|
+
JSON.parse(@response.body)
|
16
|
+
elsif @format.present? && @format.to_sym == :xml
|
17
|
+
@response.body
|
18
|
+
else
|
19
|
+
CollectionResponse.new(JSON.parse(@response.body))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def url
|
26
|
+
raise InvalidIMDBParams.new('Query String not present') unless @keyword.present?
|
27
|
+
url_string = super
|
28
|
+
url_string += "&s=#{@keyword}&page=#{@page}"
|
29
|
+
url_string
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/omdb_gateway.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'yaml'
|
4
|
+
require 'active_support'
|
5
|
+
require 'active_support/core_ext'
|
6
|
+
require "omdb_gateway/version"
|
7
|
+
require 'omdb_gateway/movie'
|
8
|
+
require 'omdb_gateway/search'
|
9
|
+
require 'omdb_gateway/response'
|
10
|
+
require 'omdb_gateway/collection_response'
|
11
|
+
require 'omdb_gateway/request'
|
12
|
+
require 'omdb_gateway/search_request'
|
13
|
+
require 'omdb_gateway/movie_request'
|
14
|
+
|
15
|
+
module OmdbGateway
|
16
|
+
class InvalidIMDBID < Exception; end
|
17
|
+
class InvalidConfiguration < Exception; end
|
18
|
+
class Unauthorized < Exception; end
|
19
|
+
class InvalidIMDBParams < Exception; end
|
20
|
+
end
|
data/omdbapi.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "omdb_gateway/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "omdb_gateway"
|
8
|
+
spec.version = OmdbGateway::VERSION
|
9
|
+
spec.authors = ["Neeraj Kumar"]
|
10
|
+
spec.email = ["neeraj.kumar@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A rubygem to fetch movie information from IMDB based on API Key.}
|
13
|
+
spec.description = %q{omdb_gateway is a rubygem to fetch the movie information, all content and images on the IMDB site based on API Key which are contributed and maintained by IMDB users.}
|
14
|
+
spec.homepage = 'https://github.com/neerajkumar/omdb_gateway'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omdb_gateway
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Neeraj Kumar
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-02 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
|
+
description: omdb_gateway is a rubygem to fetch the movie information, all content
|
56
|
+
and images on the IMDB site based on API Key which are contributed and maintained
|
57
|
+
by IMDB users.
|
58
|
+
email:
|
59
|
+
- neeraj.kumar@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CODE_OF_CONDUCT.md
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- lib/generators/omdb_gateway/install_generator.rb
|
75
|
+
- lib/generators/omdb_gateway/templates/config/initializers/omdb.yml
|
76
|
+
- lib/omdb_gateway.rb
|
77
|
+
- lib/omdb_gateway/collection_response.rb
|
78
|
+
- lib/omdb_gateway/movie.rb
|
79
|
+
- lib/omdb_gateway/movie_request.rb
|
80
|
+
- lib/omdb_gateway/request.rb
|
81
|
+
- lib/omdb_gateway/response.rb
|
82
|
+
- lib/omdb_gateway/search.rb
|
83
|
+
- lib/omdb_gateway/search_request.rb
|
84
|
+
- lib/omdb_gateway/version.rb
|
85
|
+
- omdbapi.gemspec
|
86
|
+
homepage: https://github.com/neerajkumar/omdb_gateway
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata:
|
90
|
+
allowed_push_host: https://rubygems.org
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.7.3
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: A rubygem to fetch movie information from IMDB based on API Key.
|
111
|
+
test_files: []
|