Class: ToopherAPI
- Inherits:
-
Object
- Object
- ToopherAPI
- Defined in:
- lib/toopher_api.rb
Overview
Abstracts calls to the Toopher OAuth webservice
Constant Summary collapse
- DEFAULT_BASE_URL =
Default URL for the Toopher webservice API. Can be overridden in the constructor if necessary.
'https://toopher-api.appspot.com/v1/'
Instance Method Summary collapse
-
#authenticate(pairing_id, terminal_name = '', action_name = '', options = {}) ⇒ AuthenticationStatus
Authenticate an action with Toopher.
-
#get_authentication_status(authentication_request_id) ⇒ Object
Check on the status of a previous authentication request.
-
#get_pairing_status(pairing_request_id) ⇒ PairingStatus
Check on the status of a previous pairing request.
-
#initialize(key, secret, options = {}, base_url = DEFAULT_BASE_URL) ⇒ ToopherAPI
constructor
Creates a Toopher API consumer.
-
#pair(pairing_phrase, user_name, options = {}) ⇒ PairingStatus
Create the pairing between a particular user and their mobile device.
Constructor Details
#initialize(key, secret, options = {}, base_url = DEFAULT_BASE_URL) ⇒ ToopherAPI
Creates a Toopher API consumer
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/toopher_api.rb', line 46 def initialize(key,secret,={}, base_url = DEFAULT_BASE_URL) consumer_key = key consumer_secret = secret consumer_key.empty? and raise ArgumentError, "Toopher consumer key cannot be empty!" consumer_secret.empty? and raise ArgumentError, "Toopher consumer secret cannot be empty!" @base_url = base_url @oauth_consumer = OAuth::Consumer.new(consumer_key, consumer_secret) @oauth_options = end |
Instance Method Details
#authenticate(pairing_id, terminal_name = '', action_name = '', options = {}) ⇒ AuthenticationStatus
Authenticate an action with Toopher
87 88 89 90 91 92 93 94 |
# File 'lib/toopher_api.rb', line 87 def authenticate(pairing_id, terminal_name = '', action_name = '', = {}) parameters = { 'pairing_id' => pairing_id, 'terminal_name' => terminal_name } action_name.empty? or (parameters['action_name'] = action_name) return AuthenticationStatus.new(post('authentication_requests/initiate', parameters.merge())) end |
#get_authentication_status(authentication_request_id) ⇒ Object
Check on the status of a previous authentication request
99 100 101 |
# File 'lib/toopher_api.rb', line 99 def get_authentication_status(authentication_request_id) return AuthenticationStatus.new(get('authentication_requests/' + authentication_request_id)) end |
#get_pairing_status(pairing_request_id) ⇒ PairingStatus
Check on the status of a previous pairing request
76 77 78 |
# File 'lib/toopher_api.rb', line 76 def get_pairing_status(pairing_request_id) return PairingStatus.new(get('pairings/' + pairing_request_id)) end |
#pair(pairing_phrase, user_name, options = {}) ⇒ PairingStatus
Create the pairing between a particular user and their mobile device
64 65 66 67 68 69 |
# File 'lib/toopher_api.rb', line 64 def pair(pairing_phrase, user_name, = {}) return PairingStatus.new(post('pairings/create', { 'pairing_phrase' => pairing_phrase, 'user_name' => user_name }.merge())) end |