omdb-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6a2c321db04cfe60d53a29f52e1224e9f12ced5652b36d625a4d2b89f8e1ffea
4
+ data.tar.gz: 586faa3491d686935bccd36a958656be6ecdd7f92a1f660ea384cb448baa665a
5
+ SHA512:
6
+ metadata.gz: 9caec6e78e7b108c2843825ab48013f4a105b103d621238b72439cd597ecb4be701ac9513768ec9c7871cc08fd0f81f62e1866e81e7984615e6ab55bdf79d106
7
+ data.tar.gz: 28ed895fd0cee519bd33977513de95e6d5c400530b8a935eee53523f6c5fe15dabf8a6023e82460baed53ae7786b25942698fd8ca1e98a34307928327fdd6526
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ Metrics:
2
+ Enabled: false
3
+
4
+ Style/Documentation:
5
+ Enabled: false
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'rake'
6
+
7
+ group :development do
8
+ gem 'pry'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rspec'
13
+ gem 'rubocop'
14
+ gem 'webmock'
15
+ end
16
+
17
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nick Palaniuk
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.
@@ -0,0 +1,110 @@
1
+ # Omdb Api
2
+
3
+ [![Build Status](https://travis-ci.org/nikkypx/omdb-api.svg?branch=master)](https://travis-ci.org/nikkypx/omdb-api)
4
+
5
+ > A ruby interface for the [Open Movie Database API](http://omdbapi.com/)
6
+
7
+ ## Required
8
+
9
+ You must request an API key first from [here](http://omdbapi.com/)
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'omdb-api'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install omdb-api
26
+
27
+ ## Usage
28
+
29
+ First you have to create a client object with your API key
30
+
31
+ `client = Omdb::Api::Client.new(api_key: [your API key])`
32
+
33
+ Then you can query with this client object
34
+
35
+ ```ruby
36
+ require 'omdb/api'
37
+
38
+ client.find_by_title('star wars')
39
+ => #<Omdb::Api::Movie:0x007f9a7d453cf0 @actors="Harrison Ford"...
40
+
41
+ client.find_by_id('tt0083929')
42
+ => #<Omdb::Api::Movie:0x007f960a648f28 @actors="Sean Penn, Jennifer Jason Leigh, Judge Reinhold, Robert Romanus",
43
+
44
+ client.search('indiana jones')
45
+ => [#<Omdb::Api::Movie:0x007ffec28ad1a8 @title="Indiana...
46
+ ```
47
+
48
+ You can also pass options to these methods that match the available options from
49
+ the OMDB API spec.
50
+
51
+ For example:
52
+
53
+ `client.find_by_title('star wars', plot: 'short')`
54
+
55
+ Returns an `Omdb::Api::Movie`
56
+
57
+ `#find_by_id('id')`
58
+
59
+ `#find_by_title('title')`
60
+
61
+ Returns an `Omdb::Api::Collection`
62
+
63
+ `#search('movie')`
64
+
65
+ An unsuccessful query will return an `Omdb::Api::Error` object
66
+
67
+
68
+ An `Omdb::Api::Movie` object has
69
+
70
+ ```ruby
71
+ #actors
72
+ #awards
73
+ #country
74
+ #director
75
+ #genre
76
+ #imdbid
77
+ #imdbrating
78
+ #imdbvotes
79
+ #language
80
+ #metascore
81
+ #plot
82
+ #poster
83
+ #rated
84
+ #released
85
+ #response
86
+ #runtime
87
+ #title
88
+ #type
89
+ #writer
90
+ #year
91
+ ```
92
+
93
+ An `Omdb::Api::Error` object has
94
+
95
+ ```ruby
96
+ #response
97
+ #error
98
+ ```
99
+
100
+ ## Development
101
+
102
+ `$ rake` to run the specs
103
+
104
+ ## Contributing
105
+
106
+ Bug reports and pull requests are welcome on GitHub at https://github.com/nikkypx/omdb-api.
107
+
108
+ ## License
109
+
110
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RuboCop::RakeTask.new
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ task default: %i[rubocop spec]
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omdb/api/version'
4
+ require 'omdb/api/collection'
5
+ require 'omdb/api/movie'
6
+ require 'omdb/api/public_api'
7
+ require 'omdb/api/client'
8
+ require 'omdb/api/request'
9
+ require 'omdb/api/error'
10
+ require 'httparty'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omdb
4
+ module Api
5
+ class Client
6
+ include PublicApi
7
+
8
+ attr_accessor :api_key
9
+
10
+ def initialize(options = {})
11
+ options.each_pair do |k, v|
12
+ instance_variable_set("@#{k}", v)
13
+ end
14
+ yield(self) if block_given?
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omdb
4
+ module Api
5
+ class Collection
6
+ include Enumerable
7
+ attr_accessor :movies
8
+
9
+ def initialize(movies)
10
+ self.movies = Array.new(movies)
11
+ end
12
+
13
+ def each
14
+ movies.each { |item| yield item }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omdb
4
+ module Api
5
+ class Error
6
+ ERROR_ATTRIBUTES = %i[
7
+ response
8
+ error
9
+ ].freeze
10
+
11
+ attr_reader(*ERROR_ATTRIBUTES)
12
+
13
+ def initialize(response)
14
+ attrs(response)
15
+ end
16
+
17
+ def attrs(response)
18
+ response.each_key do |key|
19
+ instance_variable_set("@#{key.downcase}".to_sym, response[key])
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omdb
4
+ module Api
5
+ class Movie
6
+ MOVIE_ATTRIBUTES = %i[
7
+ actors
8
+ awards
9
+ country
10
+ director
11
+ genre
12
+ imdbid
13
+ imdbrating
14
+ imdbvotes
15
+ language
16
+ metascore
17
+ plot
18
+ poster
19
+ rated
20
+ released
21
+ runtime
22
+ title
23
+ type
24
+ writer
25
+ year
26
+ error
27
+ ].freeze
28
+
29
+ attr_reader(*MOVIE_ATTRIBUTES)
30
+
31
+ def initialize(response)
32
+ attrs(response)
33
+ end
34
+
35
+ def attrs(response)
36
+ response.each_key do |key|
37
+ instance_variable_set("@#{key.downcase}".to_sym, response[key])
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omdb
4
+ module Api
5
+ module PublicApi
6
+ %i[find_by_id find_by_title search].each do |method|
7
+ define_method(method) do |value, **options|
8
+ request = Omdb::Api::Request.new(api_key, method, value, options)
9
+
10
+ if method == :search && request.success?
11
+ movies = [].tap do |m|
12
+ request.response.fetch('Search').each do |movie|
13
+ m << Omdb::Api::Movie.new(movie)
14
+ end
15
+ end
16
+ Omdb::Api::Collection.new(movies)
17
+ elsif request.success?
18
+ Omdb::Api::Movie.new(request.response)
19
+ else
20
+ Omdb::Api::Error.new(request.response)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omdb
4
+ module Api
5
+ class Request
6
+ BASE_URI = 'https://www.omdbapi.com'
7
+
8
+ attr_reader :api_key, :field, :value, :options
9
+
10
+ def initialize(api_key, method, value, options)
11
+ @api_key = api_key
12
+ @field = if /id/.match?(method)
13
+ 'i'
14
+ elsif /title/.match?(method)
15
+ 't'
16
+ else
17
+ 's'
18
+ end
19
+ @value = CGI.escape(value)
20
+ @options = options
21
+ end
22
+
23
+ def query_params
24
+ { query: { apikey: api_key, field.to_s => value.to_s }.merge(options) }
25
+ end
26
+
27
+ def response
28
+ @response ||= HTTParty.get(BASE_URI, query_params)
29
+ end
30
+
31
+ def success?
32
+ (response['Response'] || response['root']['response']) == 'True'
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Omdb
4
+ module Api
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'omdb/api/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'omdb-api'
9
+ spec.version = Omdb::Api::VERSION
10
+ spec.authors = ['Nick Palaniuk']
11
+ spec.email = ['npalaniuk@gmail.com']
12
+ spec.summary = 'Ruby interface for the OMDB API'
13
+ spec.description = 'A ruby interface for the OMDB API'
14
+ spec.homepage = 'https://github.com/nikkypx/omdb-api'
15
+ spec.license = 'MIT'
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+
20
+ spec.require_paths = ['lib']
21
+ spec.add_dependency 'httparty'
22
+ spec.add_development_dependency 'bundler'
23
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omdb-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nick Palaniuk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A ruby interface for the OMDB API
42
+ email:
43
+ - npalaniuk@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - lib/omdb/api.rb
57
+ - lib/omdb/api/client.rb
58
+ - lib/omdb/api/collection.rb
59
+ - lib/omdb/api/error.rb
60
+ - lib/omdb/api/movie.rb
61
+ - lib/omdb/api/public_api.rb
62
+ - lib/omdb/api/request.rb
63
+ - lib/omdb/api/version.rb
64
+ - omdb-api.gemspec
65
+ homepage: https://github.com/nikkypx/omdb-api
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.7.6
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Ruby interface for the OMDB API
89
+ test_files: []