kudago-client 0.8.0

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.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.standard.yml +3 -0
  4. data/CHANGELOG.md +16 -0
  5. data/CODE_OF_CONDUCT.md +132 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +19 -0
  8. data/Rakefile +10 -0
  9. data/lib/kudago_client/client.rb +230 -0
  10. data/lib/kudago_client/connection.rb +32 -0
  11. data/lib/kudago_client/entities/agent.rb +55 -0
  12. data/lib/kudago_client/entities/comment.rb +26 -0
  13. data/lib/kudago_client/entities/event.rb +86 -0
  14. data/lib/kudago_client/entities/event_category.rb +16 -0
  15. data/lib/kudago_client/entities/image.rb +27 -0
  16. data/lib/kudago_client/entities/list.rb +36 -0
  17. data/lib/kudago_client/entities/list_item.rb +19 -0
  18. data/lib/kudago_client/entities/location.rb +27 -0
  19. data/lib/kudago_client/entities/movie.rb +117 -0
  20. data/lib/kudago_client/entities/movie_showing.rb +26 -0
  21. data/lib/kudago_client/entities/news.rb +32 -0
  22. data/lib/kudago_client/entities/place.rb +58 -0
  23. data/lib/kudago_client/entities/place_category.rb +16 -0
  24. data/lib/kudago_client/entities/role.rb +20 -0
  25. data/lib/kudago_client/entities_list/agent_list.rb +13 -0
  26. data/lib/kudago_client/entities_list/base_list.rb +32 -0
  27. data/lib/kudago_client/entities_list/comment_list.rb +9 -0
  28. data/lib/kudago_client/entities_list/event_category_list.rb +9 -0
  29. data/lib/kudago_client/entities_list/event_list.rb +9 -0
  30. data/lib/kudago_client/entities_list/list_list.rb +9 -0
  31. data/lib/kudago_client/entities_list/location_list.rb +13 -0
  32. data/lib/kudago_client/entities_list/movie_list.rb +9 -0
  33. data/lib/kudago_client/entities_list/movie_showing_list.rb +9 -0
  34. data/lib/kudago_client/entities_list/multiple_list.rb +51 -0
  35. data/lib/kudago_client/entities_list/news_list.rb +9 -0
  36. data/lib/kudago_client/entities_list/place_category_list.rb +9 -0
  37. data/lib/kudago_client/entities_list/place_list.rb +9 -0
  38. data/lib/kudago_client/entities_list/role_list.rb +9 -0
  39. data/lib/kudago_client/error.rb +14 -0
  40. data/lib/kudago_client/requests/agent_request.rb +21 -0
  41. data/lib/kudago_client/requests/base_request.rb +34 -0
  42. data/lib/kudago_client/requests/event_category_request.rb +23 -0
  43. data/lib/kudago_client/requests/event_of_the_day_request.rb +37 -0
  44. data/lib/kudago_client/requests/event_request.rb +33 -0
  45. data/lib/kudago_client/requests/list_request.rb +31 -0
  46. data/lib/kudago_client/requests/location_request.rb +23 -0
  47. data/lib/kudago_client/requests/movie_request.rb +35 -0
  48. data/lib/kudago_client/requests/movie_showing_request.rb +23 -0
  49. data/lib/kudago_client/requests/news_request.rb +33 -0
  50. data/lib/kudago_client/requests/place_category_request.rb +23 -0
  51. data/lib/kudago_client/requests/place_request.rb +29 -0
  52. data/lib/kudago_client/requests/role_request.rb +21 -0
  53. data/lib/kudago_client/requests/search_request.rb +18 -0
  54. data/lib/kudago_client.rb +5 -0
  55. data/sig/kudago_client/client.rbs +6 -0
  56. metadata +142 -0
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KudagoClient
4
+ module Entities
5
+ class Image
6
+ attr_reader :image, :thumbnails, :source
7
+
8
+ def initialize(image:, thumbnails: {}, source: {})
9
+ @image = image
10
+ @thumbnails = thumbnails
11
+ @source = source
12
+ end
13
+
14
+ def thumbnail(size)
15
+ @thumbnails[size]
16
+ end
17
+
18
+ def source_link
19
+ @source[:link]
20
+ end
21
+
22
+ def source_name
23
+ @source[:name]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "image"
4
+ require_relative "../entities_list/multiple_list"
5
+
6
+ require "date"
7
+
8
+ module KudagoClient
9
+ module Entities
10
+ class List
11
+ attr_accessor :lang, :id, :ctype, :slug, :title, :publication_date, :favorites_count, :comments_count, :description,
12
+ :body_text, :site_url, :item_url, :disable_comments, :items, :images
13
+
14
+ def initialize(lang:, id: nil, ctype: "list", slug: nil, title: nil, publication_date: nil, favorites_count: nil,
15
+ comments_count: nil, description: nil, body_text: nil, site_url: nil, item_url: nil, disable_comments: nil,
16
+ items: [], images: [])
17
+ @lang = lang
18
+ @id = id
19
+ @ctype = ctype
20
+ @slug = slug
21
+ @title = title
22
+ @favorites_count = favorites_count
23
+ @comments_count = comments_count
24
+ @description = description
25
+ @body_text = body_text
26
+ @site_url = site_url
27
+ @item_url = item_url
28
+ @disable_comments = disable_comments
29
+ @items = KudagoClient::EntitiesList::MultipleList.new(results: items, lang: lang) if items
30
+
31
+ @publication_date = Time.at(publication_date).to_datetime if publication_date
32
+ @images = images&.map { |img| Image.new(**img) }
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KudagoClient
4
+ module Entities
5
+ class ListItem
6
+ attr_accessor :lang, :id, :ctype, :title, :description, :item_url, :age_restriction
7
+
8
+ def initialize(lang:, id: nil, ctype: "listitem", title: nil, description: nil, item_url: nil, age_restriction: nil)
9
+ @lang = lang
10
+ @id = id
11
+ @ctype = ctype
12
+ @title = title
13
+ @description = description
14
+ @item_url = item_url
15
+ @age_restriction = age_restriction
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KudagoClient
4
+ module Entities
5
+ class Location
6
+ attr_reader :slug, :name, :timezone, :coords, :language, :currency
7
+
8
+ def initialize(lang:, slug: nil, name: nil, timezone: nil, coords: nil, language: nil, currency: nil)
9
+ @lang = lang
10
+ @slug = slug
11
+ @name = name
12
+ @timezone = timezone
13
+ @coords = coords
14
+ @language = language
15
+ @currency = currency
16
+ end
17
+
18
+ def lat
19
+ coords[:lat]
20
+ end
21
+
22
+ def lon
23
+ coords[:lon]
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "image"
4
+
5
+ require "date"
6
+
7
+ module KudagoClient
8
+ module Entities
9
+ class Movie
10
+ Genre = Data.define(:id, :slug, :name, :lang)
11
+
12
+ # id - идентификатор
13
+ # site_url - адрес фильма на сайте kudago.com
14
+ # publication_date - дата публикации
15
+ # slug - слаг
16
+ # title - название
17
+ # description - описание
18
+ # body_text - полное описание
19
+ # is_editors_choice - является ли выбоором редакции
20
+ # favorites_count - число пользователей, добавивших фильм в избранное
21
+ # genres - список жанров
22
+ # comments_count - число комментариев
23
+ # original_title - оригинальное название
24
+ # locale - язык оригинала
25
+ # country - страна оригинала
26
+ # year - год выпуска
27
+ # language - язык оригинала
28
+ # running_time - продолжительность
29
+ # budget_currency - бюджет (валюта)
30
+ # budget - бюджет
31
+ # mpaa_rating - рейтинг MPAA
32
+ # age_restriction - возрастное ограничение
33
+ # stars - актеры
34
+ # director - режиссер
35
+ # writer - сценарист
36
+ # awards - награды
37
+ # trailer - трейлер
38
+ # images - галерея картинок
39
+ # poster - постер
40
+ # url - сайт фильма
41
+ # imdb_url - ссылка на страницу фильма на imdb.com
42
+ # imdb_rating - рейтинг фильма на сайте imdb.com
43
+ # disable_comments - ??
44
+
45
+ attr_reader :id, :site_url, :publication_date, :slug, :title, :description, :body_text, :is_editors_choice,
46
+ :favorites_count, :genres, :comments_count, :original_title, :locale, :country, :year, :language, :running_time,
47
+ :budget_currency, :budget, :mpaa_rating, :age_restriction, :stars, :director, :writer, :awards, :trailer,
48
+ :images, :poster, :url, :imdb_url, :imdb_rating, :disable_comments
49
+
50
+ def initialize(
51
+ lang:, text_format: "html", id: nil, site_url: nil, publication_date: nil, slug: nil, title: nil,
52
+ description: nil, body_text: nil, is_editors_choice: nil, favorites_count: nil, genres: nil,
53
+ original_title: nil, locale: nil, country: nil, year: nil, language: nil, running_time: nil,
54
+ budget_currency: nil, budget: nil, mpaa_rating: nil, age_restriction: nil, stars: nil, director: nil,
55
+ writer: nil, awards: nil, trailer: nil, images: nil, poster: nil, url: nil, imdb_url: nil,
56
+ imdb_rating: nil, disable_comments: nil, comments_count: nil
57
+ )
58
+ @lang = lang
59
+ @text_format = text_format
60
+ @id = id
61
+
62
+ @url = url
63
+ @site_url = site_url
64
+ @imdb_url = imdb_url
65
+ @trailer = trailer
66
+
67
+ @publication_date = Time.at(publication_date).to_date if publication_date
68
+
69
+ @slug = slug
70
+ @title = title
71
+ @original_title = original_title
72
+ @description = description
73
+ @body_text = body_text
74
+
75
+ @is_editors_choice = is_editors_choice
76
+ @favorites_count = favorites_count
77
+ @stars = stars
78
+
79
+ @comments_count = comments_count
80
+ @locale = locale
81
+ @country = country
82
+ @language = language
83
+
84
+ @year = year
85
+ @running_time = running_time
86
+ @budget_currency = budget_currency
87
+ @budget = budget
88
+
89
+ @mpaa_rating = mpaa_rating
90
+ @imdb_rating = imdb_rating
91
+ @age_restriction = age_restriction
92
+
93
+ @director = director
94
+ @writer = writer
95
+ @awards = awards
96
+
97
+ @disable_comments = disable_comments
98
+
99
+ @genres = genres&.map do |genre|
100
+ Genre.new(id: genre[:id], slug: genre[:slug], name: genre[:name], lang: lang)
101
+ end
102
+
103
+ if poster
104
+ @poster = KudagoClient::Entities::Image.new(
105
+ image: poster[:image],
106
+ thumbnails: poster[:thumbnails],
107
+ source: poster[:source]
108
+ )
109
+ end
110
+
111
+ @images = images&.map do |image|
112
+ KudagoClient::Entities::Image.new(image: image[:image], thumbnails: image[:thumbnails], source: image[:source])
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "image"
4
+
5
+ module KudagoClient
6
+ module Entities
7
+ class MovieShowing
8
+ attr_accessor :lang, :id, :movie, :place, :datetime, :three_d, :imax, :four_dx, :original_language, :price
9
+
10
+ def initialize(lang:, id: nil, movie: nil, place: nil, datetime: nil, three_d: false, imax: false, four_dx: false, original_language: nil, price: nil)
11
+ @lang = lang
12
+ @id = id
13
+ @price = price
14
+
15
+ @three_d = three_d
16
+ @imax = imax
17
+ @four_dx = four_dx
18
+ @original_language = original_language
19
+
20
+ @movie = KudagoClient::Entities::Movie.new(**movie, lang: lang) if movie.present?
21
+ @place = KudagoClient::Entities::Place.new(**place, lang: lang) if place.present?
22
+ @datetime = Time.at(datetime).to_datetime if datetime.present?
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "image"
4
+
5
+ require "date"
6
+
7
+ module KudagoClient
8
+ module Entities
9
+ class News
10
+ attr_accessor :lang, :id, :title, :publication_date, :slug, :place, :description, :body_text, :images, :site_url,
11
+ :favorites_count, :comments_count, :disable_comments
12
+
13
+ def initialize(lang:, id: nil, title: nil, publication_date: nil, slug: nil, place: nil, description: nil, body_text: nil,
14
+ images: [], site_url: nil, favorites_count: 0, comments_count: 0, disable_comments: false)
15
+ @lang = lang
16
+ @id = id
17
+ @title = title
18
+ @slug = slug
19
+ @description = description
20
+ @body_text = body_text
21
+ @site_url = site_url
22
+ @favorites_count = favorites_count
23
+ @comments_count = comments_count
24
+ @disable_comments = disable_comments
25
+
26
+ @publication_date = Time.at(publication_date).to_date if publication_date
27
+ @place = KudagoClient::Entities::Place.new(**place, lang: lang) if place.present?
28
+ @images = images.map { |img| KudagoClient::Entities::Image.new(**img) } if images.present?
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KudagoClient
4
+ module Entities
5
+ class Place
6
+ attr_reader :id, :lang, :title, :slug, :images, :address, :timetable, :phone, :description, :site_url, :is_stub,
7
+ :body_text, :text_format, :disable_comments, :foreign_url, :coords, :subway, :favorites_count, :comments_count,
8
+ :is_closed, :categories, :short_title, :tags, :location, :location_name, :age_restriction, :has_parking_lot
9
+
10
+ def initialize(
11
+ id: nil, lang: nil, title: nil, slug: nil, images: nil, address: nil, timetable: nil, phone: nil,
12
+ description: nil, site_url: nil, is_stub: nil, body_text: nil, text_format: "html",
13
+ disable_comments: nil, foreign_url: nil, coords: nil, subway: nil,
14
+ favorites_count: nil, comments_count: nil, is_closed: nil, categories: nil,
15
+ short_title: nil, tags: nil, location: nil, age_restriction: nil, has_parking_lot: nil
16
+ )
17
+ @lang = lang
18
+ @id = id
19
+ @slug = slug
20
+ @title = title
21
+
22
+ @address = address
23
+ @timetable = timetable
24
+ @phone = phone
25
+ @coords = coords
26
+ @subway = subway
27
+ @is_closed = is_closed
28
+ @location_name = location
29
+ @location = KudagoClient::Entities::Location.new(slug: location, lang:) if location.present?
30
+
31
+ @site_url = site_url
32
+ @foreign_url = foreign_url
33
+
34
+ @text_format = text_format
35
+ @description = description
36
+ @body_text = body_text
37
+
38
+ @is_stub = is_stub
39
+
40
+ @disable_comments = disable_comments
41
+ @favorites_count = favorites_count
42
+ @comments_count = comments_count
43
+
44
+ @categories = categories&.map do |category_name|
45
+ Entities::PlaceCategory.new(name: category_name, lang: lang)
46
+ end
47
+ @short_title = short_title
48
+ @tags = tags
49
+ @age_restriction = age_restriction
50
+ @has_parking_lot = has_parking_lot
51
+
52
+ @images = images&.map do |image|
53
+ KudagoClient::Entities::Image.new(image: image[:image], thumbnails: image[:thumbnails], source: image[:source])
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KudagoClient
4
+ module Entities
5
+ class PlaceCategory
6
+ attr_reader :id, :slug, :name, :lang
7
+
8
+ def initialize(id: nil, slug: nil, name: nil, lang: "ru")
9
+ @id = id
10
+ @slug = slug
11
+ @name = name
12
+ @lang = lang
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KudagoClient
4
+ module Entities
5
+ class Role
6
+ # id - идентификатор
7
+ # name - название роли
8
+ # name_plural - название роли во множественном числе
9
+ attr_reader :id, :slug, :name, :name_plural
10
+
11
+ def initialize(id: nil, slug: nil, name: nil, name_plural: nil, lang: "ru")
12
+ @id = id
13
+ @slug = slug
14
+ @name = name
15
+ @name_plural = name_plural
16
+ @lang = lang
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class AgentList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::Agent
7
+
8
+ def find_by_id(id)
9
+ @items.find { |agent| agent.id == id }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ module KudagoClient
2
+ module EntitiesList
3
+ class BaseList
4
+ attr_reader :count, :next_url, :previous_url, :items, :lang
5
+
6
+ def initialize(count:, next_url:, previous_url:, results:, lang: "ru", item_params: {})
7
+ @count = count
8
+ @next = next_url
9
+ @previous = previous_url
10
+ @lang = lang
11
+
12
+ @items = results.map do |item|
13
+ self.class.get_entity_class.new(**item, **item_params, lang: lang)
14
+ end
15
+ end
16
+
17
+ def ids
18
+ @items.map(&:id)
19
+ end
20
+
21
+ class << self
22
+ def entity_class(class_name = nil)
23
+ @entity_class = class_name
24
+ end
25
+
26
+ def get_entity_class
27
+ @entity_class || raise("Entity class not set for #{name}")
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class CommentList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::Comment
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class EventCategoriesList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::EventCategory
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class EventList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::Event
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class ListList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::List
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class LocationList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::Location
7
+
8
+ def find_by_slug(slug)
9
+ @items.find { |location| location.slug == slug }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class MovieList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::Movie
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class MovieShowingList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::MovieShowing
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,51 @@
1
+ require_relative "../entities/news"
2
+ require_relative "../entities/event"
3
+ require_relative "../entities/place"
4
+ require_relative "../entities/list"
5
+ require_relative "../entities/list_item"
6
+ require_relative "../entities/movie"
7
+
8
+ module KudagoClient
9
+ module EntitiesList
10
+ class MultipleList
11
+ attr_reader :items, :lang, :count, :next_url, :previous_url
12
+
13
+ def initialize(results:, lang: "ru", count: nil, next_url: nil, previous_url: nil, item_params: {})
14
+ @next_url = next_url
15
+ @previous_url = previous_url
16
+ @lang = lang
17
+ @count = count || results.size
18
+
19
+ @items = results.map do |item|
20
+ item[:site_url] = item.delete(:item_url) if item.key?(:item_url) && item[:ctype] != "listitem"
21
+ item[:publication_date] = item.delete(:date) if item.key?(:date)
22
+ item[:images] = [item.delete(:first_image)].compact if item.key?(:first_image)
23
+ item[:dates] = [item.delete(:daterange)].compact if item.key?(:daterange)
24
+
25
+ parse_entity_class(item.delete(:ctype)).new(**item, **item_params, lang: lang)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def parse_entity_class(slug_type)
32
+ case slug_type
33
+ when "news"
34
+ KudagoClient::Entities::News
35
+ when "event"
36
+ KudagoClient::Entities::Event
37
+ when "place"
38
+ KudagoClient::Entities::Place
39
+ when "list"
40
+ KudagoClient::Entities::List
41
+ when "movie"
42
+ KudagoClient::Entities::Movie
43
+ when "listitem"
44
+ KudagoClient::Entities::ListItem
45
+ else
46
+ raise "Unknown entity type: #{slug_type}"
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class NewsList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::News
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class PlaceCategoriesList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::PlaceCategory
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class PlaceList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::Place
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "base_list"
2
+
3
+ module KudagoClient
4
+ module EntitiesList
5
+ class RoleList < KudagoClient::EntitiesList::BaseList
6
+ entity_class KudagoClient::Entities::Role
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KudagoClient
4
+ class Error < StandardError
5
+ attr_reader :status, :reason
6
+
7
+ def initialize(message:, status: nil, reason: nil)
8
+ super(message)
9
+
10
+ @status = status
11
+ @reason = reason
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base_request"
4
+
5
+ module KudagoClient
6
+ module Requests
7
+ class AgentRequest < KudagoClient::Requests::BaseRequest
8
+ PATH = "agents/"
9
+
10
+ def self.list(params = {})
11
+ params.slice!(:lang, :text_format, :ids, :fields, :agent_type, :expand, :tags)
12
+ parse_response_urls(get(PATH, params))
13
+ end
14
+
15
+ def self.find(agent_id, params = {})
16
+ params.slice!(:lang, :text_format, :fields)
17
+ get("#{PATH}#{agent_id}/", params)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ require_relative "../connection"
2
+ require_relative "../error"
3
+
4
+ require "active_support/core_ext/hash"
5
+
6
+ module KudagoClient
7
+ module Requests
8
+ class BaseRequest
9
+ def self.get(path, params = {})
10
+ response = connection.get(path, params)
11
+
12
+ if response.success?
13
+ response.body
14
+ else
15
+ message = response.body.is_a?(String) ? [response.reason_phrase, response.status].join(" ") : response.body[:detail]
16
+ raise KudagoClient::Error.new(message:, status: response.status, reason: response.reason_phrase)
17
+ end
18
+ end
19
+
20
+ private_class_method
21
+
22
+ def self.connection
23
+ @@connection ||= Connection.connection
24
+ end
25
+
26
+ def self.parse_response_urls(res)
27
+ res[:next_url] = res.delete :next
28
+ res[:previous_url] = res.delete :previous
29
+
30
+ res
31
+ end
32
+ end
33
+ end
34
+ end