advisors_command_client 1.1.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55a3fa4b5e3510a41682d40394f40062adc3c932
4
- data.tar.gz: 9e9595d915f084d34cc96664ff49acca3bbfa7a7
3
+ metadata.gz: f1ecd4a524aa2e872fe9a3ef9e040668737cb8c2
4
+ data.tar.gz: b8b12f66f1833e488ca23d1cffcdefda165ea1e2
5
5
  SHA512:
6
- metadata.gz: b9de4c0aabcca9678b585ff4b6c19aeb088447decc287cd0e99dfd3e40689bab3fbcb93444a32d4aa73bc2e2c3dac2f47fbb2499f115edd24143ae2ce7f7138a
7
- data.tar.gz: c5d5454eb1cf782bc1f41202b69f50d7b737a897139b70bc32128534e55a0a7f537c23c67162bbfea28de76580f6450978070532f26776339c7468c8bbfc97d6
6
+ metadata.gz: 51a17ba948570ea80d1e9c49285b5402aa7ca9474167a8662e49d293358f9ae24642a771f136d819fb3d40410614518a8efaa451d222b450967e67ed15a0133e
7
+ data.tar.gz: 534dafeff5def1ecebb50a6fe3dc56bf9916bf527eab45f8f72374a08c5b7f921b1b071239fbed45d552e0720ec275f46a9118f714faebeefece7a023900b17b
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "faraday_middleware"
29
29
  spec.add_dependency "virtus"
30
30
  spec.add_dependency 'parallel'
31
+ spec.add_dependency 'awrence'
31
32
  end
@@ -1,31 +1,57 @@
1
1
  require 'virtus'
2
+ require 'awrence'
2
3
  require "advisors_command_client/version"
3
4
  require 'advisors_command_client/connection'
4
5
  require 'advisors_command_client/models/base'
6
+ require 'advisors_command_client/models/address'
5
7
  require 'advisors_command_client/models/contact'
6
8
  require 'advisors_command_client/models/account'
7
9
  require 'advisors_command_client/models/contact_collection'
10
+ require 'advisors_command_client/models/account_collection'
8
11
 
9
12
  module AdvisorsCommandClient
10
13
  class SearchError < ::StandardError
11
14
  end
12
15
 
16
+ class MissingAPIUrlError < ::StandardError
17
+ end
18
+
19
+ class << self
20
+ attr_accessor :config
21
+ end
22
+
23
+ def self.config
24
+ @config ||= Configuration.new
25
+ end
26
+
27
+ def self.configure
28
+ yield config
29
+ end
30
+
31
+ class Configuration
32
+ attr_accessor :api_url
33
+ end
34
+
13
35
  class Client
14
- TEST_URL = "https://qa.advisorscommand.com/api/rest/latest"
15
- PROD_URL = "https://advisorscommand.com/api/rest/latest"
36
+ # STAGING_URL = "https://qa.advisorscommand.com/api/rest/latest"
37
+ # DEMO_URL = "https://demo.advisorscommand.com/api/rest/latest"
38
+ # PROD_URL = "https://advisorscommand.com/api/rest/latest"
16
39
  attr_reader :connection
17
40
 
18
41
  def initialize(username, api_key, options = {})
19
- if options[:live]
20
- url = PROD_URL
21
- else
22
- url = TEST_URL
23
- end
42
+ url = AdvisorsCommandClient.config.api_url || options[:api_url]
43
+
44
+ raise MissingAPIUrlError.new('A url for this client has not been configured.') if url.nil?
45
+
24
46
  @connection = AdvisorsCommandClient::Connection.new(username, api_key, url).build
25
47
  end
26
48
 
27
49
  def contacts
28
50
  @contacts ||= Models::ContactCollection.new(connection: @connection)
29
51
  end
52
+
53
+ def accounts
54
+ @accounts ||= Models::AccountCollection.new(connection: @connection)
55
+ end
30
56
  end
31
57
  end
@@ -16,11 +16,11 @@ module AdvisorsCommandClient
16
16
 
17
17
  def build
18
18
  Faraday.new(@url) do |faraday|
19
- faraday.request :url_encoded
19
+ faraday.request :json
20
20
  faraday.use AdvisorsCommandClient::Connection::WsseAuth, @username, @api_key
21
21
  faraday.adapter :typhoeus
22
22
  faraday.response :json, content_type: /\bjson$/
23
- end
23
+ end
24
24
  end
25
25
 
26
26
  class WsseAuth < Faraday::Middleware
@@ -16,9 +16,17 @@ module AdvisorsCommandClient
16
16
  attribute :monthly_salary, Float
17
17
  attribute :monthly_expense, Float
18
18
  attribute :salary_increase_percent, Integer
19
+ attribute :name, String
20
+ attribute :state, String
19
21
 
20
22
  attribute :retirement_age, Integer
21
23
  attribute :marital_status, String
24
+
25
+ def as_json
26
+ {
27
+ name: name
28
+ }
29
+ end
22
30
  end
23
31
  end
24
32
  end
@@ -0,0 +1,34 @@
1
+ module AdvisorsCommandClient
2
+ module Models
3
+ class AccountCollection
4
+ def initialize(args = {})
5
+ @connection = args[:connection]
6
+ end
7
+
8
+ def create(contact_id, params)
9
+ account = AdvisorsCommandClient::Models::Account.new(params)
10
+ account_json = account.as_json
11
+ account_json = account_json.merge(default_contact: contact_id)
12
+ resp = @connection.post("accounts.json", { account: account_json })
13
+
14
+ if resp.success?
15
+ account.id = resp.body['id']
16
+ account
17
+ else
18
+ return false
19
+ end
20
+ end
21
+
22
+ def update(account_id, params)
23
+ account = AdvisorsCommandClient::Models::Account.new(params.merge(id: account_id))
24
+ resp = @connection.put("accounts/#{account_id}.json", { account: account.as_json })
25
+
26
+ if resp.success?
27
+ return account
28
+ else
29
+ return false
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,100 @@
1
+ module AdvisorsCommandClient
2
+ module Models
3
+ class Address < Base
4
+ attribute :id, Integer
5
+ attribute :primary, Boolean
6
+ attribute :street, String
7
+ attribute :street2, String
8
+ attribute :city, String
9
+ attribute :postal_code, String
10
+ attribute :created_at, DateTime
11
+ attribute :updated_at, DateTime
12
+ attribute :country, String
13
+ attribute :region, String
14
+ attribute :types, Array[String]
15
+
16
+ def region
17
+ state_map.key(@region) || @region
18
+ end
19
+
20
+ def region_code
21
+ state_map[@region] || @region
22
+ end
23
+
24
+ def full_address
25
+ [street, street2, city, region, postal_code, country].compact.join(' ')
26
+ end
27
+
28
+ def ==(other_address)
29
+ full_address.downcase == other_address.full_address.downcase
30
+ end
31
+
32
+ def as_json
33
+ json_attrs = attributes.dup
34
+ json_attrs.delete(:id)
35
+ json_attrs.delete(:types)
36
+ json_attrs.delete(:created_at)
37
+ json_attrs.delete(:updated_at)
38
+ json_attrs.to_camelback_keys
39
+ end
40
+
41
+ private
42
+
43
+ def state_map
44
+ {
45
+ "Alabama" => "AL",
46
+ "Alaska" => "AK",
47
+ "Arizona" => "AZ",
48
+ "Arkansas" => "AR",
49
+ "California" => "CA",
50
+ "Colorado" => "CO",
51
+ "Connecticut" => "CT",
52
+ "Delaware" => "DE",
53
+ "District of Columbia" => "DC",
54
+ "Florida" => "FL",
55
+ "Georgia" => "GA",
56
+ "Hawaii" => "HI",
57
+ "Idaho" => "ID",
58
+ "Illinois" => "IL",
59
+ "Indiana" => "IN",
60
+ "Iowa" => "IA",
61
+ "Kansas" => "KS",
62
+ "Kentucky" => "KY",
63
+ "Louisiana" => "LA",
64
+ "Maine" => "ME",
65
+ "Maryland" => "MD",
66
+ "Massachusetts" => "MA",
67
+ "Michigan" => "MI",
68
+ "Minnesota" => "MN",
69
+ "Mississippi" => "MS",
70
+ "Missouri" => "MO",
71
+ "Montana" => "MT",
72
+ "Nebraska" => "NE",
73
+ "Nevada" => "NV",
74
+ "New Hampshire" => "NH",
75
+ "New Jersey" => "NJ",
76
+ "New Mexico" => "NM",
77
+ "New York" => "NY",
78
+ "North Carolina" => "NC",
79
+ "North Dakota" => "ND",
80
+ "Ohio" => "OH",
81
+ "Oklahoma" => "OK",
82
+ "Oregon" => "OR",
83
+ "Pennsylvania" => "PA",
84
+ "Rhode Island" => "RI",
85
+ "South Carolina" => "SC",
86
+ "South Dakota" => "SD",
87
+ "Tennessee" => "TN",
88
+ "Texas" => "TX",
89
+ "Utah" => "UT",
90
+ "Vermont" => "VT",
91
+ "Virginia" => "VA",
92
+ "Washington" => "WA",
93
+ "West Virginia" => "WV",
94
+ "Wisconsin" => "WI",
95
+ "Wyoming" => "WY"
96
+ }
97
+ end
98
+ end
99
+ end
100
+ end
@@ -18,11 +18,11 @@ module AdvisorsCommandClient
18
18
 
19
19
  attribute :emails, Array[Hash]
20
20
  attribute :phones, Array[Hash]
21
- attribute :addresses, Array[Hash]
21
+ attribute :addresses, Array[Address]
22
22
 
23
23
 
24
24
  def full_name
25
- [name_prefix, first_name, middle_name, last_name, name_suffix].reject(&:blank?).join(' ')
25
+ [name_prefix, first_name, middle_name, last_name, name_suffix].reject(&:nil?).join(' ')
26
26
  end
27
27
 
28
28
  def accounts
@@ -33,6 +33,20 @@ module AdvisorsCommandClient
33
33
  end
34
34
  end
35
35
  end
36
+
37
+ def as_json
38
+ json_attrs = attributes.dup
39
+ json_attrs.delete(:nickname)
40
+ json_attrs.delete(:employer)
41
+ json_attrs.delete(:email)
42
+ json_attrs.delete(:id)
43
+ json_attrs.delete(:created_at)
44
+ json_attrs.delete(:updated_at)
45
+
46
+ json_attrs[:addresses] = addresses.map {|address| address.as_json }
47
+
48
+ json_attrs.to_camelback_keys
49
+ end
36
50
  end
37
51
  end
38
52
  end
@@ -10,7 +10,7 @@ module AdvisorsCommandClient
10
10
  if response.success?
11
11
  return Parallel.map(Array(response.body['data'])) do |obj|
12
12
  begin
13
- next unless obj['record_string'].present?
13
+ next unless obj['record_string']
14
14
  self.find(obj['record_id'].to_i)
15
15
  rescue Faraday::Error::ParsingError
16
16
  puts "Error parsing response for contact ID: #{obj['record_id']}"
@@ -31,6 +31,28 @@ module AdvisorsCommandClient
31
31
  end
32
32
  end
33
33
 
34
+ def create(params)
35
+ contact = AdvisorsCommandClient::Models::Contact.new(params)
36
+ resp = @connection.post("contacts.json", { contact: contact.as_json })
37
+
38
+ if resp.success?
39
+ contact.id = resp.body['id']
40
+ return contact
41
+ else
42
+ return false
43
+ end
44
+ end
45
+
46
+ def update(contact_id, params)
47
+ contact = AdvisorsCommandClient::Models::Contact.new(params.merge(id: contact_id))
48
+ resp = @connection.put("contacts/#{contact_id}.json", { contact: contact.as_json })
49
+
50
+ if resp.success?
51
+ return contact
52
+ else
53
+ return false
54
+ end
55
+ end
34
56
  end
35
57
  end
36
58
  end
@@ -1,3 +1,3 @@
1
1
  module AdvisorsCommandClient
2
- VERSION = "1.1.3"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: advisors_command_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Ostrowski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-03 00:00:00.000000000 Z
11
+ date: 2017-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: awrence
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description:
140
154
  email:
141
155
  - chris@madebyfunction.com
@@ -157,6 +171,8 @@ files:
157
171
  - lib/advisors_command_client.rb
158
172
  - lib/advisors_command_client/connection.rb
159
173
  - lib/advisors_command_client/models/account.rb
174
+ - lib/advisors_command_client/models/account_collection.rb
175
+ - lib/advisors_command_client/models/address.rb
160
176
  - lib/advisors_command_client/models/base.rb
161
177
  - lib/advisors_command_client/models/contact.rb
162
178
  - lib/advisors_command_client/models/contact_collection.rb
@@ -181,7 +197,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
197
  version: '0'
182
198
  requirements: []
183
199
  rubyforge_project:
184
- rubygems_version: 2.5.1
200
+ rubygems_version: 2.6.10
185
201
  signing_key:
186
202
  specification_version: 4
187
203
  summary: Ruby Client for integrating with Advisors Command CRM