Class: Qualtrics::Operation
- Inherits:
-
Object
- Object
- Qualtrics::Operation
- Defined in:
- lib/qualtrics/operation.rb
Constant Summary collapse
- REQUEST_METHOD_WHITELIST =
[:get, :post]
- @@listeners =
[]
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#entity_name ⇒ Object
readonly
Returns the value of attribute entity_name.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #disable_listeners(&block) ⇒ Object
-
#initialize(http_method, action, options, body_override = nil) ⇒ Operation
constructor
A new instance of Operation.
- #issue_request ⇒ Object
Constructor Details
#initialize(http_method, action, options, body_override = nil) ⇒ Operation
Returns a new instance of Operation.
7 8 9 10 11 12 13 14 |
# File 'lib/qualtrics/operation.rb', line 7 def initialize(http_method, action, , body_override = nil) @http_method = http_method @action = action @options = @entity_name = action.gsub(/(create|delete|update)/, '') @body_override = body_override @command = $1 end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
3 4 5 |
# File 'lib/qualtrics/operation.rb', line 3 def action @action end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
3 4 5 |
# File 'lib/qualtrics/operation.rb', line 3 def command @command end |
#entity_name ⇒ Object (readonly)
Returns the value of attribute entity_name.
3 4 5 |
# File 'lib/qualtrics/operation.rb', line 3 def entity_name @entity_name end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
3 4 5 |
# File 'lib/qualtrics/operation.rb', line 3 def http_method @http_method end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/qualtrics/operation.rb', line 3 def @options end |
Class Method Details
.add_listener(listener) ⇒ Object
53 54 55 |
# File 'lib/qualtrics/operation.rb', line 53 def add_listener(listener) @@listeners << listener end |
.delete_listener(listener) ⇒ Object
57 58 59 |
# File 'lib/qualtrics/operation.rb', line 57 def delete_listener(listener) @@listeners.delete(listener) end |
.flush_listeners! ⇒ Object
61 62 63 |
# File 'lib/qualtrics/operation.rb', line 61 def flush_listeners! @@listeners = [] end |
Instance Method Details
#disable_listeners(&block) ⇒ Object
46 47 48 49 50 |
# File 'lib/qualtrics/operation.rb', line 46 def disable_listeners(&block) @listeners_disabled = true block.call(self) @listeners_disabled = nil end |
#issue_request ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/qualtrics/operation.rb', line 16 def issue_request raise Qualtrics::UnexpectedRequestMethod if !REQUEST_METHOD_WHITELIST.include?(http_method) query = default_params.dup.merge() query['Request'] = action body = nil query_params = {} raw_resp = nil if @body_override body = @body_override query_params = query raw_resp = connection.send(http_method, path, body) do |req| req.params = query_params end else body = query raw_resp = connection.send(http_method, path, body) end Qualtrics::Response.new(raw_resp).tap do |response| if !@listeners_disabled @@listeners.each do |listener| listener.received_response(self, response) end end end end |