Class: TropoProvisioning

Inherits:
Object
  • Object
show all
Defined in:
lib/tropo-provisioning/tropo_provisioning.rb,
lib/tropo-provisioning/version.rb

Overview

This class is a wrapper that allows an easy way to access Tropo HTTP Provisioning API It defines a set of methods to create, update, retrieve or delete different kind of resources.

Constant Summary collapse

VERSION =

Current gem version

"0.0.29"
DEFAULT_OPTIONS =

Defaults for the creation of applications

{ :partition => 'staging', :platform  => 'scripting' }
VALID_PLATFORMS =

Array of supported platforms in Tropo

%w(scripting webapi)
VALID_PARTITIONS =

Array of supported partitions in Tropo

%w(staging production)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username, password, params = {}) ⇒ TropoProvisioning

Creates a new TropoProvisioning object

Parameters

  • required, String

    username for your Tropo user

  • required, String

    password for your Tropo user

  • optional, Hash

    params

    • optional, String

      :base_uri to use for accessing the provisioning API if you would like a custom one

    • optional, Boolean

      :verify_certificate whether to require a valid certificate if using SSL, defaults to true

Return

TropoProvisioning object



35
36
37
38
39
40
41
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 35

def initialize(username, password, params={})
  @base_uri            =  (params[:base_uri] || "https://api.tropo.com/v1/").sub(/(\/)+$/,'/')
  proxy                =  params[:proxy]    || nil
  @verify_certificate  =  params.has_key?(:verify_certificate) ? params[:verify_certificate] : true
  @tropo_client        =  TropoClient.new(username, password, @base_uri, { 'Content-Type' => 'application/json' }, proxy, @verify_certificate)
  user(username)
end

Instance Attribute Details

#base_uriObject (readonly)

Returns the value of attribute base_uri.



20
21
22
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 20

def base_uri
  @base_uri
end

#user_dataObject (readonly)

Returns the value of attribute user_data.



20
21
22
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 20

def user_data
  @user_data
end

#verify_certificateObject (readonly)

Returns the value of attribute verify_certificate.



20
21
22
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 20

def verify_certificate
  @verify_certificate
end

Instance Method Details

#account(username, password) ⇒ Object Also known as: authenticate_account

Retrieves specific user information

Parameters



46
47
48
49
50
51
52
53
54
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 46

def (username, password)
  case current_method_name
  when 'account'
    action = 'get'
  when 'authenticate_account'
    action = 'authenticate'
  end
  temp_request("/#{action}.jsp?username=#{username}&password=#{password}")
end

#add_payment_info(user_id, params = {}) ⇒ Object Also known as: modify_payment_info

Add/modify payment info for a user

Parameters

  • user_id - required, String

    to add the payment details for

  • require, Hash

    params the params to add the payment info

    • :account_number
      required, String

      the credit card number

    • required, String

      :payment_type the type, such as visa, mastercard, etc

    • required, String

      :address

    • optional, String

      :address2

    • required, String

      :city

    • required, String

      :state

    • required, String

      :postal_code

    • required, String

      :country

    • optional, String

      :email

    • required, String

      :name_on_account name on the credit card

    • required, String

      :expiration_date expiration date of the credit card

    • required, String

      :security_code back panel/front panel (Amex) code on the card

    • optional, String

      :phone_number

Return

  • Hash

    the href of the payment method added

  • ArgumentError

    if a required param is not present



327
328
329
330
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 327

def add_payment_info(user_id, params={})
  #validate_params(params, %w(account_number payment_type address city state postal_code country name_on_account expiration_date security_code recharge_amount email phone_number))
  @tropo_client.put("users/#{user_id}/payment/method", params)
end

#add_whitelist(params = {}) ⇒ Object

Add to a whitelist for a particular user

Parameters

  • Hash

    params contains a hash of the user_id and value to add

    • optional, String

      :user_id if present the user_id to add to, if not it will add to the user logged in as

    • required, String

      :value the value to add to the whitelist

Return

  • Hash

    the href



769
770
771
772
773
774
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 769

def add_whitelist(params={})
  resource = params.has_key?(:user_id) ?
  "users/#{params[:user_id]}/partitions/production/platforms/sms/whitelist" :
  "users/partitions/production/platforms/sms/whitelist"
  @tropo_client.post(resource, {:value => params[:value]})
end

#address(application_id, address_id) ⇒ Object

Get a specific address for an application

Parameters

  • required, String

    application_id to obtain the address for

  • required, String

    address_id of the address to obtain the details for

Return

  • Hash

    the details of the address

    • String

      :href the REST address for the application

    • String

      :name the name of the application

    • String

      :voiceUrl the URL that powers voices calls for your application

    • String

      :messagingUrl The URL that powers the SMS/messages sessions for your application

    • String

      :partition this defines whether the application is in staging/development or production

    • String

      :type this defines the type of address. The possibles types are number (phone numbers), pin (reserved), token, aim, jabber, msn, yahoo, gtalk & skype

    • String

      :prefix this defines the country code and area code for phone numbers

    • String

      :number the phone number assigned to the application

    • String

      :city the city associated with the assigned phone number

    • String

      :state the state associated with the assigned phone number

    • String

      :channel idenifites the type of channel, maybe ‘voice’ or ‘messaging’

    • String

      :username the messaging/IM account’s username

    • String

      :password the messaging/IM account’s password

    • String

      :token alphanumeric string that identifies your Tropo application, used with the Session API

Raises:

  • (RuntimeError)


558
559
560
561
562
563
564
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 558

def address(application_id, address_id)
  addresses(application_id).each { |address| return address if address['number']   == address_id ||
    address['username'] == address_id ||
    address['pin']      == address_id ||
  address['token']    == address_id }
  raise RuntimeError, 'Address not found with that application.'
end

#addresses(application_id) ⇒ Object

Get all of the configured addresses for an application

Parameters

  • required, String

    application_id to fetch the addresses for

Return

  • Hash

    all of the addresses configured for the application



574
575
576
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 574

def addresses(application_id)
  @tropo_client.get("applications/#{application_id.to_s}/addresses")
end

#application(application_id) ⇒ Object

Get a specific application

Parameters

  • required, String

    application_id of the application to get

Return

  • Hash

    params the key/values that make up the application

    • String

      :href the REST address for the application

    • String

      :name the name of the application

    • String

      :voiceUrl the URL that powers voice calls for your application

    • String

      :messagingUrl the URL that powers the SMS/messaging calls for your session

    • String

      :platform defines whether the application will use the Scripting API or the Web API

    • String

      :partition defines whether the application is in staging/development or production



415
416
417
418
419
420
421
422
423
424
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 415

def application(application_id)
  app = @tropo_client.get("applications/#{application_id.to_s}")
  if app.instance_of? Array
    href = app[0].href
    app[0].merge!({ :application_id => get_element(href) })
  else
    href = app.href
    app.merge!({ :application_id => get_element(href) })
  end
end

#applicationsObject

Fetches all of the applications configured for a user

Return

  • Hash

    contains the results of the inquiry with a list of applications for the authenticated user, refer to the application method for details



431
432
433
434
435
436
437
438
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 431

def applications
  results = @tropo_client.get("applications")
  result_with_ids = []
  results.each do |app|
    result_with_ids << app.merge!({ :application_id => get_element(app.href) })
  end
  result_with_ids
end

#applications_with_addresses(application_id = nil) ⇒ Object Also known as: application_with_address

Fetches the application(s) with the associated addresses in the hash

Parameters

  • optional, String

    application_id will return a single application with addresses if present

Return

  • Hash

    contains the results of the inquiry with a list of applications for the authenticated user, refer to the application method for details



448
449
450
451
452
453
454
455
456
457
458
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 448

def applications_with_addresses(application_id=nil)
  if application_id
    associate_addresses_to_application(application(application_id))
  else
    apps = []
    applications.each do |app|
      apps << associate_addresses_to_application(app)
    end
    apps
  end
end

#available_payment_typesObject

Lists the available payment types

Return

  • Hash

    an array of available payment types that each include an id, href and name



215
216
217
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 215

def available_payment_types
  @tropo_client.get("types/payment")
end

#balance(user_id) ⇒ Object

Obtain the current balance of a user

Parameters

  • required, String

    user_id of the user to obtain the balance for

Return

  • Hash

    the balance, pendingRechargeAmount and pendingUsageAmount for the user account



228
229
230
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 228

def balance(user_id)
  @tropo_client.get("users/#{user_id}/usage")
end

#confirm_user(user_id, confirmation_key, ip_address) ⇒ Object

Confirms a user after they have been created. For example, you may want to email your user to make sure they are real before activating the user.

Parameters

  • required, String

    user_id returned when you created the user you now want to confirm

  • required, String

    confirmation_key returned when you created the user you now want to confirm

  • required, String

    the ip_address of the user client that did the confirmation

Return

  • Hash

    contains a message key confirming the confirmation was successful



94
95
96
97
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 94

def confirm_user(user_id, confirmation_key, ip_address)
  params = { :key => confirmation_key, :endUserHost => ip_address }
  @tropo_client.post("users/#{user_id}/confirmations", params)
end

#countriesObject

Return the list of available countries

Return

  • Hash

    returns an Array of hashes that include the country details available



238
239
240
241
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 238

def countries
  result = @tropo_client.get("countries")
  add_ids(result)
end

#create_address(application_id, params = {}) ⇒ Object

Creates an address to an existing application

Parameters

  • required, String

    application_id to add the address to

  • required, Hash

    params the parameters used to request the address

    • String

      :type this defines the type of address. The possibles types are number (phone numbers), pin (reserved), token, aim, jabber, msn, yahoo, gtalk & skype

    • String

      :prefix this defines the country code and area code for phone numbers

    • String

      :username the messaging/IM account’s username

    • String

      :password the messaging/IM account’s password

Return

  • Hash

    params the key/values that make up the application

    • String

      :href identifies the address that was added, refer to address method for details

    • String

      :address the address that was created



393
394
395
396
397
398
399
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 393

def create_address(application_id, params={})
  validate_address_parameters(params)

  result = @tropo_client.post("applications/#{application_id.to_s}/addresses", params)
  result[:address] = get_element(result.href)
  result
end

#create_application(params = {}) ⇒ Object

Create a new application

Parameters

  • required, Hash

    params to create the application

    • required, String

      :name the name to assign to the application

    • required, String

      :partition this defines whether the application is in staging/development or production

    • required, String

      :platform (scripting) whether to use scripting or the webapi

    • required, String

      :messagingUrl or :messaging_url The URL that powers the SMS/messages sessions for your application

    • optional, String

      :voiceUrl or :voice_url the URL that powers voices calls for your application

Return

  • Hash

    returns the href of the application created and the application_id of the application created



474
475
476
477
478
479
480
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 474

def create_application(params={})
  merged_params = DEFAULT_OPTIONS.merge(params)
  validate_application_params(merged_params)
  result = @tropo_client.post("applications", params)
  result[:application_id] = get_element(result.href)
  result
end

#create_invitation(options) ⇒ Object #create_user_invitation(user_id, options) ⇒ Object Also known as: create_user_invitation

Create an invitation

Parameters

* [required, Hash] params the parameters used to create the application
  * [optional, String] :code the invitation code (defaults to a random alphanum string of length 6 if not specified on POST)
  * [optional, String] :count the number of accounts that may signup with this code (decrements on each signup)
  * [optional, String] :credit starting account balance for users who signup with this code (replaces the default for the brand)
  * [optional, String] :partition whether to create in staging or production
  * [optional, String] :owner URI identifying the user to which this invite code belongs (optional - null implies this is a "global" code)

Parameters

* [requried, String] user_id to create the invitation for
* [required, Hash] params the parameters used to create the application
  * [optional, String] :code the invitation code (defaults to a random alphanum string of length 6 if not specified on POST)
  * [optional, String] :count the number of accounts that may signup with this code (decrements on each signup)
  * [optional, String] :credit starting account balance for users who signup with this code (replaces the default for the brand)
  * [optional, String] :partition whether to create in staging or production
  * [optional, String] :owner URI identifying the user to which this invite code belongs (optional - null implies this is a "global" code)

Return

  • Hash

    returns the href of the invitation created



680
681
682
683
684
685
686
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 680

def create_invitation(*args)
  if args.length == 1
    @tropo_client.post("invitations", args[0])
  elsif args.length == 2
    @tropo_client.post("users/#{args[0]}/invitations", args[1])
  end
end

#create_user(params = {}) ⇒ Object

Creates a new user in a pending state. Once you receive the href/user_id/confirmation_key you may then invoke the confirm_user method once you have taken appropriate steps to confirm the user

Parameters

  • required, Hash

    params to create the user

    • required, String

      :username the name of the user to create the user for

    • required, String

      :password the password to use for the user

    • required, String

      :email the email address to use

    • required, String

      :first_name of the user

    • required, String

      :last_name of the user

    • optional, String

      :website the URL of the user’s website

    • optional, String

      :organization of the user, such as a company name

    • optional, String

      :job_title of the user

    • optional, String

      :address of the user

    • optional, String

      :address2 second live of the address of the user

    • optional, String

      :city of the user

    • optional, String

      :state of the user

    • optional, String

      :postal_code of the user

    • optional, String

      :country of the user

    • optional, String

      :marketing_opt_in

    • optional, String

      :twitter_id

    • optional, String

      :joined_from_host IP address of the host they signed up from

Return

  • Hash

    details of the user created

    includes the href, user_id and confirmation_key

  • ArgumentError

    if missing the :username, :password or :email parameters



129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 129

def create_user(params={})
  validate_params(params, %w(username password first_name last_name email))

  # Set the Company Branding ID, or use default
  params[:website] = 'tropo' unless params[:website]

  result = @tropo_client.post("users", params)
  result[:user_id] = get_element(result.href)
  result[:confirmation_key] = result['confirmationKey']
  result.delete('confirmationKey')
  result
end

#delete_address(application_id, address_id) ⇒ Object

Deletes a address from a specific application

Parameters

  • String

    application_id that the address is associated to

  • String

    address_id for the address



500
501
502
503
504
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 500

def delete_address(application_id, address_id)
  address_to_delete = address(application_id, address_id)

  @tropo_client.delete("applications/#{application_id.to_s}/addresses/#{address_to_delete['type']}/#{address_id.to_s}")
end

#delete_application(application_id) ⇒ Object

Deletes an application

Parameters

  • required, String

    application_id to be deleted

Return

  • Hash

    not sure since it does 204 now, need to check with Cervantes, et al



490
491
492
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 490

def delete_application(application_id)
  @tropo_client.delete("applications/#{application_id.to_s}")
end

#delete_invitation(invitation_id) ⇒ Object #delete_user_invitation(invitation_id, user_id) ⇒ Object Also known as: delete_user_invitation

Fetch an invitation

Parameters

* [required, String] the invitation id to delete

Parameters

* [required, String] the invitation id to delete
* [required, String] the user id to delete

Return

  • Hash

    return an invitation



649
650
651
652
653
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 649

def delete_invitation(invitation_id, user_id = nil)
  path = user_id.nil? ? "invitations/#{invitation_id}" : "users/#{user_id}/invitations/#{invitation_id}"

  @tropo_client.delete(path)
end

#delete_whitelist(params = {}) ⇒ Object

Delete from a whitelist for a particular user

  • Hash

    params contains a hash of the user_id and value to delete

    • optional, String

      :user_id if present the user_id to delete from, if not it will add to the user logged in as

    • required, String

      :value the value to delete from the whitelist

Return

  • Hash

    the href



786
787
788
789
790
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 786

def delete_whitelist(params={})
  resource = params.has_key?(:user_id) ? "users/#{params[:user_id]}/partitions/production/platforms/sms/whitelist/" : "users/partitions/production/platforms/sms/whitelist/"

  @tropo_client.delete("#{resource}#{params[:value]}")
end

#exchangesObject

Provides a list of available exchanges to obtain Numbers from

Return

  • Array

    the list of available exchanges



511
512
513
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 511

def exchanges
  @tropo_client.get("exchanges")
end

#featuresObject

Lists the available features

Return

  • Hash

    an array of available features that each include an id, href, name and description



260
261
262
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 260

def features
  @tropo_client.get("features")
end

#get_recurrence(user_id) ⇒ Object

Add/modify recurring fund amount and threshold

Parameters

  • required, String

    user_id to get the recurrence info for

Return

  • Hash


358
359
360
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 358

def get_recurrence(user_id)
  result = @tropo_client.get("users/#{user_id}/payment/recurrence")
end

#invitation(invitation_id) ⇒ Object #user_invitation(user_id, invitation_id) ⇒ Object Also known as: user_invitation

Fetch an invitation

Parameters

* [required, String] the invitation id to fetch

Parameters

* [required, String] the invitation id to fetch
* [optional, String] the user id to fetch the invitation for

Return

  • Hash

    return an invitation



628
629
630
631
632
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 628

def invitation(invitation_id, user_id = nil)
  path = user_id.nil? ? "invitations/#{invitation_id}" : "users/#{user_id}/invitations/#{invitation_id}"

  @tropo_client.get(path)
end

#invitationsObject #user_inivitations(user_id) ⇒ Object Also known as: user_invitations

Fetch all invitations, or invitations by user

Parameters

* [optional, String] the user_id to fetch the invitations for, if not present, will fetch all invitations

Return

  • Hash

    returns a list of the invitations



606
607
608
609
610
611
612
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 606

def invitations(user_id = nil)
  if user_id
    @tropo_client.get("users/#{user_id}/invitations")
  else
    @tropo_client.get("invitations")
  end
end

#make_payment(user_id, amount) ⇒ Object

Makes a payment on behalf of a user

Parameters

  • required, String

    the user_id to make the payment for

  • required, Float

    the amount, in US Dollars to make the payment for

Return

  • Hash

    a message with the success or failure of the payment



372
373
374
375
376
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 372

def make_payment(user_id, amount)
  amount.instance_of?(Float) or raise ArgumentError, 'amount must be of type Float'

  @tropo_client.post("users/#{user_id}/payments", { :amount => amount })
end

#modify_user(user_id, params = {}) ⇒ Object

Modify/update an existing user

Parameters

  • required, String

    user_id of the user you would like to update

  • required, Hash

    the parameters of the user you would like to update

Return

  • Hash

    the href of the resource that was modified/updated



152
153
154
155
156
157
158
159
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 152

def modify_user(user_id, params={})
  result = @tropo_client.put("users/#{user_id}", params)
  if result['href']
    # Only add/update this if we are fetching the user we are logged in as
    @user_data.merge!(params) if user_id == @user_data['id']
  end
  result
end

#move_address(params = {}) ⇒ Object

Used to move a address between one application and another

Parameters

  • Hash

    params contains a hash of the applications and address to move

    • required, String

      :from

    • required, String

      :to

    • required, String

      :address



523
524
525
526
527
528
529
530
531
532
533
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 523

def move_address(params={})
  validate_params(params, %w(from to address))

  begin
    address_to_move = address(params[:from], params[:address])
    delete_address(params[:from], params[:address])
    @tropo_client.post("applications/#{params[:to]}/addresses/#{address_to_move['type']}/#{params[:address]}")
  rescue
    raise RuntimeError, 'Unable to move the address'
  end
end

#partitionsObject

Get the available partitions available

Return

  • Array

    an array of hashes containing the partitions available



727
728
729
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 727

def partitions
  @tropo_client.get("partitions")
end

#platforms(partition) ⇒ Object

Get the available platforms available under a certain partition

Parameters

Return

  • Array

    an array of hashes containing the platforms available



739
740
741
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 739

def platforms(partition)
  @tropo_client.get("partitions/#{partition}/platforms")
end

#search_users(search_term) ⇒ Object

Allows you to search users to find a list of users

Parameters

  • required

    search_term

    • String

      a key/value of the search term you would like to use, such as ‘username=foobar’, or ‘city=Orlando’

    • Hash

      a Hash instance, such as => “foobar”, or => “Orlando”

Return

  • Array

    a hash containing an array of hashes with the qualifying account details



172
173
174
175
176
177
178
179
180
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 172

def search_users(search_term)
  if search_term.is_a?(String)
    @tropo_client.get("users/?#{search_term}")
  elsif search_term.is_a?(Hash)
    @tropo_client.get('users/', search_term)
  else
    nil
  end
end

#states(id) ⇒ Object

Return the list of available states for a country

Return

  • Hash

    returns an Array of hashes that include the state details for a country that are available



249
250
251
252
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 249

def states(id)
  result = @tropo_client.get("countries/#{id}/states")
  add_ids(result)
end

#update_application(application_id, params = {}) ⇒ Object

Updated an existing application

Parameters

  • required, String

    the application id to update

  • required, Hash

    params the parameters used to create the application

    • optional, String

      :name the name of the application

    • optional, String

      :voiceUrl the URL that powers voices calls for your application

    • optional, String

      :messagingUrl The URL that powers the SMS/messages sessions for your application

    • optional, String

      :partition whether to create in staging or production

    • optional, String

      :platform whehter to use scripting or the webapi

Return

  • Hash

    returns the href of the application created



592
593
594
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 592

def update_application(application_id, params={})
  @tropo_client.put("applications/#{application_id.to_s}", params )
end

#update_invitation(invitation_id, options) ⇒ Object #updated_user_invitation(invitation_id, user_id, options) ⇒ Object Also known as: update_user_invitation

Update an invitation

Parameters

* [required, String] id of the invitation to udpate (code)
* [required, Hash] params the parameters used to update the application
  * [optional, String] :count the number of accounts that may signup with this code (decrements on each signup)
  * [optional, String] :credit starting account balance for users who signup with this code (replaces the default for the brand)
  * [optional, String] :partition whether to create in staging or production
  * [optional, String] :owner URI identifying the user to which this invite code belongs (optional - null implies this is a "global" code)

Parameters

* [required, String] id of the invitation to udpate (code)
* [required, String] id of the user to update the invitation code for
* [required, Hash] params the parameters used to update the application
  * [optional, String] :count the number of accounts that may signup with this code (decrements on each signup)
  * [optional, String] :credit starting account balance for users who signup with this code (replaces the default for the brand)
  * [optional, String] :partition whether to create in staging or production
  * [optional, String] :owner URI identifying the user to which this invite code belongs (optional - null implies this is a "global" code)

Return

  • Hash

    returns the href of the invitation created



712
713
714
715
716
717
718
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 712

def update_invitation(*args)
  if args.length == 2
    @tropo_client.put("invitations/#{args[0]}", args[1])
  elsif args.length == 3
    @tropo_client.put("users/#{args[1]}/invitations/#{args[0]}", args[2])
  end
end

#update_recurrence(user_id, params = {}) ⇒ Object

Add/modify recurring fund amount and threshold

Parameters

  • required, String

    user_id to add the payment details for

  • require, Hash

    params the params to add the recurrence

    • required, Float

      :recharge_amount

    • required, Float

      :recharge_threshold

Return

  • Hash


344
345
346
347
348
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 344

def update_recurrence(user_id, params={})
  validate_params(params, %w(recharge_amount threshold_percentage))

  @tropo_client.put("users/#{user_id}/payment/recurrence", params)
end

#user(user_identifier) ⇒ Object

Obtain information about a user

Parameters

  • required, String

    the user ID or username to obtain the account details of

Return

  • Hash

    contains the information on the user



73
74
75
76
77
78
79
80
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 73

def user(user_identifier)
  result = @tropo_client.get("users/#{user_identifier}")
  if result['username']
    # Only add/update this if we are fetching the user we are logged in as
    result['username'].downcase == username.downcase and @user_data = result
  end
  result
end

#user_disable_feature(user_id, feature_number) ⇒ Object

Disable a particular feature for a user

Parameters

  • required, String

    user_id of the user to disable the feature to

  • required, String

    feature number of the feature you want to disable

Return

  • Hash

    the href of the feature disable



298
299
300
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 298

def user_disable_feature(user_id, feature_number)
  @tropo_client.delete("users/#{user_id}/features/#{feature_number}")
end

#user_enable_feature(user_id, feature) ⇒ Object

Enable a particular feature for a user

Parameters

  • required, String

    user_id of the user to add the feature to

  • required, String

    feature identifier of the feature you want to add

Return

  • Hash

    the href of the feature added



284
285
286
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 284

def user_enable_feature(user_id, feature)
  @tropo_client.post("users/#{user_id}/features", { :feature => feature })
end

#user_features(user_id) ⇒ Object

Lists the features configured for a user

Return

  • Hash

    an array of available features that each include an href, feature and featureName



270
271
272
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 270

def user_features(user_id)
  @tropo_client.get("users/#{user_id}/features")
end

#user_payment_method(user_id) ⇒ Object

Fetches the payment information for a user

Parameters

  • required, String

    user_id to fetch the payment details for

Return

  • Hash

    a hash containing the accountNumber, paymentType, paymentTypeName, rechargeAmount and rechargeThreshold



203
204
205
206
207
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 203

def user_payment_method(user_id)
  result = @tropo_client.get("users/#{user_id}/payment/method")
  result.merge!({ :id => get_element(result.paymentType) })
  result
end

#usernameObject

Username used for HTTP authentication (valid Tropo user)



58
59
60
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 58

def username
  @tropo_client.username
end

#username_exists?(username) ⇒ Boolean

Allows you to search if a username exists or not

Parameters

  • required, String

    a username to check

Return

  • Array

    a hash containing an array of hashes with the qualifying account details

Returns:

  • (Boolean)


190
191
192
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 190

def username_exists?(username)
  @tropo_client.get("usernames/#{username}")
end

#whitelist(user_id = nil) ⇒ Object

Get the whitelist of the numbers on a particular users list

Parameters

  • required, String

    user_id of the user you would like to update

Return

  • Hash

    the href and value containing the number on the whitelist



752
753
754
755
756
# File 'lib/tropo-provisioning/tropo_provisioning.rb', line 752

def whitelist(user_id = nil)
  resource = user_id.nil? ? "users/partitions/production/platforms/sms/whitelist" : "users/#{user_id}/partitions/production/platforms/sms/whitelist"

  @tropo_client.get(resource)
end