contactually-rb 0.1.1

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.
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ env: CODECLIMATE_REPO_TOKEN=9457072d7c7f1610175a27a9c1aa484dfc680e6b66cabc4dea96dba7658aa93c
6
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at pair+ncavig@realscout.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in contactually-api.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ contactually-rb (0.1.1)
5
+ faraday (~> 0.9.2)
6
+ faraday_middleware (~> 0.10.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.3.8)
12
+ codeclimate-test-reporter (0.6.0)
13
+ simplecov (>= 0.7.1, < 1.0.0)
14
+ coderay (1.1.0)
15
+ crack (0.4.3)
16
+ safe_yaml (~> 1.0.0)
17
+ diff-lcs (1.2.5)
18
+ docile (1.1.5)
19
+ faraday (0.9.2)
20
+ multipart-post (>= 1.2, < 3)
21
+ faraday_middleware (0.10.0)
22
+ faraday (>= 0.7.4, < 0.10)
23
+ hashdiff (0.3.0)
24
+ json (2.0.2)
25
+ method_source (0.8.2)
26
+ multipart-post (2.0.0)
27
+ pry (0.10.4)
28
+ coderay (~> 1.1.0)
29
+ method_source (~> 0.8.1)
30
+ slop (~> 3.4)
31
+ rake (10.5.0)
32
+ rspec (3.5.0)
33
+ rspec-core (~> 3.5.0)
34
+ rspec-expectations (~> 3.5.0)
35
+ rspec-mocks (~> 3.5.0)
36
+ rspec-core (3.5.3)
37
+ rspec-support (~> 3.5.0)
38
+ rspec-expectations (3.5.0)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.5.0)
41
+ rspec-mocks (3.5.0)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.5.0)
44
+ rspec-support (3.5.0)
45
+ safe_yaml (1.0.4)
46
+ simplecov (0.12.0)
47
+ docile (~> 1.1.0)
48
+ json (>= 1.8, < 3)
49
+ simplecov-html (~> 0.10.0)
50
+ simplecov-html (0.10.0)
51
+ slop (3.6.0)
52
+ webmock (2.1.0)
53
+ addressable (>= 2.3.6)
54
+ crack (>= 0.3.2)
55
+ hashdiff
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ bundler (~> 1.12)
62
+ codeclimate-test-reporter (~> 0.6.0)
63
+ contactually-rb!
64
+ pry
65
+ rake (~> 10.0)
66
+ rspec (~> 3.0)
67
+ webmock
68
+
69
+ BUNDLED WITH
70
+ 1.12.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # contactually-rb
2
+
3
+ [![Build Status](https://travis-ci.org/RealScout/contactually-rb.svg?branch=master)](https://travis-ci.org/RealScout/contactually-rb)
4
+ [![Code Climate](https://codeclimate.com/github/RealScout/contactually-rb/badges/gpa.svg)](https://codeclimate.com/github/RealScout/contactually-rb)
5
+ [![Test Coverage](https://codeclimate.com/github/RealScout/contactually-rb/badges/coverage.svg)](https://codeclimate.com/github/RealScout/contactually-rb)
6
+
7
+ A simple ruby wrapper around [Contactually v2 Api](https://developers.contactually.com/docs/v2/).
8
+
9
+ __NOTE__: This is a heavily work in progress codebase, and will most definitely have breaking changes as things progress.
10
+
11
+ ## Installation
12
+
13
+ Gemfile
14
+
15
+ ```
16
+ gem 'contactually-rb', '~> 0.1.1'
17
+ ```
18
+
19
+ System
20
+
21
+ ```
22
+ gem install contactually-rb
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ Simple list contacts example,
28
+
29
+ ```ruby
30
+ require 'contactually'
31
+
32
+ client = Contactually::Client.new(auth_token: '<auth_token>')
33
+ # or
34
+ client = Contactually::Client.new(api_key: '<api_key>')
35
+
36
+ response = client.contacts.list
37
+ # => #<Contactually::Response>
38
+
39
+ response.data
40
+ # => #<Contactually::Collection>
41
+
42
+ response.data.total # => 73
43
+ response.raw_response # => #<Faraday::Response>
44
+
45
+ data = response.data
46
+ contact = data.first # => #<Contactually::Models::Contact>
47
+ contact.first_name # => "Nic"
48
+
49
+ ```
50
+
51
+ Loop through all contacts (it will yield contact and transparently loop through all contacts in batches of 50 using Contacutally pagination),
52
+
53
+ ```ruby
54
+ client = Contactually::Client.new(auth_token: '<auth_token>')
55
+
56
+ client.contacts.list_each do |contact|
57
+ # do something with contact
58
+ end
59
+ ```
60
+
61
+ ## Development
62
+
63
+ 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.
64
+
65
+ 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).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/contactually-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
70
+
71
+ ## Todos
72
+
73
+ - Support update endpoints
74
+ - Support Contact convenience endpoints (eg: /contacts/:id/notes)
75
+ - Support Create, Destroy endpoints
76
+ - Support other endpoints
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/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "contactually"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'contactually/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "contactually-rb"
8
+ spec.version = Contactually::VERSION
9
+ spec.authors = ["Nick Blumenthal", "Nic Cavigliano"]
10
+ spec.email = ["nick@realscout.com", "ncavig@gmail.com"]
11
+
12
+ spec.summary = ''
13
+ spec.description = ''
14
+ spec.homepage = "https://github.com/RealScout/contactually-api"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "faraday", "~> 0.9.2"
30
+ spec.add_dependency "faraday_middleware", "~> 0.10.0"
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.12"
33
+ spec.add_development_dependency "codeclimate-test-reporter", "~> 0.6.0"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "rspec", "~> 3.0"
36
+ spec.add_development_dependency "pry"
37
+ spec.add_development_dependency "webmock"
38
+ end
@@ -0,0 +1,72 @@
1
+ require 'date'
2
+ require 'forwardable'
3
+
4
+ require 'faraday'
5
+ require 'faraday_middleware'
6
+
7
+ require 'contactually/version'
8
+
9
+ module Contactually
10
+ class << self
11
+ attr_accessor :configuration
12
+ end
13
+
14
+ def self.configure
15
+ yield(configuration)
16
+ end
17
+
18
+ def self.configuration
19
+ @configuration ||= Configuration.new
20
+ end
21
+
22
+ class Configuration
23
+ attr_accessor :adapter
24
+
25
+ def initialize
26
+ @adapter = Faraday.default_adapter
27
+ end
28
+ end
29
+
30
+ class Error < StandardError
31
+ attr_reader :messages
32
+
33
+ def initialize(messages)
34
+ @messages = messages
35
+ super(messages.join(','))
36
+ end
37
+ end
38
+
39
+ class ForbiddenError < Error
40
+ end
41
+
42
+ class NotFoundError < Error
43
+ end
44
+
45
+ class UnauthorizedError < Error
46
+ end
47
+ end
48
+
49
+ require 'contactually/models/model'
50
+ require 'contactually/middleware/error_middleware'
51
+
52
+ require 'contactually/models/address'
53
+ require 'contactually/models/bucket'
54
+ require 'contactually/models/email_address'
55
+ require 'contactually/models/phone_number'
56
+ require 'contactually/models/social_media_profile'
57
+ require 'contactually/models/tag'
58
+ require 'contactually/models/website'
59
+ require 'contactually/models/contact'
60
+ require 'contactually/models/task'
61
+ require 'contactually/models/user'
62
+
63
+ require 'contactually/client'
64
+ require 'contactually/base'
65
+ require 'contactually/buckets'
66
+ require 'contactually/collection'
67
+ require 'contactually/contacts'
68
+ require 'contactually/interface'
69
+ require 'contactually/me'
70
+ require 'contactually/response'
71
+ require 'contactually/tags'
72
+ require 'contactually/tasks'
@@ -0,0 +1,88 @@
1
+ module Contactually
2
+ class Base
3
+ attr_reader :url, :interface
4
+
5
+ def self.implements(*method_list)
6
+ @implements = method_list
7
+ end
8
+
9
+ def self.implement_list
10
+ @implements
11
+ end
12
+
13
+ def initialize(url:, interface:)
14
+ @url = url
15
+ @interface = interface
16
+ end
17
+
18
+ def list(params = {})
19
+ check_implementation(:list)
20
+ Response.new(interface.get(url, params), self)
21
+ end
22
+
23
+ def list_each(params = {}, &block)
24
+ check_implementation(:list)
25
+
26
+ if block_given?
27
+ list_in_batches(params) do |items|
28
+ items.each do |item|
29
+ block.call(item)
30
+ end
31
+ end
32
+ else
33
+ enum_for :list_each, params
34
+ end
35
+ end
36
+
37
+ def create
38
+ check_implementation(:create)
39
+ end
40
+
41
+ def fetch(id, params = {})
42
+ check_implementation(:fetch)
43
+ Response.new(interface.get(build_fetch_url(id), params), self)
44
+ end
45
+
46
+ def update
47
+ check_implementation(:update)
48
+ end
49
+
50
+ def delete
51
+ check_implementation(:delete)
52
+ end
53
+
54
+ def check_implementation(method)
55
+ raise 'Error' unless self.class.implement_list.include?(method)
56
+ end
57
+
58
+ def model
59
+ OpenStruct
60
+ end
61
+
62
+ private
63
+
64
+ def build_fetch_url(id = nil)
65
+ if id
66
+ url + "/" + id.to_s
67
+ else
68
+ url
69
+ end
70
+ end
71
+
72
+ def list_in_batches(params)
73
+ collection = Response.new(interface.get(url, params), self).data
74
+ return unless collection.total > 0
75
+
76
+ while collection.items.any?
77
+ yield collection
78
+
79
+ break unless collection.has_next_page?
80
+
81
+ url = collection.next_page
82
+ _old_page = params.delete(:page)
83
+
84
+ collection = Response.new(interface.get(url, params), self).data
85
+ end
86
+ end
87
+ end
88
+ end