Class: Pushover::Response
- Inherits:
-
Struct
- Object
- Struct
- Pushover::Response
- Defined in:
- lib/pushover/response.rb
Overview
Response encapsulates the response back from pushover. Class to wrap the user and basic functions related to it.
Instance Attribute Summary collapse
-
#attributes ⇒ String
Any extra k/v pairs from the server.
-
#errors ⇒ Array
Errors includes any errors made.
-
#headers ⇒ Hash
Headers is the headers returned from the call.
-
#receipt ⇒ String
Receipt returns a receipt if requested.
-
#request ⇒ String
Request is a UUID representing the specific call.
-
#status ⇒ Numeric
Status of the response.
Class Method Summary collapse
-
.create_from_excon_response(excon_response) ⇒ Object
New response object, from an excon_response @return [Response] populated response object.
Instance Method Summary collapse
-
#to_s ⇒ Object
purty.
Instance Attribute Details
#attributes ⇒ String
Returns any extra k/v pairs from the server.
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 45 |
# File 'lib/pushover/response.rb', line 16 Response = Struct.new(:status, :request, :errors, :receipt, :headers, :attributes, keyword_init: true) do # New response object, from an excon_response # @return [Response] populated response object def self.create_from_excon_response(excon_response) json = Oj.load excon_response[:body] values = {} attributes = {} json.each { |k, v| members.include?(k.to_sym) ? values.store(k, v) : attributes.store(k, v) } Response.new values.merge(headers: excon_response.headers, attributes: attributes) end # purty. def to_s "#{errors ? 'errors: ' + errors.join("\n") : 'status: ok'}, #{limits}" end private # :nocov: # Application limits # @return [Array] 0: Remaining Calls, 1: Total Limit, 2: Limit Reset def limits return '' unless headers.include? 'X-Limit-App-Limit' output = [headers['X-Limit-App-Remaining'], headers['X-Limit-App-Limit'], headers['X-Limit-App-Reset']] output.define_singleton_method(:to_s) { "requests #{self[0]} of #{self[1]}, reset on #{Time.at(self[2].to_f)}" } output end end |
#errors ⇒ Array
Returns errors includes any errors made.
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 45 |
# File 'lib/pushover/response.rb', line 16 Response = Struct.new(:status, :request, :errors, :receipt, :headers, :attributes, keyword_init: true) do # New response object, from an excon_response # @return [Response] populated response object def self.create_from_excon_response(excon_response) json = Oj.load excon_response[:body] values = {} attributes = {} json.each { |k, v| members.include?(k.to_sym) ? values.store(k, v) : attributes.store(k, v) } Response.new values.merge(headers: excon_response.headers, attributes: attributes) end # purty. def to_s "#{errors ? 'errors: ' + errors.join("\n") : 'status: ok'}, #{limits}" end private # :nocov: # Application limits # @return [Array] 0: Remaining Calls, 1: Total Limit, 2: Limit Reset def limits return '' unless headers.include? 'X-Limit-App-Limit' output = [headers['X-Limit-App-Remaining'], headers['X-Limit-App-Limit'], headers['X-Limit-App-Reset']] output.define_singleton_method(:to_s) { "requests #{self[0]} of #{self[1]}, reset on #{Time.at(self[2].to_f)}" } output end end |
#headers ⇒ Hash
Returns headers is the headers returned from the call.
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 45 |
# File 'lib/pushover/response.rb', line 16 Response = Struct.new(:status, :request, :errors, :receipt, :headers, :attributes, keyword_init: true) do # New response object, from an excon_response # @return [Response] populated response object def self.create_from_excon_response(excon_response) json = Oj.load excon_response[:body] values = {} attributes = {} json.each { |k, v| members.include?(k.to_sym) ? values.store(k, v) : attributes.store(k, v) } Response.new values.merge(headers: excon_response.headers, attributes: attributes) end # purty. def to_s "#{errors ? 'errors: ' + errors.join("\n") : 'status: ok'}, #{limits}" end private # :nocov: # Application limits # @return [Array] 0: Remaining Calls, 1: Total Limit, 2: Limit Reset def limits return '' unless headers.include? 'X-Limit-App-Limit' output = [headers['X-Limit-App-Remaining'], headers['X-Limit-App-Limit'], headers['X-Limit-App-Reset']] output.define_singleton_method(:to_s) { "requests #{self[0]} of #{self[1]}, reset on #{Time.at(self[2].to_f)}" } output end end |
#receipt ⇒ String
Returns receipt returns a receipt if requested.
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 45 |
# File 'lib/pushover/response.rb', line 16 Response = Struct.new(:status, :request, :errors, :receipt, :headers, :attributes, keyword_init: true) do # New response object, from an excon_response # @return [Response] populated response object def self.create_from_excon_response(excon_response) json = Oj.load excon_response[:body] values = {} attributes = {} json.each { |k, v| members.include?(k.to_sym) ? values.store(k, v) : attributes.store(k, v) } Response.new values.merge(headers: excon_response.headers, attributes: attributes) end # purty. def to_s "#{errors ? 'errors: ' + errors.join("\n") : 'status: ok'}, #{limits}" end private # :nocov: # Application limits # @return [Array] 0: Remaining Calls, 1: Total Limit, 2: Limit Reset def limits return '' unless headers.include? 'X-Limit-App-Limit' output = [headers['X-Limit-App-Remaining'], headers['X-Limit-App-Limit'], headers['X-Limit-App-Reset']] output.define_singleton_method(:to_s) { "requests #{self[0]} of #{self[1]}, reset on #{Time.at(self[2].to_f)}" } output end end |
#request ⇒ String
Returns request is a UUID representing the specific call.
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 45 |
# File 'lib/pushover/response.rb', line 16 Response = Struct.new(:status, :request, :errors, :receipt, :headers, :attributes, keyword_init: true) do # New response object, from an excon_response # @return [Response] populated response object def self.create_from_excon_response(excon_response) json = Oj.load excon_response[:body] values = {} attributes = {} json.each { |k, v| members.include?(k.to_sym) ? values.store(k, v) : attributes.store(k, v) } Response.new values.merge(headers: excon_response.headers, attributes: attributes) end # purty. def to_s "#{errors ? 'errors: ' + errors.join("\n") : 'status: ok'}, #{limits}" end private # :nocov: # Application limits # @return [Array] 0: Remaining Calls, 1: Total Limit, 2: Limit Reset def limits return '' unless headers.include? 'X-Limit-App-Limit' output = [headers['X-Limit-App-Remaining'], headers['X-Limit-App-Limit'], headers['X-Limit-App-Reset']] output.define_singleton_method(:to_s) { "requests #{self[0]} of #{self[1]}, reset on #{Time.at(self[2].to_f)}" } output end end |
#status ⇒ Numeric
Returns status of the response.
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 45 |
# File 'lib/pushover/response.rb', line 16 Response = Struct.new(:status, :request, :errors, :receipt, :headers, :attributes, keyword_init: true) do # New response object, from an excon_response # @return [Response] populated response object def self.create_from_excon_response(excon_response) json = Oj.load excon_response[:body] values = {} attributes = {} json.each { |k, v| members.include?(k.to_sym) ? values.store(k, v) : attributes.store(k, v) } Response.new values.merge(headers: excon_response.headers, attributes: attributes) end # purty. def to_s "#{errors ? 'errors: ' + errors.join("\n") : 'status: ok'}, #{limits}" end private # :nocov: # Application limits # @return [Array] 0: Remaining Calls, 1: Total Limit, 2: Limit Reset def limits return '' unless headers.include? 'X-Limit-App-Limit' output = [headers['X-Limit-App-Remaining'], headers['X-Limit-App-Limit'], headers['X-Limit-App-Reset']] output.define_singleton_method(:to_s) { "requests #{self[0]} of #{self[1]}, reset on #{Time.at(self[2].to_f)}" } output end end |
Class Method Details
.create_from_excon_response(excon_response) ⇒ Object
New response object, from an excon_response
@return [Response] populated response object
19 20 21 22 23 24 25 26 |
# File 'lib/pushover/response.rb', line 19 def self.create_from_excon_response(excon_response) json = Oj.load excon_response[:body] values = {} attributes = {} json.each { |k, v| members.include?(k.to_sym) ? values.store(k, v) : attributes.store(k, v) } Response.new values.merge(headers: excon_response.headers, attributes: attributes) end |
Instance Method Details
#to_s ⇒ Object
purty.
29 30 31 |
# File 'lib/pushover/response.rb', line 29 def to_s "#{errors ? 'errors: ' + errors.join("\n") : 'status: ok'}, #{limits}" end |