Class: DribbbleBucketApi::Shot

Inherits:
Object
  • Object
show all
Defined in:
lib/dribbble_bucket_api/shot.rb

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Shot

Returns a new instance of Shot.



6
7
8
9
10
11
12
# File 'lib/dribbble_bucket_api/shot.rb', line 6

def initialize(attrs = {})
	@attrs = attrs
	# ensure we have an id
	unless @attrs.has_key?(:id) && @attrs[:id]
		raise ArgumentError, "Shot must be initialized with an id"
	end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dribbble_bucket_api/shot.rb', line 14

def method_missing(method, *args, &block)
	# if attrs has the method, and this is an accessor
	if @attrs.has_key?(method.to_sym) && args.empty? && !block_given?
		@attrs[method.to_sym]
	# if we haven't requested the data yet, and this is a accessor
	elsif !requested_full_data? && args.empty? && !block_given?
		# request the data, then resubmit the method
		request_full_data && send(method)
	else
		super
	end
end

Instance Method Details

#request_full_dataObject



27
28
29
30
31
# File 'lib/dribbble_bucket_api/shot.rb', line 27

def request_full_data
	@requested_full_data = true
	properties = OfficialApi.new.get_shot_properties(id)
	@attrs.merge!(properties)
end

#requested_full_data?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/dribbble_bucket_api/shot.rb', line 33

def requested_full_data?
	!!@requested_full_data
end