advisors_command_client 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec6b477a1d7c88df05c8922b5a251d097b0deb8e
4
+ data.tar.gz: a83b3e054ead8434bec05900ba0d6b61a11a6692
5
+ SHA512:
6
+ metadata.gz: dc1633d60676da5e2f54ef1e352978d8941c2b353da7b7ec7f02b7f6d2e885dd755205bb10e03c605ed477c9b6850c23184e8d8902c12aeb753b24716fb7060c
7
+ data.tar.gz: b73b93d63d7263dacb609ff8d86d4f84cd9697d6716d7aebbb066bb1314ffe0250c2be377b0b4c7265d5653a2937e89319c4eaee7dc0322c9dc40475c2a51d48
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in advisors_command.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Christopher Ostrowski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Advisors Command Client
2
+
3
+ A small gem to use AdvisorsCommand in a ruby application.
4
+
5
+ * Full support for WSSE authentication.
6
+ * Simple Virtus POROs for models.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'advisors_command'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install advisors_command
23
+
24
+ ## Usage
25
+
26
+ Create a client:
27
+ ```ruby
28
+ $advisors_client = AdvisorsCommandClient::Client.new(username, api_key)
29
+ ```
30
+
31
+ ### Contacts
32
+ Find contacts, returns a collection of `Model::Contact`
33
+ ```ruby
34
+ $advisors_client.contacts.search("Bob")
35
+ ```
36
+
37
+ Find a single contact, returns a `Model::Contact`
38
+ ```ruby
39
+ $advisors_client.contacts.find(1234)
40
+ ```
41
+
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/RepPro/advisors_command/fork )
52
+ 2. Create your feature branch (`git checkout -b f/my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin f/my-new-feature`)
55
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'advisors_command_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "advisors_command_client"
8
+ spec.version = AdvisorsCommandClient::VERSION
9
+ spec.authors = ["Christopher Ostrowski"]
10
+ spec.email = ["chris@madebyfunction.com"]
11
+
12
+ spec.summary = %q{Ruby Client for integrating with Advisors Command CRM}
13
+ # spec.description = %q{TODO: Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/RepPro/AdvisorsCommand"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_dependency "akami", "~> 1.3"
26
+ spec.add_dependency "typhoeus"
27
+ spec.add_dependency "faraday"
28
+ spec.add_dependency "faraday_middleware"
29
+ spec.add_dependency "virtus"
30
+ spec.add_dependency 'parallel'
31
+ end
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "advisors_command"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ require "pry"
11
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,30 @@
1
+ require 'virtus'
2
+ require "advisors_command_client/version"
3
+ require 'advisors_command_client/connection'
4
+ require 'advisors_command_client/models/base'
5
+ require 'advisors_command_client/models/contact'
6
+ require 'advisors_command_client/models/contact_collection'
7
+
8
+ module AdvisorsCommandClient
9
+ class SearchError < ::StandardError
10
+ end
11
+
12
+ class Client
13
+ TEST_URL = "https://qa.advisorscommand.com/api/rest/v1"
14
+ PROD_URL = "https://www.advisorscommand.com/api/rest/v1"
15
+ attr_reader :connection
16
+
17
+ def initialize(username, api_key, options = {})
18
+ if options[:live]
19
+ url = PROD_URL
20
+ else
21
+ url = TEST_URL
22
+ end
23
+ @connection = AdvisorsCommandClient::Connection.new(username, api_key, url).build
24
+ end
25
+
26
+ def contacts
27
+ @contacts ||= Models::ContactCollection.new(connection: @connection)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,48 @@
1
+ require 'parallel'
2
+ require 'akami'
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+ require 'typhoeus'
6
+ require 'typhoeus/adapters/faraday'
7
+
8
+ module AdvisorsCommandClient
9
+ class Connection
10
+
11
+ def initialize(username, api_key, url)
12
+ @username = username
13
+ @api_key = api_key
14
+ @url = url
15
+ end
16
+
17
+ def build
18
+ Faraday.new(@url) do |faraday|
19
+ faraday.request :url_encoded
20
+ faraday.use AdvisorsCommandClient::Connection::WsseAuth, @username, @api_key
21
+ faraday.adapter :typhoeus
22
+ faraday.response :json, content_type: /\bjson$/
23
+ end
24
+ end
25
+
26
+ class WsseAuth < Faraday::Middleware
27
+ def initialize(app, username, api_key)
28
+ super(app)
29
+ @username = username
30
+ @api_key = api_key
31
+ end
32
+
33
+ def call(request_env)
34
+ request_env[:request_headers].merge!({"X-WSSE" => wsse_auth_string})
35
+ @app.call(request_env)
36
+ end
37
+
38
+ private
39
+ def wsse_auth_string
40
+ wsse = Akami.wsse
41
+ wsse.credentials @username, @api_key, :digest
42
+ wsse.timestamp = true
43
+
44
+ %{UsernameToken Username="#{wsse.username}", PasswordDigest="#{wsse.send(:digest_password)}", Nonce="#{Base64.encode64(wsse.send(:nonce)).chomp}", Created="#{wsse.send(:timestamp)}"}
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,32 @@
1
+ module AdvisorsCommandClient
2
+ module Models
3
+ class Base
4
+ include Virtus.model
5
+
6
+ def self.load(hash)
7
+ new(deep_underscore_params(hash))
8
+ end
9
+
10
+ #JSON comes back as SnakeCase.
11
+ #This will convert all hash keys to snake_case.
12
+ def self.deep_underscore_params(val = {})
13
+ snake_caser = -> val {val.to_s.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase}
14
+
15
+ case val
16
+ when Array
17
+ val.map { |v| deep_underscore_params(v) }
18
+ when Hash
19
+ val.keys.each do |k, v = val[k]|
20
+ val.delete k
21
+ val[snake_caser.call(k)] = deep_underscore_params(v)
22
+ end
23
+ params = val
24
+ else
25
+ val
26
+ end
27
+
28
+ return val
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ module AdvisorsCommandClient
2
+ module Models
3
+ class Contact < Base
4
+ attribute :id, Integer
5
+ attribute :nickname, String
6
+ attribute :first_name, String
7
+ attribute :middle_name, String
8
+ attribute :last_name, String
9
+ attribute :gender, String
10
+ attribute :birthday, DateTime
11
+ attribute :email, String
12
+ attribute :created_at, DateTime
13
+ attribute :updated_at, DateTime
14
+
15
+ attribute :emails, Array[Hash]
16
+ attribute :phones, Array[Hash]
17
+ attribute :addresses, Array[Hash]
18
+
19
+
20
+ def full_name
21
+ [first_name, middle_name, last_name].compact.join(' ')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ module AdvisorsCommandClient
2
+ module Models
3
+ class ContactCollection
4
+ def initialize(args = {})
5
+ @connection = args[:connection]
6
+ end
7
+
8
+ def search(query)
9
+ response = @connection.get('search', {search: query, from: 'orocrm_contact'})
10
+ if response.success?
11
+ return Parallel.map(Array(response.body['data']), in_threads: 4) do |obj|
12
+ self.find(obj['record_id'].to_i)
13
+ end.compact
14
+ else
15
+ raise ::AdvisorsCommandClient::SearchError, "Error connecting to advisors command."
16
+ end
17
+ end
18
+
19
+ def find(contact_id)
20
+ resp = @connection.get("contacts/#{contact_id}")
21
+ if resp.success?
22
+ return AdvisorsCommandClient::Models::Contact.load(resp.body)
23
+ else
24
+ return nil
25
+ end
26
+ end
27
+
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,3 @@
1
+ module AdvisorsCommandClient
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: advisors_command_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Christopher Ostrowski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: akami
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: typhoeus
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday_middleware
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: virtus
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: parallel
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - chris@madebyfunction.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - CODE_OF_CONDUCT.md
150
+ - Gemfile
151
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - advisors_command_client.gemspec
155
+ - bin/console
156
+ - bin/setup
157
+ - lib/advisors_command_client.rb
158
+ - lib/advisors_command_client/connection.rb
159
+ - lib/advisors_command_client/models/base.rb
160
+ - lib/advisors_command_client/models/contact.rb
161
+ - lib/advisors_command_client/models/contact_collection.rb
162
+ - lib/advisors_command_client/version.rb
163
+ homepage: https://github.com/RepPro/AdvisorsCommand
164
+ licenses:
165
+ - MIT
166
+ metadata: {}
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubyforge_project:
183
+ rubygems_version: 2.5.1
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: Ruby Client for integrating with Advisors Command CRM
187
+ test_files: []