Class: RHapi::Lead
- Inherits:
-
Object
- Object
- RHapi::Lead
- Extended by:
- Connection::ClassMethods
- Includes:
- Connection
- Defined in:
- lib/r_hapi/lead.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#changed_attributes ⇒ Object
Returns the value of attribute changed_attributes.
Class Method Summary collapse
-
.find(search = nil, options = {}) ⇒ Object
Finds leads and returns an array of leads.
-
.find_by_guid(guid) ⇒ Object
Finds specified lead by the guid.
Instance Method Summary collapse
-
#initialize(data) ⇒ Lead
constructor
A new instance of Lead.
-
#method_missing(method, *args, &block) ⇒ Object
Work with data in the data hash.
-
#update(params = {}) ⇒ Object
Instance methods ——————————————————-.
- #update_attributes(params) ⇒ Object
Methods included from Connection::ClassMethods
Methods included from Connection
Constructor Details
#initialize(data) ⇒ Lead
Returns a new instance of Lead.
14 15 16 17 |
# File 'lib/r_hapi/lead.rb', line 14 def initialize(data) self.attributes = data self.changed_attributes = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Work with data in the data hash
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/r_hapi/lead.rb', line 65 def method_missing(method, *args, &block) attribute = ActiveSupport::Inflector.camelize(method.to_s, false) if attribute =~ /=$/ attribute = attribute.chop return super unless self.attributes.include?(attribute) self.changed_attributes[attribute] = args[0] self.attributes[attribute] = args[0] else return super unless self.attributes.include?(attribute) self.attributes[attribute] end end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
12 13 14 |
# File 'lib/r_hapi/lead.rb', line 12 def attributes @attributes end |
#changed_attributes ⇒ Object
Returns the value of attribute changed_attributes.
12 13 14 |
# File 'lib/r_hapi/lead.rb', line 12 def changed_attributes @changed_attributes end |
Class Method Details
.find(search = nil, options = {}) ⇒ Object
Finds leads and returns an array of leads. An optional string value that is used to search several basic lead fields: first name, last name, email address, and company name. According to HubSpot docs, a more advanced search is coming in the future. The default value for is nil, meaning return all leads.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/r_hapi/lead.rb', line 25 def self.find(search=nil, ={}) [:search] = search unless search.nil? response = get(url_for("list", nil, )) lead_data = JSON.parse(response.body_str) leads = [] lead_data.each do |data| lead = Lead.new(data) leads << lead end leads end |
Instance Method Details
#update(params = {}) ⇒ Object
Instance methods ——————————————————-
46 47 48 49 50 |
# File 'lib/r_hapi/lead.rb', line 46 def update(params={}) update_attributes(params) unless params.empty? response = put(Lead.url_for("lead", self.guid), self.changed_attributes) true end |
#update_attributes(params) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/r_hapi/lead.rb', line 52 def update_attributes(params) raise(RHapi::AttributeError, "The params must be a hash.") unless params.is_a?(Hash) params.each do |key, value| attribute = ActiveSupport::Inflector.camelize(key.to_s, false) raise(RHapi::AttributeError, "No Hubspot attribute with the name #{attribute}.") unless self.attributes.include?(attribute) self.changed_attributes[attribute] = value self.attributes[attribute] = value end end |