assonnato 0.7 → 0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb7af04b0977c4df4607a2e61a00e3b1ea4d19d5
4
- data.tar.gz: bc4c445fc893849d427859879716add9ae3ebaca
3
+ metadata.gz: 86572c17cd9eec41d61f1bdf7fe27f786363a045
4
+ data.tar.gz: b65e9cb5ae9c19043a44e5d50da9eba486d65908
5
5
  SHA512:
6
- metadata.gz: 573f854531ce12f59032cab343bf4553636b8ba2a362e6447221b41ff389cfd9f07065a04eae0bc9e14e2960d20e8530666922f9c6ed146a6162b0109b2c9c54
7
- data.tar.gz: 44b56aae93a3cbc218943e15c0e348cbdbce5e323adca65b66a320711b96c61935e7be15c935b527d566ea0866e3d18a966bca2f86dfa1d6978132a4fa25583f
6
+ metadata.gz: c69c0c4059a21c9ace704db71e34a9d71a54431b6ed993de9651a9fb6e87cfa08e91b68b3d0826943dbb8fa0fdb97e81ec528d5fe5fcf46ca1fc2d6cdb966703
7
+ data.tar.gz: 97c2ec89e11b724156988db432fc4c91cc9959fc8f04b14fee54fd91a07ccfb7ae14b7c86e8cfd394cc901633c9846ab841624d09498e9707a1e3772e02848c5
@@ -0,0 +1,41 @@
1
+ #--
2
+ # Copyright (c) 2014 Giovanni Capuano <webmaster@giovannicapuano.net>
3
+ #
4
+ # Released under the MIT License
5
+ # http://opensource.org/licenses/MIT
6
+ #++
7
+
8
+ module Assonnato
9
+
10
+ class Episode
11
+ include Parser
12
+
13
+ def initialize(client)
14
+ @client = client
15
+ end
16
+
17
+ def all(show)
18
+ parse @client.get("/api/v1/episodes/#{URI.escape show}")
19
+ end
20
+
21
+ def get(show, episode)
22
+ all(show).select { |ep| ep.episode == episode }
23
+ end
24
+
25
+ def last(status)
26
+ parse @client.get("/api/v1/episodes/last/#{status}")
27
+ end
28
+
29
+ def search(keyword)
30
+ raise NotImplementedError, 'you cannot search episodes'
31
+ end
32
+
33
+ def edit(name, episode, fields)
34
+ path = '/api/v1/episode/edit'
35
+ data = { name: name, episode: episode, _csrf: @client.user.csrf_token }.merge fields
36
+
37
+ @client.post path, data
38
+ end
39
+ end
40
+
41
+ end
@@ -0,0 +1,68 @@
1
+ #--
2
+ # Copyright (c) 2014 Giovanni Capuano <webmaster@giovannicapuano.net>
3
+ #
4
+ # Released under the MIT License
5
+ # http://opensource.org/licenses/MIT
6
+ #++
7
+
8
+ module Assonnato
9
+
10
+ class Show
11
+ include Parser
12
+
13
+ def initialize(client)
14
+ @client = client
15
+ end
16
+
17
+ def all(status = :ongoing, options = {})
18
+ filters = ''.tap { |str|
19
+ if options.has_key? :fansub
20
+ str << by_fansub(options[:fansub])
21
+ elsif options.has_key? :user
22
+ if options.has_key? :role
23
+ str << by_role(options[:user], options[:role])
24
+ else
25
+ str << by_staff(options[:user])
26
+ end
27
+ end
28
+ }
29
+
30
+ parse @client.get("/api/v1/#{filters}/shows/all/#{status}")
31
+ end
32
+
33
+ def get(show_name)
34
+ search(show_name).select { |show| show.name == show_name }
35
+ end
36
+
37
+ def last!(status)
38
+ raise NotImplementedError, 'Show#last is not implemented'
39
+ end
40
+
41
+ def search(keyword)
42
+ parse @client.get("/api/v1/shows/search/#{URI.escape keyword}")
43
+ end
44
+
45
+ def edit(name, episode, fields)
46
+ path = '/api/v1/episode/edit'
47
+ data = { name: name, episode: episode, _csrf: @client.user.csrf_token }.merge fields
48
+
49
+ @client.post path, data
50
+ end
51
+
52
+ private
53
+ def by_fansub(fansub)
54
+ "/fansubs/#{URI.escape fansub}"
55
+ end
56
+
57
+ private
58
+ def by_staff(user)
59
+ "/users/#{URI.escape user}"
60
+ end
61
+
62
+ private
63
+ def by_role(user, role)
64
+ "/users/#{URI.escape user}/#{role}"
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,36 @@
1
+ #--
2
+ # Copyright (c) 2014 Giovanni Capuano <webmaster@giovannicapuano.net>
3
+ #
4
+ # Released under the MIT License
5
+ # http://opensource.org/licenses/MIT
6
+ #++
7
+
8
+ module Assonnato
9
+
10
+ class User
11
+ def initialize(client)
12
+ @client = client
13
+ end
14
+
15
+ def login(username, password)
16
+ path = '/api/v1/user/login'
17
+ data = { username: username, password: password }
18
+
19
+ @client.post path, data
20
+ end
21
+
22
+ def logout
23
+ path = '/api/v1/user/logout'
24
+ data = { _csrf: @client.user.csrf_token }
25
+
26
+ @client.post path, data
27
+ end
28
+
29
+ def csrf_token
30
+ path = '/api/v1/user/csrf_token'
31
+
32
+ @client.get(path)['message']
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,30 @@
1
+ #--
2
+ # Copyright (c) 2011 Peter Murach
3
+ # Copyright (c) 2014 Giovanni Capuano <webmaster@giovannicapuano.net>
4
+ #
5
+ # Released under the MIT License
6
+ # http://opensource.org/licenses/MIT
7
+ #++
8
+
9
+ module Assonnato
10
+
11
+ class ApiFactory
12
+ class << self
13
+ def new(klass, options = {})
14
+ return create_instance(klass, options) if klass
15
+ raise ArgumentError, 'must provide API class to be instantiated'
16
+ end
17
+
18
+ def create_instance(klass, options)
19
+ convert_to_constant(klass.to_s).new options
20
+ end
21
+
22
+ def convert_to_constant(classes)
23
+ classes.split('::').inject(Assonnato) do |constant, klass|
24
+ constant.const_get klass
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ end
@@ -1,11 +1,26 @@
1
1
  #--
2
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
- # Version 2, December 2004
2
+ # Copyright (c) 2011 Peter Murach
3
+ # Copyright (c) 2014 Giovanni Capuano <webmaster@giovannicapuano.net>
4
4
  #
5
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
- # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
- #
8
- # 0. You just DO WHAT THE FUCK YOU WANT TO.
5
+ # Released under the MIT License
6
+ # http://opensource.org/licenses/MIT
9
7
  #++
10
8
 
11
- module Assonnato; end
9
+ module Assonnato
10
+
11
+ class << self
12
+ def new(domain, port = 80, ssl = false)
13
+ Client.new domain, port, ssl
14
+ end
15
+
16
+ def method_missing(method, *args, &block)
17
+ return super unless new.respond_to?(method)
18
+ new.send method, *args, &block
19
+ end
20
+
21
+ def respond_to?(method, include_private = false)
22
+ new.respond_to?(method, include_private) || super(method, include_private)
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,47 @@
1
+ #--
2
+ # Copyright (c) 2014 Giovanni Capuano <webmaster@giovannicapuano.net>
3
+ #
4
+ # Released under the MIT License
5
+ # http://opensource.org/licenses/MIT
6
+ #++
7
+
8
+ module Assonnato
9
+
10
+ class Client
11
+ include Request
12
+
13
+ attr_accessor :host, :port
14
+ attr_reader :cookies
15
+
16
+ def initialize(host, port = 80, ssl = false)
17
+ @host = host
18
+ @port = port
19
+ @ssl = ssl
20
+ @cookies = CookieJar.new
21
+ end
22
+
23
+ def self.namespace(*names)
24
+ options = names.last.is_a?(Hash) ? names.pop : {}
25
+ names = names.map(&:to_sym)
26
+ name = names.pop
27
+ return if public_method_defined?(name)
28
+
29
+ converted = options.fetch(:full_name, name).to_s
30
+ converted = converted.split('_').map(&:capitalize).join
31
+ class_name = ''
32
+ class_name = "#{self.name.split('::').last}::" unless options.fetch(:root, false)
33
+ class_name += converted
34
+
35
+ define_method(name) do
36
+ ApiFactory.new class_name, self
37
+ end
38
+
39
+ self
40
+ end
41
+
42
+ namespace :user, root: true
43
+ namespace :show, root: true
44
+ namespace :episode, root: true
45
+ end
46
+
47
+ end
@@ -0,0 +1,31 @@
1
+ #--
2
+ # Copyright (c) 2014 Giovanni Capuano <webmaster@giovannicapuano.net>
3
+ #
4
+ # Released under the MIT License
5
+ # http://opensource.org/licenses/MIT
6
+ #++
7
+
8
+ module Assonnato
9
+
10
+ class CookieJar
11
+ def initialize
12
+ @cookies = ''
13
+ end
14
+
15
+ def set(cookie)
16
+ @cookies = cookie
17
+ end
18
+
19
+ def get
20
+ @cookies
21
+ end
22
+
23
+ def <<(cookie)
24
+ @cookies << "; #{cookie}"
25
+ end
26
+
27
+ alias_method :append, :<<
28
+ alias_method :to_s, :get
29
+ end
30
+
31
+ end
@@ -1,30 +1,22 @@
1
1
  #--
2
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
- # Version 2, December 2004
2
+ # Copyright (c) 2014 Giovanni Capuano <webmaster@giovannicapuano.net>
4
3
  #
5
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
- # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
- #
8
- # 0. You just DO WHAT THE FUCK YOU WANT TO.
4
+ # Released under the MIT License
5
+ # http://opensource.org/licenses/MIT
9
6
  #++
10
7
 
11
8
  module Assonnato
12
- module Parser
13
-
14
- def parse(what, format = :json)
15
- collection = case format.to_sym
16
- when :json then JSON.parse what
17
- when :xml, :csv, :yaml then raise NotImplementedError, 'the support for XML, CSV or YAML data is not supported yet'
18
- else raise ArgumentError, 'format not recognized'
19
- end
20
9
 
21
- [].tap { |res|
22
- [collection].flatten.each { |element|
23
- keys = element.keys.map { |k| k.to_sym }
24
- values = element.values
25
- res << Struct.new(*keys).new(*values)
26
- }
10
+ module Parser
11
+ def parse(what)
12
+ [].tap { |res|
13
+ [what].flatten.each { |element|
14
+ keys = element.keys.map { |k| k.to_sym }
15
+ values = element.values
16
+ res << Struct.new(*keys).new(*values)
27
17
  }
28
- end
18
+ }
29
19
  end
20
+ end
21
+
30
22
  end
@@ -1,43 +1,41 @@
1
1
  #--
2
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
- # Version 2, December 2004
2
+ # Copyright (c) 2014 Giovanni Capuano <webmaster@giovannicapuano.net>
4
3
  #
5
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
- # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
- #
8
- # 0. You just DO WHAT THE FUCK YOU WANT TO.
4
+ # Released under the MIT License
5
+ # http://opensource.org/licenses/MIT
9
6
  #++
10
7
 
11
8
  module Assonnato
12
- module Request
13
- def get(host, base_path, path)
14
- uri = URI.parse "#{host}#{base_path}#{path}"
15
- request :get, uri
16
- end
9
+
10
+ module Request
11
+ def get(path, headers = {})
12
+ request :get, path, {}, headers
13
+ end
17
14
 
18
- def post(host, base_path, path, params = {})
19
- uri = URI.parse "#{host}#{base_path}#{path}"
20
- request :post, uri, params
21
- end
15
+ def post(path, data = {}, headers = {})
16
+ request :post, path, data, headers
17
+ end
18
+
19
+ private
20
+ def request(method, path, data, headers)
21
+ headers['Cookie'] = @cookies.get
22
22
 
23
- private
24
- def request(method, url, params = {})
25
- uri = URI url
26
- ssl = uri.scheme == 'https'
23
+ Net::HTTP.start(@host, @port, use_ssl: @ssl) do |http|
24
+ resp = case method.to_sym
25
+ when :get
26
+ http.get path, headers
27
+ when :post
28
+ data = URI.encode_www_form data
29
+ headers['Content-Type'] = 'application/x-www-form-urlencoded'
27
30
 
28
- Net::HTTP.start(uri.hostname, uri.port, use_ssl: ssl) do |http|
29
- request = case method.to_sym
30
- when :get
31
- Net::HTTP::Get.new uri
32
- when :post
33
- Net::HTTP.post_form uri, params
34
- else
35
- raise ArgumentError, 'format not recognized'
36
- end
37
- response = http.request request
38
- raise ResourceNotFound unless response.body
39
- response.body
31
+ http.post path, data, headers
32
+ else raise ArgumentError, 'format not recognized'
40
33
  end
34
+
35
+ @cookies << resp.response['set-cookie'].split('; ')[0] rescue @cookies.get
36
+ JSON.parse resp.body
41
37
  end
42
38
  end
39
+ end
40
+
43
41
  end
@@ -1,13 +1,12 @@
1
- #--
2
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
- # Version 2, December 2004
4
- #
5
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
- # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
- #
8
- # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
- #++
10
-
11
- module Assonnato
12
- VERSION = '0.7'
1
+ #--
2
+ # Copyright (c) 2014 Giovanni Capuano <webmaster@giovannicapuano.net>
3
+ #
4
+ # Released under the MIT License
5
+ # http://opensource.org/licenses/MIT
6
+ #++
7
+
8
+ module Assonnato
9
+
10
+ VERSION = '0.8'
11
+
13
12
  end
data/lib/assonnato.rb CHANGED
@@ -1,21 +1,23 @@
1
1
  #--
2
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
- # Version 2, December 2004
2
+ # Copyright (c) 2014 Giovanni Capuano <webmaster@giovannicapuano.net>
4
3
  #
5
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
- # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
- #
8
- # 0. You just DO WHAT THE FUCK YOU WANT TO.
4
+ # Released under the MIT License
5
+ # http://opensource.org/licenses/MIT
9
6
  #++
10
7
 
11
8
  require 'uri'
12
9
  require 'net/http'
13
10
  require 'json'
14
11
 
15
- require 'assonnato/exception'
12
+ require 'assonnato/assonnato'
13
+ require 'assonnato/api_factory'
14
+ require 'assonnato/cookie_jar'
16
15
  require 'assonnato/request'
17
16
  require 'assonnato/parser'
18
- require 'assonnato/type/show'
19
- require 'assonnato/type/episode'
20
- require 'assonnato/assonnato'
17
+
18
+ require 'assonnato/client'
19
+ require 'assonnato/api/user'
20
+ require 'assonnato/api/show'
21
+ require 'assonnato/api/episode'
22
+
21
23
  require 'assonnato/version'
data/spec/episode_spec.rb CHANGED
@@ -1,13 +1,11 @@
1
1
  #! /usr/bin/env ruby
2
2
  require 'assonnato'
3
3
 
4
- describe 'Assonnato' do
5
- before do
6
- @episode = Assonnato::Episode.new 'http://pigro.omnivium.it'
7
- end
4
+ describe Assonnato::Episode do
5
+ let(:client) { Assonnato::Episode.new Assonnato.new('pigro.omnivium.it') }
8
6
 
9
- it 'returns all the episodes of the given show' do
10
- res = @episode.all! 'Strike the Blood'
7
+ it 'returns all the episodes of given show' do
8
+ res = client.all 'Strike the Blood'
11
9
  res.should be_kind_of(Array)
12
10
  res.should_not be_empty
13
11
  res.first.should be_kind_of(Struct)
@@ -16,20 +14,20 @@ describe 'Assonnato' do
16
14
 
17
15
  it 'can\'t search episodes' do
18
16
  expect {
19
- @episode.search!('le_too_derp')
17
+ client.search 'le_too_derp'
20
18
  }.to raise_error(NotImplementedError)
21
19
  end
22
20
 
23
- it 'returns a specific episode of the given show' do
24
- res = @episode.get! 'Strike the Blood', 1
21
+ it 'returns a specific episode of given show' do
22
+ res = client.get 'Strike the Blood', 1
25
23
  res.should be_kind_of(Array)
26
24
  res.should_not be_empty
27
25
  res.first.should be_kind_of(Struct)
28
26
  res.first.episode.should eql(1)
29
27
  end
30
28
 
31
- it 'returns the last episode of each show with the given status' do
32
- res = @episode.last! :ongoing
29
+ it 'returns the last episode of each show with given status' do
30
+ res = client.last :ongoing
33
31
  res.should be_kind_of(Array)
34
32
  res.should_not be_empty
35
33
  res.first.should be_kind_of(Struct)
data/spec/show_spec.rb CHANGED
@@ -1,50 +1,48 @@
1
1
  #! /usr/bin/env ruby
2
2
  require 'assonnato'
3
3
 
4
- describe 'Assonnato' do
5
- before do
6
- @show = Assonnato::Show.new
7
- end
4
+ describe Assonnato::Show do
5
+ let(:client) { Assonnato::Show.new Assonnato.new('pigro.omnivium.it') }
8
6
 
9
- it 'returns all the ongoing shows' do
10
- res = @show.all! :ongoing
7
+ it 'returns all the on-going shows' do
8
+ res = client.all :ongoing
11
9
  res.should be_kind_of(Array)
12
10
  res.should_not be_empty
13
11
  res.first.should be_kind_of(Struct)
14
12
  res.first.status.should eql('ongoing')
15
13
  end
16
14
 
17
- it 'search all the shows which name is similar to the given keyword' do
18
- res = @show.search! 'strike'
15
+ it 'search all the shows which name is similar to given keyword' do
16
+ res = client.search 'strike'
19
17
  res.should be_kind_of(Array)
20
18
  res.should_not be_empty
21
19
  res.first.should be_kind_of(Struct)
22
20
  res.first.name.should eql('Strike the Blood')
23
21
  end
24
22
 
25
- it 'returns all the ongoing shows of the given fansub' do
26
- res = @show.all! :ongoing, fansub: 'Omnivium'
23
+ it 'returns all the on-going shows of given fansub' do
24
+ res = client.all :ongoing, fansub: 'Omnivium'
27
25
  res.should be_kind_of(Array)
28
26
  res.should_not be_empty
29
27
  res.first.should be_kind_of(Struct)
30
28
  res.first.fansub.should eql('Omnivium')
31
29
  end
32
30
 
33
- it 'returns all the ongoing shows in wich the given user has worked' do
34
- res = @show.all! :ongoing, user: 'Roxas Shadow'
31
+ it 'returns all the on-going shows in wich given user has worked' do
32
+ res = client.all :ongoing, user: 'Roxas Shadow'
35
33
  res.should be_kind_of(Array)
36
34
  res.should_not be_empty
37
35
  end
38
36
 
39
- it 'returns all the ongoing shows in wich the given user has worked in the given role' do
40
- res = @show.all! :ongoing, { user: 'Roxas Shadow', role: :translator }
37
+ it 'returns all the on-going shows in wich given user has worked in given role' do
38
+ res = client.all :ongoing, { user: 'Roxas Shadow', role: :translator }
41
39
  res.should be_kind_of(Array)
42
40
  res.should_not be_empty
43
41
  res.first.translator.should eql('Roxas Shadow')
44
42
  end
45
43
 
46
- it 'returns all the informations of the given show' do
47
- res = @show.get! 'Strike the Blood'
44
+ it 'returns all the informations of given show' do
45
+ res = client.get 'Strike the Blood'
48
46
  res.should be_kind_of(Array)
49
47
  res.should_not be_empty
50
48
  res.first.should be_kind_of(Struct)
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: assonnato
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Capuano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-19 00:00:00.000000000 Z
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: json
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
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -52,25 +38,28 @@ dependencies:
52
38
  - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '0'
55
- description: RESTful wrapper gem for pigro's APIs
41
+ description: RESTful wrapper gem for Pigro's APIs
56
42
  email: webmaster@giovannicapuano.net
57
43
  executables: []
58
44
  extensions: []
59
45
  extra_rdoc_files: []
60
46
  files:
47
+ - lib/assonnato/api/episode.rb
48
+ - lib/assonnato/api/show.rb
49
+ - lib/assonnato/api/user.rb
50
+ - lib/assonnato/api_factory.rb
61
51
  - lib/assonnato/assonnato.rb
62
- - lib/assonnato/exception.rb
52
+ - lib/assonnato/client.rb
53
+ - lib/assonnato/cookie_jar.rb
63
54
  - lib/assonnato/parser.rb
64
55
  - lib/assonnato/request.rb
65
- - lib/assonnato/type/episode.rb
66
- - lib/assonnato/type/show.rb
67
56
  - lib/assonnato/version.rb
68
57
  - lib/assonnato.rb
69
58
  - spec/episode_spec.rb
70
59
  - spec/show_spec.rb
71
60
  homepage: http://www.giovannicapuano.net
72
61
  licenses:
73
- - WTFPL
62
+ - MIT
74
63
  metadata: {}
75
64
  post_install_message:
76
65
  rdoc_options: []
@@ -91,7 +80,7 @@ rubyforge_project:
91
80
  rubygems_version: 2.0.3
92
81
  signing_key:
93
82
  specification_version: 4
94
- summary: RESTful gem wrapping pigro's APIs
83
+ summary: RESTful gem for wrapping Pigro's APIs
95
84
  test_files:
96
85
  - spec/episode_spec.rb
97
86
  - spec/show_spec.rb
@@ -1,13 +0,0 @@
1
- #--
2
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
- # Version 2, December 2004
4
- #
5
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
- # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
- #
8
- # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
- #++
10
-
11
- module Assonnato
12
- class ResourceNotFound < URI::Error; end
13
- end
@@ -1,29 +0,0 @@
1
- #--
2
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
- # Version 2, December 2004
4
- #
5
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
- # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
- #
8
- # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
- #++
10
-
11
- module Assonnato
12
- class Episode < Show
13
- def all!(show)
14
- parse get(@host, @path, "/episodes/#{URI.escape show}")
15
- end
16
-
17
- def search!(keyword)
18
- raise NotImplementedError, 'you cannot search episodes'
19
- end
20
-
21
- def get!(show, episode)
22
- all!(show).select { |ep| ep.episode == episode }
23
- end
24
-
25
- def last!(status)
26
- parse get(@host, @path, "/episodes/last/#{status}")
27
- end
28
- end
29
- end
@@ -1,67 +0,0 @@
1
- #--
2
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
3
- # Version 2, December 2004
4
- #
5
- # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
6
- # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
7
- #
8
- # 0. You just DO WHAT THE FUCK YOU WANT TO.
9
- #++
10
-
11
- module Assonnato
12
- class Show
13
- attr_accessor :host, :path
14
- include Request
15
- include Parser
16
-
17
- def initialize(host = nil, path = nil)
18
- @host = host || 'http://pigro.omnivium.it'
19
- @path = path || '/api/v1'
20
- end
21
-
22
- def all!(status = :ongoing, options = {})
23
- filters = ''.tap { |str|
24
- if options.has_key? :fansub
25
- str << by_fansub(options[:fansub])
26
- elsif options.has_key? :user
27
- if options.has_key? :role
28
- str << by_role(options[:user], options[:role])
29
- else
30
- str << by_staff(options[:user])
31
- end
32
- end
33
- }
34
-
35
- parse get(@host, @path, "#{filters}/shows/all/#{status}")
36
- end
37
-
38
- def search!(keyword)
39
- parse get(@host, @path, "/shows/search/#{URI.escape keyword}")
40
- end
41
-
42
- def get!(show_name)
43
- search!(show_name).select { |show|
44
- show.name == show_name
45
- }
46
- end
47
-
48
- def last!(status)
49
- raise NotImplementedError, 'Show#last is not implemented'
50
- end
51
-
52
- private
53
- def by_fansub(fansub)
54
- "/fansubs/#{URI.escape fansub}"
55
- end
56
-
57
- private
58
- def by_staff(user)
59
- "/users/#{URI.escape user}"
60
- end
61
-
62
- private
63
- def by_role(user, role)
64
- "/users/#{URI.escape user}/#{role}"
65
- end
66
- end
67
- end