diff --git a/advisors_command_client.gemspec b/advisors_command_client.gemspec index 1368b1d..c55ac57 100644 --- a/advisors_command_client.gemspec +++ b/advisors_command_client.gemspec @@ -28,4 +28,5 @@ Gem::Specification.new do |spec| spec.add_dependency "faraday_middleware" spec.add_dependency "virtus" spec.add_dependency 'parallel' + spec.add_dependency 'awrence' end diff --git a/bin/console b/bin/console index bb867bf..802cc94 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,7 @@ #!/usr/bin/env ruby require "bundler/setup" -require "advisors_command" +require "advisors_command_client" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. diff --git a/lib/advisors_command_client.rb b/lib/advisors_command_client.rb index 22070af..e1128a1 100644 --- a/lib/advisors_command_client.rb +++ b/lib/advisors_command_client.rb @@ -1,3 +1,4 @@ +require 'awrence' require 'virtus' require "advisors_command_client/version" require 'advisors_command_client/connection' diff --git a/lib/advisors_command_client/models/contact.rb b/lib/advisors_command_client/models/contact.rb index 90162fa..89e774b 100644 --- a/lib/advisors_command_client/models/contact.rb +++ b/lib/advisors_command_client/models/contact.rb @@ -2,7 +2,6 @@ module AdvisorsCommandClient module Models class Contact < Base attribute :id, Integer - attribute :nickname, String attribute :name_prefix, String attribute :first_name, String attribute :middle_name, String @@ -13,13 +12,18 @@ class Contact < Base attribute :email, String attribute :created_at, DateTime attribute :updated_at, DateTime - attribute :employer, String attribute :job_title, String attribute :emails, Array[Hash] attribute :phones, Array[Hash] attribute :addresses, Array[Hash] + def self.create(params = {}) + # Take params and massage them + # Post them to /contacts + # initialize new contact and load resp + # return new contact + end def full_name [name_prefix, first_name, middle_name, last_name, name_suffix].reject(&:blank?).join(' ') @@ -33,6 +37,29 @@ def accounts end end end + + def save + resp = @connection.put("contacts/#{id}", transform_attributes(attributes)) + puts resp.inspect + if resp.success? + underscored_params = self.class.deep_underscore_params(resp) + self.attributes = underscored_params + return true + end + + return false + end + + private + + def transform_attributes(attributes) + wrapped_attributes = wrap(attributes) + wrapped_attributes.to_camelback_keys + end + + def wrap(attributes) + { contact: attributes } + end end end end \ No newline at end of file diff --git a/lib/advisors_command_client/version.rb b/lib/advisors_command_client/version.rb index 195845f..ba69106 100644 --- a/lib/advisors_command_client/version.rb +++ b/lib/advisors_command_client/version.rb @@ -1,3 +1,3 @@ module AdvisorsCommandClient - VERSION = "1.1.3" + VERSION = "1.2.0" end