Class: Verboice
- Inherits:
-
Object
- Object
- Verboice
- Defined in:
- lib/verboice.rb,
lib/verboice/exception.rb
Overview
Provides access to the Verboice Public API.
Defined Under Namespace
Classes: Exception
Instance Method Summary collapse
- #call(address, options = {}) ⇒ Object
- #call_redirect(id) ⇒ Object
- #call_state(id) ⇒ Object
- #channel(name) ⇒ Object
- #create_channel(channel) ⇒ Object
- #create_schedule(project_id, schedule) ⇒ Object
-
#delete_channel(name) ⇒ Object
Deletes a channel given its name.
- #delete_schedule(project_id, name) ⇒ Object
-
#initialize(url, account, password, default_channel = nil) ⇒ Verboice
constructor
Creates an account-authenticated Verboice api access.
- #list_channels ⇒ Object
- #schedule(project_id, name) ⇒ Object
- #schedules(project_id) ⇒ Object
- #update_channel(channel, name = ) ⇒ Object
- #update_schedule(project_id, name, schedule) ⇒ Object
Constructor Details
#initialize(url, account, password, default_channel = nil) ⇒ Verboice
Creates an account-authenticated Verboice api access.
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/verboice.rb', line 21 def initialize(url, account, password, default_channel = nil) @url = url @account = account @password = password @default_channel = default_channel @options = { :user => account, :password => password, :headers => {:content_type => 'application/json'}, } end |
Instance Method Details
#call(address, options = {}) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/verboice.rb', line 33 def call address, = {} = .dup args = {} if channel = .delete(:channel) args[:channel] = channel else args[:channel] = @default_channel end args[:address] = address if not_before = .delete(:not_before) args[:not_before] = not_before.iso8601 end flow = .delete(:flow) callback_url = .delete(:callback_url) args.merge!() if flow post "/api/call?#{self.class.to_query args}", flow do |response, error| raise Verboice::Exception.new error. if error JSON.parse response.body end else args[:callback_url] = callback_url if callback_url get_json "/api/call?#{self.class.to_query args}" end end |
#call_redirect(id) ⇒ Object
69 70 71 |
# File 'lib/verboice.rb', line 69 def call_redirect id get_json "/api/calls/#{id}/redirect" end |
#call_state(id) ⇒ Object
65 66 67 |
# File 'lib/verboice.rb', line 65 def call_state id get_json "/api/calls/#{id}/state" end |
#channel(name) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/verboice.rb', line 73 def channel(name) get("/api/channels/#{name}.json") do |response, error| handle_channel_error error if error channel = JSON.parse response.body with_indifferent_access channel end end |
#create_channel(channel) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/verboice.rb', line 82 def create_channel(channel) post "/api/channels.json", channel.to_json do |response, error| handle_channel_error error if error channel = JSON.parse response.body with_indifferent_access channel end end |
#create_schedule(project_id, schedule) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/verboice.rb', line 123 def create_schedule(project_id, schedule) post "/api/projects/#{project_id}/schedules", schedule.to_json do |response, error| raise Verboice::Exception.new error. if error response end end |
#delete_channel(name) ⇒ Object
Deletes a channel given its name.
Raises Verboice::Exception if something goes wrong.
103 104 105 106 107 108 109 |
# File 'lib/verboice.rb', line 103 def delete_channel(name) delete "/api/channels/#{name}" do |response, error| raise Verboice::Exception.new error. if error response end end |
#delete_schedule(project_id, name) ⇒ Object
137 138 139 140 141 142 |
# File 'lib/verboice.rb', line 137 def delete_schedule(project_id, name) delete "/api/projects/#{project_id}/schedules/#{name}" do |response, error| raise Verboice::Exception.new error. if error response end end |
#list_channels ⇒ Object
111 112 113 |
# File 'lib/verboice.rb', line 111 def list_channels() get_json "/api/channels.json" end |
#schedule(project_id, name) ⇒ Object
119 120 121 |
# File 'lib/verboice.rb', line 119 def schedule(project_id, name) get_json "/api/projects/#{project_id}/schedules/#{name}.json" end |
#schedules(project_id) ⇒ Object
115 116 117 |
# File 'lib/verboice.rb', line 115 def schedules(project_id) get_json "/api/projects/#{project_id}/schedules.json" end |
#update_channel(channel, name = ) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/verboice.rb', line 91 def update_channel(channel, name = channel['name']) put "/api/channels/#{name}.json", channel.to_json do |response, error| handle_channel_error error if error channel = JSON.parse response.body with_indifferent_access channel end end |
#update_schedule(project_id, name, schedule) ⇒ Object
130 131 132 133 134 135 |
# File 'lib/verboice.rb', line 130 def update_schedule(project_id, name, schedule) put "/api/projects/#{project_id}/schedules/#{name}", schedule.to_json do |response, error| raise Verboice::Exception.new error. if error response end end |