traktion 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/traktion/control.rb +7 -0
- data/lib/traktion/middleware/api_key_authenticator.rb +19 -0
- data/lib/traktion/models/base.rb +8 -0
- data/lib/traktion/models/show.rb +34 -0
- data/lib/traktion/version.rb +3 -0
- data/lib/traktion.rb +31 -0
- data/traktion.gemspec +30 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 13b7036911202e70d9af34cb1476ffad5c706f0b
|
4
|
+
data.tar.gz: c1c317b759e1a1fb21c2dd67ee7013c2ddc36e0c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1acbdbf93c611caa40def2a4e2c9037a58e2079830c708b1fedeeeb86d8b51575e75bb142adcbb8eca589e5de68650036d675859455d91a38c7ad07056bd987a
|
7
|
+
data.tar.gz: 10db52a9939eb9b568e3fbaab7ab5996cb967da2e1b43cc62b1cbbbb69edcc7c38ae0578702d7daff537173a9f3ed177da797ce2e315c197920c2e2802b524e9
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Alan Ly
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Traktion
|
2
|
+
|
3
|
+
Traktion is an API client for Trakt.tv's V2 API. Based on the [Her ORM](https://github.com/remiprev/her) library, Traktion allows you to interface with the Trakt.tv API as if it's endpoints are Rails models. This means that it's extremely easy and intuitive to build applications that make use of Trakt.tv's vast dataset.
|
4
|
+
|
5
|
+
This API client is targetted at server side applications that will build upon the Trakt data, such as querying metadata for a personal video library. It is not intended for applications that require client-side authentication (i.e. OAuth) in order to interface with an end-user's Trakt.tv account.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'traktion'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install traktion
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Obtain a **Client ID** from Trakt.tv by [applying for API access](https://trakt.tv/oauth/applications). Once you have registered an API application on Trakt.tv, you will find the ID/key in the respective application's _Details_ page.
|
26
|
+
|
27
|
+
After having installed Traktion, you can use it by first obtaining the client instance (called Traktion Control, huehuehue) by calling the `.start` method with the client ID you've obtained:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
client = Traktion.start('<client ID>')
|
31
|
+
```
|
32
|
+
|
33
|
+
Once you have the client instance, you may now perform queries against the Trakt.tv API. For example, to get the summary for a TV show, you'd call the `find` method with the appropriate slug value on the `shows` resource.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
client.shows.find('community')
|
37
|
+
#<Traktion::Models::Show(shows) title="Community" year=2009 ids={"trakt"=>18265, "slug"=>"community", "tvdb"=>94571, "imdb"=>"tt1439629", "tmdb"=>18347, "tvrage"=>22589}>
|
38
|
+
```
|
39
|
+
|
40
|
+
## Development
|
41
|
+
|
42
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
43
|
+
|
44
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
The client is currently incomplete, with a lot of the Trakt API endpoints currently being unimplemented. If you need access to a specific endpoint and/or are interested in contributing, bug reports and pull requests are always welcomed on GitHub at https://github.com/alanly/traktion.
|
49
|
+
|
50
|
+
|
51
|
+
## License
|
52
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
53
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "traktion"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Traktion
|
2
|
+
module Middleware
|
3
|
+
class ApiKeyAuthenticator < Faraday::Middleware
|
4
|
+
def initialize(app, options={})
|
5
|
+
@app = app
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:request_headers].merge!({
|
11
|
+
'Content-type' => 'application/json',
|
12
|
+
'trakt-api-key' => @options[:api_key],
|
13
|
+
'trakt-api-version' => '2',
|
14
|
+
})
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Traktion
|
2
|
+
class Control
|
3
|
+
def shows
|
4
|
+
@shows ||= Traktion::Models::Show
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module Models
|
9
|
+
class Show < Base
|
10
|
+
custom_get :popular, :trending
|
11
|
+
|
12
|
+
def self.updates(date)
|
13
|
+
get("shows/updates/#{date}")
|
14
|
+
end
|
15
|
+
|
16
|
+
# Create accessor methods for the nested resources.
|
17
|
+
['aliases', 'comments', 'people', 'ratings', 'translations'].each do |path|
|
18
|
+
define_method(path.to_s) do |argument = ''|
|
19
|
+
raw_resource(path.to_s, argument)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def slug
|
26
|
+
self.ids['slug']
|
27
|
+
end
|
28
|
+
|
29
|
+
def raw_resource(name, parameter = '')
|
30
|
+
Show.get_raw("shows/#{slug}/#{name}/#{parameter}") {|parsed_response| parsed_response[:data]}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/traktion.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "her"
|
2
|
+
|
3
|
+
require "traktion/version"
|
4
|
+
require "traktion/middleware/api_key_authenticator"
|
5
|
+
|
6
|
+
module Traktion
|
7
|
+
ENDPOINT = "http://api-v2launch.trakt.tv/"
|
8
|
+
|
9
|
+
def self.api
|
10
|
+
@api
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.start(api_key)
|
14
|
+
@api = Her::API.new
|
15
|
+
@api.setup(url: Traktion::ENDPOINT) do |c|
|
16
|
+
# Request Middleware
|
17
|
+
c.use Traktion::Middleware::ApiKeyAuthenticator, :api_key => api_key
|
18
|
+
c.use Faraday::Request::UrlEncoded
|
19
|
+
|
20
|
+
# Response Middleware
|
21
|
+
c.use Her::Middleware::DefaultParseJSON
|
22
|
+
|
23
|
+
# Adapter
|
24
|
+
c.use Faraday::Adapter::NetHttp
|
25
|
+
end
|
26
|
+
|
27
|
+
# Create the client instance.
|
28
|
+
require 'traktion/control'
|
29
|
+
Traktion::Control.new
|
30
|
+
end
|
31
|
+
end
|
data/traktion.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'traktion/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "traktion"
|
8
|
+
spec.version = Traktion::VERSION
|
9
|
+
spec.authors = ["Alan Ly"]
|
10
|
+
spec.email = ["hello@alan.ly"]
|
11
|
+
|
12
|
+
spec.summary = %q{An ORM-styled client for server-side applications that use the Trakt.tv API v2.}
|
13
|
+
spec.description = %q{This is an API client built on-top of Her, which allows for ActiveRecord-like
|
14
|
+
interactions with the Trakt.tv API. It is intended to be used in server-side applications that do not
|
15
|
+
require client-side authentication (i.e. OAuth).}
|
16
|
+
spec.homepage = "https://github.com/alanly/traktion"
|
17
|
+
spec.license = "MIT"
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "her", "~> 0.7"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
29
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: traktion
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alan Ly
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: her
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.7'
|
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.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
description: |-
|
84
|
+
This is an API client built on-top of Her, which allows for ActiveRecord-like
|
85
|
+
interactions with the Trakt.tv API. It is intended to be used in server-side applications that do not
|
86
|
+
require client-side authentication (i.e. OAuth).
|
87
|
+
email:
|
88
|
+
- hello@alan.ly
|
89
|
+
executables: []
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- ".rspec"
|
95
|
+
- ".travis.yml"
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- lib/traktion.rb
|
103
|
+
- lib/traktion/control.rb
|
104
|
+
- lib/traktion/middleware/api_key_authenticator.rb
|
105
|
+
- lib/traktion/models/base.rb
|
106
|
+
- lib/traktion/models/show.rb
|
107
|
+
- lib/traktion/version.rb
|
108
|
+
- traktion.gemspec
|
109
|
+
homepage: https://github.com/alanly/traktion
|
110
|
+
licenses:
|
111
|
+
- MIT
|
112
|
+
metadata: {}
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubyforge_project:
|
129
|
+
rubygems_version: 2.4.6
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: An ORM-styled client for server-side applications that use the Trakt.tv API
|
133
|
+
v2.
|
134
|
+
test_files: []
|