omdb_api 0.0.7

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ # Specify your gem's dependencies in omdb_api.gemspec
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ross Nelson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # OmdbApi
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'omdb_api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install omdb_api
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/omdb/movie.rb ADDED
@@ -0,0 +1,19 @@
1
+ module Omdb
2
+ class Movie
3
+
4
+ ##
5
+ # Turn Any hash into attributes of a class
6
+ #
7
+ # Omdb::Movie.new({:title => "Darkwing Duck", :year => "1991"})
8
+ #
9
+ def initialize(attributes)
10
+ attributes.each do |k,v|
11
+ k = k.downcase
12
+ self.instance_variable_set("@#{k}", v) ## create and initialize an instance variable for this key/value pair
13
+ self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")}) ## create the getter that returns the instance variable
14
+ self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)}) ## create the setter that sets the instance variable
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,47 @@
1
+ module Omdb
2
+ class Search
3
+ attr_reader :query
4
+
5
+ ##
6
+ # Initialize a new Omdb search with the specified query
7
+ #
8
+ # search = Omdb::Search.new(:title => "True Grit", :year => "1969")
9
+ #
10
+ def initialize(query={})
11
+ @query = query
12
+ end
13
+
14
+ ##
15
+ # Return new Omdb::Movie object with json hash as attributes
16
+ #
17
+ def movie
18
+ @movie ||= parse_json
19
+ end
20
+
21
+ private
22
+
23
+ ##
24
+ # Retrive json utilizing omdbapi.com
25
+ #
26
+ def document
27
+ json = Net::HTTP.get_response URI.parse(query_string(@query))
28
+ json.body
29
+ end
30
+
31
+ ##
32
+ # Bulid url from Omdb::search instance @query attribute
33
+ #
34
+ def query_string(query)
35
+ "http://www.omdbapi.com/?t=#{CGI::escape(query[:title])}&y=#{CGI::escape(query[:year]) unless query[:year].nil?}"
36
+ end
37
+
38
+ ##
39
+ # Parse returned json and initialize new Omdb::Movie object
40
+ #
41
+ def parse_json
42
+ attributes = JSON.parse(document)
43
+ Omdb::Movie.new(attributes)
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module OmdbApi
2
+ VERSION = "0.0.7"
3
+ end
data/lib/omdb_api.rb ADDED
@@ -0,0 +1,9 @@
1
+ ROOT = File.dirname(__FILE__)
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'cgi'
6
+
7
+ require File.join(ROOT, 'omdb', 'version')
8
+ require File.join(ROOT, 'omdb', 'search')
9
+ require File.join(ROOT, 'omdb', 'movie')
data/omdb_api.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omdb/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "omdb_api"
8
+ gem.version = OmdbApi::VERSION
9
+ gem.authors = ["Ross Nelson"]
10
+ gem.email = ["axcess1@me.com"]
11
+ gem.description = %q{utilize omdbapi.com to retrive movie info}
12
+ gem.summary = %q{utilize omdbapi.com to retrive movie info}
13
+ gem.homepage = "http://github.com/rossnelson/omdb_api"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.date = %q{2011-08-12}
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_dependency(%q<json>, [">= 0"])
22
+ gem.add_dependency(%q<shoulda>, [">= 0"])
23
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'omdb_api'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,38 @@
1
+ require 'helper'
2
+
3
+ class TestOmdbApi < Test::Unit::TestCase
4
+ should "Create an instance of Omdb::Search" do
5
+ search = Omdb::Search.new()
6
+ assert_not_nil Omdb::Search
7
+ end
8
+
9
+ should "be a query hash" do
10
+ search = Omdb::Search.new()
11
+ assert_equal search.query.class, Hash
12
+ end
13
+
14
+ should "return instance of Omdb::Movie" do
15
+ search = Omdb::Search.new({:title => "Back to the future"})
16
+ assert_equal search.movie.class, Omdb::Movie
17
+ end
18
+
19
+ should "Keys should equal those listed" do
20
+ keys = [:@title, :@year, :@rated, :@released, :@genre, :@director, :@writer, :@actors, :@plot, :@poster, :@runtime, :@imdbrating, :@imdbid, :@imdbvotes, :@response]
21
+
22
+ search = Omdb::Search.new({:title => "True Grit"})
23
+ keys.each do |key|
24
+ assert_equal true, search.movie.instance_variables.include?(key), "#{key} was not found in this Class"
25
+ end
26
+ end
27
+
28
+ should "return False" do
29
+ search = Omdb::Search.new({:title => ""})
30
+ assert_equal search.movie.response, "False"
31
+ end
32
+
33
+ should "be able to pass any hash as attriubtes into ImDB::Movie" do
34
+ movie = Omdb::Movie.new({:arrbitrary_key => "Yeah, you know it."})
35
+ assert_equal movie.arrbitrary_key, "Yeah, you know it."
36
+ end
37
+
38
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omdb_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ross Nelson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: &70324055980820 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70324055980820
25
+ - !ruby/object:Gem::Dependency
26
+ name: shoulda
27
+ requirement: &70324055980220 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70324055980220
36
+ description: utilize omdbapi.com to retrive movie info
37
+ email:
38
+ - axcess1@me.com
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - LICENSE.txt
46
+ - README.md
47
+ - Rakefile
48
+ - lib/omdb/movie.rb
49
+ - lib/omdb/search.rb
50
+ - lib/omdb/version.rb
51
+ - lib/omdb_api.rb
52
+ - omdb_api.gemspec
53
+ - test/helper.rb
54
+ - test/test_omdb_api.rb
55
+ homepage: http://github.com/rossnelson/omdb_api
56
+ licenses: []
57
+ post_install_message:
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 1.8.15
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: utilize omdbapi.com to retrive movie info
79
+ test_files:
80
+ - test/helper.rb
81
+ - test/test_omdb_api.rb