Class: Vidyard::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/vidyard/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(auth_token) ⇒ Client



11
12
13
# File 'lib/vidyard/client.rb', line 11

def initialize(auth_token)
  @options = { :auth_token => auth_token }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



15
16
17
18
19
20
21
# File 'lib/vidyard/client.rb', line 15

def method_missing(meth, *args, &block)
  if meth.to_s =~ /^get_(.+)$/
    get_resources($1, args)
  else
    super
  end
end

Instance Method Details

#get_resources(resource, args) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/vidyard/client.rb', line 23

def get_resources(resource, args)
  if Vidyard::Util.singular?(resource)
    resource = "#{resource.to_s.pluralize}/#{args.shift}"
  end
  query = @options.try(:merge, args[0] || {})
  payload = self.class.get("/#{resource}.json", :query => query)
  parse_resources(resource, payload)
end

#parse_resources(resource, payload) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/vidyard/client.rb', line 32

def parse_resources(resource, payload)
  if resource == 'players'
    payload.parsed_response.collect { |player| Vidyard::Player.new(player) }
  else
    payload.parsed_response
  end
rescue
  []
end