Module: Gmail::Util

Defined in:
lib/gmail/util.rb

Class Method Summary collapse

Class Method Details

.convert_to_gmail_object(resp, key = nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/gmail/util.rb', line 16

def self.convert_to_gmail_object(resp, key=nil)
  case resp
    when Array
      resp.map { |i| convert_to_gmail_object(i, key) }
    when Hash
      # Try converting to a known object class.  If none available, fall back to generic StripeObject
      object_classes.fetch(key , GmailObject).new(resp)
    else
      resp
  end
end

.object_classesObject



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/gmail/util.rb', line 4

def self.object_classes
  @object_classes ||= {
      # data structures

      # business objects
      'draft' => Draft,
      'label' => Label,
      'message' => Message,
      'thread' => Thread
  }
end

.symbolize_names(object) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gmail/util.rb', line 29

def self.symbolize_names(object)
  case object
    when Hash
      new_hash = {}
      object.each do |key, value|
        key = (key.to_sym rescue key) || key
        new_hash[key] = symbolize_names(value)
      end
      new_hash
    when Array
      object.map { |value| symbolize_names(value) }
    else
      object
  end
end