Class: Foaas::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/foaas-client/client.rb

Constant Summary collapse

URL =
Addressable::Template.new("http://foaas.com/{method}{/name}/{from}{/other}")
METHODS_ONE_PARAM =
[:anyway, :awesome, :because, :bucket, :bye, :cool, :diabetes, :everyone, :everything, :family, :fascinating, :flying, :give, :horse, :life, :looking, :me, :mornin, :pink, :retard, :sake, :thanks, :this, :tucker, :thumbs,:what, :zayn, :zero]
METHODS_TWO_PARAMS =
[:back, :bday, :bm, :bus, :caniuse, :chainsaw, :dalton, :donut, :greed, :gfy, :keep, :keepcalm, :king, :linus, :look, :madison, :no, :nugget, :off, :outside, :pulp, :shakespeare, :shutup, :single,:think, :you, :xmas, :yoda]
METHODS_THREE_PARAMS =
[:ballmer, :dosomething, :field]

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/foaas-client/client.rb', line 14

def method_missing(sym, *args, &block)
    kwargs = {}
    kwargs = args[-1] if args[-1].class == Hash
    if METHODS_TWO_PARAMS.include? sym
      make_request(URL.expand(method: sym, name: args[0], from: args[1]), type=kwargs[:type], i18n=kwargs[:i18n], shoutcloud=kwargs[:shoutcloud])
    elsif  METHODS_ONE_PARAM.include? sym
      make_request(URL.expand(method: sym, from: args[0]), type=kwargs[:type], i18n=kwargs[:i18n], shoutcloud=kwargs[:shoutcloud])
    elsif METHODS_THREE_PARAMS.include? sym
      make_request(URL.expand(method: sym, name: args[0], from: args[1], other: args[2]), type=kwargs[:type], i18n=kwargs[:i18n], shoutcloud=kwargs[:shoutcloud])
    elsif sym == :thing
      make_request(URL.expand(method: args[0], from: args[1]), type=kwargs[:type], i18n=kwargs[:i18n], shoutcloud=kwargs[:shoutcloud])
    else
      super(sym, *args, &block)
    end
end

Instance Method Details

#operationsObject



30
31
32
# File 'lib/foaas-client/client.rb', line 30

def operations
  make_request(URL.expand(method: :operations), nil)
end

#respond_to?(sym, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/foaas-client/client.rb', line 34

def respond_to?(sym, include_private = false)
  METHODS_ONE_PARAM.include?(sym) or METHODS_TWO_PARAMS.include?(sym) or sym == :thing or super(sym, include_private)
end

#version(opts = {}) ⇒ Object



38
39
40
# File 'lib/foaas-client/client.rb', line 38

def version(opts={})
  make_request(URL.expand(method: :version), opts[:type])
end