anilibria-api-ruby 1.0.2 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/anilibria/api/client/_methods.rb +6 -6
- data/lib/anilibria/api/client.rb +27 -11
- data/lib/anilibria/api/exceptions/api_error.rb +2 -1
- data/lib/anilibria/api/exceptions/auth_error.rb +16 -5
- data/lib/anilibria/api/exceptions/response_error.rb +3 -2
- data/lib/anilibria/api/types/base.rb +0 -1
- data/lib/anilibria/api/types/dry_types.rb +0 -3
- data/lib/anilibria/api/types/schedule.rb +1 -1
- data/lib/anilibria/api/types/seed_stats.rb +3 -3
- data/lib/anilibria/api/types/t.rb +15 -0
- data/lib/anilibria/api/types/team.rb +1 -1
- data/lib/anilibria/api/types/title.rb +72 -70
- data/lib/anilibria/api/types/youtube.rb +6 -6
- data/lib/anilibria/api/types.rb +1 -0
- data/lib/anilibria/api/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3e1395dc7fa5e9867cf3b9419eb0692a8e09a82b024bf4b35208acd132daab1
|
4
|
+
data.tar.gz: 99193ab067172c7bd3ac16f90aa12887ebfafc9c655eddf60b5dde4411e99f0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67e552501fcd5d2a5603cb8ce10d562028f33e70172e480315db9343cf26c5e9c7a591ec162f90d3eb9d95c3cc2ba24756159bb809ee9872c673a65de27cadeb
|
7
|
+
data.tar.gz: 02db06b36eebbdf244a556ca0823d795574f511a925af9947302205611838a9190b9ab2331031ad9d3bf963f25bfd10bbb6dd1088c8c761e0dbc33cbdb8cbd23
|
data/Gemfile.lock
CHANGED
@@ -10,19 +10,19 @@ module Anilibria
|
|
10
10
|
api_method :get_random_title, returns: Types::Title
|
11
11
|
api_method :get_youtube, 'getYouTube', returns: DryTypes::Array.of(Types::YouTube)
|
12
12
|
api_method :get_feed, returns: Types::Feed
|
13
|
-
api_method :get_years, returns: DryTypes::Array.of(DryTypes::
|
14
|
-
api_method :get_genres, returns: DryTypes::Array.of(DryTypes::
|
15
|
-
api_method :get_caching_nodes, returns: DryTypes::Array.of(DryTypes::
|
13
|
+
api_method :get_years, returns: DryTypes::Array.of(DryTypes::Integer)
|
14
|
+
api_method :get_genres, returns: DryTypes::Array.of(DryTypes::String)
|
15
|
+
api_method :get_caching_nodes, returns: DryTypes::Array.of(DryTypes::String)
|
16
16
|
api_method :get_team, returns: DryTypes.Constructor(Types::Team) { |team| team[:team] }
|
17
|
-
api_method :get_rss, 'getRSS', returns: DryTypes::
|
17
|
+
api_method :get_rss, 'getRSS', returns: DryTypes::String | DryTypes::Hash
|
18
18
|
api_method :get_seed_stats, returns: DryTypes::Array.of(Types::SeedStats)
|
19
19
|
api_method :search_titles, returns: DryTypes::Array.of(Types::Title)
|
20
20
|
api_method :advanced_search, returns: DryTypes::Array.of(Types::Title)
|
21
21
|
|
22
22
|
# Methods that require authorization
|
23
23
|
api_method :get_favorites, returns: DryTypes::Array.of(Types::Title)
|
24
|
-
api_method :add_favorite, http_method: :put, returns:
|
25
|
-
api_method :del_favorite, http_method: :delete, returns:
|
24
|
+
api_method :add_favorite, http_method: :put, returns: Types::T::Success
|
25
|
+
api_method :del_favorite, http_method: :delete, returns: Types::T::Success
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
data/lib/anilibria/api/client.rb
CHANGED
@@ -63,7 +63,7 @@ module Anilibria
|
|
63
63
|
def auth(mail, passwd)
|
64
64
|
response = auth_response(mail, passwd)
|
65
65
|
|
66
|
-
return unless response
|
66
|
+
return unless auth_successful?(response)
|
67
67
|
|
68
68
|
response[:sessionId]
|
69
69
|
end
|
@@ -71,7 +71,12 @@ module Anilibria
|
|
71
71
|
def auth!(mail, passwd)
|
72
72
|
response = auth_response(mail, passwd)
|
73
73
|
|
74
|
-
|
74
|
+
unless auth_successful?(response)
|
75
|
+
raise(
|
76
|
+
Exceptions::AuthError.new(response),
|
77
|
+
'Failed authorization attempt'
|
78
|
+
)
|
79
|
+
end
|
75
80
|
|
76
81
|
response[:sessionId]
|
77
82
|
end
|
@@ -82,23 +87,34 @@ module Anilibria
|
|
82
87
|
|
83
88
|
private
|
84
89
|
|
90
|
+
def check_response!(response)
|
91
|
+
return if response.status == 200
|
92
|
+
|
93
|
+
if !response.body.respond_to?(:to_hash) ||
|
94
|
+
!response.body[:error].respond_to?(:to_hash)
|
95
|
+
raise Exceptions::ResponseError.new(
|
96
|
+
'Unexpected response from API', response
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
raise Exceptions::ApiError.new(response), response.body.dig(:error, :message)
|
101
|
+
end
|
102
|
+
|
85
103
|
def auth_response(mail, passwd)
|
86
104
|
response = connection.post(
|
87
105
|
AUTH_ENDPOINT,
|
88
106
|
{ mail: mail, passwd: passwd }
|
89
107
|
)
|
90
108
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
return if response.status == 200
|
96
|
-
|
97
|
-
if !response.body.respond_to?(:to_hash) || !response.body.key?(:error)
|
98
|
-
raise Exceptions::ResponseError.new('Unexpected response from API', response)
|
109
|
+
begin
|
110
|
+
JSON.parse(response.body, { symbolize_names: true })
|
111
|
+
rescue JSON::ParserError
|
112
|
+
{}
|
99
113
|
end
|
114
|
+
end
|
100
115
|
|
101
|
-
|
116
|
+
def auth_successful?(response)
|
117
|
+
response[:key] == 'success' && response.key?(:sessionId)
|
102
118
|
end
|
103
119
|
end
|
104
120
|
end
|
@@ -2,14 +2,25 @@ module Anilibria
|
|
2
2
|
module Api
|
3
3
|
module Exceptions
|
4
4
|
class AuthError < Base
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :data
|
6
|
+
|
7
|
+
def initialize(data = {})
|
8
|
+
@data = data
|
6
9
|
|
7
|
-
def initialize(response_body)
|
8
|
-
@err = response_body[:err]
|
9
|
-
@key = response_body[:key]
|
10
|
-
@mes = response_body[:mes]
|
11
10
|
super("#{mes} (#{key})")
|
12
11
|
end
|
12
|
+
|
13
|
+
def err
|
14
|
+
data[:err]
|
15
|
+
end
|
16
|
+
|
17
|
+
def mes
|
18
|
+
data[:mes]
|
19
|
+
end
|
20
|
+
|
21
|
+
def key
|
22
|
+
data[:key]
|
23
|
+
end
|
13
24
|
end
|
14
25
|
end
|
15
26
|
end
|
@@ -2,9 +2,9 @@ module Anilibria
|
|
2
2
|
module Api
|
3
3
|
module Types
|
4
4
|
class SeedStats < Base
|
5
|
-
attribute? :downloaded,
|
6
|
-
attribute? :uploaded,
|
7
|
-
attribute? :user,
|
5
|
+
attribute? :downloaded, T::Integer
|
6
|
+
attribute? :uploaded, T::Integer
|
7
|
+
attribute? :user, T::String
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Anilibria
|
2
|
+
module Api
|
3
|
+
module Types
|
4
|
+
module T
|
5
|
+
String = DryTypes::String.optional
|
6
|
+
Integer = DryTypes::Integer.optional
|
7
|
+
Bool = DryTypes::Bool.optional
|
8
|
+
Nil = DryTypes::Nil.optional
|
9
|
+
|
10
|
+
Timestamp = DryTypes.Constructor(Time, Time.method(:at)).optional
|
11
|
+
Success = DryTypes.Constructor(Bool) { |value| value[:success] }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -3,25 +3,36 @@ module Anilibria
|
|
3
3
|
module Types
|
4
4
|
class Title < Base
|
5
5
|
class Series < Base
|
6
|
-
attribute? :first,
|
7
|
-
attribute? :last,
|
8
|
-
attribute? :string,
|
6
|
+
attribute? :first, T::Integer
|
7
|
+
attribute? :last, T::Integer
|
8
|
+
attribute? :string, T::String
|
9
|
+
end
|
10
|
+
|
11
|
+
class Posters < Base
|
12
|
+
class Poster < Base
|
13
|
+
attribute? :url, T::String
|
14
|
+
attribute? :raw_base64_file, T::String
|
15
|
+
end
|
16
|
+
|
17
|
+
%i[small medium original].each do |size|
|
18
|
+
attribute? size, Poster
|
19
|
+
end
|
9
20
|
end
|
10
21
|
|
11
22
|
class Player < Base
|
12
23
|
class Playlist < Base
|
13
|
-
attribute? :serie,
|
14
|
-
attribute? :created_timestamp,
|
24
|
+
attribute? :serie, T::Integer
|
25
|
+
attribute? :created_timestamp, T::Timestamp
|
15
26
|
|
16
|
-
attribute? :hls do
|
17
|
-
attribute? :fhd,
|
18
|
-
attribute? :hd,
|
19
|
-
attribute? :sd,
|
27
|
+
attribute? :hls, Base do
|
28
|
+
attribute? :fhd, T::String
|
29
|
+
attribute? :hd, T::String
|
30
|
+
attribute? :sd, T::String
|
20
31
|
end
|
21
32
|
end
|
22
33
|
|
23
|
-
attribute? :alternative_player,
|
24
|
-
attribute? :host,
|
34
|
+
attribute? :alternative_player, T::String
|
35
|
+
attribute? :host, T::String
|
25
36
|
attribute? :series, Title::Series
|
26
37
|
|
27
38
|
attribute?(
|
@@ -36,101 +47,92 @@ module Anilibria
|
|
36
47
|
class Torrent < Base
|
37
48
|
class Metadata < Base
|
38
49
|
class FilesList < Base
|
39
|
-
attribute? :file,
|
40
|
-
attribute? :size,
|
41
|
-
attribute? :offset,
|
50
|
+
attribute? :file, T::String
|
51
|
+
attribute? :size, T::Integer
|
52
|
+
attribute? :offset, T::Integer
|
42
53
|
end
|
43
54
|
|
44
55
|
undef hash
|
45
56
|
|
46
|
-
attribute? :hash,
|
47
|
-
attribute? :name,
|
48
|
-
attribute? :announce, DryTypes::Array.of(
|
49
|
-
attribute? :created_timestamp,
|
50
|
-
|
57
|
+
attribute? :hash, T::String
|
58
|
+
attribute? :name, T::String
|
59
|
+
attribute? :announce, DryTypes::Array.of(T::String)
|
60
|
+
attribute? :created_timestamp, T::Timestamp
|
51
61
|
attribute? :files_list, DryTypes::Array.of(FilesList)
|
52
62
|
end
|
53
63
|
|
54
64
|
undef hash
|
55
65
|
|
56
|
-
attribute? :torrent_id,
|
66
|
+
attribute? :torrent_id, T::Integer
|
57
67
|
attribute? :series, Title::Series
|
58
68
|
|
59
|
-
attribute? :quality do
|
60
|
-
attribute? :string,
|
61
|
-
attribute? :type,
|
62
|
-
attribute? :resolution,
|
63
|
-
attribute? :encoder,
|
64
|
-
attribute? :lq_audio,
|
69
|
+
attribute? :quality, Base do
|
70
|
+
attribute? :string, T::String
|
71
|
+
attribute? :type, T::String
|
72
|
+
attribute? :resolution, T::Integer
|
73
|
+
attribute? :encoder, T::String
|
74
|
+
attribute? :lq_audio, T::Bool
|
65
75
|
end
|
66
76
|
|
67
77
|
%i[leechers seeders downloads total_size].each do |i|
|
68
|
-
attribute? i,
|
78
|
+
attribute? i, T::Integer
|
69
79
|
end
|
70
80
|
|
71
|
-
attribute? :url,
|
72
|
-
attribute? :uploaded_timestamp,
|
73
|
-
attribute? :hash,
|
74
|
-
attribute? :metadata,
|
75
|
-
attribute? :raw_base64_file,
|
81
|
+
attribute? :url, T::String
|
82
|
+
attribute? :uploaded_timestamp, T::Timestamp
|
83
|
+
attribute? :hash, T::String
|
84
|
+
attribute? :metadata, Metadata.optional
|
85
|
+
attribute? :raw_base64_file, T::String
|
76
86
|
end
|
77
87
|
|
78
88
|
attribute? :series, Title::Series
|
79
89
|
attribute? :list, DryTypes::Array.of(Torrent)
|
80
90
|
end
|
81
91
|
|
82
|
-
attribute? :id,
|
83
|
-
attribute? :code,
|
92
|
+
attribute? :id, T::Integer
|
93
|
+
attribute? :code, T::String
|
84
94
|
|
85
|
-
attribute? :names do
|
86
|
-
attribute? :ru,
|
87
|
-
attribute? :en,
|
88
|
-
attribute? :alternative,
|
95
|
+
attribute? :names, Base do
|
96
|
+
attribute? :ru, T::String
|
97
|
+
attribute? :en, T::String
|
98
|
+
attribute? :alternative, T::String
|
89
99
|
end
|
90
100
|
|
91
|
-
attribute? :announce,
|
92
|
-
|
93
|
-
attribute? :status do
|
94
|
-
attribute? :string, DryTypes::Strict::String
|
95
|
-
attribute? :code, DryTypes::Strict::Integer
|
96
|
-
end
|
101
|
+
attribute? :announce, T::String
|
97
102
|
|
98
|
-
attribute? :
|
99
|
-
|
100
|
-
|
101
|
-
attribute? :url, DryTypes::String.optional
|
102
|
-
attribute? :raw_base64_file, DryTypes::String.optional
|
103
|
-
end
|
104
|
-
end
|
103
|
+
attribute? :status, Base do
|
104
|
+
attribute? :string, T::String
|
105
|
+
attribute? :code, T::Integer
|
105
106
|
end
|
106
107
|
|
107
|
-
attribute? :
|
108
|
-
attribute? :
|
108
|
+
attribute? :posters, Posters
|
109
|
+
attribute? :updated, T::Timestamp
|
110
|
+
attribute? :last_change, T::Timestamp
|
109
111
|
|
110
|
-
attribute? :type do
|
111
|
-
attribute? :full_string,
|
112
|
-
attribute? :string,
|
113
|
-
attribute? :length,
|
114
|
-
attribute? :series,
|
115
|
-
attribute? :code,
|
112
|
+
attribute? :type, Base do
|
113
|
+
attribute? :full_string, T::String
|
114
|
+
attribute? :string, T::String
|
115
|
+
attribute? :length, T::Integer
|
116
|
+
attribute? :series, T::Integer
|
117
|
+
attribute? :code, T::Integer
|
116
118
|
end
|
117
119
|
|
118
|
-
attribute? :genres, DryTypes::Array.of(
|
120
|
+
attribute? :genres, DryTypes::Array.of(T::String)
|
119
121
|
attribute? :team, Types::Team
|
120
122
|
|
121
|
-
attribute? :season do
|
122
|
-
attribute? :string,
|
123
|
-
attribute? :code,
|
124
|
-
attribute? :year,
|
125
|
-
attribute? :week_day,
|
123
|
+
attribute? :season, Base do
|
124
|
+
attribute? :string, T::String
|
125
|
+
attribute? :code, T::Integer
|
126
|
+
attribute? :year, T::Integer
|
127
|
+
attribute? :week_day, T::Integer
|
126
128
|
end
|
127
129
|
|
128
|
-
attribute? :description,
|
129
|
-
attribute? :in_favorites,
|
130
|
+
attribute? :description, T::String
|
131
|
+
attribute? :in_favorites, T::Integer
|
130
132
|
|
131
|
-
attribute? :blocked do
|
132
|
-
attribute? :blocked,
|
133
|
-
attribute? :bakanim,
|
133
|
+
attribute? :blocked, Base do
|
134
|
+
attribute? :blocked, T::Bool
|
135
|
+
attribute? :bakanim, T::Bool
|
134
136
|
end
|
135
137
|
|
136
138
|
attribute? :player, Player
|
@@ -2,12 +2,12 @@ module Anilibria
|
|
2
2
|
module Api
|
3
3
|
module Types
|
4
4
|
class YouTube < Base
|
5
|
-
attribute? :id,
|
6
|
-
attribute? :image,
|
7
|
-
attribute? :youtube_id,
|
8
|
-
attribute? :comments,
|
9
|
-
attribute? :views,
|
10
|
-
attribute? :timestamp,
|
5
|
+
attribute? :id, T::Integer
|
6
|
+
attribute? :image, T::String
|
7
|
+
attribute? :youtube_id, T::String
|
8
|
+
attribute? :comments, T::Integer
|
9
|
+
attribute? :views, T::Integer
|
10
|
+
attribute? :timestamp, T::Timestamp
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
data/lib/anilibria/api/types.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anilibria-api-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roman Kozachenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-struct
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- lib/anilibria/api/types/feed.rb
|
68
68
|
- lib/anilibria/api/types/schedule.rb
|
69
69
|
- lib/anilibria/api/types/seed_stats.rb
|
70
|
+
- lib/anilibria/api/types/t.rb
|
70
71
|
- lib/anilibria/api/types/team.rb
|
71
72
|
- lib/anilibria/api/types/title.rb
|
72
73
|
- lib/anilibria/api/types/youtube.rb
|