Class: Cubscout::Object

Inherits:
Object
  • Object
show all
Includes:
Scopes
Defined in:
lib/cubscout/object.rb

Overview

the Object class is the base class for any object retrieved from the Helpscout API. it’s attributes can be read either as they are returned (usually camel case) but also in snake case.

Examples:

obj = Cubscout::Object.new("firstName" => "Joren")
puts obj.firstName # => "Joren"
puts obj.first_name # => "Joren"

Direct Known Subclasses

Conversation, ThreadItem, User

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Scopes

included

Constructor Details

#initialize(attributes) ⇒ Object

Returns a new instance of Object.



14
15
16
17
# File 'lib/cubscout/object.rb', line 14

def initialize(attributes)
  # Dirty deep_transform_keys to strings
  @attributes = JSON.parse(attributes.to_json)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



19
20
21
22
23
24
# File 'lib/cubscout/object.rb', line 19

def method_missing(method_name, *args, &block)
  key = camelize(method_name)
  return super unless @attributes.key?(key)

  @attributes[key]
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



12
13
14
# File 'lib/cubscout/object.rb', line 12

def attributes
  @attributes
end