Class: Pigeon::Verboice
- Inherits:
-
Object
show all
- Includes:
- Utils
- Defined in:
- lib/pigeon/verboice.rb
Class Method Summary
collapse
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
Methods included from Utils
#delete, #get, #get_json, #handle_channel_error, #post, #put, #to_query, #with_indifferent_access
Constructor Details
#initialize(url, account, password, default_channel = nil) ⇒ Verboice
Creates an account-authenticated Verboice api access.
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/pigeon/verboice.rb', line 29
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
|
Class Method Details
.from_config ⇒ Object
22
23
24
25
26
|
# File 'lib/pigeon/verboice.rb', line 22
def self.from_config
config = Pigeon.config
self.new config.verboice_host, config.verboice_account, config.verboice_password
end
|
Instance Method Details
#call(address, options = {}) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/pigeon/verboice.rb', line 41
def call address, options = {}
options = options.dup
args = {}
if channel = options.delete(:channel)
args[:channel] = channel
else
args[:channel] = @default_channel
end
args[:address] = address
if not_before = options.delete(:not_before)
args[:not_before] = not_before.iso8601
end
flow = options.delete(:flow)
callback_url = options.delete(:callback_url)
args.merge!(options)
if flow
post "/api/call?#{to_query args}", flow do |response, error|
raise ::Pigeon::VerboiceException.new error.message if error
JSON.parse response.body
end
else
args[:callback_url] = callback_url if callback_url
get_json "/api/call?#{to_query args}"
end
end
|
#call_redirect(id) ⇒ Object
77
78
79
|
# File 'lib/pigeon/verboice.rb', line 77
def call_redirect id
get_json "/api/calls/#{id}/redirect"
end
|
#call_state(id) ⇒ Object
73
74
75
|
# File 'lib/pigeon/verboice.rb', line 73
def call_state id
get_json "/api/calls/#{id}/state"
end
|
#channel(name) ⇒ Object
81
82
83
84
85
86
87
88
|
# File 'lib/pigeon/verboice.rb', line 81
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
90
91
92
93
94
95
96
97
|
# File 'lib/pigeon/verboice.rb', line 90
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
131
132
133
134
135
136
|
# File 'lib/pigeon/verboice.rb', line 131
def create_schedule(project_id, schedule)
post "/api/projects/#{project_id}/schedules", schedule.to_json do |response, error|
raise ::Pigeon::VerboiceException.new error.message if error
response
end
end
|
#delete_channel(name) ⇒ Object
Deletes a channel given its name.
Raises Verboice::Exception if something goes wrong.
111
112
113
114
115
116
117
|
# File 'lib/pigeon/verboice.rb', line 111
def delete_channel(name)
delete "/api/channels/#{name}" do |response, error|
raise ::Pigeon::VerboiceException.new error.message if error
response
end
end
|
#delete_schedule(project_id, name) ⇒ Object
145
146
147
148
149
150
|
# File 'lib/pigeon/verboice.rb', line 145
def delete_schedule(project_id, name)
delete "/api/projects/#{project_id}/schedules/#{name}" do |response, error|
raise ::Pigeon::VerboiceException.new error.message if error
response
end
end
|
#list_channels ⇒ Object
119
120
121
|
# File 'lib/pigeon/verboice.rb', line 119
def list_channels()
get_json "/api/channels.json"
end
|
#schedule(project_id, name) ⇒ Object
127
128
129
|
# File 'lib/pigeon/verboice.rb', line 127
def schedule(project_id, name)
get_json "/api/projects/#{project_id}/schedules/#{name}.json"
end
|
#schedules(project_id) ⇒ Object
123
124
125
|
# File 'lib/pigeon/verboice.rb', line 123
def schedules(project_id)
get_json "/api/projects/#{project_id}/schedules.json"
end
|
#update_channel(channel, name = ) ⇒ Object
99
100
101
102
103
104
105
106
|
# File 'lib/pigeon/verboice.rb', line 99
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
138
139
140
141
142
143
|
# File 'lib/pigeon/verboice.rb', line 138
def update_schedule(project_id, name, schedule)
put "/api/projects/#{project_id}/schedules/#{name}", schedule.to_json do |response, error|
raise ::Pigeon::VerboiceException.new error.message if error
response
end
end
|