assonnato 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assonnato.rb +22 -22
- data/lib/assonnato/api/episode.rb +48 -41
- data/lib/assonnato/api/show.rb +68 -68
- data/lib/assonnato/api/user.rb +35 -35
- data/lib/assonnato/api_factory.rb +28 -29
- data/lib/assonnato/assonnato.rb +24 -25
- data/lib/assonnato/client.rb +46 -46
- data/lib/assonnato/cookie_jar.rb +30 -30
- data/lib/assonnato/parser.rb +21 -21
- data/lib/assonnato/request.rb +40 -40
- data/lib/assonnato/version.rb +2 -2
- data/spec/episode_spec.rb +34 -34
- data/spec/show_spec.rb +51 -51
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f07b8f32a089af853e46258703e92a5b5845eac3
|
4
|
+
data.tar.gz: 7efa4bb28bc5741c65fe03a33909f60e108f9eac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73bdcf9e7b370f0caffa64ff8e9ad58ad4a8ea0406f460cb25154db8f627fb4da55b0a6e4bdbf8edce7ff0f8834c9f3ba7f4f354231ea24b028cf041f0751ac1
|
7
|
+
data.tar.gz: 8314f35194277b4f030f48f968aa5f8de537369a1c195103c39a38f9e2dbe5949530dedac31b45d90461f330970f8b27631bd7a65bff0efb10fd38d43b080a30
|
data/lib/assonnato.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
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
|
-
require 'uri'
|
9
|
-
require 'net/http'
|
10
|
-
require 'json'
|
11
|
-
|
12
|
-
require 'assonnato/assonnato'
|
13
|
-
require 'assonnato/api_factory'
|
14
|
-
require 'assonnato/cookie_jar'
|
15
|
-
require 'assonnato/request'
|
16
|
-
require 'assonnato/parser'
|
17
|
-
|
18
|
-
require 'assonnato/client'
|
19
|
-
require 'assonnato/api/user'
|
20
|
-
require 'assonnato/api/show'
|
21
|
-
require 'assonnato/api/episode'
|
22
|
-
|
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
|
+
require 'uri'
|
9
|
+
require 'net/http'
|
10
|
+
require 'json'
|
11
|
+
|
12
|
+
require 'assonnato/assonnato'
|
13
|
+
require 'assonnato/api_factory'
|
14
|
+
require 'assonnato/cookie_jar'
|
15
|
+
require 'assonnato/request'
|
16
|
+
require 'assonnato/parser'
|
17
|
+
|
18
|
+
require 'assonnato/client'
|
19
|
+
require 'assonnato/api/user'
|
20
|
+
require 'assonnato/api/show'
|
21
|
+
require 'assonnato/api/episode'
|
22
|
+
|
23
23
|
require 'assonnato/version'
|
@@ -1,41 +1,48 @@
|
|
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
|
34
|
-
path = '/api/v1/episode/
|
35
|
-
data = { name: name, episode: episode, _csrf: @client.user.csrf_token }.merge fields
|
36
|
-
|
37
|
-
@client.post path, data
|
38
|
-
end
|
39
|
-
|
40
|
-
|
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 add(name, episode, fields)
|
34
|
+
path = '/api/v1/episode/add'
|
35
|
+
data = { name: name, episode: episode, _csrf: @client.user.csrf_token }.merge fields
|
36
|
+
|
37
|
+
@client.post path, data
|
38
|
+
end
|
39
|
+
|
40
|
+
def edit(name, episode, fields)
|
41
|
+
path = '/api/v1/episode/edit'
|
42
|
+
data = { name: name, episode: episode, _csrf: @client.user.csrf_token }.merge fields
|
43
|
+
|
44
|
+
@client.post path, data
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/lib/assonnato/api/show.rb
CHANGED
@@ -1,68 +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
|
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
|
data/lib/assonnato/api/user.rb
CHANGED
@@ -1,36 +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
|
-
|
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
36
|
end
|
@@ -1,30 +1,29 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c)
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
class
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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 ApiFactory
|
11
|
+
class << self
|
12
|
+
def new(klass, options = {})
|
13
|
+
return create_instance(klass, options) if klass
|
14
|
+
raise ArgumentError, 'must provide API class to be instantiated'
|
15
|
+
end
|
16
|
+
|
17
|
+
def create_instance(klass, options)
|
18
|
+
convert_to_constant(klass.to_s).new options
|
19
|
+
end
|
20
|
+
|
21
|
+
def convert_to_constant(classes)
|
22
|
+
classes.split('::').inject(Assonnato) do |constant, klass|
|
23
|
+
constant.const_get klass
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
30
29
|
end
|
data/lib/assonnato/assonnato.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
|
-
#--
|
2
|
-
# Copyright (c)
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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 << self
|
11
|
+
def new(host = 'pigro.omnivium.it', port = 80, ssl = false)
|
12
|
+
Client.new host, port, ssl
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(method, *args, &block)
|
16
|
+
return super unless new.respond_to?(method)
|
17
|
+
new.send method, *args, &block
|
18
|
+
end
|
19
|
+
|
20
|
+
def respond_to?(method, include_private = false)
|
21
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
26
25
|
end
|
data/lib/assonnato/client.rb
CHANGED
@@ -1,47 +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 = 'pigro.omnivium.it', 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
|
-
|
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 = 'pigro.omnivium.it', 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
47
|
end
|
data/lib/assonnato/cookie_jar.rb
CHANGED
@@ -1,31 +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
|
-
|
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
31
|
end
|
data/lib/assonnato/parser.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
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
|
-
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)
|
17
|
-
}
|
18
|
-
}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
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
|
+
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)
|
17
|
+
}
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
22
|
end
|
data/lib/assonnato/request.rb
CHANGED
@@ -1,41 +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
|
-
module Request
|
11
|
-
def get(path, headers = {})
|
12
|
-
request :get, path, {}, headers
|
13
|
-
end
|
14
|
-
|
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
|
-
|
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'
|
30
|
-
|
31
|
-
http.post path, data, headers
|
32
|
-
else raise ArgumentError, 'format not recognized'
|
33
|
-
end
|
34
|
-
|
35
|
-
@cookies << resp.response['set-cookie'].split('; ')[0] rescue @cookies.get
|
36
|
-
JSON.parse resp.body
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
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
|
+
module Request
|
11
|
+
def get(path, headers = {})
|
12
|
+
request :get, path, {}, headers
|
13
|
+
end
|
14
|
+
|
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
|
+
|
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'
|
30
|
+
|
31
|
+
http.post path, data, headers
|
32
|
+
else raise ArgumentError, 'format not recognized'
|
33
|
+
end
|
34
|
+
|
35
|
+
@cookies << resp.response['set-cookie'].split('; ')[0] rescue @cookies.get
|
36
|
+
JSON.parse resp.body
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
41
|
end
|
data/lib/assonnato/version.rb
CHANGED
data/spec/episode_spec.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
require 'assonnato'
|
3
|
-
|
4
|
-
describe Assonnato::Episode do
|
5
|
-
let(:client) { Assonnato::Episode.new Assonnato.new('pigro.omnivium.it') }
|
6
|
-
|
7
|
-
it 'returns all the episodes of given show' do
|
8
|
-
res = client.all 'Strike the Blood'
|
9
|
-
res.should be_kind_of(Array)
|
10
|
-
res.should_not be_empty
|
11
|
-
res.first.should be_kind_of(Struct)
|
12
|
-
res.first.episode.should eql(1)
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'can\'t search episodes' do
|
16
|
-
expect {
|
17
|
-
client.search 'le_too_derp'
|
18
|
-
}.to raise_error(NotImplementedError)
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'returns a specific episode of given show' do
|
22
|
-
res = client.get 'Strike the Blood', 1
|
23
|
-
res.should be_kind_of(Array)
|
24
|
-
res.should_not be_empty
|
25
|
-
res.first.should be_kind_of(Struct)
|
26
|
-
res.first.episode.should eql(1)
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'returns the last episode of each show with given status' do
|
30
|
-
res = client.last :ongoing
|
31
|
-
res.should be_kind_of(Array)
|
32
|
-
res.should_not be_empty
|
33
|
-
res.first.should be_kind_of(Struct)
|
34
|
-
end
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'assonnato'
|
3
|
+
|
4
|
+
describe Assonnato::Episode do
|
5
|
+
let(:client) { Assonnato::Episode.new Assonnato.new('pigro.omnivium.it') }
|
6
|
+
|
7
|
+
it 'returns all the episodes of given show' do
|
8
|
+
res = client.all 'Strike the Blood'
|
9
|
+
res.should be_kind_of(Array)
|
10
|
+
res.should_not be_empty
|
11
|
+
res.first.should be_kind_of(Struct)
|
12
|
+
res.first.episode.should eql(1)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'can\'t search episodes' do
|
16
|
+
expect {
|
17
|
+
client.search 'le_too_derp'
|
18
|
+
}.to raise_error(NotImplementedError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns a specific episode of given show' do
|
22
|
+
res = client.get 'Strike the Blood', 1
|
23
|
+
res.should be_kind_of(Array)
|
24
|
+
res.should_not be_empty
|
25
|
+
res.first.should be_kind_of(Struct)
|
26
|
+
res.first.episode.should eql(1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'returns the last episode of each show with given status' do
|
30
|
+
res = client.last :ongoing
|
31
|
+
res.should be_kind_of(Array)
|
32
|
+
res.should_not be_empty
|
33
|
+
res.first.should be_kind_of(Struct)
|
34
|
+
end
|
35
35
|
end
|
data/spec/show_spec.rb
CHANGED
@@ -1,51 +1,51 @@
|
|
1
|
-
#! /usr/bin/env ruby
|
2
|
-
require 'assonnato'
|
3
|
-
|
4
|
-
describe Assonnato::Show do
|
5
|
-
let(:client) { Assonnato::Show.new Assonnato.new('pigro.omnivium.it') }
|
6
|
-
|
7
|
-
it 'returns all the on-going shows' do
|
8
|
-
res = client.all :ongoing
|
9
|
-
res.should be_kind_of(Array)
|
10
|
-
res.should_not be_empty
|
11
|
-
res.first.should be_kind_of(Struct)
|
12
|
-
res.first.status.should eql('ongoing')
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'search all the shows which name is similar to given keyword' do
|
16
|
-
res = client.search '
|
17
|
-
res.should be_kind_of(Array)
|
18
|
-
res.should_not be_empty
|
19
|
-
res.first.should be_kind_of(Struct)
|
20
|
-
res.first.name.should eql('Strike the Blood')
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'returns all the on-going shows of given fansub' do
|
24
|
-
res = client.all :ongoing, fansub: 'Omnivium'
|
25
|
-
res.should be_kind_of(Array)
|
26
|
-
res.should_not be_empty
|
27
|
-
res.first.should be_kind_of(Struct)
|
28
|
-
res.first.fansub.should eql('Omnivium')
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'returns all the on-going shows in wich given user has worked' do
|
32
|
-
res = client.all :ongoing, user: 'Roxas Shadow'
|
33
|
-
res.should be_kind_of(Array)
|
34
|
-
res.should_not be_empty
|
35
|
-
end
|
36
|
-
|
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 }
|
39
|
-
res.should be_kind_of(Array)
|
40
|
-
res.should_not be_empty
|
41
|
-
res.first.translator.should eql('Roxas Shadow')
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'returns all the informations of given show' do
|
45
|
-
res = client.get 'Strike the Blood'
|
46
|
-
res.should be_kind_of(Array)
|
47
|
-
res.should_not be_empty
|
48
|
-
res.first.should be_kind_of(Struct)
|
49
|
-
res.first.id.should eql(1)
|
50
|
-
end
|
51
|
-
end
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'assonnato'
|
3
|
+
|
4
|
+
describe Assonnato::Show do
|
5
|
+
let(:client) { Assonnato::Show.new Assonnato.new('pigro.omnivium.it') }
|
6
|
+
|
7
|
+
it 'returns all the on-going shows' do
|
8
|
+
res = client.all :ongoing
|
9
|
+
res.should be_kind_of(Array)
|
10
|
+
res.should_not be_empty
|
11
|
+
res.first.should be_kind_of(Struct)
|
12
|
+
res.first.status.should eql('ongoing')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'search all the shows which name is similar to given keyword' do
|
16
|
+
res = client.search 'Strike'
|
17
|
+
res.should be_kind_of(Array)
|
18
|
+
res.should_not be_empty
|
19
|
+
res.first.should be_kind_of(Struct)
|
20
|
+
res.first.name.should eql('Strike the Blood')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'returns all the on-going shows of given fansub' do
|
24
|
+
res = client.all :ongoing, fansub: 'Omnivium'
|
25
|
+
res.should be_kind_of(Array)
|
26
|
+
res.should_not be_empty
|
27
|
+
res.first.should be_kind_of(Struct)
|
28
|
+
res.first.fansub.should eql('Omnivium')
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'returns all the on-going shows in wich given user has worked' do
|
32
|
+
res = client.all :ongoing, user: 'Roxas Shadow'
|
33
|
+
res.should be_kind_of(Array)
|
34
|
+
res.should_not be_empty
|
35
|
+
end
|
36
|
+
|
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 }
|
39
|
+
res.should be_kind_of(Array)
|
40
|
+
res.should_not be_empty
|
41
|
+
res.first.translator.should eql('Roxas Shadow')
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns all the informations of given show' do
|
45
|
+
res = client.get 'Strike the Blood'
|
46
|
+
res.should be_kind_of(Array)
|
47
|
+
res.should_not be_empty
|
48
|
+
res.first.should be_kind_of(Struct)
|
49
|
+
res.first.id.should eql(1)
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assonnato
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Giovanni Capuano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -44,6 +44,7 @@ executables: []
|
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
46
46
|
files:
|
47
|
+
- lib/assonnato.rb
|
47
48
|
- lib/assonnato/api/episode.rb
|
48
49
|
- lib/assonnato/api/show.rb
|
49
50
|
- lib/assonnato/api/user.rb
|
@@ -54,7 +55,6 @@ files:
|
|
54
55
|
- lib/assonnato/parser.rb
|
55
56
|
- lib/assonnato/request.rb
|
56
57
|
- lib/assonnato/version.rb
|
57
|
-
- lib/assonnato.rb
|
58
58
|
- spec/episode_spec.rb
|
59
59
|
- spec/show_spec.rb
|
60
60
|
homepage: http://www.giovannicapuano.net
|
@@ -77,10 +77,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
version: '0'
|
78
78
|
requirements: []
|
79
79
|
rubyforge_project:
|
80
|
-
rubygems_version: 2.
|
80
|
+
rubygems_version: 2.6.1
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: RESTful gem for wrapping Pigro's APIs
|
84
84
|
test_files:
|
85
85
|
- spec/episode_spec.rb
|
86
86
|
- spec/show_spec.rb
|
87
|
+
has_rdoc:
|