Class: FlickRaw::Request

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

Direct Known Subclasses

Flickr

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flickr = nil) ⇒ Request

:nodoc:



105
106
107
108
109
110
111
112
# File 'lib/flickraw.rb', line 105

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:



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/flickraw.rb', line 114

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 of the flickr methods of this object



146
# File 'lib/flickraw.rb', line 146

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

.flickr_objectsObject

List of the flickr subobjects of this object



143
# File 'lib/flickraw.rb', line 143

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

.request_nameObject

Returns the prefix of the request corresponding to this class.



149
# File 'lib/flickraw.rb', line 149

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