Permalink
Browse files

Merge branch 'master' of github.com:twilio/twilio-ruby

  • Loading branch information...
2 parents e13aefd + c30f477 commit ffb043ba0c7ac19869fe7548e36cae19ebf5a56e @dougblack dougblack committed Oct 16, 2013
View
8 examples/examples.rb
@@ -29,7 +29,9 @@
end
# get a particular call and list its recording urls
-@account.calls.get('CAXXXXXXX').recordings.list.each do {|r| puts r.wav}
+@account.calls.get('CAXXXXXXX').recordings.list.each do |r|
+ puts r.wav
+end
# make a new outgoing call. returns a call object just like calls.get
@call = @account.calls.create({:from => '+14159341234', :to => '+18004567890', :url => 'http://example.com/call-handler'})
@@ -85,7 +87,9 @@
@participants = @account.conferences.get('CFbbe46ff1274e283f7e3ac1df0072ab39').participants
# list participants
-@participants.list.each do {|p| puts p.sid}
+@participants.list.each do |p|
+ puts p.sid
+end
# update a conference participant
@participants.get('CA386025c9bf5d6052a1d1ea42b4d16662').update({:muted => 'true'})
View
1 lib/twilio-ruby.rb
@@ -21,6 +21,7 @@
require 'twilio-ruby/rest/calls'
require 'twilio-ruby/rest/sms'
require 'twilio-ruby/rest/sms/short_codes'
+require 'twilio-ruby/rest/sms/messages'
require 'twilio-ruby/rest/sip'
require 'twilio-ruby/rest/sip/domains'
require 'twilio-ruby/rest/sip/domains/ip_access_control_list_mappings'
View
3 lib/twilio-ruby/rest/instance_resource.rb
@@ -89,7 +89,8 @@ def resource(*resources)
resource = twilify r
relative_path = custom_resource_names.fetch(r, resource)
path = "#{@path}/#{relative_path}"
- resource_class = Twilio::REST.const_get resource
+ enclosing_module = @submodule == nil ? (Twilio::REST) : (Twilio::REST.const_get(@submodule))
+ resource_class = enclosing_module.const_get resource
instance_variable_set("@#{r}", resource_class.new(path, @client))
end
self.class.instance_eval {attr_reader *resources}
View
8 lib/twilio-ruby/rest/list_resource.rb
@@ -9,7 +9,13 @@ def initialize(path, client)
@path, @client = path, client
resource_name = self.class.name.split('::')[-1]
instance_name = custom_names.fetch(resource_name, resource_name.chop)
- @instance_class = Twilio::REST.const_get instance_name
+
+ # The next line grabs the enclosing module. Necessary for resources
+ # contained in their own submodule like /SMS/Messages
+ parent_module = self.class.to_s.split('::')[-2]
+ full_module_path = parent_module == "REST" ? (Twilio::REST) : (Twilio::REST.const_get parent_module)
+
+ @instance_class = full_module_path.const_get instance_name
@list_key, @instance_id_key = detwilify(resource_name), 'sid'
end
View
1 lib/twilio-ruby/rest/sms.rb
@@ -3,6 +3,7 @@ module REST
class Sms < InstanceResource
def initialize(path, client, params={})
super
+ @submodule = :SMS
resource :messages, :short_codes
end
end
View
15 lib/twilio-ruby/rest/sms/messages.rb
@@ -0,0 +1,15 @@
+module Twilio
+ module REST
+ module SMS
+ class Messages < ListResource
+ def initialize(path, client)
+ super
+ @list_key = 'sms_messages'
+ end
+ end
+
+ class Message < InstanceResource
+ end
+ end
+ end
+end
View
6 lib/twilio-ruby/rest/sms/short_codes.rb
@@ -1,6 +1,8 @@
module Twilio
module REST
- class ShortCodes < ListResource; end
- class ShortCode < InstanceResource; end
+ module SMS
+ class ShortCodes < ListResource; end
+ class ShortCode < InstanceResource; end
+ end
end
end
View
21 pull.txt
@@ -0,0 +1,21 @@
+This pull moves the /SMS endpoints into their own `SMS` module. This allows both of the `Message` classes to coexist, since one is in its own namespace, so I was able to bring back the class living at `sms.messages`. This means `@client.account.sms.messages` will once again make requests to the `/SMS/Messages` endpoint. This change re-enables Test Credentials for the `sms.messages` class.
+
+This required a change to both `instance_resource.rb` and `list_resource.rb` because both were relying on the assumption that all classes live in the Twilio::REST module.
+
+To use the new submodule functionality, just set the `@submodule` variable to the name of the new submodule on the class declaring the subresources. Here is how it was done for `/SMS/Messages`.
+
+```ruby
+module Twilio
+ module REST
+ class Sms < InstanceResource
+ def initialize(path, client, params={})
+ super
+ @submodule = :SMS
+ resource :messages, :short_codes
+ end
+ end
+ end
+end
+```
+
+@labcoder @carlosdp @alexcchan
View
5 spec/rest/message_spec.rb
@@ -9,9 +9,4 @@
@message.should respond_to(:media)
@message.media.instance_variable_get('@path').should == 'someUri/Media'
end
-
- it 'does not use the old endpoint' do
- client = Twilio::REST::Client.new('someId', 'sometoken')
- client.account.sms.messages.instance_variable_get('@path').include?('/SMS').should be_false
- end
end

0 comments on commit ffb043b

Please sign in to comment.