Class: Jabbify::Comet
- Inherits:
-
Object
- Object
- Jabbify::Comet
- Defined in:
- lib/jabbify/comet.rb
Constant Summary collapse
- DEFAULT_ATTRIBUTES =
{ :action => :create, :api_key => nil, :message => nil, :name => 'Server', :to => nil, :type => :message, }
Class Method Summary collapse
Instance Method Summary collapse
- #attributes ⇒ Object
- #deliver(overridden_attributes = {}) ⇒ Object
-
#initialize(custom_attributes = {}) ⇒ Comet
constructor
A new instance of Comet.
- #jabbify_uri ⇒ Object
- #uri_params ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(custom_attributes = {}) ⇒ Comet
Returns a new instance of Comet.
16 17 18 |
# File 'lib/jabbify/comet.rb', line 16 def initialize(custom_attributes = {}) @customized_attributes = DEFAULT_ATTRIBUTES.merge custom_attributes end |
Class Method Details
.deliver(options) ⇒ Object
41 42 43 |
# File 'lib/jabbify/comet.rb', line 41 def self.deliver() new().deliver end |
Instance Method Details
#attributes ⇒ Object
20 21 22 |
# File 'lib/jabbify/comet.rb', line 20 def attributes @customized_attributes end |
#deliver(overridden_attributes = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/jabbify/comet.rb', line 24 def deliver(overridden_attributes = {}) customized_attributes = @customized_attributes.dup @customized_attributes.merge! overridden_attributes return_value = false if valid? begin RestClient.post jabbify_uri, uri_params return_value = true rescue end end @customized_attributes = customized_attributes return_value end |
#jabbify_uri ⇒ Object
45 46 47 |
# File 'lib/jabbify/comet.rb', line 45 def jabbify_uri 'https://jabbify.com:8443/message_push' end |
#uri_params ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jabbify/comet.rb', line 49 def uri_params { :action => @customized_attributes[:action], :key => @customized_attributes[:api_key], :message => @customized_attributes[:message], :name => @customized_attributes[:name], :to => @customized_attributes[:to], :type => @customized_attributes[:type], }.reject { |key, value| value.nil? } end |
#valid? ⇒ Boolean
60 61 62 63 64 65 |
# File 'lib/jabbify/comet.rb', line 60 def valid? [ :api_key, :name, :message ].each do |attribute| return false if @customized_attributes[attribute].nil? or @customized_attributes[attribute].strip.length == 0 end true end |