Class: AnalyzeData::UserAuth
- Inherits:
-
Object
- Object
- AnalyzeData::UserAuth
- Defined in:
- lib/client.rb
Overview
The UserAuth class allows interaction with a UserAuth project
Instance Method Summary collapse
-
#initialize(user_id, endpoint, authToken) ⇒ UserAuth
constructor
Construction, when interacting with UserAuth, a user_id is required.
-
#setParameter(name, value) ⇒ Object
Send an arbitrary piece of data.
-
#setRequestURI(uri) ⇒ Object
Set the request URI.
-
#sync(default = UserAuthResult::INDECISIVE) ⇒ Object
Performs a synchronous request.
Constructor Details
#initialize(user_id, endpoint, authToken) ⇒ UserAuth
Construction, when interacting with UserAuth, a user_id is required
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/client.rb', line 57 def initialize(user_id, endpoint, authToken) #The map containing @data = {} #The array with reserved keywords @reservedKeys = ['user_id'] #init the user_id @data["user_id"] = user_id @endpoint = endpoint @authToken = authToken self end |
Instance Method Details
#setParameter(name, value) ⇒ Object
Send an arbitrary piece of data
79 80 81 82 83 84 85 |
# File 'lib/client.rb', line 79 def setParameter(name, value) if @reservedKeys.include?(name) throw new Exception("You cannot set a parameter with name="+name+", as is a reserved entry"); end @data[name] = value self end |
#setRequestURI(uri) ⇒ Object
Set the request URI
90 91 92 93 |
# File 'lib/client.rb', line 90 def setRequestURI(uri) @data['request_uri'] = uri self end |
#sync(default = UserAuthResult::INDECISIVE) ⇒ Object
Performs a synchronous request
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/client.rb', line 100 def sync(default = UserAuthResult::INDECISIVE) begin #return doSync response = doSync() #parse the result body json = JSON.parse(response.body) #if it is a valid result, return it, otherwise default if (json['code'] != 200) default else json['result'] end rescue Exception => e #Return the default value puts e. default end end |