relateiq_client 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2d76f0dcb80b88ed13562008b96e62dc0f05262c
4
+ data.tar.gz: a83f7a7529adaf15afb70a4e2798e46d76502e09
5
+ SHA512:
6
+ metadata.gz: 4554051152c064be0e3bdca324b7e63aa04b553e5cfe4fef648717679b31481df4b2c3a617626b9eef6a8bb6820fa3056ce78b2addc22abd68427e005521991c
7
+ data.tar.gz: efdb4428faabdd3f1e6e48f3867a427202ff9024dd2c76dd5b8507c52ecad0461ddf5a6d3feb12a55feab031f1986b993066a7e9143cebf91d8da91066223860
data/.gitignore ADDED
@@ -0,0 +1,55 @@
1
+ .env
2
+ *.gem
3
+ *.rbc
4
+ /.config
5
+ /coverage/
6
+ /InstalledFiles
7
+ /pkg/
8
+ /spec/reports/
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /lib/bundler/man/
27
+
28
+ # for a library or gem, you might want to ignore these files since the code is
29
+ # intended to run in multiple environments; otherwise, check them in:
30
+ # Gemfile.lock
31
+ # .ruby-version
32
+ # .ruby-gemset
33
+
34
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
+ .rvmrc
36
+
37
+ # zenflow (gitflow in ruby)
38
+ .zenflow-log
39
+
40
+ # atom
41
+ npm-debug.log
42
+ .live-archive
43
+
44
+ # ctags
45
+ tags
46
+ .tags
47
+ .gemtags
48
+ .tags_sorted_by_file
49
+
50
+ # mac shit..
51
+ .DS_Store
52
+
53
+ # cadre
54
+ errors.err
55
+ .cadre
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ Documentation:
2
+ Enabled: false
3
+
4
+ Encoding:
5
+ Enabled: false
6
+
7
+ HandleExceptions:
8
+ Enabled: false
9
+
10
+ LineLength:
11
+ Max: 120
12
+
13
+ NumericLiterals:
14
+ Enabled: false
data/.simplecov ADDED
@@ -0,0 +1,9 @@
1
+ require 'cadre/simplecov'
2
+
3
+ #SimpleCov.start 'rails' do #if, you know: Rails.
4
+ SimpleCov.start do
5
+ formatter SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Cadre::SimpleCov::VimFormatter
8
+ ]
9
+ end
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.0.0"
4
+ - "2.2.2"
5
+ before_install: gem install bundler -v 1.10.6
6
+ script: CODECLIMATE_REPO_TOKEN=5267ad324eea6d39245a52388849b7d8d2f22c5f221beee5d1bceee60a5661f3 bundle exec rspec spec
data/.zenflow ADDED
@@ -0,0 +1,11 @@
1
+ ---
2
+ project: RelateIQClient
3
+ development_branch: master
4
+ staging_branch: false
5
+ qa_branch: false
6
+ release_branch: release
7
+ merge_strategy: rebase
8
+ remote: origin
9
+ backup_remote: false
10
+ confirm_staging: false
11
+ confirm_review: true
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ * add logging capability
2
+ * refactored relateiqclient to have a more of a active resource style api and added find methods to contact and list items
3
+ * add find methods for contact and list item by contact. Also symbolize all keys for a more rubyish experience.
4
+ --------------------------------------------------------------------------------
5
+ ^ ADD NEW CHANGES ABOVE ^
6
+ --------------------------------------------------------------------------------
7
+
8
+ CHANGELOG
9
+ =========
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in relateiq.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,112 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ relateiq_client (0.1.0)
5
+ rest-client (~> 1.7)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.3.8)
11
+ ast (2.0.0)
12
+ astrolabe (1.3.0)
13
+ parser (>= 2.2.0.pre.3, < 3.0)
14
+ binding_of_caller (0.7.2)
15
+ debug_inspector (>= 0.0.1)
16
+ cadre (1.0.1)
17
+ thor (>= 0.14, < 1.0)
18
+ tilt (> 1.0)
19
+ valise (~> 1.1.2)
20
+ codeclimate-test-reporter (0.2.0)
21
+ simplecov (>= 0.7.1, < 1.0.0)
22
+ coderay (1.1.0)
23
+ colored (1.2)
24
+ crack (0.4.2)
25
+ safe_yaml (~> 1.0.0)
26
+ debug_inspector (0.0.2)
27
+ diff-lcs (1.2.5)
28
+ httparty (0.13.5)
29
+ json (~> 1.8)
30
+ multi_xml (>= 0.5.2)
31
+ json (1.8.2)
32
+ method_source (0.8.2)
33
+ mime-types (2.6.1)
34
+ multi_json (1.10.1)
35
+ multi_xml (0.5.5)
36
+ netrc (0.7.9)
37
+ parser (2.2.2.0)
38
+ ast (>= 1.1, < 3.0)
39
+ powerpack (0.1.0)
40
+ pry (0.10.1)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.8.1)
43
+ slop (~> 3.4)
44
+ pry-stack_explorer (0.4.9.1)
45
+ binding_of_caller (>= 0.7)
46
+ pry (>= 0.9.11)
47
+ rainbow (2.0.0)
48
+ rake (10.4.2)
49
+ rest-client (1.7.2)
50
+ mime-types (>= 1.16, < 3.0)
51
+ netrc (~> 0.7)
52
+ rspec (3.1.0)
53
+ rspec-core (~> 3.1.0)
54
+ rspec-expectations (~> 3.1.0)
55
+ rspec-mocks (~> 3.1.0)
56
+ rspec-core (3.1.4)
57
+ rspec-support (~> 3.1.0)
58
+ rspec-expectations (3.1.2)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.1.0)
61
+ rspec-mocks (3.1.2)
62
+ rspec-support (~> 3.1.0)
63
+ rspec-support (3.1.1)
64
+ rubocop (0.30.0)
65
+ astrolabe (~> 1.3)
66
+ parser (>= 2.2.0.1, < 3.0)
67
+ powerpack (~> 0.1)
68
+ rainbow (>= 1.99.1, < 3.0)
69
+ ruby-progressbar (~> 1.4)
70
+ ruby-progressbar (1.7.5)
71
+ safe_yaml (1.0.4)
72
+ simplecov (0.7.1)
73
+ multi_json (~> 1.0)
74
+ simplecov-html (~> 0.7.1)
75
+ simplecov-html (0.7.1)
76
+ simplecov-json (0.2)
77
+ json
78
+ simplecov
79
+ slop (3.6.0)
80
+ terminal-table (1.4.5)
81
+ thor (0.19.1)
82
+ tilt (2.0.1)
83
+ valise (1.1.4)
84
+ webmock (1.21.0)
85
+ addressable (>= 2.3.6)
86
+ crack (>= 0.3.2)
87
+ zenflow (0.8.12)
88
+ colored (~> 1.2)
89
+ httparty (~> 0.13.0)
90
+ terminal-table (~> 1.4.5)
91
+ thor (~> 0.19.0)
92
+
93
+ PLATFORMS
94
+ ruby
95
+
96
+ DEPENDENCIES
97
+ bundler (~> 1.7)
98
+ cadre
99
+ codeclimate-test-reporter
100
+ pry (~> 0.10)
101
+ pry-stack_explorer (~> 0.4.9)
102
+ rake (~> 10.0)
103
+ relateiq_client!
104
+ rspec (~> 3.1)
105
+ rubocop
106
+ simplecov
107
+ simplecov-json
108
+ webmock
109
+ zenflow
110
+
111
+ BUNDLED WITH
112
+ 1.10.6
data/Guardfile ADDED
@@ -0,0 +1,17 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ # Note: The cmd option is now required due to the increasing number of ways
5
+ # rspec may be run, below are examples of the most common uses.
6
+ # * bundler: 'bundle exec rspec'
7
+ # * bundler binstubs: 'bin/rspec'
8
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
9
+ # installed the spring binstubs per the docs)
10
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
11
+ # * 'just' rspec: 'rspec'
12
+ guard :rspec, cmd: 'bundle exec rspec' do
13
+ watch(%r{^spec/.+_spec\.rb$})
14
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
15
+ watch(/(.+)\.rb$/) { |m| "spec/#{m[1]}_spec.rb" }
16
+ watch('spec/spec_helper.rb') { 'spec' }
17
+ end
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ [![Code Climate](https://codeclimate.com/github/dkarter/RelateIQClient/badges/gpa.svg)](https://codeclimate.com/github/dkarter/RelateIQClient) [![Test Coverage](https://codeclimate.com/github/dkarter/RelateIQClient/badges/coverage.svg)](https://codeclimate.com/github/dkarter/RelateIQClient/coverage) ![Travis CI](https://travis-ci.org/dkarter/RelateIQClient.svg?branch=master)
2
+
3
+ # RelateIQ Client
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'relateiq'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install relateiq
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ 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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/relateiq.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
39
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/relateiq.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'relateiq/version'
2
+ require 'rest_client'
3
+
4
+ require 'relateiq/service_factory'
5
+ require 'relateiq/utils/field_value_encoder'
6
+ require 'relateiq/contact'
7
+ require 'relateiq/account'
8
+ require 'relateiq/list'
9
+ require 'relateiq/list_item'
10
+
11
+ module RelateIq
12
+ class << self
13
+ attr_accessor :configuration
14
+ end
15
+
16
+ def self.configure
17
+ self.configuration ||= Configuration.new
18
+ yield(configuration)
19
+ RestClient.log = self.configuration.logger
20
+ end
21
+
22
+ class Configuration
23
+ attr_accessor :base_url, :username, :password, :logger
24
+
25
+ def initialize
26
+ @base_url = 'https://api.relateiq.com/v2'
27
+ @username = ''
28
+ @password = ''
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,43 @@
1
+ module RelateIq
2
+ class Account
3
+ attr_accessor :id, :name
4
+
5
+ def self.resource
6
+ @resource ||= RelateIq::ServiceFactory.get_endpoint('accounts')
7
+ end
8
+
9
+ def self.find(id)
10
+ from_json(resource["#{id}"].get)
11
+ end
12
+
13
+ def self.create(attrs = {})
14
+ RelateIq::Account.new(attrs).save
15
+ end
16
+
17
+ def self.from_json(json_string)
18
+ account_hash = JSON.parse(json_string, symbolize_names: true)
19
+ RelateIq::Account.new(account_hash)
20
+ end
21
+
22
+ def initialize(attrs = {})
23
+ @id = attrs.fetch(:id, nil)
24
+ @name = attrs.fetch(:name, nil)
25
+ end
26
+
27
+ def to_json
28
+ account_hash = {
29
+ name: @name
30
+ }
31
+ account_hash[:id] = id if id
32
+ account_hash.to_json
33
+ end
34
+
35
+ def save
36
+ if id
37
+ RelateIq::Account.from_json(RelateIq::Account.resource["#{id}"].put(to_json))
38
+ else
39
+ RelateIq::Account.from_json(RelateIq::Account.resource.post(to_json))
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,127 @@
1
+ module RelateIq
2
+ class Contact
3
+ attr_accessor :id,
4
+ :first_name,
5
+ :last_name,
6
+ :email,
7
+ :phone,
8
+ :address,
9
+ :city,
10
+ :state,
11
+ :zipcode,
12
+ :company,
13
+ :title,
14
+ :twitter,
15
+ :linkedin
16
+
17
+ def self.resource
18
+ @resource ||= ServiceFactory.get_endpoint('contacts')
19
+ end
20
+
21
+ def self.find(id)
22
+ from_json(resource["#{id}"].get)
23
+ end
24
+
25
+ def self.find_by_email(email)
26
+ from_json(resource["?properties.email=#{email}"].get)
27
+ end
28
+
29
+ def self.create(attrs)
30
+ Contact.new(attrs).save
31
+ end
32
+
33
+ def full_name
34
+ return nil unless first_name || last_name
35
+ "#{first_name} #{last_name}"
36
+ end
37
+
38
+ def full_address
39
+ return nil unless address || city || state || zipcode
40
+ "#{address}, #{city}, #{state} #{zipcode}"
41
+ end
42
+
43
+ def save
44
+ if id
45
+ Contact.from_json(Contact.resource["#{id}"].put to_json)
46
+ else
47
+ Contact.from_json(Contact.resource.post to_json)
48
+ end
49
+ end
50
+
51
+ def self.from_json(json_string)
52
+ contact_hash = JSON.parse(json_string, symbolize_names: true)
53
+ if contact_hash.key? :objects
54
+ contact_hash[:objects].map { |li| Contact.new(li) }
55
+ else
56
+ Contact.new(contact_hash)
57
+ end
58
+ end
59
+
60
+ def initialize(attrs = {})
61
+ if attrs.key? :properties
62
+ initialize_from_api(attrs)
63
+ else
64
+ initialize_by_user(attrs)
65
+ end
66
+ end
67
+
68
+ def to_json
69
+ riq_hash = { properties: { email: [{ value: @email }] } }
70
+ riq_hash[:id] = id if id
71
+ inject_property_value_hash(riq_hash[:properties], 'name', full_name)
72
+ inject_property_value_hash(riq_hash[:properties], 'phone', phone)
73
+ inject_property_value_hash(riq_hash[:properties], 'address', address)
74
+ inject_property_value_hash(riq_hash[:properties], 'liurl', linkedin)
75
+ inject_property_value_hash(riq_hash[:properties], 'twhan', twitter)
76
+ inject_property_value_hash(riq_hash[:properties], 'company', company)
77
+ inject_property_value_hash(riq_hash[:properties], 'title', title)
78
+ riq_hash.to_json
79
+ end
80
+
81
+ private
82
+
83
+ def inject_property_value_hash(hash, name, value)
84
+ if value.is_a? Array
85
+ hash.merge!(name => value.map { |v| property_value(v) })
86
+ else
87
+ hash.merge!(value ? { name => [property_value(value)] } : {})
88
+ end
89
+ end
90
+
91
+ def property_value(value)
92
+ { value: value }
93
+ end
94
+
95
+ def array_or_single(value)
96
+ value.count > 1 ? value : value[0]
97
+ end
98
+
99
+ def initialize_by_user(attrs)
100
+ @id = attrs.fetch(:id, nil)
101
+ @email = attrs.fetch(:email, nil)
102
+ @first_name = attrs.fetch(:first_name, nil)
103
+ @last_name = attrs.fetch(:last_name, nil)
104
+ @title = attrs.fetch(:title, nil)
105
+ @company = attrs.fetch(:company, nil)
106
+ @phone = attrs.fetch(:phone, nil)
107
+ @address = attrs.fetch(:address, nil)
108
+ @linkedin = attrs.fetch(:linkedin, nil)
109
+ @twitter = attrs.fetch(:twitter, nil)
110
+ end
111
+
112
+ def initialize_from_api(attrs)
113
+ # extract attributes from properties
114
+ attrs[:properties].map { |k, v| attrs.merge!(k => extract_values(v)) }
115
+ attrs.delete(:properties)
116
+ # rename some keys
117
+ attrs[:twitter] = attrs.delete(:twhan)
118
+ attrs[:linkedin] = attrs.delete(:liurl)
119
+ initialize_by_user(attrs)
120
+ end
121
+
122
+ def extract_values(api_values)
123
+ return nil if api_values.nil?
124
+ array_or_single api_values.map { |v| v[:value] }
125
+ end
126
+ end
127
+ end