Class: Flickr::Reflection

Inherits:
APIBase
  • Object
show all
Defined in:
lib/flickr/reflection.rb

Instance Attribute Summary

Attributes inherited from APIBase

#flickr

Instance Method Summary collapse

Methods inherited from APIBase

#initialize

Constructor Details

This class inherits a constructor from Flickr::APIBase

Instance Method Details

#getMethodInfo(method_name) ⇒ Object

We don’t bother with caching because it’s not worth it for the reflection API.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/flickr/reflection.rb', line 31

def getMethodInfo(method_name)
  res = @flickr.call_method('flickr.reflection.getMethodInfo',
                            'method_name' => method_name)
  els = res.elements
  att = res.root.attributes
  desc = els['/method/description'] ?
    els['/method/description'].text : nil
  resp = els['/method/response'] ?
    els['/method/response'].text : nil
  expl = els['/method/explanation'] ?
    els['/method/explanation'].text : nil
  meth = Flickr::Method.new(att['name'],att['needslogin'].to_i==1,
                            desc,resp,expl)
  els['/method/arguments'].each_element do |el|
    att = el.attributes
    arg = Flickr::MethodArgument.new(att['name'],
                                     att['optional'].to_i == 1,el.text)
    meth.arguments << arg
  end
  els['/method/errors'].each_element do |el|
    att = el.attributes
    err = XMLRPC::FaultException.new(att['code'].to_i,
                                     el.text)
    meth.errors << err
  end		
  return meth
end

#getMethodsObject



59
60
61
62
63
64
65
66
# File 'lib/flickr/reflection.rb', line 59

def getMethods
  res = @flickr.call_method('flickr.reflection.getMethods')
  list = []
  res.elements['/methods'].each_element do |el|
    list << el.text
  end
  return list
end

#missing_methodsObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/flickr/reflection.rb', line 68

def missing_methods
  list = []
  methods = self.getMethods
  methods.each do |mname|
    parts = mname.split('.')
    parts.shift
    call = parts.pop
    obj = @flickr
    parts.each do |part|
      if obj.respond_to?(part)
        obj = obj.method(part).call
      else
        obj = nil
        list << mname
        break
      end
    end
    list << mname if (obj && !obj.respond_to?(call))
  end
  return list
end