class GirlScout::Conversation

Public Class Methods

create(attributes) click to toggle source
# File lib/girlscout/conversation.rb, line 16
def create(attributes)
  attributes = attributes.as_json if attributes.respond_to?(:as_json)
  resource.post(payload: attributes)
end
find(id) click to toggle source
# File lib/girlscout/conversation.rb, line 8
def find(id)
  Conversation.new(resource["/#{id}"].get)
end
list(query = {}) click to toggle source
# File lib/girlscout/conversation.rb, line 12
def list(query = {})
  List.new(resource.get(query: query), Conversation)
end

Public Instance Methods

as_json() click to toggle source
# File lib/girlscout/conversation.rb, line 47
def as_json
  json = super
  json['customer'] = customer.as_json if key?('customer')
  json['threads'] = threads.map(&:as_json) if key?('threads')
  json['mailbox'] = mailbox.as_json if key?('mailbox')
  json
end
customer() click to toggle source
# File lib/girlscout/conversation.rb, line 22
def customer
  @customer ||= Customer.new(self['customer'] || self['primary_customer'] || {})
end
mailbox() click to toggle source
# File lib/girlscout/conversation.rb, line 37
def mailbox
  @mailbox ||= begin
    if self['mailbox'].is_a?(Hash)
      Mailbox.new(self['mailbox'] || {})
    else
      Mailbox.new(Resource.new(url: self['Links']['mailbox']['href']).get)
    end
  end
end
threads() click to toggle source
# File lib/girlscout/conversation.rb, line 26
def threads
  # `threads` is a number in response but must be an array in request payload.
  @threads ||= begin
    if self['threads'].is_a?(Array)
      (self['threads'] || []).map { |attr| Thread.new(attr) }
    else
      List.new(threads_resouce.get, Thread)
    end
  end
end

Private Instance Methods

threads_resouce() click to toggle source
# File lib/girlscout/conversation.rb, line 57
def threads_resouce
  @threads_resouce ||= Resource.new(url: self['Links']['threads']['href'])
end