Module: TwicasStream
- Extended by:
- RequestHeader
- Defined in:
- lib/twicas_stream/version.rb,
lib/twicas_stream.rb,
lib/twicas_stream/user.rb,
lib/twicas_stream/movie.rb,
lib/twicas_stream/search.rb,
lib/twicas_stream/comment.rb,
lib/twicas_stream/category.rb,
lib/twicas_stream/supporter.rb,
lib/twicas_stream/live_thumbnail.rb,
lib/twicas_stream/request_header.rb,
lib/twicas_stream/twicas_api_object/app.rb,
lib/twicas_stream/twicas_api_object/user.rb,
lib/twicas_stream/twicas_api_object/error.rb,
lib/twicas_stream/twicas_api_object/movie.rb,
lib/twicas_stream/twicas_api_object/comment.rb,
lib/twicas_stream/twicas_api_object/category.rb,
lib/twicas_stream/twicas_api_object/sub_category.rb,
lib/twicas_stream/twicas_api_object/supporter_user.rb
Overview
! /opt/local/bin/ruby coding: utf-8
Defined Under Namespace
Modules: Category, Comment, LiveThumbnail, Movie, RequestHeader, Search, Supporter, TwicasApiObject, User
Constant Summary
collapse
- BASE_URL =
'https://apiv2.twitcasting.tv'
- VERSION =
'1.3.1'
RequestHeader::DEFAULT_ACCEPT_ENCODING, RequestHeader::DEFAULT_ACCESS_TOKEN, RequestHeader::DEFAULT_API_VERSION, RequestHeader::REQUEST_HEADER
Class Method Summary
collapse
configure, extended, reset
Class Method Details
.body(result) ⇒ Object
81
82
83
|
# File 'lib/twicas_stream.rb', line 81
def body result
result[:body]
end
|
.get(url) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/twicas_stream.rb', line 89
def get url
c = Curl.get(url) do |curl|
TwicasStream.configure do ||
curl.['X-Api-Version'] = .api_version
curl.['Accept'] = .accept_encoding
curl.['Authorization'] = 'Bearer ' + .access_token
end
end
response, * = c..split(/[\r\n]+/).map(&:strip)
= Hash[.flat_map{ |s| s.scan(/^(\S+): (.+)/) }]
{ :header => , :body => JSON.parse(c.body_str), :response_code => c.response_code }
end
|
.get_image(url, path) ⇒ Object
104
105
106
107
108
109
110
111
|
# File 'lib/twicas_stream.rb', line 104
def get_image url, path
c = Curl.get(url)
response, * = c..split(/[\r\n]+/).map(&:strip)
= Hash[.flat_map{ |s| s.scan(/^(\S+): (.+)/) }]
save_image(path, ['Location'])
end
|
85
86
87
|
# File 'lib/twicas_stream.rb', line 85
def result
result[:header]
end
|
.make_query_string(options) ⇒ Object
113
114
115
116
117
118
119
120
|
# File 'lib/twicas_stream.rb', line 113
def make_query_string options
query = "?"
options.each do |key, value|
query += "#{key}=#{value.to_s.gsub(" ", "+")}&"
end
query[0...-1]
end
|
.parse(result) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/twicas_stream.rb', line 28
def parse result
response = Hash.new
response_code = response_code(result)
body = body(result)
= (result)
body.each{ |key, value|
if key == 'movies'
if is_TwicasApiObject?(value.first.keys.first)
response[key.to_sym] = value.map{ |i|
child_response = Hash.new
i.each{ |child_key, child_value| child_response[child_key.to_sym] = parse_deep(child_key, child_value) }
child_response
}
else
response[key.to_sym] = value.map{ |i| parse_deep(key, i) }
end
elsif key == 'supporting' or key == 'supporters'
response[key.to_sym] = value.map{ |i| parse_deep('SupporterUser', i) }
elsif (key != key.singularize) and is_TwicasApiObject?(key)
response[key.to_sym] = value.map{ |i| parse_deep(key, i) }
else
response[key.to_sym] = parse_deep(key, value)
end
}
response
end
|
.response_code(result) ⇒ Object
77
78
79
|
# File 'lib/twicas_stream.rb', line 77
def response_code result
result[:response_code]
end
|