syoboi_calendar 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/LICENSE +1 -1
- data/README.md +109 -775
- data/lib/syoboi_calendar/client.rb +39 -24
- data/lib/syoboi_calendar/queries/{channel_group_query.rb → list_channel_groups_query.rb} +1 -1
- data/lib/syoboi_calendar/queries/{channel_query.rb → list_channels_query.rb} +1 -1
- data/lib/syoboi_calendar/queries/{program_query.rb → list_programs_query.rb} +1 -1
- data/lib/syoboi_calendar/queries/{title_query.rb → list_titles_query.rb} +1 -1
- data/lib/syoboi_calendar/resources/base_resource.rb +2 -0
- data/lib/syoboi_calendar/resources/program_resource.rb +2 -0
- data/lib/syoboi_calendar/responses/base_response.rb +93 -0
- data/lib/syoboi_calendar/{response_parsers/channel_groups_response_parser.rb → responses/list_channel_groups_response.rb} +8 -3
- data/lib/syoboi_calendar/{response_parsers/channels_response_parser.rb → responses/list_channels_response.rb} +8 -3
- data/lib/syoboi_calendar/{response_parsers/programs_response_parser.rb → responses/list_programs_response.rb} +8 -3
- data/lib/syoboi_calendar/{response_parsers/titles_response_parser.rb → responses/list_titles_response.rb} +8 -3
- data/lib/syoboi_calendar/version.rb +1 -1
- data/lib/syoboi_calendar.rb +9 -14
- data/spec/spec_helper.rb +0 -1
- data/spec/syoboi_calendar/client_spec.rb +119 -143
- data/syoboi_calendar.gemspec +0 -1
- metadata +11 -26
- data/lib/syoboi_calendar/response.rb +0 -49
- data/lib/syoboi_calendar/response_parsers/base_response_parser.rb +0 -52
@@ -1,3 +1,6 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday_middleware"
|
3
|
+
|
1
4
|
module SyoboiCalendar
|
2
5
|
class Client
|
3
6
|
ENDPOINT_BASE_URL = "http://cal.syoboi.jp"
|
@@ -7,47 +10,48 @@ module SyoboiCalendar
|
|
7
10
|
def connection
|
8
11
|
@connection ||= ::Faraday::Connection.new(url: ENDPOINT_BASE_URL) do |connection|
|
9
12
|
connection.adapter :net_http
|
13
|
+
connection.response :xml
|
10
14
|
connection.response :raise_error
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
|
-
# @
|
18
|
+
# @param options [Hash]
|
19
|
+
# @return [SyoboiCalendar::Response]
|
15
20
|
def list_channel_groups(options = {})
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
response_parser_class: ::SyoboiCalendar::ResponseParsers::ChannelGroupsResponseParser,
|
21
|
+
list(
|
22
|
+
options: options,
|
23
|
+
query_class: ::SyoboiCalendar::Queries::ListChannelGroupsQuery,
|
24
|
+
response_class: ::SyoboiCalendar::Responses::ListChannelGroupsResponse,
|
21
25
|
)
|
22
26
|
end
|
23
27
|
|
24
|
-
# @
|
28
|
+
# @param options [Hash]
|
29
|
+
# @return [SyoboiCalendar::Response]
|
25
30
|
def list_channels(options = {})
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
response_parser_class: ::SyoboiCalendar::ResponseParsers::ChannelsResponseParser,
|
31
|
+
list(
|
32
|
+
options: options,
|
33
|
+
query_class: ::SyoboiCalendar::Queries::ListChannelsQuery,
|
34
|
+
response_class: ::SyoboiCalendar::Responses::ListChannelsResponse,
|
31
35
|
)
|
32
36
|
end
|
33
37
|
|
34
|
-
# @
|
38
|
+
# @param options [Hash]
|
39
|
+
# @return [SyoboiCalendar::Response]
|
35
40
|
def list_programs(options = {})
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
response_parser_class: ::SyoboiCalendar::ResponseParsers::ProgramsResponseParser,
|
41
|
+
list(
|
42
|
+
options: options,
|
43
|
+
query_class: ::SyoboiCalendar::Queries::ListProgramsQuery,
|
44
|
+
response_class: ::SyoboiCalendar::Responses::ListProgramsResponse,
|
41
45
|
)
|
42
46
|
end
|
43
47
|
|
44
|
-
# @
|
48
|
+
# @param options [Hash]
|
49
|
+
# @return [SyoboiCalendar::Response]
|
45
50
|
def list_titles(options = {})
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
response_parser_class: ::SyoboiCalendar::ResponseParsers::TitlesResponseParser,
|
51
|
+
list(
|
52
|
+
options: options,
|
53
|
+
query_class: ::SyoboiCalendar::Queries::ListTitlesQuery,
|
54
|
+
response_class: ::SyoboiCalendar::Responses::ListTitlesResponse,
|
51
55
|
)
|
52
56
|
end
|
53
57
|
|
@@ -59,5 +63,16 @@ module SyoboiCalendar
|
|
59
63
|
def get(query)
|
60
64
|
connection.get(ENDPOINT_PATH, query)
|
61
65
|
end
|
66
|
+
|
67
|
+
# @private
|
68
|
+
# @param options [Hash]
|
69
|
+
# @param query_class [Class]
|
70
|
+
# @param response_class [Class]
|
71
|
+
# @return [SyoboiCalendar::Responses::ListBaseResponse]
|
72
|
+
def list(options:, query_class:, response_class:)
|
73
|
+
query = query_class.new(options)
|
74
|
+
faraday_response = get(query.to_hash)
|
75
|
+
response_class.new(faraday_response)
|
76
|
+
end
|
62
77
|
end
|
63
78
|
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module SyoboiCalendar
|
2
|
+
module Responses
|
3
|
+
class BaseResponse
|
4
|
+
include ::Enumerable
|
5
|
+
|
6
|
+
# @param faraday_response [Faraday::Response]
|
7
|
+
def initialize(faraday_response)
|
8
|
+
@faraday_response = faraday_response
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [String]
|
12
|
+
def body
|
13
|
+
faraday_response.body
|
14
|
+
end
|
15
|
+
|
16
|
+
# @return [Integer]
|
17
|
+
def code
|
18
|
+
body[response_key]["Result"]["Code"].to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
# @note Implementation for Enumerable
|
22
|
+
def each(&block)
|
23
|
+
resources.each(&block)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [Boolean]
|
27
|
+
def has_error?
|
28
|
+
code != 200
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Faraday::Utils::Headers]
|
32
|
+
def headers
|
33
|
+
faraday_response.headers
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [String, nil]
|
37
|
+
def message
|
38
|
+
body[response_key]["Result"]["Message"]
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [Array<SyoboiCalendar::Resources::BaseResource>]
|
42
|
+
def resources
|
43
|
+
sources.map do |source|
|
44
|
+
resource_class.new(source)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# @return [Integer]
|
49
|
+
def status
|
50
|
+
faraday_response.status
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# @return [Faraday::Response]
|
56
|
+
def faraday_response
|
57
|
+
@faraday_response
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [Class]
|
61
|
+
def resource_class
|
62
|
+
raise ::NotImplementedError
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [String]
|
66
|
+
def response_key
|
67
|
+
raise ::NotImplementedError
|
68
|
+
end
|
69
|
+
|
70
|
+
# @return [Array<Hash>, Hash]
|
71
|
+
def source_or_sources
|
72
|
+
raise ::NotImplementedError
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [Array<Hash>]
|
76
|
+
def sources
|
77
|
+
if has_error?
|
78
|
+
[]
|
79
|
+
else
|
80
|
+
object = source_or_sources
|
81
|
+
case
|
82
|
+
when object.nil?
|
83
|
+
[]
|
84
|
+
when object.respond_to?(:to_ary)
|
85
|
+
object.to_ary || [object]
|
86
|
+
else
|
87
|
+
[object]
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SyoboiCalendar
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Responses
|
3
|
+
class ListChannelGroupsResponse < BaseResponse
|
4
4
|
private
|
5
5
|
|
6
6
|
# @note Override
|
@@ -8,9 +8,14 @@ module SyoboiCalendar
|
|
8
8
|
::SyoboiCalendar::Resources::ChannelGroupResource
|
9
9
|
end
|
10
10
|
|
11
|
+
# @note Override
|
12
|
+
def response_key
|
13
|
+
"ChGroupLookupResponse"
|
14
|
+
end
|
15
|
+
|
11
16
|
# @note Override
|
12
17
|
def source_or_sources
|
13
|
-
|
18
|
+
body[response_key]["ChGroupItems"]["ChGroupItem"]
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SyoboiCalendar
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Responses
|
3
|
+
class ListChannelsResponse < BaseResponse
|
4
4
|
private
|
5
5
|
|
6
6
|
# @note Override
|
@@ -8,9 +8,14 @@ module SyoboiCalendar
|
|
8
8
|
::SyoboiCalendar::Resources::ChannelResource
|
9
9
|
end
|
10
10
|
|
11
|
+
# @note Override
|
12
|
+
def response_key
|
13
|
+
"ChLookupResponse"
|
14
|
+
end
|
15
|
+
|
11
16
|
# @note Override
|
12
17
|
def source_or_sources
|
13
|
-
|
18
|
+
body[response_key]["ChItems"]["ChItem"]
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SyoboiCalendar
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Responses
|
3
|
+
class ListProgramsResponse < BaseResponse
|
4
4
|
private
|
5
5
|
|
6
6
|
# @note Override
|
@@ -8,9 +8,14 @@ module SyoboiCalendar
|
|
8
8
|
::SyoboiCalendar::Resources::ProgramResource
|
9
9
|
end
|
10
10
|
|
11
|
+
# @note Override
|
12
|
+
def response_key
|
13
|
+
"ProgLookupResponse"
|
14
|
+
end
|
15
|
+
|
11
16
|
# @note Override
|
12
17
|
def source_or_sources
|
13
|
-
|
18
|
+
body[response_key]["ProgItems"]["ProgItem"]
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SyoboiCalendar
|
2
|
-
module
|
3
|
-
class
|
2
|
+
module Responses
|
3
|
+
class ListTitlesResponse < BaseResponse
|
4
4
|
private
|
5
5
|
|
6
6
|
# @note Override
|
@@ -8,9 +8,14 @@ module SyoboiCalendar
|
|
8
8
|
::SyoboiCalendar::Resources::TitleResource
|
9
9
|
end
|
10
10
|
|
11
|
+
# @note Override
|
12
|
+
def response_key
|
13
|
+
"TitleLookupResponse"
|
14
|
+
end
|
15
|
+
|
11
16
|
# @note Override
|
12
17
|
def source_or_sources
|
13
|
-
|
18
|
+
body[response_key]["TitleItems"]["TitleItem"]
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
data/lib/syoboi_calendar.rb
CHANGED
@@ -1,21 +1,16 @@
|
|
1
|
-
require "faraday"
|
2
|
-
require "faraday_middleware"
|
3
|
-
require "multi_xml"
|
4
|
-
|
5
1
|
require "syoboi_calendar/client"
|
6
2
|
require "syoboi_calendar/queries/base_query"
|
7
|
-
require "syoboi_calendar/queries/
|
8
|
-
require "syoboi_calendar/queries/
|
9
|
-
require "syoboi_calendar/queries/
|
10
|
-
require "syoboi_calendar/queries/
|
3
|
+
require "syoboi_calendar/queries/list_channel_groups_query"
|
4
|
+
require "syoboi_calendar/queries/list_channels_query"
|
5
|
+
require "syoboi_calendar/queries/list_programs_query"
|
6
|
+
require "syoboi_calendar/queries/list_titles_query"
|
11
7
|
require "syoboi_calendar/resources/base_resource"
|
12
8
|
require "syoboi_calendar/resources/channel_group_resource"
|
13
9
|
require "syoboi_calendar/resources/channel_resource"
|
14
10
|
require "syoboi_calendar/resources/program_resource"
|
15
11
|
require "syoboi_calendar/resources/title_resource"
|
16
|
-
require "syoboi_calendar/
|
17
|
-
require "syoboi_calendar/
|
18
|
-
require "syoboi_calendar/
|
19
|
-
require "syoboi_calendar/
|
20
|
-
require "syoboi_calendar/
|
21
|
-
require "syoboi_calendar/response_parsers/titles_response_parser"
|
12
|
+
require "syoboi_calendar/responses/base_response"
|
13
|
+
require "syoboi_calendar/responses/list_channel_groups_response"
|
14
|
+
require "syoboi_calendar/responses/list_channels_response"
|
15
|
+
require "syoboi_calendar/responses/list_programs_response"
|
16
|
+
require "syoboi_calendar/responses/list_titles_response"
|