tropo_rest 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.gitignore +6 -0
  2. data/.rspec +3 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +88 -0
  5. data/LICENSE +19 -0
  6. data/README.md +104 -0
  7. data/Rakefile +35 -0
  8. data/autotest/discover.rb +1 -0
  9. data/lib/faraday/request/serialize_json.rb +17 -0
  10. data/lib/faraday/response/raise_http_errors.rb +52 -0
  11. data/lib/faraday/response/resource.rb +26 -0
  12. data/lib/hashie/twash.rb +61 -0
  13. data/lib/tropo_rest/client/address.rb +76 -0
  14. data/lib/tropo_rest/client/application.rb +72 -0
  15. data/lib/tropo_rest/client/exchange.rb +18 -0
  16. data/lib/tropo_rest/client/session.rb +20 -0
  17. data/lib/tropo_rest/client/signal.rb +26 -0
  18. data/lib/tropo_rest/client.rb +27 -0
  19. data/lib/tropo_rest/configuration.rb +61 -0
  20. data/lib/tropo_rest/connection.rb +28 -0
  21. data/lib/tropo_rest/error.rb +33 -0
  22. data/lib/tropo_rest/request.rb +66 -0
  23. data/lib/tropo_rest/resource/address.rb +20 -0
  24. data/lib/tropo_rest/resource/application.rb +15 -0
  25. data/lib/tropo_rest/resource/exchange.rb +13 -0
  26. data/lib/tropo_rest/utils.rb +33 -0
  27. data/lib/tropo_rest/version.rb +3 -0
  28. data/lib/tropo_rest.rb +31 -0
  29. data/script/console +8 -0
  30. data/spec/spec_helper.rb +64 -0
  31. data/spec/tropo_rest/client/address_spec.rb +172 -0
  32. data/spec/tropo_rest/client/application_spec.rb +210 -0
  33. data/spec/tropo_rest/client/exchange_spec.rb +71 -0
  34. data/spec/tropo_rest/client/session_spec.rb +47 -0
  35. data/spec/tropo_rest/client/signal_spec.rb +34 -0
  36. data/spec/tropo_rest/client_spec.rb +246 -0
  37. data/spec/tropo_rest/resource/address_spec.rb +12 -0
  38. data/spec/tropo_rest/resource/application_spec.rb +12 -0
  39. data/spec/tropo_rest/resource/exchange_spec.rb +12 -0
  40. data/spec/tropo_rest_spec.rb +22 -0
  41. data/tropo_rest.gemspec +50 -0
  42. metadata +343 -0
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .yardoc
5
+ doc/*
6
+ *.rbc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --format=nested
3
+ --backtrace
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in tropo_rest.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,88 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tropo_rest (0.0.1)
5
+ faraday (~> 0.5.3)
6
+ faraday_middleware (~> 0.3.1)
7
+ hashie (~> 0.4.0)
8
+ multi_json (~> 0.0.5)
9
+ multi_xml (~> 0.2.0)
10
+
11
+ GEM
12
+ remote: http://rubygems.org/
13
+ specs:
14
+ addressable (2.2.2)
15
+ archive-tar-minitar (0.5.2)
16
+ autotest (4.3.2)
17
+ autotest-fsevent (0.2.4)
18
+ sys-uname
19
+ autotest-growl (0.2.9)
20
+ columnize (0.3.2)
21
+ crack (0.1.8)
22
+ diff-lcs (1.1.2)
23
+ faraday (0.5.3)
24
+ addressable (~> 2.2.2)
25
+ multipart-post (~> 1.0.1)
26
+ rack (>= 1.1.0, < 2)
27
+ faraday_middleware (0.3.1)
28
+ faraday (~> 0.5.3)
29
+ hashie (0.4.0)
30
+ json (1.4.6)
31
+ json (1.4.6-java)
32
+ linecache19 (0.5.11)
33
+ ruby_core_source (>= 0.1.4)
34
+ multi_json (0.0.5)
35
+ multi_xml (0.2.0)
36
+ multipart-post (1.0.1)
37
+ nokogiri (1.4.4)
38
+ nokogiri (1.4.4-java)
39
+ weakling (>= 0.0.3)
40
+ rack (1.2.1)
41
+ rake (0.8.7)
42
+ rspec (2.3.0)
43
+ rspec-core (~> 2.3.0)
44
+ rspec-expectations (~> 2.3.0)
45
+ rspec-mocks (~> 2.3.0)
46
+ rspec-core (2.3.1)
47
+ rspec-expectations (2.3.0)
48
+ diff-lcs (~> 1.1.2)
49
+ rspec-mocks (2.3.0)
50
+ ruby-debug-base19 (0.11.24)
51
+ columnize (>= 0.3.1)
52
+ linecache19 (>= 0.5.11)
53
+ ruby_core_source (>= 0.1.4)
54
+ ruby-debug19 (0.11.6)
55
+ columnize (>= 0.3.1)
56
+ linecache19 (>= 0.5.11)
57
+ ruby-debug-base19 (>= 0.11.19)
58
+ ruby_core_source (0.1.4)
59
+ archive-tar-minitar (>= 0.5.2)
60
+ sys-uname (0.8.5)
61
+ weakling (0.0.4-java)
62
+ webmock (1.6.1)
63
+ addressable (>= 2.2.2)
64
+ crack (>= 0.1.7)
65
+ yard (0.6.4)
66
+
67
+ PLATFORMS
68
+ java
69
+ ruby
70
+
71
+ DEPENDENCIES
72
+ autotest (~> 4.3.2)
73
+ autotest-fsevent (~> 0.2.4)
74
+ autotest-growl (~> 0.2.9)
75
+ bundler (>= 1.0.0)
76
+ faraday (~> 0.5.3)
77
+ faraday_middleware (~> 0.3.1)
78
+ hashie (~> 0.4.0)
79
+ json (~> 1.4)
80
+ multi_json (~> 0.0.5)
81
+ multi_xml (~> 0.2.0)
82
+ nokogiri (~> 1.4.4)
83
+ rake (~> 0.8.7)
84
+ rspec (~> 2.3.0)
85
+ ruby-debug19
86
+ tropo_rest!
87
+ webmock (~> 1.6.1)
88
+ yard (~> 0.6.4)
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 by Christopher Durtschi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,104 @@
1
+ TropoRest
2
+ =========
3
+
4
+ A simple Ruby wrapper for the Tropo REST API
5
+
6
+ Installation
7
+ ------------
8
+
9
+ $ gem install tropo_rest
10
+
11
+ You will also need to install your favorite JSON and XML libraries.
12
+ Acceptable choices are yajl-ruby, json, active_support, or json_pure for JSON,
13
+ and nokogiri, libxml, or rexml for XML.
14
+
15
+
16
+ Usage Examples
17
+ --------------
18
+
19
+ require 'tropo_rest'
20
+
21
+ TropoRest.configure do |config|
22
+ config.username = 'tropousername'
23
+ config.password = 'tropopassword'
24
+ end
25
+
26
+ # Gets all of your applications
27
+ puts TropoRest.applications
28
+
29
+ # Gets a specific application by ID
30
+ puts TropoRest.application(123456)
31
+
32
+ # You can also pass in the HREF of the application instead of the ID
33
+ puts TropoRest.application('https://api.tropo.com/v1/applications/123456')
34
+
35
+ # Create an application
36
+ puts TropoRest.create_application(
37
+ :name => "new app",
38
+ :voice_url => "http://website.com",
39
+ :messaging_url => "http://website2.com",
40
+ :platform => "scripting",
41
+ :partition => "staging"
42
+ ) # returns an object with the "href" of the new application
43
+
44
+ # Update an application
45
+ puts TropoRest.update_application(123456,
46
+ :name => "newer app",
47
+ :platform => "webapi",
48
+ :partition => "production"
49
+ ) # returns an object with the "href" of the new application
50
+
51
+ # Delete an application
52
+ puts TropoRest.delete_application(123456)
53
+
54
+ # Gets all addresses for an application
55
+ puts TropoRest.addresses(123456)
56
+
57
+ # Gets a specific address
58
+ puts TropoRest.address(12345, "skype", "+99000936209990123456")
59
+
60
+ # You can also pass in the HREF of the address
61
+ puts TropoRest.address("https://api.tropo.com/v1/applications/123456/addresses/skype/+99000936209990123456")
62
+
63
+ # Create an address
64
+ puts TropoRest.create_address(123456,
65
+ :type => "number",
66
+ :prefix => "1407"
67
+ ) # returns an object with the "href" of the new address
68
+
69
+ # Delete an address
70
+ puts TropoRest.delete_address(123456, "skype", "+99000936209990123456")
71
+
72
+ # Gets all of the exchanges
73
+ puts TropoRest.exchanges
74
+
75
+ # Creates a session for the given token
76
+ puts TropoRest.create_session("TOKEN")
77
+
78
+ # Sends a signal to a current session.
79
+ # First parameter is the session ID, second is the signal to send.
80
+ puts TropoRest.create_signal("9a5c43f30b414d51901c4cfde00f43e8", "exit")
81
+
82
+
83
+ Note on Patches/Pull Requests
84
+ -----------------------------
85
+
86
+ * Fork the project.
87
+ * Make your feature addition or bug fix.
88
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
89
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
90
+ * Send me a pull request. Bonus points for topic branches.
91
+
92
+
93
+ Credits
94
+ -------
95
+
96
+ Thanks to [Tropo](https://www.tropo.com/) for creating such an awesome service.
97
+
98
+ Thanks to the creators of the [twitter](https://github.com/jnunemaker/twitter/) gem, whose lovely code I shamelessly ripped off :)
99
+
100
+
101
+ Copyright
102
+ ---------
103
+
104
+ Copyright (c) 2011 Christopher Durtschi. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Default: run specs.'
7
+ task :default => :spec
8
+
9
+ desc "Run specs"
10
+ RSpec::Core::RakeTask.new do |t|
11
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
12
+ # Put spec opts in a file named .rspec in root
13
+ end
14
+
15
+ desc "Generate code coverage"
16
+ RSpec::Core::RakeTask.new(:coverage) do |t|
17
+ t.pattern = "./spec/**/*_spec.rb" # don't need this, it's default.
18
+ t.rcov = true
19
+ t.rcov_opts = ['--exclude', 'spec']
20
+ end
21
+
22
+ namespace :doc do
23
+ require 'yard'
24
+ YARD::Rake::YardocTask.new do |task|
25
+ task.files = ['HISTORY.mkd', 'LICENSE.mkd', 'lib/**/*.rb']
26
+ task.options = [
27
+ '--protected',
28
+ '--output-dir', 'doc/yard',
29
+ '--tag', 'format:Supported formats',
30
+ '--tag', 'authenticated:Requires Authentication',
31
+ '--tag', 'rate_limited:Rate Limited',
32
+ '--markup', 'markdown',
33
+ ]
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ Autotest.add_discovery { "rspec2" }
@@ -0,0 +1,17 @@
1
+ module Faraday
2
+ class Request::SerializeJson < Faraday::Middleware
3
+ begin
4
+ require 'multi_json'
5
+ rescue LoadError, NameError => error
6
+ self.load_error = error
7
+ end
8
+
9
+ def call(env)
10
+ env[:request_headers]['Content-Type'] = 'application/json'
11
+ if env[:body] && !env[:body].respond_to?(:to_str)
12
+ env[:body] = ::MultiJson.encode(env[:body])
13
+ end
14
+ @app.call env
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,52 @@
1
+ module Faraday
2
+ class Response::RaiseHttpErrors < Response::Middleware
3
+ def self.register_on_complete(env)
4
+ env[:response].on_complete do |response|
5
+ case response[:status].to_i
6
+ when 400
7
+ raise TropoRest::BadRequest, error_message(response)
8
+ when 401
9
+ raise TropoRest::NotAuthorized, error_message(response)
10
+ when 403
11
+ raise TropoRest::AccessDenied, error_message(response)
12
+ when 404
13
+ raise TropoRest::NotFound, error_message(response)
14
+ when 405
15
+ raise TropoRest::MethodNotAllowed, error_message(response)
16
+ when 415
17
+ raise TropoRest::UnsupportedMediaType, error_message(response)
18
+ when 500
19
+ raise TropoRest::InternalServerError, error_message(response)
20
+ when 503
21
+ raise TropoRest::ServiceUnavailable, error_message(response)
22
+ end
23
+ end
24
+ end
25
+
26
+ def initialize(app)
27
+ super
28
+ @parser = nil
29
+ end
30
+
31
+ private
32
+
33
+ def self.error_message(response)
34
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
35
+ end
36
+
37
+ def self.error_body(body)
38
+ if body.nil?
39
+ nil
40
+ elsif body['error']
41
+ ": #{body['error']}"
42
+ elsif body['errors']
43
+ first = body['errors'].to_a.first
44
+ if first.kind_of? Hash
45
+ ": #{first['message'].chomp}"
46
+ else
47
+ ": #{first.chomp}"
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,26 @@
1
+ module Faraday
2
+ class Response::Resource < Response::Middleware
3
+ class << self
4
+ attr_accessor :resource
5
+ end
6
+
7
+ def self.register_on_complete(env)
8
+ env[:response].on_complete do |response|
9
+ if resource
10
+ response_body = response[:body]
11
+ if response_body.is_a?(Hash)
12
+ response[:body] = resource.new(response_body)
13
+ elsif response_body.is_a?(Array)
14
+ response[:body] = response_body.map{|item| item.is_a?(Hash) ? resource.new(item) : item}
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ def initialize(app, resource=nil)
21
+ super app
22
+ self.class.resource = resource
23
+ @parser = nil
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,61 @@
1
+ require 'hashie/dash'
2
+
3
+ module Hashie
4
+ # A Twash is a two-way Trash. You can get back to the original keys using #to_hash
5
+ class Twash < Hashie::Dash
6
+
7
+ # Defines a property on the Twash. Options are as follows:
8
+ #
9
+ # * <tt>:default</tt> - Specify a default value for this property, to be
10
+ # returned before a value is set on the property in a new Dash.
11
+ # * <tt>:from</tt> - Specify the original key name that will be write only.
12
+ def self.property(property_name, options = {})
13
+ super
14
+
15
+ if options[:from]
16
+ translations[options[:from].to_sym] = property_name.to_sym
17
+ class_eval <<-RUBY
18
+ def #{options[:from]}=(val)
19
+ self[:#{property_name}] = val
20
+ end
21
+ RUBY
22
+ end
23
+ end
24
+
25
+ # Set a value on the Twash in a Hash-like way. Only works
26
+ # on pre-existing properties.
27
+ def []=(property, value)
28
+ if self.class.translations.keys.include? property.to_sym
29
+ send("#{property}=", value)
30
+ elsif property_exists? property
31
+ super
32
+ end
33
+ end
34
+
35
+ def to_hash
36
+ out = super
37
+ self.class.translations.each do |from, to|
38
+ to_s = to.to_s
39
+ if out.keys.include?(to_s)
40
+ out[from.to_s] = out.delete(to_s)
41
+ end
42
+ end
43
+ out
44
+ end
45
+
46
+ private
47
+
48
+ def self.translations
49
+ @translations ||= {}
50
+ end
51
+
52
+ # Raises an NoMethodError if the property doesn't exist
53
+ #
54
+ def property_exists?(property)
55
+ unless self.class.property?(property.to_sym)
56
+ raise NoMethodError, "The property '#{property}' is not defined for this Trash."
57
+ end
58
+ true
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,76 @@
1
+ module TropoRest
2
+ class Client
3
+ module Address
4
+
5
+ SINGULAR_PATH = "applications/%d/addresses/%s/%s".freeze
6
+ PLURAL_PATH = "applications/%d/addresses".freeze
7
+ RESOURCE = TropoRest::Resource::Address
8
+
9
+ # Returns the addresses for the specified application
10
+ #
11
+ # @param application_id [String, Integer] The ID of the application.
12
+ # @return [Array] The addresses.
13
+ # @raise [TropoRest::NotFound] Error raised when ID does not identify an active application.
14
+ # @see https://www.tropo.com/docs/rest/prov_view_app_addresses.htm
15
+ def addresses(application_id)
16
+ path = get_path(PLURAL_PATH, application_id)
17
+ get(path, RESOURCE)
18
+ end
19
+
20
+ # Returns the specified address
21
+ #
22
+ # @overload address(application_id, type, identifier)
23
+ # @param application_id [String, Integer] The ID of the application.
24
+ # @param type [String] The type of address (aim, gtalk, jabber, msn, skype, number, token, yahoo)
25
+ # @param identifier [String] The address, number, or username
26
+ # @overload address(href)
27
+ # @param href [String] The HREF of the address
28
+ # @return [TropoRest::Resource::Address] The address.
29
+ # @raise [TropoRest::NotFound] Error raised when address not found.
30
+ def address(*args)
31
+ path = get_path(SINGULAR_PATH, *args)
32
+ get(path, RESOURCE)
33
+ end
34
+
35
+ # Creates a new address for the specified application
36
+ #
37
+ # @param application_id_or_href [String, Integer] The ID or HREF of the application.
38
+ # @param params [Hash] The attributes of the address to be created.
39
+ # @option params [String] :type The type of address to create (aim, gtalk, jabber, msn, number, token, yahoo). Required.
40
+ # @option params [String] :prefix The country and area code for a number
41
+ # @option params [String] :number A complete phone number already assigned to an existing application
42
+ # @option params [String] :channel Either "voice" or "messaging", used when creating a token
43
+ # @option params [String] :username An IM username. Required when adding an IM account
44
+ # @option params [String] :password An IM password. Required when adding an IM account
45
+ # @return [Hashie::Mash] An object containing the "href" of the new application
46
+ # @raise [TropoRest::BadRequest] Error raised when invalid parameters are supplied.
47
+ # @see https://www.tropo.com/docs/rest/prov_add_number.htm
48
+ # @see https://www.tropo.com/docs/rest/prov_add_toll_free.htm
49
+ # @see https://www.tropo.com/docs/rest/prov_add_international.htm
50
+ # @see https://www.tropo.com/docs/rest/prov_add_specific_num.htm
51
+ # @see https://www.tropo.com/docs/rest/prov_add_im.htm
52
+ # @see https://www.tropo.com/docs/rest/prov_add_token.htm
53
+ def create_address(application_id_or_href, params={})
54
+ path = get_path(PLURAL_PATH, application_id_or_href)
55
+ post(path, RESOURCE.new(params))
56
+ end
57
+
58
+ # Removes an address from an application
59
+ #
60
+ # @overload delete_address(application_id, type, identifier)
61
+ # @param application_id [String, Integer] The ID of the application.
62
+ # @param type [String] The type of address (aim, gtalk, jabber, msn, skype, number, token, yahoo)
63
+ # @param identifier [String] The address, number, or username
64
+ # @overload delete_address(href)
65
+ # @param href [String] The HREF of the address to be deleted.
66
+ # @return [Hashie::Mash] An object with a "message" attribute indicating success.
67
+ # @raise [TropoRest::NotFound] Error raised when address not found.
68
+ # @see https://www.tropo.com/docs/rest/prov_delete_address.htm
69
+ def delete_address(*args)
70
+ path = get_path(SINGULAR_PATH, *args)
71
+ delete(path)
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,72 @@
1
+ module TropoRest
2
+ class Client
3
+ module Application
4
+
5
+ SINGULAR_PATH = "applications/%d".freeze
6
+ PLURAL_PATH = "applications".freeze
7
+ RESOURCE = TropoRest::Resource::Application
8
+
9
+ # Returns the authenticated user's applications
10
+ #
11
+ # @return [Array] The applications.
12
+ # @see https://www.tropo.com/docs/rest/prov_view_apps.htm
13
+ def applications
14
+ get(PLURAL_PATH, RESOURCE)
15
+ end
16
+
17
+ # Returns the application specified by an ID
18
+ #
19
+ # @param id_or_href [String, Integer] The ID or HREF of the application.
20
+ # @return [TropoRest::Resource::Application] The application.
21
+ # @raise [TropoRest::NotFound] Error raised when ID does not identify an active application.
22
+ def application(id_or_href)
23
+ path = get_path(SINGULAR_PATH, id_or_href)
24
+ get(path, RESOURCE)
25
+ end
26
+
27
+ # Creates a new application
28
+ #
29
+ # @param params [Hash] The attributes of the application to be created.
30
+ # @option params [String] :name The name of the application. Required.
31
+ # @option params [String] :platform Either "scripting" or "webapi". Required.
32
+ # @option params [String] :partition Either "staging" or "production". Defaults to "staging" if not specified.
33
+ # @option params [String] :voice_url The voice endpoint of the application. Optional.
34
+ # @option params [String] :messaging_url The messaging endpoint of the application. Optional.
35
+ # @return [Hashie::Mash] An object containing the "href" of the new application
36
+ # @raise [TropoRest::BadRequest] Error raised when invalid parameters are supplied.
37
+ # @see https://www.tropo.com/docs/rest/prov_new_app.htm
38
+ def create_application(params={})
39
+ post(PLURAL_PATH, RESOURCE.new(params))
40
+ end
41
+
42
+ # Permanently destroys the application specified by an ID
43
+ #
44
+ # @param id_or_href [String, Integer] The ID or HREF of the application to be deleted.
45
+ # @return [Hashie::Mash] An object with a "message" attribute indicating success.
46
+ # @raise [TropoRest::NotFound] Error raised when ID does not identify an active application.
47
+ def delete_application(id_or_href)
48
+ path = get_path(SINGULAR_PATH, id_or_href)
49
+ delete(path)
50
+ end
51
+
52
+ # Updates an application
53
+ #
54
+ # @param id_or_href [String, Integer] The ID or HREF of the application to be updated.
55
+ # @param params [Hash] The attributes to be updated. of the application.
56
+ # @option params [String] :name The name of the application. Required.
57
+ # @option params [String] :platform Either "scripting" or "webapi". Required.
58
+ # @option params [String] :partition Either "staging" or "production". Defaults to "staging" if not specified.
59
+ # @option params [String] :voice_url The voice endpoint of the application. Optional.
60
+ # @option params [String] :messaging_url The messaging endpoint of the application. Optional.
61
+ # @return [Hashie::Mash] An object containing the "href" of the new application
62
+ # @raise [TropoRest::NotFound] Error raised when ID does not identify an active application.
63
+ # @see https://www.tropo.com/docs/rest/prov_update_name.htm
64
+ # @see https://www.tropo.com/docs/rest/prov_add_urls.htm
65
+ def update_application(id_or_href, params={})
66
+ path = get_path(SINGULAR_PATH, id_or_href)
67
+ put(path, RESOURCE.new(params))
68
+ end
69
+
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,18 @@
1
+ module TropoRest
2
+ class Client
3
+ module Exchange
4
+
5
+ PLURAL_PATH = "exchanges".freeze
6
+ RESOURCE = TropoRest::Resource::Exchange
7
+
8
+ # Returns the exchanges available for the authenticated user
9
+ #
10
+ # @return [Array] The exchanges.
11
+ # @see https://www.tropo.com/docs/rest/prov_view_exchanges.htm
12
+ def exchanges
13
+ get(PLURAL_PATH, RESOURCE)
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ module TropoRest
2
+ class Client
3
+ module Session
4
+
5
+ PLURAL_PATH = "sessions".freeze
6
+
7
+ # Creates a session for the given token
8
+ #
9
+ # @param token [String] The token of the application.
10
+ # @param params [Hash] The parameters to pass to the session.
11
+ # @return [Hashie::Mash] The session object.
12
+ # @see https://www.tropo.com/docs/rest/starting_session.htm
13
+ def create_session(token, params={})
14
+ params.merge! 'action' => 'create', 'token' => token
15
+ get(PLURAL_PATH, params)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,26 @@
1
+ module TropoRest
2
+ class Client
3
+ module Signal
4
+
5
+ PLURAL_PATH = "sessions/%s/signals".freeze
6
+
7
+ # Sends a signal for the given session ID
8
+ #
9
+ # @param session_id [String] The 16-byte GUID session ID.
10
+ # @param signal [String] The signal to send to the session.
11
+ # @return [Hashie::Mash] The signal object. Will have a field "status" with one of these values: "QUEUED", "NOTFOUND", "FAILED"
12
+ # @see https://www.tropo.com/docs/rest/interrupting_code_one_signal.htm
13
+ # @see https://www.tropo.com/docs/rest/interrupting_code_multiple.htm
14
+ # @see https://www.tropo.com/docs/rest/unnamed_signals.htm
15
+ # @see https://www.tropo.com/docs/rest/redirecting_app_based_on_signal.htm
16
+ # @see https://www.tropo.com/docs/rest/event_queuing.htm
17
+ # @see https://www.tropo.com/docs/rest/starting_session.htm
18
+ # @see https://www.tropo.com/docs/rest/parameters.htm
19
+ def create_signal(session_id, signal)
20
+ path = get_path(PLURAL_PATH, session_id)
21
+ post(path, {"signal" => signal})
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ module TropoRest
2
+ class Client
3
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
4
+
5
+ include Connection
6
+ include Request
7
+
8
+ require 'tropo_rest/client/application'
9
+ require 'tropo_rest/client/exchange'
10
+ require 'tropo_rest/client/address'
11
+ require 'tropo_rest/client/session'
12
+ require 'tropo_rest/client/signal'
13
+
14
+ include TropoRest::Client::Application
15
+ include TropoRest::Client::Exchange
16
+ include TropoRest::Client::Address
17
+ include TropoRest::Client::Session
18
+ include TropoRest::Client::Signal
19
+
20
+ def initialize(options={})
21
+ options = TropoRest.options.merge(options)
22
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
23
+ send("#{key}=", options[key])
24
+ end
25
+ end
26
+ end
27
+ end