Class: ContextIO::Source
Overview
A message source. Create one of these for each mailbox a user has
Instance Attribute Summary collapse
- #account_id ⇒ Object readonly
- #authentication_type ⇒ Object
- #email ⇒ Object readonly
- #label ⇒ Object
- #port ⇒ Object
- #server ⇒ Object
- #service_level ⇒ Object
- #source_type ⇒ Object
- #status ⇒ Object
- #sync_period ⇒ Object
- #use_ssl ⇒ Object
- #username ⇒ Object
Class Method Summary collapse
-
.all(account, query = {}) ⇒ Object
Public: Get all sources for given account.
-
.find(account, label) ⇒ Source
Find a source for given ID.
-
.from_json(account_id, json) ⇒ Source
private
Create a Source instance from the JSON returned by the Context.IO server.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroys current source object.
-
#folders ⇒ Object
Returns all source’s folders.
-
#initialize(account_id, attributes = {}) ⇒ Source
constructor
A new instance of Source.
-
#save ⇒ true, false
Sends the source data to Context.IO.
-
#update_attributes(attributes = {}) ⇒ true, false
Update attributes on the Source object and then send them to Context.IO.
Methods included from Request
#delete, #get, #post, #put, #request
Constructor Details
#initialize(account_id, attributes = {}) ⇒ Source
Returns a new instance of Source.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/context-io/source.rb', line 57 def initialize(account_id, attributes = {}) raise ArgumentError if account_id.to_s.empty? @account_id = account_id.to_s @email = attributes['email'] @label = attributes['label'] || '' @authentication_type = attributes['authentication_type'] @port = attributes['port'] || 143 @service_level = attributes['service_level'] @username = attributes['username'] @server = attributes['server'] @source_type = attributes['type'] || 'IMAP' @sync_period = attributes['sync_period'] @use_ssl = attributes['use_ssl'] || false @status = attributes['status'] @password = attributes['password'] @provider_token = attributes['provider_token'] @provider_token_secret = attributes['provider_token_secret'] @provider_consumer_key = attributes['provider_consumer_key'] end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
10 11 12 |
# File 'lib/context-io/source.rb', line 10 def account_id @account_id end |
#authentication_type ⇒ Object
8 9 10 |
# File 'lib/context-io/source.rb', line 8 def authentication_type @authentication_type end |
#email ⇒ Object (readonly)
10 11 12 |
# File 'lib/context-io/source.rb', line 10 def email @email end |
#label ⇒ Object
8 9 10 |
# File 'lib/context-io/source.rb', line 8 def label @label end |
#port ⇒ Object
8 9 10 |
# File 'lib/context-io/source.rb', line 8 def port @port end |
#server ⇒ Object
8 9 10 |
# File 'lib/context-io/source.rb', line 8 def server @server end |
#service_level ⇒ Object
8 9 10 |
# File 'lib/context-io/source.rb', line 8 def service_level @service_level end |
#source_type ⇒ Object
8 9 10 |
# File 'lib/context-io/source.rb', line 8 def source_type @source_type end |
#status ⇒ Object
8 9 10 |
# File 'lib/context-io/source.rb', line 8 def status @status end |
#sync_period ⇒ Object
8 9 10 |
# File 'lib/context-io/source.rb', line 8 def sync_period @sync_period end |
#use_ssl ⇒ Object
8 9 10 |
# File 'lib/context-io/source.rb', line 8 def use_ssl @use_ssl end |
#username ⇒ Object
8 9 10 |
# File 'lib/context-io/source.rb', line 8 def username @username end |
Class Method Details
.all(account, query = {}) ⇒ Object
Public: Get all sources for given account.
query - An optional Hash (default: {}) containing a query to filter the
responses. For possible values see Context.IO API documentation.
Returns an Array of Source objects.
account - Account object or ID
19 20 21 22 23 24 25 26 |
# File 'lib/context-io/source.rb', line 19 def self.all(account, query = {}) return [] if account.nil? account_id = account.is_a?(Account) ? account.id : account.to_s get("/2.0/accounts/#{account_id}/sources", query).map do |msg| Source.from_json(account_id, msg) end end |
.find(account, label) ⇒ Source
Find a source for given ID
38 39 40 41 42 43 |
# File 'lib/context-io/source.rb', line 38 def self.find(account, label) return nil if account.nil? or label.to_s.empty? account_id = account.is_a?(Account) ? account.id : account.to_s Source.from_json(account_id, get("/2.0/accounts/#{account_id}/sources/#{label.to_s}")) end |
.from_json(account_id, json) ⇒ Source
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a Source instance from the JSON returned by the Context.IO server
53 54 55 |
# File 'lib/context-io/source.rb', line 53 def self.from_json(account_id, json) source = new(account_id, json) end |
Instance Method Details
#destroy ⇒ Object
Destroys current source object
103 104 105 106 107 108 109 110 |
# File 'lib/context-io/source.rb', line 103 def destroy return false if @label.to_s.empty? response = delete("/2.0/accounts/#{@account_id}/sources/#{@label}") @label = '' if response['success'] response['success'] end |
#folders ⇒ Object
Returns all source’s folders.
79 80 81 |
# File 'lib/context-io/source.rb', line 79 def folders ContextIO::Folder.all(@account_id, @label) end |
#save ⇒ true, false
Sends the source data to Context.IO
If the source has been sent to Context.IO before, this will update allowed source attributes.
98 99 100 |
# File 'lib/context-io/source.rb', line 98 def save @label.to_s.empty? ? create_record : update_record end |
#update_attributes(attributes = {}) ⇒ true, false
Update attributes on the Source object and then send them to Context.IO
attributes are status, sync period, service level, password, provider token, provider token secret and provider consumer key
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/context-io/source.rb', line 124 def update_attributes(attributes = {}) raise ArgumentError.new("Cannot set attributes on new record") if @label.to_s.empty? attributes.each do |k,v| if ["status", "sync_period", "service_level", "password", "provider_token", "provider_token_secret", "provider_consumer_key"].include? k send("#{k}=", v) end end update_record end |