canistreamit 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 21c119c8b36aacceaaa3cd0979a50fddf0ecea5b
4
+ data.tar.gz: e785faa36285750a56d7d3da87740de5da0250f5
5
+ SHA512:
6
+ metadata.gz: 22b5b595637ead0d7101ef0566f4fbf41a10210e7ceda82bd5738a3a6c23f660e1d7f3becac2ee2bf25b8d410909d67cf16450c0aae3496c1a8a0b882f0bc25f
7
+ data.tar.gz: 5644b7a4bfe63ca7ec767babb63d1b95858d06b336265b12e7e7e4bd4cef970cb32985e114beb831bf28de0b839c61831f01288f98eefa49d50d52958ce7df4d
@@ -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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in canistreamit.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Kevin Bongart
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.
@@ -0,0 +1,101 @@
1
+ # canistreamit
2
+
3
+ A Ruby wrapper for [canistream.it](http://www.canistream.it/) API inspired by [Niels Lemmens's Python wrapper](https://github.com/Bulv1ne/CanIStreamIt).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'canistreamit'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ $ gem install canistreamit
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Create a new client:
28
+
29
+ ```ruby
30
+ client = Canistreamit::Client.new
31
+ ```
32
+
33
+ Search for movies by title:
34
+
35
+ ```ruby
36
+ client.search("Everything is Illuminated")
37
+ => [{"actors"=>"Elijah Wood, Eugene Hutz, Boris Leskin",
38
+ "year"=>2005,
39
+ "description"=>"",
40
+ "title"=>"Everything is Illuminated",
41
+ "image"=>"http://content7.flixster.com/movie/25/01/250121_det.jpg",
42
+ "rating"=>3.3,
43
+ "_id"=>"4ebdd5f9f5f807716100001b",
44
+ "links"=>
45
+ {"rottentomatoes"=>
46
+ "http://www.rottentomatoes.com/m/everything_is_illuminated/",
47
+ "imdb"=>"http://www.imdb.com/title/tt0404030/",
48
+ "shortUrl"=>
49
+ "http://www.canistream.it/search/movie/4ebdd5f9f5f807716100001b/everything-is-illuminated"}}]
50
+ ```
51
+
52
+ Query canistream.it by movie id and media type:
53
+
54
+ ```ruby
55
+ client.query("4ebdd5f9f5f807716100001b", "rental")
56
+ => {"apple_itunes_rental"=>
57
+ {"url"=>"http://www.canistream.it/link/go/4f33decdf5f8073e10000025",
58
+ "price"=>3.99,
59
+ "external_id"=>293314469,
60
+ "date_checked"=>1391095519,
61
+ "direct_url"=>
62
+ "http://click.linksynergy.com/fs-bin/click?id=g0LjNrUM/ms&subid=&offerid=146261.1&type=10&tmpid=3909&RD_PARM1=https%3A%2F%2Fitunes.apple.com%2Fus%2Fmovie%2Feverything-is-illuminated%2Fid293314469%3Fuo%3D4",
63
+ "time"=>0,
64
+ "friendlyName"=>"Apple iTunes Rental",
65
+ "cache"=>true},
66
+ "youtube_rental"=>
67
+ {"url"=>"http://www.canistream.it/link/go/4f33decdf5f8073e10000027",
68
+ "price"=>"1.99",
69
+ "external_id"=>"KdHNp9FPGG8",
70
+ "date_checked"=>1391118942,
71
+ "direct_url"=>
72
+ "http://www.youtube.com/watch?v=KdHNp9FPGG8&feature=youtube_gdata_player",
73
+ "time"=>0,
74
+ "friendlyName"=>"Youtube Rental",
75
+ "cache"=>true},
76
+ "android_rental"=>
77
+ {"url"=>"http://www.canistream.it/link/go/4f47c662f5f8076d43000001",
78
+ "price"=>1.99,
79
+ "external_id"=>"movie-KdHNp9FPGG8",
80
+ "date_checked"=>1391095520,
81
+ "direct_url"=>
82
+ "https://play.google.com/store/movies/details/Everything_is_Illuminated?id=KdHNp9FPGG8",
83
+ "time"=>0,
84
+ "friendlyName"=>"Google Play Rental",
85
+ "cache"=>true}
86
+ ```
87
+
88
+ Available media types:
89
+ - streaming
90
+ - rental
91
+ - purchase
92
+ - dvd
93
+ - xfinity
94
+
95
+ ## Contributing
96
+
97
+ 1. Fork it (http://github.com/KevinBongart/canistreamit/fork)
98
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
99
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
100
+ 4. Push to the branch (`git push origin my-new-feature`)
101
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.ruby_opts << "-rubygems"
7
+ test.pattern = 'test/**/*_test.rb'
8
+ test.verbose = true
9
+ end
10
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'canistreamit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "canistreamit"
8
+ spec.version = Canistreamit::VERSION
9
+ spec.authors = ["Kevin Bongart"]
10
+ spec.email = ["contact@kevinbongart.net"]
11
+ spec.summary = "A Ruby wrapper for canistream.it API"
12
+ spec.description = "A Ruby wrapper for canistream.it API"
13
+ spec.homepage = "https://github.com/KevinBongart/canistreamit"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "httparty"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ end
@@ -0,0 +1,7 @@
1
+ require "canistreamit/version"
2
+ require "canistreamit/configuration"
3
+ require "canistreamit/client"
4
+
5
+ module Canistreamit
6
+ extend Configuration
7
+ end
@@ -0,0 +1,39 @@
1
+ require "httparty"
2
+
3
+ module Canistreamit
4
+ class Client
5
+ include HTTParty
6
+
7
+ # Define the same set of accessors as the Canistreamit module
8
+ attr_accessor *Configuration::VALID_CONFIG_KEYS
9
+
10
+ base_uri Configuration::DEFAULT_ENDPOINT
11
+
12
+ def initialize(options={})
13
+ # Merge the config values from the module and those passed
14
+ # to the client.
15
+ merged_options = Canistreamit.options.merge(options)
16
+
17
+ # Copy the merged values to this client and ignore those
18
+ # not part of our configuration
19
+ Configuration::VALID_CONFIG_KEYS.each do |key|
20
+ send("#{key}=", merged_options[key])
21
+ end
22
+ end
23
+
24
+ def search(movie_name)
25
+ response = self.class.get "/search", query: { movieName: movie_name }
26
+ response.parsed_response
27
+ end
28
+
29
+ def query(movie_id, media_type)
30
+ response = self.class.get "/query", query: {
31
+ movieId: movie_id,
32
+ attributes: '1',
33
+ mediaType: media_type
34
+ }
35
+
36
+ response.parsed_response
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,36 @@
1
+ module Canistreamit
2
+ module Configuration
3
+ VALID_CONNECTION_KEYS = [:endpoint, :user_agent, :method].freeze
4
+ VALID_OPTIONS_KEYS = [:format].freeze
5
+ VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
6
+
7
+ DEFAULT_ENDPOINT = "http://www.canistream.it/services"
8
+ DEFAULT_FORMAT = :json
9
+ DEFAULT_METHOD = :get
10
+ DEFAULT_USER_AGENT = "canistream.it API Ruby Gem #{Canistreamit::VERSION}".freeze
11
+
12
+ # Build accessor methods for every config options so we can do this, for example:
13
+ # Canistreamit.format = :xml
14
+ attr_accessor *VALID_CONFIG_KEYS
15
+
16
+ # Make sure we have the default values set when we get "extended"
17
+ def self.extended(base)
18
+ base.reset
19
+ end
20
+
21
+ def reset
22
+ self.endpoint = DEFAULT_ENDPOINT
23
+ self.format = DEFAULT_FORMAT
24
+ self.method = DEFAULT_METHOD
25
+ self.user_agent = DEFAULT_USER_AGENT
26
+ end
27
+
28
+ def configure
29
+ yield self
30
+ end
31
+
32
+ def options
33
+ Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module Canistreamit
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ describe Canistreamit do
4
+ it 'should have a version' do
5
+ Canistreamit::VERSION.wont_be_nil
6
+ end
7
+ end
@@ -0,0 +1,58 @@
1
+ require "helper"
2
+
3
+ describe Canistreamit::Client do
4
+ before do
5
+ @keys = Canistreamit::Configuration::VALID_CONFIG_KEYS
6
+ end
7
+
8
+ describe "with module configuration" do
9
+ before do
10
+ Canistreamit.configure do |config|
11
+ @keys.each do |key|
12
+ config.send("#{key}=", key)
13
+ end
14
+ end
15
+ end
16
+
17
+ after do
18
+ Canistreamit.reset
19
+ end
20
+
21
+ it "should inherit module configuration" do
22
+ api = Canistreamit::Client.new
23
+ @keys.each do |key|
24
+ api.send(key).must_equal key
25
+ end
26
+ end
27
+
28
+ describe "with class configuration" do
29
+ before do
30
+ @config = {
31
+ :format => "of",
32
+ :endpoint => "ep",
33
+ :user_agent => "ua",
34
+ :method => "hm",
35
+ }
36
+ end
37
+
38
+ it "should override module configuration" do
39
+ api = Canistreamit::Client.new(@config)
40
+ @keys.each do |key|
41
+ api.send(key).must_equal @config[key]
42
+ end
43
+ end
44
+
45
+ it "should override module configuration after" do
46
+ api = Canistreamit::Client.new
47
+
48
+ @config.each do |key, value|
49
+ api.send("#{key}=", value)
50
+ end
51
+
52
+ @keys.each do |key|
53
+ api.send("#{key}").must_equal @config[key]
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,24 @@
1
+ describe "configuration" do
2
+ after do
3
+ Canistreamit.reset
4
+ end
5
+
6
+ describe ".configure" do
7
+ Canistreamit::Configuration::VALID_CONFIG_KEYS.each do |key|
8
+ it "should set the #{key}" do
9
+ Canistreamit.configure do |config|
10
+ config.send("#{key}=", key)
11
+ Canistreamit.send(key).must_equal key
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ Canistreamit::Configuration::VALID_CONFIG_KEYS.each do |key|
18
+ describe ".#{key}" do
19
+ it "should return the default value" do
20
+ Canistreamit.send(key).must_equal Canistreamit::Configuration.const_get("DEFAULT_#{key.upcase}")
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ require 'canistreamit'
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: canistreamit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Bongart
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-30 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: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A Ruby wrapper for canistream.it API
56
+ email:
57
+ - contact@kevinbongart.net
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - canistreamit.gemspec
68
+ - lib/canistreamit.rb
69
+ - lib/canistreamit/client.rb
70
+ - lib/canistreamit/configuration.rb
71
+ - lib/canistreamit/version.rb
72
+ - test/canistreamit/canistreamit_test.rb
73
+ - test/canistreamit/client_test.rb
74
+ - test/canistreamit/configuration_test.rb
75
+ - test/helper.rb
76
+ homepage: https://github.com/KevinBongart/canistreamit
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.0
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: A Ruby wrapper for canistream.it API
100
+ test_files:
101
+ - test/canistreamit/canistreamit_test.rb
102
+ - test/canistreamit/client_test.rb
103
+ - test/canistreamit/configuration_test.rb
104
+ - test/helper.rb