Class: Socialoud::Client

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(services = {}) ⇒ Client

Returns a new instance of Client.



36
37
38
# File 'lib/socialoud/socialoud.rb', line 36

def initialize(services = {})
  @services = services
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/socialoud/socialoud.rb', line 28

def method_missing(method, *args)
  if args.length > 0
    @services[method].send(args.shift, *args)
  else
    @services[method]
  end
end

Instance Attribute Details

#servicesObject

Returns the value of attribute services.



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

def services
  @services
end

Class Method Details

.configure(data) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/socialoud/socialoud.rb', line 7

def self.configure(data)
  aggr = Client.new
  hash = data.is_a?(Hash) ? data : YAML.load_file(data)

  services = {}
  hash['services'].each_pair do |service, config|
    service_const = Socialoud::Services.const_get("#{service[0..0].upcase}#{service[1..-1]}")
    services[service] = service_const.new(config, aggr)
  end
  services.each do |name, instance|
    aggr.services[name.to_sym] = instance
    instance.setup!
  end
  aggr
end

Instance Method Details

#add_service!(name, instance) ⇒ Object



23
24
25
26
# File 'lib/socialoud/socialoud.rb', line 23

def add_service!(name, instance)
  services[name] = instance
  instance.setup!
end