Class: TwicasStream::Supporter::SupporterList

Inherits:
Object
  • Object
show all
Defined in:
lib/twicas_stream/supporter.rb

Constant Summary collapse

PREFIX_URL =
'users'
SUFFIX_URL =
'supporters'
DEFAULT_OFFSET =
0
LOWER_OFFSET =
0
DEFAULT_LIMIT =
20
LOWER_LIMIT =
1
UPPER_LIMIT =
20
SORT_LIMITATION =
['new', 'ranking']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id, offset = DEFAULT_OFFSET, limit = DEFAULT_LIMIT, sort) ⇒ SupporterList

Returns a new instance of SupporterList.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/twicas_stream/supporter.rb', line 93

def initialize user_id, offset = DEFAULT_OFFSET, limit = DEFAULT_LIMIT, sort
	@response = Hash.new
	param = Hash.new

	if offset < LOWER_OFFSET
		STDERR.puts "#{__FILE__}:#{__LINE__}:Warning: out of limitation. offset should be over #{LOWER_OFFSET}."
	end

	unless limit >= LOWER_LIMIT and limit <= UPPER_LIMIT
		STDERR.puts "#{__FILE__}:#{__LINE__}:Warning: out of limitation. limit range is #{LOWER_LIMIT} ~ #{UPPER_LIMIT}."
	end

	unless SORT_LIMITATION.include?(sort)
		STDERR.puts "#{__FILE__}:#{__LINE__}:Warning: out of limitation. sort is '#{SORT_LIMITATION.join("' or '")}'."
	end

	param['offset'] = offset
	param['limit'] = limit
	param['sort'] = sort

	url = [BASE_URL, PREFIX_URL, user_id, SUFFIX_URL].join('/') + TwicasStream.make_query_string(param)
	# => 'https://apiv2.twitcasting.tv/users/twitcasting_jp/supporting?offset=10&limit=20'

	@response = TwicasStream.parse(TwicasStream.get(url))
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



75
76
77
# File 'lib/twicas_stream/supporter.rb', line 75

def response
  @response
end