omdbapi 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fbc5708989f9d4a0c3238cba60519c45c660db3
4
- data.tar.gz: 5ff47e43fe3546e7cc99861ae6596ffcf78c3a2b
3
+ metadata.gz: c26bd37809d517fee3add5282bd1c0010e28cf66
4
+ data.tar.gz: a060eb969c24d18b1ea70884d8d9fa83e67be255
5
5
  SHA512:
6
- metadata.gz: 817dcd802df11328e12d0970d74424fc19b33bb8f1a10d61b2927eb79b70253035568a81e23cbe8450d4aef54eecde63efbc2be8d899009aabc36e79a3f663d8
7
- data.tar.gz: 6568db143c86f0e038a5209882060063d49e151eb4c78e3f6e4a69cc44fc9b7cd7d72345e2e0942c6aad821682db5f4efa5568d7f6f579bce4dbcf16f17e8fe8
6
+ metadata.gz: 876544a128f6edb7170d7e141dffff71a500ae2b108ec4376cbf0108827b883cf773fcab3aad69f3cad5d1716c60420c4f7d4fb8915aa442bfc182aea4e28269
7
+ data.tar.gz: db4110cbb81529cc03214376bc11039861b98016f33c6efbd1bbfd2c74588f9eb4b984fa62b7d8a38db05a72f09b503ca3146534f085f60962171a7185dd9814
@@ -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
- def method_missing(name, *args, &block)
19
- client.send(name, *args, &block)
20
- end
22
+ def method_missing(name, *args, &block)
23
+ client.send(name, *args, &block)
24
+ end
21
25
 
22
26
  end
23
27
  end
@@ -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))
@@ -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
- # Monkey patch the Hash class to allow accessing hashes using
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
- # 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"
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').
@@ -1,3 +1,6 @@
1
1
  module OMDB
2
- VERSION = "0.1.1"
2
+ # OMDB current version
3
+ #
4
+ # @return [String]
5
+ VERSION = "0.1.2"
3
6
  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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Casey Scarborough