Class: FlickRaw::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/flickraw/request.rb

Direct Known Subclasses

Flickr

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flickr = nil) ⇒ Request

:nodoc:



3
4
5
6
7
8
9
10
# File 'lib/flickraw/request.rb', line 3

def initialize(flickr = nil) # :nodoc:
  @flickr = flickr

  self.class.flickr_objects.each {|name|
    klass = self.class.const_get name.capitalize
    instance_variable_set "@#{name}", klass.new(@flickr)
  }
end

Class Method Details

.build_request(req) ⇒ Object

:nodoc:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/flickraw/request.rb', line 12

def self.build_request(req) # :nodoc:
  method_nesting = req.split '.'
  raise "'#{@name}' : Method name mismatch" if method_nesting.shift != request_name.split('.').last

  if method_nesting.size > 1
    name = method_nesting.first
    class_name = name.capitalize
    if flickr_objects.include? name
      klass = const_get(class_name)
    else
      klass = Class.new Request
      const_set(class_name, klass)
      attr_reader name
      flickr_objects << name
    end

    klass.build_request method_nesting.join('.')
  else
    req = method_nesting.first
    module_eval %{
      def #{req}(*args, &block)
        @flickr.call("#{request_name}.#{req}", *args, &block)
      end
    }
    flickr_methods << req
  end
end

.flickr_methodsObject

List the flickr methods of this object



44
# File 'lib/flickraw/request.rb', line 44

def self.flickr_methods; @flickr_methods ||= [] end

.flickr_objectsObject

List the flickr subobjects of this object



41
# File 'lib/flickraw/request.rb', line 41

def self.flickr_objects; @flickr_objects ||= [] end

.request_nameObject

Returns the prefix of the request corresponding to this class.



47
# File 'lib/flickraw/request.rb', line 47

def self.request_name; name.downcase.gsub(/::/, '.').sub(/[^\.]+\./, '') end