Class: GoogleSAAuth::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/google-sa-auth/client.rb

Class Method Summary collapse

Class Method Details

.run(args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/google-sa-auth/client.rb', line 4

def run(args)
  # Clean up our arguments.
  args = args.inject({}){|item,(k,v)| item[k.to_sym] = v; item}
  args = args.delete_if {|k,v| ![:uri, :data, :headers, :method].include?(k)}
  args[:data] ||= {}
  args[:headers] ||= {}

  # Parse the uri.
  protocol, host, path = parse_uri(args[:uri])

  # Set up a nice host info hash.
  host_info = {
    :host => host,
    :path => path,
    :protocol => protocol,
    :headers => args[:headers]
  }

  # Perform the request.
  if args[:method] == 'get'
    CurbFu.get(host_info, args[:data])
  elsif args[:method] == 'post'
    CurbFu.post(host_info, args[:data])
  elsif args[:method] == 'put'
    CurbFu.put(host_info, args[:data])
  elsif args[:method] == 'delete'
    CurbFu.delete(host_info, args[:data])
  else
    raise 'InvalidRequestType', "Unknown method: #{method}"
  end
end