Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added the username search resource

  • Loading branch information...
commit bb113c865035e89ddb969f0ea1ecf59132f83de0 1 parent d282fc6
@jsgoecke jsgoecke authored
View
2  VERSION
@@ -1 +1 @@
-0.0.18
+0.0.19
View
15 examples/users_search.rb
@@ -0,0 +1,15 @@
+require 'rubygems'
+require 'yaml'
+require 'lib/tropo-provisioning'
+require 'json'
+
+config = YAML.load(File.open('examples/config.yml'))
+
+# Create a new provisioning object with your Tropo credentials
+provisioning = TropoProvisioning.new(config['tropo']['username'], config['tropo']['password'], :base_uri => 'http://api.smsified.com/v1')
+
+# Create an account
+p provisioning.search_users 'username=jsg'
+
+p provisioning.username_exists? 'jsgoecke'
+p provisioning.username_exists? 'fooeyfooy'
View
10 lib/tropo-provisioning/tropo-provisioning.rb
@@ -126,6 +126,16 @@ def modify_user(user_id, params={})
def search_users(search_term)
request(:get, { :resource => 'users/?' + search_term })
end
+
+ ##
+ # Allows you to search if a username exists or not
+ #
+ # @param [required, String] a username to check
+ # @return [Array]
+ # a hash containing an array of hashes with the qualifying account details
+ def username_exists?(username)
+ request(:get, { :resource => 'usernames/' + username })
+ end
##
# Fetches the payment information for a user
View
12 spec/tropo-provisioning_spec.rb
@@ -596,6 +596,14 @@
:body => ActiveSupport::JSON.encode(@invitations[1]),
:content_type => "application/json",
:status => ["200", "OK"])
+
+ @username_check = { 'available' => false, 'href' => "http://api.smsified.com/v1/usernames/jsgoecke", 'valid' => true }
+ # List invitation for a user
+ FakeWeb.register_uri(:get,
+ "http://foo:bar@api.tropo.com/v1/usernames/12345",
+ :body => ActiveSupport::JSON.encode(@username_check),
+ :content_type => "application/json",
+ :status => ["200", "OK"])
end
before(:each) do
@@ -900,6 +908,10 @@
result.href.should == 'http://api-smsified-eng.voxeo.net/v1/users/12345'
@tropo_provisioning.user_data['password'].should == 'foobar'
end
+
+ it 'should see if a username is available' do
+ @tropo_provisioning.username_exists?('12345').should == @username_check
+ end
end
describe 'features' do
View
2  tropo-provisioning.gemspec
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{tropo-provisioning}
- s.version = "0.0.18"
+ s.version = "0.0.19"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jason Goecke"]
Please sign in to comment.
Something went wrong with that request. Please try again.