Class: Flickr

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

Defined Under Namespace

Classes: Tokens

Instance Method Summary collapse

Constructor Details

#initialize(api_key, shared_secret, auth_token = nil) ⇒ Flickr

Returns a new instance of Flickr.



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

def initialize(api_key, shared_secret, auth_token=nil)
	@tokens = Flickr::Tokens.new(api_key, shared_secret, auth_token)
	@api_request = FlickrApiRequest.new(@tokens)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/flickr.rb', line 29

def method_missing(method, *arguments, &block)
  if method.to_s =~ /^flickr_[\w]+/
    self.class.send :define_method, method do |*arguments|
      if (arguments = arguments.flatten) != []
        args = arguments[0][:args]
        auth = arguments[0][:auth]
        get = arguments[0][:get]
      end

      @api_request.call("#{method.to_s.gsub('_', '.')}", args || {}, (auth == nil ? false : auth), (get == nil ? true : get))
    end
    self.send(method, arguments)
  else
    super
  end
end

Instance Method Details

#apiObject



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

def api
	@api ||= Api.new(@api_request, self)
end

#auth_token(auth_token) ⇒ Object



9
10
11
12
# File 'lib/flickr.rb', line 9

def auth_token(auth_token)
	@tokens.auth_token = auth_token
	self
end