filmtipset 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: a6699b96e8571bdf6a02935108ed69f4aae57598
4
+ data.tar.gz: 00a00c0f9315c1f1a0381684bc72a3d1fdef90a0
5
+ SHA512:
6
+ metadata.gz: b2784da212f38a7032aff8775b7b7713d0772fa8dce476464bd82e6ed3889b65800d68a9a1c78e7cbb175c69811142ccf1073bdf55f831d9e4e487f70a36ba77
7
+ data.tar.gz: 976b76d508aaa40a2703c66d70f2b3092de39c73dd57c6826da907d70b2f70439915a1eb932f57698bdc908938dca0038732dd808325a3d85fc633e9b64e9577
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .env
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-19mode
6
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in filmtipset.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Peter Hellberg
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,50 @@
1
+ # Filmtipset
2
+
3
+ API client for the Filmtipset API (requires access key)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'filmtipset'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install filmtipset
18
+
19
+ ## Setup
20
+
21
+ ```ruby
22
+ Filmtipset.access_key = 'your_access_key'
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ # Get 'The Matrix' by id
29
+ Filmtipset.movie id: 143
30
+
31
+ # Get 'Brad Pitt' by id
32
+ Filmtipset.person id: 123
33
+
34
+ # Get 'Pulp Fiction' by IMDB id
35
+ Filmtipset.imdb id: '0110912'
36
+
37
+ # Get a list the movies you’ve seen
38
+ Filmtipset.list userkey: <YOUR_USER_KEY>, id: 'seen'
39
+
40
+ # Get recommendations for 'Kortfilm'
41
+ Filmtipset.recommendations userkey: <YOUR_USER_KEY>, id: 2
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+
3
+ require "rake/testtask"
4
+ require "bundler/gem_tasks"
5
+
6
+ task :default => :spec
7
+
8
+ Rake::TestTask.new(:spec) do |t|
9
+ t.test_files = FileList['spec/**/*_spec.rb']
10
+ end
11
+
12
+ desc "Console"
13
+ task :console do
14
+ Bundler.with_clean_env do
15
+ code = 'Filmtipset.access_key = FILMTIPSET_ACCESS_KEY if eval(`cat .env`)'
16
+ exec "pry -r./lib/filmtipset -e '#{code}'"
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require "filmtipset/version"
7
+
8
+ Gem::Specification.new do |gem|
9
+ gem.required_ruby_version = '>= 1.9.3'
10
+
11
+ gem.name = "filmtipset"
12
+ gem.version = Filmtipset::VERSION
13
+ gem.authors = ["Peter Hellberg"]
14
+ gem.email = ["peter@c7.se"]
15
+ gem.summary = "API client for the Filmtipset API (requires access key)"
16
+ gem.homepage = "https://github.com/peterhellberg/skatteverket"
17
+ gem.license = "MIT"
18
+
19
+ gem.files = `git ls-files`.split($/)
20
+ gem.test_files = gem.files.grep(%r{^spec/})
21
+ gem.require_paths = ["lib"]
22
+
23
+ gem.add_development_dependency "bundler", "~> 1.3"
24
+ gem.add_development_dependency "rake", "~> 10.0"
25
+ gem.add_development_dependency "minitest", "~> 5.0"
26
+
27
+ gem.post_install_message = "\nYou need an access key in order to " +
28
+ "use this gem.\n\n Required setup: " +
29
+ "Filmtipset.access_key = 'your_access_key'\n\n"
30
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require "forwardable"
4
+
5
+ require "filmtipset/api"
6
+ require "filmtipset/version"
7
+
8
+ module Filmtipset
9
+ class << self
10
+ extend Forwardable
11
+
12
+ def api
13
+ @api ||= Api.new
14
+ end
15
+
16
+ def_delegators :api, :access_key=, :movie, :person, :comment,
17
+ :imdb, :list, :add_to_list, :recommendations,
18
+ :user, :user_latest, :user_messages, :message,
19
+ :mark_message_unread, :send_message, :grade, :search
20
+ end
21
+ end
@@ -0,0 +1,153 @@
1
+ # encoding: utf-8
2
+
3
+ require "uri"
4
+ require "open-uri"
5
+ require "json"
6
+
7
+ require_relative "api/genre"
8
+
9
+ module Filmtipset
10
+ class Api
11
+ attr_accessor :access_key
12
+
13
+ def movie(params = {})
14
+ action 'movie', params, :id
15
+ end
16
+
17
+ def person(params = {})
18
+ action 'person', params, :id
19
+ end
20
+
21
+ def comment(params = {})
22
+ action 'comment', params, :userkey, :id, :comment
23
+ end
24
+
25
+ def imdb(params = {})
26
+ action 'imdb', params, :id
27
+ end
28
+
29
+ def list(params = {})
30
+ action 'list', params
31
+ end
32
+
33
+ def add_to_list(params = {})
34
+ action 'add-to-list', params, :userkey, :id, :movie
35
+ end
36
+
37
+ def recommendations(params = {})
38
+ verify_genre_id(params[:id])
39
+
40
+ action 'recommendations', params, :userkey, :id
41
+ end
42
+
43
+ def user(params = {})
44
+ action 'user', params, :id
45
+ end
46
+
47
+ def user_latest(params = {})
48
+ action 'user-latest', params, :id
49
+ end
50
+
51
+ def user_messages(params = {})
52
+ action 'user-messages', params, :userkey
53
+ end
54
+
55
+ def message(params = {})
56
+ action 'message', params, :id
57
+ end
58
+
59
+ def mark_message_unread(params = {})
60
+ action 'mark-message-unread', params, :id
61
+ end
62
+
63
+ def send_message(params = {})
64
+ action 'send-message', params, :userkey, :recipient, :subject, :body
65
+ end
66
+
67
+ def grade(params = {})
68
+ verify_grade params[:grade]
69
+
70
+ action 'grade', params, :userkey, :id, :grade
71
+ end
72
+
73
+ def search(params = {})
74
+ action 'search', params, :id
75
+ end
76
+
77
+ private
78
+
79
+ def action(name, params, *required)
80
+ access_key_is_required
81
+ verify_required(params, required)
82
+
83
+ get params.merge(action: name)
84
+ end
85
+
86
+ def get(params = {})
87
+ fetch prepared_uri(params)
88
+ end
89
+
90
+ def fetch(uri)
91
+ parse open(uri).read
92
+ rescue OpenURI::HTTPError => e
93
+ raise HTTPError, uri
94
+ end
95
+
96
+ def parse(json)
97
+ JSON.parse(json)
98
+ rescue JSON::ParserError => e
99
+ raise JSONError, e
100
+ end
101
+
102
+ def prepared_uri(params = {})
103
+ base_uri.tap do |uri|
104
+ uri.query = query_params(params)
105
+ end
106
+ end
107
+
108
+ def query_params(params)
109
+ URI.encode_www_form handle_params(params)
110
+ end
111
+
112
+ def handle_params(params)
113
+ {
114
+ accesskey: access_key,
115
+ returntype: 'json'
116
+ }.merge(params)
117
+ end
118
+
119
+ def base_uri
120
+ URI.parse('http://www.filmtipset.se/api/api.cgi')
121
+ end
122
+
123
+ def access_key_is_required
124
+ if access_key.nil? || access_key.empty?
125
+ raise NoAccessKeyError, "You need to provide an access key!"
126
+ end
127
+ end
128
+
129
+ def verify_genre_id(id)
130
+ Genre.verify_id(id)
131
+ end
132
+
133
+ def verify_grade(rating)
134
+ unless (1..5).include?(rating.to_i)
135
+ raise InvalidGrade, "The grade must be in the range 1-5"
136
+ end
137
+ end
138
+
139
+ def verify_required(params, keys)
140
+ keys.each do |key|
141
+ if params[key].to_s.empty?
142
+ raise MissingParameter, "The params must include :#{key}"
143
+ end
144
+ end
145
+ end
146
+
147
+ class HTTPError < StandardError; end
148
+ class JSONError < StandardError; end
149
+ class NoAccessKeyError < StandardError; end
150
+ class InvalidGrade < StandardError; end
151
+ class MissingParameter < StandardError; end
152
+ end
153
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ module Filmtipset
4
+ class Api
5
+ class Genre
6
+ class << self
7
+ def valid_id?(id)
8
+ TABLE.has_key?(id.to_s)
9
+ end
10
+
11
+ def verify_id(id)
12
+ unless valid_id?(id)
13
+ raise InvalidId, "The genre id '#{id}' is not valid!"
14
+ end
15
+ end
16
+ end
17
+
18
+ TABLE = {
19
+ "0" => "Generella tips",
20
+ "1" => "Drama",
21
+ "2" => "Kortfilm",
22
+ "3" => "Komedi",
23
+ "4" => "Dokumentär",
24
+ "5" => "Animerad",
25
+ "6" => "Vuxenfilm",
26
+ "7" => "Familjefilm",
27
+ "8" => "Action",
28
+ "9" => "Kriminalare",
29
+ "10" => "Romantik",
30
+ "11" => "Thriller",
31
+ "12" => "Musikal",
32
+ "13" => "Äventyr",
33
+ "14" => "Western",
34
+ "15" => "Skräck",
35
+ "16" => "Science Fiction",
36
+ "17" => "Fantasy",
37
+ "18" => "Mysterium",
38
+ "19" => "Krig",
39
+ "20" => "Film-Noir",
40
+ "21" => "Scenshow",
41
+ "22" => "Anime",
42
+ "23" => "Mini-serie",
43
+ "24" => "Stumfilm",
44
+ "25" => "Amatörfilm",
45
+ "38" => "Experimentfilm",
46
+ "39" => "Roadmovie",
47
+ "40" => "Biografi"
48
+ }
49
+
50
+ class InvalidId < StandardError; end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module Filmtipset
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ describe Filmtipset do
6
+ subject { Filmtipset }
7
+
8
+ describe "api" do
9
+ it "returns a (default) api object" do
10
+ subject.api.must_be_instance_of Filmtipset::Api
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # encoding: utf-8
2
+
3
+ require "minitest/autorun"
4
+ require "minitest/spec"
5
+ require "minitest/pride"
6
+
7
+ require_relative "../lib/filmtipset"
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: filmtipset
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Peter Hellberg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description:
56
+ email:
57
+ - peter@c7.se
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - filmtipset.gemspec
69
+ - lib/filmtipset.rb
70
+ - lib/filmtipset/api.rb
71
+ - lib/filmtipset/api/genre.rb
72
+ - lib/filmtipset/version.rb
73
+ - spec/filmtipset_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: https://github.com/peterhellberg/skatteverket
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message: |2+
80
+
81
+ You need an access key in order to use this gem.
82
+
83
+ Required setup: Filmtipset.access_key = 'your_access_key'
84
+
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: 1.9.3
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.0.5
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: API client for the Filmtipset API (requires access key)
104
+ test_files:
105
+ - spec/filmtipset_spec.rb
106
+ - spec/spec_helper.rb