Class: SmugProxy

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

Instance Method Summary collapse

Constructor Details

#initialize(base = "", params = {}) ⇒ SmugProxy

Returns a new instance of SmugProxy.



4
5
6
7
# File 'lib/smugmug/proxy.rb', line 4

def initialize(base="", params = {})
  @base = base
  @params = params
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, params = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/smugmug/proxy.rb', line 9

def method_missing(method, params={})
  method = method.to_s.gsub(/_(.)/) { $1.upcase }
  method = method.gsub(/URL/i, "URL").gsub(/EXIF/i, "EXIF")
  
  # it would be better to have a smugmug reflection method to get this information
  # but this is a fairly exhaustive list and it will be easy to add to this as well
  groups = %w(albums albumtemplates categories images login subcategories users 
              communities family friends orders pricing propricing sharegroups styles themes watermarks)
              
  if groups.include?(method)  
    SmugProxy.new(@base + "." + method.to_s, params)
  else
    puts "CALL: #{@base + "." + method}(#{params.inspect})"
  end
end

Instance Method Details

#to_sObject



25
26
27
# File 'lib/smugmug/proxy.rb', line 25

def to_s
  @base + "(#{@params.inspect})"
end