Class: TropoREST::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/tropo-rest.rb

Direct Known Subclasses

Troplets

Constant Summary collapse

SESSION_URI =
'/1.0/sessions'

Class Method Summary collapse

Class Method Details

.fire_event(event_name, session_id) ⇒ Object



52
53
54
55
56
57
# File 'lib/tropo-rest.rb', line 52

def fire_event(event_name, session_id)
  logger.info "Firing event #{event_name} into Tropo session #{session_id}"
  resp = request "#{SESSION_URI}/#{session_id}/signals", value: event_name
  logger.info "Tropo event trigger responded with: #{resp.inspect}"
  resp
end

.options_with_token(options, type = :voice) ⇒ Object



65
66
67
# File 'lib/tropo-rest.rb', line 65

def options_with_token(options, type = :voice)
  options.merge! token: type == :messaging ? messaging_token : voice_token
end

.originate(options = {}) ⇒ Object



45
46
47
48
49
50
# File 'lib/tropo-rest.rb', line 45

def originate(options = {})
  logger.info "Originating Tropo call with parameters #{options}"
  resp = request SESSION_URI, options, options[:channel]
  logger.info "Tropo origination responded with: #{resp.inspect}"
  resp
end

.request(target, body, type = nil) ⇒ Object



59
60
61
62
63
# File 'lib/tropo-rest.rb', line 59

def request(target, body, type = nil)
  options = options_with_token body, type
  logger.debug "Making request to #{target} with #{options.inspect}"
  post target, body: options.to_json
end