Class: Message
- Inherits:
-
Object
- Object
- Message
- Defined in:
- lib/writeit-rails/message.rb
Instance Attribute Summary collapse
-
#answers ⇒ Object
Returns the value of attribute answers.
-
#author_email ⇒ Object
Returns the value of attribute author_email.
-
#author_name ⇒ Object
Returns the value of attribute author_name.
-
#content ⇒ Object
Returns the value of attribute content.
-
#recipients ⇒ Object
Returns the value of attribute recipients.
-
#remote_id ⇒ Object
Returns the value of attribute remote_id.
-
#remote_uri ⇒ Object
Returns the value of attribute remote_uri.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#writeitinstance ⇒ Object
Returns the value of attribute writeitinstance.
Instance Method Summary collapse
Instance Attribute Details
#answers ⇒ Object
Returns the value of attribute answers.
13 14 15 |
# File 'lib/writeit-rails/message.rb', line 13 def answers @answers end |
#author_email ⇒ Object
Returns the value of attribute author_email.
12 13 14 |
# File 'lib/writeit-rails/message.rb', line 12 def end |
#author_name ⇒ Object
Returns the value of attribute author_name.
11 12 13 |
# File 'lib/writeit-rails/message.rb', line 11 def end |
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/writeit-rails/message.rb', line 6 def content @content end |
#recipients ⇒ Object
Returns the value of attribute recipients.
8 9 10 |
# File 'lib/writeit-rails/message.rb', line 8 def recipients @recipients end |
#remote_id ⇒ Object
Returns the value of attribute remote_id.
10 11 12 |
# File 'lib/writeit-rails/message.rb', line 10 def remote_id @remote_id end |
#remote_uri ⇒ Object
Returns the value of attribute remote_uri.
9 10 11 |
# File 'lib/writeit-rails/message.rb', line 9 def remote_uri @remote_uri end |
#subject ⇒ Object
Returns the value of attribute subject.
5 6 7 |
# File 'lib/writeit-rails/message.rb', line 5 def subject @subject end |
#writeitinstance ⇒ Object
Returns the value of attribute writeitinstance.
7 8 9 |
# File 'lib/writeit-rails/message.rb', line 7 def writeitinstance @writeitinstance end |
Instance Method Details
#push_to_api ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/writeit-rails/message.rb', line 31 def push_to_api validate data = { :author_name => self., :author_email => self., :subject => self.subject, :content => self.content, :writeitinstance => self.writeitinstance.url, :persons => self.recipients } = 'ApiKey %{username}:%{api_key}' % { :username => self.writeitinstance.username, :api_key => self.writeitinstance.api_key, } url = self.writeitinstance.base_url + '/api/v1/message/' request = RestClient::Request.new( :method => :post, :url => url, :headers => { :accept => :json, :authorization => , }, :payload => data.to_json ) request.processed_headers["Content-Type"] = 'application/json' response = request.execute data = JSON.parse(response.body) self.remote_id = data['id'] self.remote_uri = data['resource_uri'] end |
#validate ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/writeit-rails/message.rb', line 15 def validate wrong_recipients = self.recipients.nil? if not wrong_recipients wrong_recipients = not(self.recipients.any?) end raise ArgumentError, 'No recipients, please add some first' unless not wrong_recipients = self..nil? raise ArgumentError, 'No author, set it first' unless not validates_instance = self.writeitinstance.nil? raise ArgumentError, 'No instance, please set one first' unless not validates_instance end |