omdbapi 0.1.1 → 0.1.2
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/lib/omdbapi.rb +7 -3
- data/lib/omdbapi/client.rb +34 -0
- data/lib/omdbapi/default.rb +16 -6
- data/lib/omdbapi/version.rb +4 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c26bd37809d517fee3add5282bd1c0010e28cf66
|
4
|
+
data.tar.gz: a060eb969c24d18b1ea70884d8d9fa83e67be255
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 876544a128f6edb7170d7e141dffff71a500ae2b108ec4376cbf0108827b883cf773fcab3aad69f3cad5d1716c60420c4f7d4fb8915aa442bfc182aea4e28269
|
7
|
+
data.tar.gz: db4110cbb81529cc03214376bc11039861b98016f33c6efbd1bbfd2c74588f9eb4b984fa62b7d8a38db05a72f09b503ca3146534f085f60962171a7185dd9814
|
data/lib/omdbapi.rb
CHANGED
@@ -4,10 +4,14 @@ require 'omdbapi/version'
|
|
4
4
|
require 'omdbapi/default'
|
5
5
|
require 'omdbapi/client'
|
6
6
|
|
7
|
+
# Ruby wrapper for omdbapi.com API.
|
7
8
|
module OMDB
|
8
9
|
|
9
10
|
class << self
|
10
11
|
|
12
|
+
# API client for making calls to the omdbapi API.
|
13
|
+
#
|
14
|
+
# return [OMDB::Client] API Wrapper
|
11
15
|
def client
|
12
16
|
@client = Client.new unless @client
|
13
17
|
@client
|
@@ -15,9 +19,9 @@ module OMDB
|
|
15
19
|
|
16
20
|
private
|
17
21
|
|
18
|
-
|
19
|
-
|
20
|
-
|
22
|
+
def method_missing(name, *args, &block)
|
23
|
+
client.send(name, *args, &block)
|
24
|
+
end
|
21
25
|
|
22
26
|
end
|
23
27
|
end
|
data/lib/omdbapi/client.rb
CHANGED
@@ -1,17 +1,40 @@
|
|
1
1
|
module OMDB
|
2
|
+
|
3
|
+
# Client for handling requests to the omdbapi.com API.
|
4
|
+
#
|
5
|
+
# @see http://omdbapi.com
|
2
6
|
class Client
|
3
7
|
|
4
8
|
include HTTParty
|
5
9
|
base_uri OMDB::Default::API_ENDPOINT
|
6
10
|
|
11
|
+
# Retrieves a movie or show based on its title.
|
12
|
+
#
|
13
|
+
# @param title [String] The title of the movie or show.
|
14
|
+
# @return [Hash]
|
15
|
+
# @example
|
16
|
+
# OMDB.title('Game of Thrones')
|
7
17
|
def title(title, year=nil)
|
8
18
|
get '/', { t: title }
|
9
19
|
end
|
10
20
|
|
21
|
+
|
22
|
+
# Retrieves a movie or show based on its IMDb ID.
|
23
|
+
#
|
24
|
+
# @param imdb_id [String] The IMDb ID of the movie or show.
|
25
|
+
# @return [Hash]
|
26
|
+
# @example
|
27
|
+
# OMDB.id('tt0944947')
|
11
28
|
def id(imdb_id)
|
12
29
|
return get '/', { i: imdb_id }
|
13
30
|
end
|
14
31
|
|
32
|
+
# Find a movie by its title.
|
33
|
+
#
|
34
|
+
# @param title [String] The title of the movie or show to find.
|
35
|
+
# @return [Array, Hash]
|
36
|
+
# @example
|
37
|
+
# OMDB.find('Star Wars')
|
15
38
|
def find(title)
|
16
39
|
results = get '/', { s: title }
|
17
40
|
results[:search] ? results[:search] : results
|
@@ -19,6 +42,10 @@ module OMDB
|
|
19
42
|
|
20
43
|
private
|
21
44
|
|
45
|
+
# Performs a method on all hash keys.
|
46
|
+
#
|
47
|
+
# @param value [Array, Hash, Object]
|
48
|
+
# @return [Array, Hash, Object]
|
22
49
|
def convert_hash_keys(value)
|
23
50
|
case value
|
24
51
|
when Array
|
@@ -30,6 +57,13 @@ module OMDB
|
|
30
57
|
end
|
31
58
|
end
|
32
59
|
|
60
|
+
# Performs a get request.
|
61
|
+
#
|
62
|
+
# @param url [String] The url to perform the get request to.
|
63
|
+
# @param params [Hash] The parameters to pass in the query string.
|
64
|
+
# @return [Hash] The response from the get request.
|
65
|
+
# @example
|
66
|
+
# get '/users', { username: 'caseyscarborough' }
|
33
67
|
def get(url, params={})
|
34
68
|
request = self.class.get '/', query: params
|
35
69
|
convert_hash_keys(JSON.parse(request.parsed_response))
|
data/lib/omdbapi/default.rb
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
module OMDB
|
2
|
+
|
3
|
+
# Default configuration options for OMDB.
|
2
4
|
module Default
|
3
5
|
|
6
|
+
# Default API endpoint
|
4
7
|
API_ENDPOINT = 'http://omdbapi.com'
|
5
8
|
|
6
9
|
end
|
7
10
|
end
|
8
11
|
|
9
|
-
#
|
10
|
-
# dot notation.
|
11
|
-
# For instance: hash['key'] => hash.key
|
12
|
+
# Reopen the Hash class to add method.
|
12
13
|
class ::Hash
|
14
|
+
|
15
|
+
# Allow accessing hashes via dot notation.
|
16
|
+
#
|
17
|
+
# @param name [String] The method name.
|
18
|
+
# @return [Object]
|
13
19
|
def method_missing(name)
|
14
20
|
return self[name] if key? name
|
15
21
|
self.each { |k,v| return v if k.to_s.to_sym == name }
|
@@ -17,10 +23,14 @@ class ::Hash
|
|
17
23
|
end
|
18
24
|
end
|
19
25
|
|
20
|
-
#
|
21
|
-
# camel case to snake case. Is this too much monkey patching?
|
22
|
-
# For instance: "CamelCasedString".to_snake_case => "camel_cased_string"
|
26
|
+
# Reopen the String class to add to_snake_case method.
|
23
27
|
class String
|
28
|
+
|
29
|
+
# Convert string to snake case from camel case.
|
30
|
+
#
|
31
|
+
# @return [String]
|
32
|
+
# @example
|
33
|
+
# "CamelCasedString".to_snake_case # => "camel_cased_string"
|
24
34
|
def to_snake_case
|
25
35
|
self.gsub(/::/, '/').
|
26
36
|
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
data/lib/omdbapi/version.rb
CHANGED