contactually-rb 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile.lock +4 -4
- data/README.md +32 -15
- data/contactually-api.gemspec +3 -3
- data/lib/contactually.rb +9 -0
- data/lib/contactually/base.rb +7 -4
- data/lib/contactually/buckets.rb +1 -1
- data/lib/contactually/client.rb +5 -1
- data/lib/contactually/contacts.rb +1 -1
- data/lib/contactually/interactions.rb +14 -0
- data/lib/contactually/interface.rb +17 -11
- data/lib/contactually/me.rb +5 -1
- data/lib/contactually/middleware/error_middleware.rb +10 -1
- data/lib/contactually/models/interaction.rb +19 -0
- data/lib/contactually/models/model.rb +6 -0
- data/lib/contactually/models/participant.rb +10 -0
- data/lib/contactually/tasks.rb +1 -1
- data/lib/contactually/version.rb +1 -1
- metadata +14 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ca86ed4a44105737365ae712c44cd516ca6239e
|
4
|
+
data.tar.gz: 2ba957b4f8e90c16ac3a35affdee95d5cc728eed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c6e12acce324a5a1c27c24294ced9e5dd44ee2cf85107df1cbfb7f3f35167b08ebfafa8c48beb2a92d75e35aa1465871e5c7241cf7a270171c3c492d6b966cc
|
7
|
+
data.tar.gz: b9818e01a7c379f8c32b9e25b901daac99b453232019a941f8f181b4a327dd2e83de57010282a6956f97500d049b7d5ebdfe8cdf7c3543156c0e198c71458971
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
contactually-rb (0.1.
|
4
|
+
contactually-rb (0.1.2)
|
5
5
|
faraday (~> 0.9.2)
|
6
6
|
faraday_middleware (~> 0.10.0)
|
7
7
|
|
@@ -61,10 +61,10 @@ DEPENDENCIES
|
|
61
61
|
bundler (~> 1.12)
|
62
62
|
codeclimate-test-reporter (~> 0.6.0)
|
63
63
|
contactually-rb!
|
64
|
-
pry
|
64
|
+
pry (~> 0.10)
|
65
65
|
rake (~> 10.0)
|
66
66
|
rspec (~> 3.0)
|
67
|
-
webmock
|
67
|
+
webmock (~> 2.1)
|
68
68
|
|
69
69
|
BUNDLED WITH
|
70
|
-
1.
|
70
|
+
1.13.6
|
data/README.md
CHANGED
@@ -24,7 +24,9 @@ gem install contactually-rb
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
Simple list contacts example
|
27
|
+
### Simple list contacts example
|
28
|
+
|
29
|
+
Create a client instance
|
28
30
|
|
29
31
|
```ruby
|
30
32
|
require 'contactually'
|
@@ -32,45 +34,60 @@ require 'contactually'
|
|
32
34
|
client = Contactually::Client.new(auth_token: '<auth_token>')
|
33
35
|
# or
|
34
36
|
client = Contactually::Client.new(api_key: '<api_key>')
|
37
|
+
```
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# List contacts
|
41
|
+
contacts = client.contacts.list
|
42
|
+
# => #<Contactually::Collection>
|
35
43
|
|
36
|
-
response
|
44
|
+
# Access to response wrapper
|
45
|
+
client.contacts.response
|
37
46
|
# => #<Contactually::Response>
|
38
47
|
|
39
|
-
response
|
40
|
-
|
48
|
+
# Raw farday response
|
49
|
+
client.contacts.response.raw_response
|
50
|
+
# => #<Faraday::Response>
|
41
51
|
|
42
|
-
|
43
|
-
|
52
|
+
contacts.total # => 73 Total contact count
|
53
|
+
contacts.size # => 50 Total contacts in current list
|
44
54
|
|
45
|
-
|
46
|
-
contact = data.first # => #<Contactually::Models::Contact>
|
55
|
+
contact = contacts.first # => #<Contactually::Models::Contact>
|
47
56
|
contact.first_name # => "Nic"
|
48
|
-
|
49
57
|
```
|
50
58
|
|
51
|
-
|
59
|
+
Looping through all contacts (it will yield contact and transparently loop through all contacts in batches of 50 using Contacutally pagination),
|
52
60
|
|
53
61
|
```ruby
|
54
62
|
client = Contactually::Client.new(auth_token: '<auth_token>')
|
55
63
|
|
56
64
|
client.contacts.list_each do |contact|
|
57
|
-
# do something with contact
|
65
|
+
# do something with contact, 50 per batch as specified by Contactually API
|
58
66
|
end
|
59
67
|
```
|
60
68
|
|
69
|
+
### Searching
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
collection = client.contacts.list({q: 'Nic'})
|
73
|
+
collection.first.name # => Nic
|
74
|
+
```
|
75
|
+
|
61
76
|
## Development
|
62
77
|
|
63
78
|
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
79
|
|
65
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
80
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
66
81
|
|
67
82
|
## Contributing
|
68
83
|
|
69
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
84
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/RealScout/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
85
|
|
71
86
|
## Todos
|
72
87
|
|
73
|
-
- Support update endpoints
|
88
|
+
- ~~Support update endpoints~~
|
74
89
|
- Support Contact convenience endpoints (eg: /contacts/:id/notes)
|
75
|
-
- Support Create, Destroy endpoints
|
90
|
+
- ~~Support Create, Destroy endpoints~~
|
76
91
|
- Support other endpoints
|
92
|
+
- Better client testing support (`Contactually.configuration.test_mode = true`)
|
93
|
+
- Documentation
|
data/contactually-api.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Nick Blumenthal", "Nic Cavigliano"]
|
10
10
|
spec.email = ["nick@realscout.com", "ncavig@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = ''
|
12
|
+
spec.summary = 'Simple wrapper around Contactually v2 API'
|
13
13
|
spec.description = ''
|
14
14
|
spec.homepage = "https://github.com/RealScout/contactually-api"
|
15
15
|
|
@@ -33,6 +33,6 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.6.0"
|
34
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
35
|
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
-
spec.add_development_dependency "pry"
|
37
|
-
spec.add_development_dependency "webmock"
|
36
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
37
|
+
spec.add_development_dependency "webmock", "~> 2.1"
|
38
38
|
end
|
data/lib/contactually.rb
CHANGED
@@ -42,8 +42,14 @@ module Contactually
|
|
42
42
|
class NotFoundError < Error
|
43
43
|
end
|
44
44
|
|
45
|
+
class PaymentRequiredError < Error
|
46
|
+
end
|
47
|
+
|
45
48
|
class UnauthorizedError < Error
|
46
49
|
end
|
50
|
+
|
51
|
+
class TypeMismatchError < Error
|
52
|
+
end
|
47
53
|
end
|
48
54
|
|
49
55
|
require 'contactually/models/model'
|
@@ -52,11 +58,13 @@ require 'contactually/middleware/error_middleware'
|
|
52
58
|
require 'contactually/models/address'
|
53
59
|
require 'contactually/models/bucket'
|
54
60
|
require 'contactually/models/email_address'
|
61
|
+
require 'contactually/models/participant'
|
55
62
|
require 'contactually/models/phone_number'
|
56
63
|
require 'contactually/models/social_media_profile'
|
57
64
|
require 'contactually/models/tag'
|
58
65
|
require 'contactually/models/website'
|
59
66
|
require 'contactually/models/contact'
|
67
|
+
require 'contactually/models/interaction'
|
60
68
|
require 'contactually/models/task'
|
61
69
|
require 'contactually/models/user'
|
62
70
|
|
@@ -65,6 +73,7 @@ require 'contactually/base'
|
|
65
73
|
require 'contactually/buckets'
|
66
74
|
require 'contactually/collection'
|
67
75
|
require 'contactually/contacts'
|
76
|
+
require 'contactually/interactions'
|
68
77
|
require 'contactually/interface'
|
69
78
|
require 'contactually/me'
|
70
79
|
require 'contactually/response'
|
data/lib/contactually/base.rb
CHANGED
@@ -34,8 +34,9 @@ module Contactually
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
def create
|
37
|
+
def create(body)
|
38
38
|
check_implementation(:create)
|
39
|
+
Response.new(interface.post(build_fetch_url, body), self)
|
39
40
|
end
|
40
41
|
|
41
42
|
def fetch(id, params = {})
|
@@ -43,12 +44,14 @@ module Contactually
|
|
43
44
|
Response.new(interface.get(build_fetch_url(id), params), self)
|
44
45
|
end
|
45
46
|
|
46
|
-
def update
|
47
|
+
def update(id, body)
|
47
48
|
check_implementation(:update)
|
49
|
+
Response.new(interface.patch(build_fetch_url(id), body), self)
|
48
50
|
end
|
49
51
|
|
50
|
-
def
|
51
|
-
check_implementation(:
|
52
|
+
def destroy(id)
|
53
|
+
check_implementation(:destroy)
|
54
|
+
interface.destroy(build_fetch_url(id))
|
52
55
|
end
|
53
56
|
|
54
57
|
def check_implementation(method)
|
data/lib/contactually/buckets.rb
CHANGED
data/lib/contactually/client.rb
CHANGED
@@ -21,8 +21,12 @@ module Contactually
|
|
21
21
|
@contacts ||= Contactually::Contacts.new(interface: interface)
|
22
22
|
end
|
23
23
|
|
24
|
+
def interactions
|
25
|
+
@interactions ||= Contactually::Interactions.new(interface: interface)
|
26
|
+
end
|
27
|
+
|
24
28
|
def me
|
25
|
-
@
|
29
|
+
@me ||= Contactually::Me.new(interface: interface)
|
26
30
|
end
|
27
31
|
|
28
32
|
def tags
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Contactually
|
2
|
+
class Interactions < Base
|
3
|
+
implements :create, :fetch, :update, :destroy
|
4
|
+
|
5
|
+
def initialize(url: '/v2/interactions', interface: nil)
|
6
|
+
@url = url
|
7
|
+
@interface = interface
|
8
|
+
end
|
9
|
+
|
10
|
+
def model
|
11
|
+
Models::Interaction
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -7,22 +7,35 @@ module Contactually
|
|
7
7
|
@api_key = api_key
|
8
8
|
@adapter = Contactually.configuration.adapter || :net_http
|
9
9
|
@base_url = base_url
|
10
|
-
|
11
|
-
set_headers
|
12
10
|
end
|
13
11
|
|
14
12
|
def get(url, params)
|
15
13
|
connection.get(build_full_url(url), params)
|
16
14
|
end
|
17
15
|
|
16
|
+
def patch(url, body)
|
17
|
+
connection.patch(build_full_url(url), body)
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(url, body)
|
21
|
+
connection.post(build_full_url(url), body)
|
22
|
+
end
|
23
|
+
|
24
|
+
def destroy(url)
|
25
|
+
connection.delete(build_full_url(url))
|
26
|
+
end
|
27
|
+
|
18
28
|
def connection
|
19
29
|
@connection ||= Faraday.new do |conn|
|
20
|
-
conn.
|
30
|
+
conn.request :json
|
31
|
+
|
21
32
|
conn.response :json, :content_type => /\bjson$/
|
22
33
|
conn.use Contactually::Middleware::ErrorHandler
|
23
34
|
|
24
|
-
conn.headers['Content-type'] = 'application/json',
|
25
35
|
conn.headers['Authorization'] = "Bearer #{token}"
|
36
|
+
conn.headers['Content-type'] = 'application/json'
|
37
|
+
|
38
|
+
conn.adapter @adapter
|
26
39
|
end
|
27
40
|
end
|
28
41
|
|
@@ -39,12 +52,5 @@ module Contactually
|
|
39
52
|
def token
|
40
53
|
auth_token || api_key
|
41
54
|
end
|
42
|
-
|
43
|
-
def set_headers
|
44
|
-
@headers = {
|
45
|
-
'Content-type' => 'application/json',
|
46
|
-
'Authorization' => "Bearer #{token}"
|
47
|
-
}
|
48
|
-
end
|
49
55
|
end
|
50
56
|
end
|
data/lib/contactually/me.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Contactually
|
2
2
|
class Me < Base
|
3
|
-
implements :fetch
|
3
|
+
implements :fetch, :update
|
4
4
|
|
5
5
|
def initialize(url: '/v2/me', interface: nil)
|
6
6
|
@url = url
|
@@ -11,6 +11,10 @@ module Contactually
|
|
11
11
|
super(nil)
|
12
12
|
end
|
13
13
|
|
14
|
+
def update(body)
|
15
|
+
super(nil, body)
|
16
|
+
end
|
17
|
+
|
14
18
|
def model
|
15
19
|
Models::User
|
16
20
|
end
|
@@ -7,6 +7,9 @@ module Contactually
|
|
7
7
|
when 401
|
8
8
|
# Missing or invalid auth token
|
9
9
|
raise Contactually::UnauthorizedError.new(error_messages(env.response))
|
10
|
+
when 402
|
11
|
+
# Auth token could be invalid due to non-payment
|
12
|
+
raise Contactually::PaymentRequiredError.new(error_messages(env.response))
|
10
13
|
when 403
|
11
14
|
# App does not have permission to perform the operation
|
12
15
|
raise Contactually::ForbiddenError.new(error_messages(env.response))
|
@@ -25,7 +28,13 @@ module Contactually
|
|
25
28
|
body = parse_body(response)
|
26
29
|
|
27
30
|
if body.has_key?('errors')
|
28
|
-
body['errors']
|
31
|
+
case body['errors']
|
32
|
+
when Array
|
33
|
+
body['errors']
|
34
|
+
else
|
35
|
+
# Sometimes Contactually returns an errors key with a nested object instead of a list of errors
|
36
|
+
[body['errors'].to_s]
|
37
|
+
end
|
29
38
|
else
|
30
39
|
generic_error
|
31
40
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Contactually
|
2
|
+
module Models
|
3
|
+
class Interaction
|
4
|
+
include Model
|
5
|
+
|
6
|
+
field :created_at, :datetime
|
7
|
+
field :body, :string
|
8
|
+
field :id, :string
|
9
|
+
field :initiated_by_contact, :boolean
|
10
|
+
field :participants, [Participant]
|
11
|
+
field :subject, :string
|
12
|
+
field :type, :string
|
13
|
+
|
14
|
+
# field :custom_fields, [String] TODO: should be it's own model type
|
15
|
+
field :extra_data, Hash
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -41,6 +41,12 @@ module Contactually
|
|
41
41
|
when :integer then value.to_i
|
42
42
|
when :float then value.to_f
|
43
43
|
when :date then value.to_date
|
44
|
+
when :boolean
|
45
|
+
if !!value == value
|
46
|
+
value
|
47
|
+
else
|
48
|
+
raise Contactually::TypeMismatchError.new(["Expected a boolean but got #{value.class}"])
|
49
|
+
end
|
44
50
|
when :datetime then DateTime.parse(value)
|
45
51
|
else
|
46
52
|
case type
|
data/lib/contactually/tasks.rb
CHANGED
data/lib/contactually/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contactually-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Blumenthal
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-01-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -99,30 +99,30 @@ dependencies:
|
|
99
99
|
name: pry
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - "
|
102
|
+
- - "~>"
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: '0'
|
104
|
+
version: '0.10'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - "
|
109
|
+
- - "~>"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: '0'
|
111
|
+
version: '0.10'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: webmock
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
115
115
|
requirements:
|
116
|
-
- - "
|
116
|
+
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
118
|
+
version: '2.1'
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- - "
|
123
|
+
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: '
|
125
|
+
version: '2.1'
|
126
126
|
description: ''
|
127
127
|
email:
|
128
128
|
- nick@realscout.com
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- lib/contactually/client.rb
|
152
152
|
- lib/contactually/collection.rb
|
153
153
|
- lib/contactually/contacts.rb
|
154
|
+
- lib/contactually/interactions.rb
|
154
155
|
- lib/contactually/interface.rb
|
155
156
|
- lib/contactually/me.rb
|
156
157
|
- lib/contactually/middleware/error_middleware.rb
|
@@ -158,7 +159,9 @@ files:
|
|
158
159
|
- lib/contactually/models/bucket.rb
|
159
160
|
- lib/contactually/models/contact.rb
|
160
161
|
- lib/contactually/models/email_address.rb
|
162
|
+
- lib/contactually/models/interaction.rb
|
161
163
|
- lib/contactually/models/model.rb
|
164
|
+
- lib/contactually/models/participant.rb
|
162
165
|
- lib/contactually/models/phone_number.rb
|
163
166
|
- lib/contactually/models/social_media_profile.rb
|
164
167
|
- lib/contactually/models/tag.rb
|
@@ -192,6 +195,5 @@ rubyforge_project:
|
|
192
195
|
rubygems_version: 2.5.1
|
193
196
|
signing_key:
|
194
197
|
specification_version: 4
|
195
|
-
summary:
|
198
|
+
summary: Simple wrapper around Contactually v2 API
|
196
199
|
test_files: []
|
197
|
-
has_rdoc:
|