anilibria-api-ruby 1.0.1 → 1.0.2

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
  SHA256:
3
- metadata.gz: 7e8f99d41325b4d8e4d22877388d0cdeb216acc3ee3f4ad57cd7c3076973d9e9
4
- data.tar.gz: 2050b7e07d8dca2303ac52bc5097ff35ce39bb581f74533253c2caa46d7c64c6
3
+ metadata.gz: c1600677f7901b71024caf80adf4e17463fda64c344ddcac962d55305318998c
4
+ data.tar.gz: b787db999dac37e6d812abcaab9159e0ee21814ef036e8d1ae1845745a9a8a7f
5
5
  SHA512:
6
- metadata.gz: 51ef2354baa68cba34551fff411ad549f3650423b961f89357d811f646bfa0885b178b98f394cfeff6cf463e03a2dc5af70e7756e62a87bcad02435949b6129f
7
- data.tar.gz: ad841e35f03244b4f266288fa316ba4d43100003bdc9867d303e4dbde36ffec0a87c85f6efc441ccadaf0c42dd188f6af4593cf84f0492e79e1cb73865fcf248
6
+ metadata.gz: 062ab13c47527afc37ceae05ed450b119bb4bae333d5c979c2cf1d95aca127aca94b92b2e453811fd95fd64da8ba66692ec203637d678b00a9e95aa78113e4f8
7
+ data.tar.gz: dd4ad7f81fe6487dedb6cd6a9057cc440082abddb9240134a942af1bbd24aec7492f1a3772024289e87caf2b62af8feb036cf282f6a423f3816b8ab83a94f77d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- anilibria-api-ruby (1.0.1)
4
+ anilibria-api-ruby (1.0.2)
5
5
  dry-struct (~> 1.4)
6
6
  faraday (~> 2)
7
7
 
data/README.md CHANGED
@@ -32,11 +32,16 @@ Usage example:
32
32
  require 'anilibria/api'
33
33
 
34
34
  anilibria = Anilibria::Api::Client.new
35
+ # => #<Anilibria::Api::Client:0x00007f25c52fc1b8 ...
35
36
 
36
- anilibria.get_years # => [1996, 1998, 2001, 2003, 2004, 2005, 2006, ...]
37
+ anilibria.get_years
38
+ # => [1996, 1998, 2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, ...
37
39
 
38
- title = anilibria.get_title(code: 'steinsgate') # => #<Anilibria::Api::Types::Title id=8674 ...
39
- title.names.en # => "Steins;Gate"
40
+ title = anilibria.get_title(code: 'steinsgate')
41
+ # => #<Anilibria::Api::Types::Title id=8674 code="steinsgate" ...
42
+
43
+ title.names.en
44
+ # => "Steins;Gate"
40
45
  ```
41
46
 
42
47
  `anilibria` object implements [AniLibria API methods](https://github.com/anilibria/docs/blob/master/api_v2.md#method-list) as is. All methods are available in *snake_case* notation. Same with the `title` object - it implements the [Title](https://github.com/anilibria/docs/blob/master/api_v2.md#возвращаемые-значения-при-запросе-информации-о-тайтле) specification.
@@ -46,17 +51,20 @@ title.names.en # => "Steins;Gate"
46
51
  The gem supports authorization:
47
52
 
48
53
  ```ruby
49
- # session = anilibria.auth('wrong@example.com', 'WrongPassword') # => nil
54
+ # session = anilibria.auth('wrong@example.com', 'WrongPassword')
55
+ # => nil
50
56
 
51
57
  # session = anilibria.auth!('wrong@example.com', 'WrongPassword')
52
- # (raises an error Anilibria::Api::Exceptions::AuthError)
58
+ # raises an error Anilibria::Api::Exceptions::AuthError
53
59
 
54
- session = anilibria.auth('correct@example.com', 'CorrectPassword') # returns the session string
60
+ session = anilibria.auth('correct@example.com', 'CorrectPassword')
61
+ # => "VdZnNZRpEl9w2HcKNRyj1BWXLqdynpog"
55
62
 
56
- anilibria.add_favorite(title_id: 9114, session: session) # => true
63
+ anilibria.add_favorite(title_id: 9114, session: session)
64
+ # => true
57
65
 
58
66
  titles = anilibria.get_favorites(filter: 'id,code,names,description', session: session)
59
- # => [#<Anilibria::Api::Types::Title id=9114 code="shingeki-no-k...
67
+ # => [#<Anilibria::Api::Types::Title id=9114 code="shingeki-no-kyojin-the-final-season-part-2" ...
60
68
  ```
61
69
 
62
70
  ### API Version
@@ -64,7 +72,8 @@ titles = anilibria.get_favorites(filter: 'id,code,names,description', session: s
64
72
  You can get the currently used version of [AniLibria API](https://github.com/anilibria/docs/blob/master/api_v2.md):
65
73
 
66
74
  ```ruby
67
- anilibria.api_version # => "2.13.10"
75
+ anilibria.api_version
76
+ # => "2.13.10"
68
77
  ```
69
78
 
70
79
  ## Contributing
@@ -41,7 +41,10 @@ module Anilibria
41
41
  attr_reader :connection
42
42
 
43
43
  def initialize(url: ENDPOINT)
44
- @connection = Faraday.new(url: url) do |f|
44
+ @connection = Faraday.new(
45
+ url: url,
46
+ headers: { 'User-Agent' => "anilibria-api-ruby/#{VERSION}" }
47
+ ) do |f|
45
48
  f.request :url_encoded
46
49
  f.response :json, parser_options: { symbolize_names: true }
47
50
  end
@@ -74,7 +77,7 @@ module Anilibria
74
77
  end
75
78
 
76
79
  def api_version
77
- connection.get.headers['api-version']
80
+ connection.head.headers['API-Version']
78
81
  end
79
82
 
80
83
  private
@@ -1,6 +1,6 @@
1
1
  module Anilibria
2
2
  module Api
3
- VERSION = '1.0.1'.freeze
3
+ VERSION = '1.0.2'.freeze
4
4
  public_constant :VERSION
5
5
  end
6
6
  end
data/sample/rss.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'anilibria/api'
2
+ require 'rss'
3
+
4
+ anilibria = Anilibria::Api::Client.new
5
+
6
+ today_ts = Date.today.to_time.to_i
7
+ raw_rss = anilibria.get_rss(since: today_ts)
8
+
9
+ feed = RSS::Parser.parse(raw_rss)
10
+
11
+ puts feed.channel.title
12
+ feed.items.each do |item|
13
+ puts "#{item.pubDate.strftime('%H:%M:%S')} | #{item.title}"
14
+ end
@@ -0,0 +1,25 @@
1
+ require 'anilibria/api'
2
+
3
+ WEEK_DAYS = %w[
4
+ Понедельник
5
+ Вторник
6
+ Среда
7
+ Четверг
8
+ Пятница
9
+ Суббота
10
+ Воскресенье
11
+ ].freeze
12
+
13
+ anilibria = Anilibria::Api::Client.new
14
+
15
+ schedules = anilibria.get_schedule(filter: 'names.ru')
16
+
17
+ schedules.each do |schedule|
18
+ puts "#{WEEK_DAYS[schedule.day]}:"
19
+
20
+ schedule.list.each do |title|
21
+ puts " #{title.names.ru}"
22
+ end
23
+
24
+ puts
25
+ end
@@ -0,0 +1,29 @@
1
+ require 'anilibria/api'
2
+
3
+ anilibria = Anilibria::Api::Client.new
4
+
5
+ limit = 10
6
+
7
+ puts 'Введите поисковый запрос:'
8
+ input = $stdin.gets.chomp
9
+ puts
10
+
11
+ titles = anilibria.search_titles(
12
+ search: input,
13
+ filter: 'id,names,season,type,team,genres[0]',
14
+ limit: limit
15
+ )
16
+
17
+ puts 'Результаты:'
18
+ puts
19
+
20
+ titles.each do |title|
21
+ puts " id: #{title.id}"
22
+ puts " #{title.names.ru} / #{title.names.en}"
23
+ puts " Сезон: #{title.season.string} #{title.season.year}"
24
+ puts " Тип: #{title.type.full_string}"
25
+ puts " Жанр: #{title.genres.join(', ')}"
26
+ puts
27
+ end
28
+
29
+ puts "Всего найдено #{titles.size}, лимит: #{limit}"
data/sample/title.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'anilibria/api'
2
+
3
+ anilibria = Anilibria::Api::Client.new
4
+
5
+ title = anilibria.get_random_title(remove: 'posters,player,torrents')
6
+ # title = anilibria.get_title(id: 495, remove: 'posters,player,torrents')
7
+
8
+ subtitle_team = title.team.translator + title.team.editing + title.team.decor
9
+
10
+ puts "#{title.names.ru} / #{title.names.en}"
11
+ puts
12
+ puts "Сезон: #{title.season.year} #{title.season.string}"
13
+ puts "Тип: #{title.type.full_string}"
14
+ puts "Жанры: #{title.genres.join(', ')}"
15
+ puts "Озвучка: #{title.team.voice.join(', ')}"
16
+ puts "Тайминг: #{title.team.timing.join(', ')}" if title.team.timing.any?
17
+ puts "Работа над субтитрами: #{subtitle_team.join(', ')}" if subtitle_team.any?
18
+ puts
19
+ puts title.description
20
+ puts
21
+ puts format('https://www.anilibria.tv/release/%<code>s.html', code: title.code)
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.1
4
+ version: 1.0.2
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-05 00:00:00.000000000 Z
11
+ date: 2022-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-struct
@@ -71,6 +71,10 @@ files:
71
71
  - lib/anilibria/api/types/title.rb
72
72
  - lib/anilibria/api/types/youtube.rb
73
73
  - lib/anilibria/api/version.rb
74
+ - sample/rss.rb
75
+ - sample/schedule.rb
76
+ - sample/search_titles.rb
77
+ - sample/title.rb
74
78
  homepage: https://github.com/psychosocial88/anilibria-api-ruby
75
79
  licenses:
76
80
  - MIT