Class: TwicasStream::Movie::GetMoviesbyUser

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

Constant Summary collapse

PREFIX_URL =
'users'
SUFFIX_URL =
'movies'
DEFAULT_OFFSET =
0
LOWER_OFFSET =
0
UPPER_OFFSET =
1000
DEFAULT_LIMIT =
20
LOWER_LIMIT =
1
UPPER_LIMIT =
50
DEFAULT_SLICE_ID =
'none'
LOWER_SLICE_ID =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user_id, offset = DEFAULT_OFFSET, limit = DEFAULT_LIMIT, slice_id = DEFAULT_SLICE_ID) ⇒ GetMoviesbyUser

Returns a new instance of GetMoviesbyUser.



86
87
88
89
90
91
92
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/movie.rb', line 86

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

	unless offset >= LOWER_OFFSET and offset <= UPPER_OFFSET
		STDERR.puts "#{__FILE__}:#{__LINE__}:Warning: out of limitation. offset range is #{LOWER_OFFSET} ~ #{UPPER_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

	if slice_id.kind_of?(Integer)
		if slice_id < LOWER_SLICE_ID
			STDERR.puts "#{__FILE__}:#{__LINE__}:Warning: out of limitation. slice id (comment id) should be over #{LOWER_SLICE_ID}."
		end
	else
		unless slice_id == DEFAULT_SLICE_ID
			STDERR.puts "#{__FILE__}:#{__LINE__}:Error: invalid parameter. default is '#{DEFAULT_SLICE_ID}'."
		end
	end

	param['offset'] = offset
	param['limit'] = limit
	param['slice_id'] = slice_id unless slice_id == DEFAULT_SLICE_ID

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

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

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



64
65
66
# File 'lib/twicas_stream/movie.rb', line 64

def response
  @response
end