omdbapi 0.0.1 → 0.1.0
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 +4 -4
- data/README.md +53 -8
- data/lib/omdbapi/client.rb +33 -0
- data/lib/omdbapi/default.rb +31 -0
- data/lib/omdbapi/version.rb +1 -1
- data/lib/omdbapi.rb +20 -2
- data/omdbapi.gemspec +2 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2de7faaa8d9ad133af6f5dfc803173dd742bfe5
|
4
|
+
data.tar.gz: cb36660f877d024b1c94860af7938ed4ebbde38a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 288e3a4d6ba500124e1ae7d1ed056d7a93ef7df41365298b2579d184344479840223a41208f96a7a0677b668801c1e3e4a1e7d66592b1eb7f0670d66e78bceaf
|
7
|
+
data.tar.gz: 21509ad0bfee941208fd4acdbdff12a246a0d4f811076e9f4e90a7a387c66eeb8fa3456521c50d24f13d36fd49ce06f78837871a258651e315a588f4f7562c0f
|
data/README.md
CHANGED
@@ -1,24 +1,69 @@
|
|
1
|
-
#
|
1
|
+
# omdbapi
|
2
2
|
|
3
|
-
|
3
|
+
This gem is (will be) a simple and easy to use wrapper for the [omdbapi.com](http://omdbapi.com/) API.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
You can install the gem by adding it your application's Gemfile:
|
8
8
|
|
9
|
-
|
9
|
+
```ruby
|
10
|
+
gem 'omdbapi'
|
11
|
+
```
|
10
12
|
|
11
13
|
And then execute:
|
12
14
|
|
13
|
-
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
14
18
|
|
15
|
-
Or install it
|
19
|
+
Or you can install it manually by issuing the following command:
|
16
20
|
|
17
|
-
|
21
|
+
```bash
|
22
|
+
$ gem install omdbapi
|
23
|
+
```
|
18
24
|
|
19
25
|
## Usage
|
20
26
|
|
21
|
-
|
27
|
+
```ruby
|
28
|
+
require 'omdbapi'
|
29
|
+
```
|
30
|
+
### Title
|
31
|
+
|
32
|
+
You can get a movie or TV show's information in a Hash by using the title method, shown below:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
game_of_thrones = OMDB.title('Game of Thrones')
|
36
|
+
# => {:title=>"Game of Thrones", :year=>"2011", :rated=>"TV-MA", :released=>"17 Apr 2011", :runtime=>"1 h", :genre=>"Adventure, Drama, Fantasy", :director=>"N/A", :writer=>"David Benioff, D.B. Weiss", :actors=>"Peter Dinklage, Lena Headey, Maisie Williams, Emilia Clarke", :plot=>"Seven noble families fight for control of the mythical land of Westeros.", :poster=>"http://ia.media-imdb.com/images/M/MV5BNTY2MzAxNzM0Ml5BMl5BanBnXkFtZTcwNDA0MDkxOQ@@._V1_SX300.jpg", :imdb_rating=>"9.4", :imdb_votes=>"382,638", :imdb_id=>"tt0944947", :type=>"series", :response=>"True"}
|
37
|
+
game_of_thrones.title # => "Game of Thrones"
|
38
|
+
game_of_thrones.year # => "2011"
|
39
|
+
game_of_thrones.rated # => "TV-MA"
|
40
|
+
# etc...
|
41
|
+
```
|
42
|
+
|
43
|
+
This function will return a Hash with the following information about the title:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
:title, :year, :rated, :released, :runtime, :genre, :director, :writer,
|
47
|
+
:actors, :plot, :poster, :imdb_rating, :imdb_votes, :imdb_id, :type
|
48
|
+
```
|
49
|
+
|
50
|
+
### Search
|
51
|
+
|
52
|
+
You can search for a title by using the search method:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
search = OMDB.search('Star Wars')
|
56
|
+
# => [{:title=>"Star Wars", :year=>"1977", :imdb_id=>"tt0076759", :type=>"movie"}, {:title=>"Star Wars: Episode V - The Empire Strikes Back", :year=>"1980", :imdb_id=>"tt0080684", :type=>"movie"}, {:title=>"Star Wars: Episode VI - Return of the Jedi", :year=>"1983", :imdb_id=>"tt0086190", :type=>"movie"}, {:title=>"Star Wars: Episode I - The Phantom Menace", :year=>"1999", :imdb_id=>"tt0120915", :type=>"movie"}, {:title=>"Star Wars: Episode III - Revenge of the Sith", :year=>"2005", :imdb_id=>"tt0121766", :type=>"movie"}, {:title=>"Star Wars: Episode II - Attack of the Clones", :year=>"2002", :imdb_id=>"tt0121765", :type=>"movie"}, {:title=>"Star Wars: The Clone Wars", :year=>"2008", :imdb_id=>"tt1185834", :type=>"movie"}, {:title=>"Star Wars: Clone Wars", :year=>"2003", :imdb_id=>"tt0361243", :type=>"series"}, {:title=>"Star Wars: The Clone Wars", :year=>"2008", :imdb_id=>"tt0458290", :type=>"series"}, {:title=>"The Star Wars Holiday Special", :year=>"1978", :imdb_id=>"tt0193524", :type=>"movie"}]
|
57
|
+
search.each { |result| puts result.title }
|
58
|
+
# etc...
|
59
|
+
```
|
60
|
+
|
61
|
+
This method returns an Array of search results. Each search result is a Hash with the following information about the result:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
:title, :year, :imdb_id, :type
|
65
|
+
```
|
66
|
+
|
22
67
|
|
23
68
|
## Contributing
|
24
69
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module OMDB
|
2
|
+
class Client
|
3
|
+
|
4
|
+
include HTTParty
|
5
|
+
base_uri OMDB::Default::API_ENDPOINT
|
6
|
+
|
7
|
+
def title(title)
|
8
|
+
get '/', { t: title }
|
9
|
+
end
|
10
|
+
|
11
|
+
def search(query)
|
12
|
+
(get '/', { s: query }).search
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def convert_hash_keys(value)
|
18
|
+
case value
|
19
|
+
when Array
|
20
|
+
value.map { |v| convert_hash_keys(v) }
|
21
|
+
when Hash
|
22
|
+
Hash[value.map { |k, v| [k.to_snake_case.to_sym, convert_hash_keys(v)] }]
|
23
|
+
else
|
24
|
+
value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def get(url, params={})
|
29
|
+
request = self.class.get '/', query: params
|
30
|
+
convert_hash_keys(JSON.parse(request.parsed_response))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module OMDB
|
2
|
+
module Default
|
3
|
+
|
4
|
+
API_ENDPOINT = 'http://omdbapi.com'
|
5
|
+
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
# Monkey patch the Hash class to allow accessing hashes using
|
10
|
+
# dot notation.
|
11
|
+
# For instance: hash['key'] => hash.key
|
12
|
+
class ::Hash
|
13
|
+
def method_missing(name)
|
14
|
+
return self[name] if key? name
|
15
|
+
self.each { |k,v| return v if k.to_s.to_sym == name }
|
16
|
+
super.method_missing name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Monkey patch the string class to convert strings from
|
21
|
+
# camel case to snake case. Is this too much monkey patching?
|
22
|
+
# For instance: "CamelCasedString".to_snake_case => "camel_cased_string"
|
23
|
+
class String
|
24
|
+
def to_snake_case
|
25
|
+
self.gsub(/::/, '/').
|
26
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
27
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
28
|
+
tr("-", "_").
|
29
|
+
downcase
|
30
|
+
end
|
31
|
+
end
|
data/lib/omdbapi/version.rb
CHANGED
data/lib/omdbapi.rb
CHANGED
@@ -1,5 +1,23 @@
|
|
1
|
-
require
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
require 'omdbapi/version'
|
4
|
+
require 'omdbapi/default'
|
5
|
+
require 'omdbapi/client'
|
2
6
|
|
3
7
|
module OMDB
|
4
|
-
|
8
|
+
|
9
|
+
class << self
|
10
|
+
|
11
|
+
def client
|
12
|
+
@client = Client.new unless @client
|
13
|
+
@client
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def method_missing(name, *args, &block)
|
19
|
+
client.send(name, *args, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
5
23
|
end
|
data/omdbapi.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Casey Scarborough"]
|
10
10
|
spec.email = ["caseyscarborough@gmail.com"]
|
11
11
|
spec.description = '[In Progress] A wrapper for the omdbapi.com movie API.'
|
12
|
-
spec.summary = ''
|
12
|
+
spec.summary = 'This gem provides easy access for information retrieval from omdbapi.com.'
|
13
13
|
spec.homepage = "https://github.com/caseyscarborough/omdb"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency 'httparty', '0.11.0'
|
23
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omdbapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Casey Scarborough
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: httparty
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.11.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.11.0
|
41
55
|
description: '[In Progress] A wrapper for the omdbapi.com movie API.'
|
42
56
|
email:
|
43
57
|
- caseyscarborough@gmail.com
|
@@ -51,6 +65,8 @@ files:
|
|
51
65
|
- README.md
|
52
66
|
- Rakefile
|
53
67
|
- lib/omdbapi.rb
|
68
|
+
- lib/omdbapi/client.rb
|
69
|
+
- lib/omdbapi/default.rb
|
54
70
|
- lib/omdbapi/version.rb
|
55
71
|
- omdbapi.gemspec
|
56
72
|
homepage: https://github.com/caseyscarborough/omdb
|
@@ -76,5 +92,5 @@ rubyforge_project:
|
|
76
92
|
rubygems_version: 2.0.6
|
77
93
|
signing_key:
|
78
94
|
specification_version: 4
|
79
|
-
summary:
|
95
|
+
summary: This gem provides easy access for information retrieval from omdbapi.com.
|
80
96
|
test_files: []
|