outreach 0.0.1

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: 72f658d033d57bbdbf06abb68f300d63f660260a
4
+ data.tar.gz: 698a2d0171428bb54be9e047761540ef44544b20
5
+ SHA512:
6
+ metadata.gz: 2b3be014ee575b6e5f3f682171c8fd14f41ab74ddb7bd9e364fe29bbedb18b9c73ed4dc7c32e1a462df012cdcc4e6c7a0fcd8b933ad172d5dd54282dc49e0a61
7
+ data.tar.gz: 43918793ef5f573a5bae628231880f7db7a817644c743b4abe84f3085b48c3219c45411c54b28e91255af2343750a1c67014a6d8303cfaaee4ef77a1791b9fd5
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /bin
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.gem
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.3.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in outreach.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chris O'Sullivan
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,116 @@
1
+ # Outreach
2
+
3
+ outreach is a wrapper for the outreach.io REST API.
4
+
5
+ You can find the outreach.io api docs here: https://github.com/getoutreach/outreach-platform-sdk
6
+
7
+ ## Installation
8
+
9
+ First off you need to grab your [outreach.io](https://www.outreach.io) api oauth keys. You can sign up for access [here](http://goo.gl/forms/RWk35DeZAK)
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'outreach'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install outrach
24
+
25
+ Set your api access with:
26
+ ```ruby
27
+ Outreach.application_identifier = 'YOUR APPLICATION IDENTIFIER'
28
+ Outreach.application_secret = 'YOUR APPLICATION SECRET'
29
+ Outreach.scopes = 'SCOPES FOR API ACCESS'
30
+ Outreach.redirect_uri = 'YOUR REDIRECT URI UPON OAUTH'
31
+ ```
32
+ (Put this into an initializer i.e. ```app/initializers/outreach.rb``` if using Rails.)
33
+
34
+ ## Authorization
35
+ First off you need to grab the authorization key for your user. You do this by getting them to follow the authorization URL:
36
+ ```ruby
37
+ Outreach::Authorization.authorization_url
38
+ ```
39
+
40
+ For example, if using Rails this could be in a view
41
+ ```
42
+ <%= link_to("Connect to Outreach", Outreach::Authorization.authorization_url)
43
+ ```
44
+
45
+ This will take the user through the oauth process - afterwards they will be redirected back to your site to whatever the url you have setup in Outreach.redirect_uri. This will also provide the authorization key so you can get access for that user using the Outreach::Authorization.create method.
46
+
47
+ Here's a Rails example:
48
+
49
+ ```ruby
50
+ class OutreachController < ApplicationController
51
+
52
+ def callback
53
+ user = current_user
54
+ user.auth_code = params[:code]
55
+
56
+ codes = Outreach::Authorization.create(params[:code])
57
+ user.access_code = codes.token
58
+ user.refresh_code = codes.refresh_token
59
+ user.save
60
+
61
+ flash[:notice] = "Outreach oauth connected"
62
+ redirect_to home_path
63
+ end
64
+ end
65
+ ```
66
+
67
+ The access code can expire, but this can be refreshed using the refresh token
68
+
69
+ ```ruby
70
+ # after authorization exception
71
+ codes = Outreach::Authorization.refresh(user.refresh_code)
72
+ user.access_code = codes.token
73
+ user.refresh_code = codes.refresh_token
74
+ user.save
75
+ ```
76
+
77
+ ## API Client
78
+ Once you have the access code for a user you can then create an api client for that user.
79
+ ```ruby
80
+ client = Outreach::Client.new(user.access_code)
81
+ ```
82
+
83
+ ## Prospects
84
+ To find all prospects:
85
+ ```ruby
86
+ client.prospects.all
87
+ # returns an array of prospects
88
+ ```
89
+
90
+ Filtering is possible by using the following conditions:
91
+ ```ruby
92
+ # first_name
93
+ # last_name
94
+ # email
95
+ # company_name
96
+ # e.g.
97
+ client.prospects.all({ first_name: "Chris", last_name: "O'Sullivan" })
98
+ ```
99
+
100
+ The results of client.prospects.all is paginated. You can control pagination by passing in which page you want to see:
101
+ ```ruby
102
+ client.prospects.all({ page: 2 })
103
+ ```
104
+
105
+ You can find a specific prospect given the prospect id:
106
+ ```ruby
107
+ clients.prospect.find(2345)
108
+ ```
109
+
110
+ ## Contributing
111
+
112
+ 1. Fork it ( https://github.com/[my-github-username]/outreach/fork )
113
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
114
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
115
+ 4. Push to the branch (`git push origin my-new-feature`)
116
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,50 @@
1
+ require 'uri'
2
+
3
+ module Outreach
4
+ class Authorization
5
+ API_URL = "https://api.outreach.io/oauth/token"
6
+
7
+ attr_reader :token, :refresh_token, :expires_in
8
+
9
+ def initialize(attrs)
10
+ @token = attrs[:access_token]
11
+ @refresh_token = attrs[:refresh_token]
12
+ @expires_in = attrs[:expires_in]
13
+ end
14
+
15
+ def self.authorization_url
16
+ url = "https://api.outreach.io/oauth/authorize"
17
+ params = {
18
+ client_id: Outreach.application_identifier,
19
+ redirect_uri: Outreach.redirect_uri,
20
+ response_type: 'code',
21
+ scope: Outreach.scopes
22
+ }
23
+ url + "?" + URI.encode_www_form(params)
24
+ end
25
+
26
+ def self.create(authorization_code)
27
+ params = {
28
+ client_id: Outreach.application_identifier,
29
+ client_secret: Outreach.application_secret,
30
+ redirect_uri: Outreach.redirect_uri,
31
+ grant_type: 'authorization_code',
32
+ code: authorization_code
33
+ }
34
+ response = Request.new.post(API_URL, params)
35
+ new(response)
36
+ end
37
+
38
+ def self.refresh(refresh_token)
39
+ params = {
40
+ client_id: Outreach.application_identifier,
41
+ client_secret: Outreach.application_secret,
42
+ redirect_uri: Outreach.redirect_uri,
43
+ grant_type: 'refresh_token',
44
+ refresh_token: refresh_token
45
+ }
46
+ response = Request.new.post(API_URL, params)
47
+ new(response)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,17 @@
1
+ module Outreach
2
+ class Client
3
+ def initialize(api_token)
4
+ @api_token = api_token
5
+ end
6
+
7
+ def prospect
8
+ Outreach::ProspectFinder.new(request)
9
+ end
10
+
11
+ private
12
+
13
+ def request
14
+ Request.new(@api_token)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+
3
+ module Outreach
4
+ module Errors
5
+ class Unauthorized < StandardError; end
6
+
7
+ def check_for_error(status_code)
8
+ # raise error if status code isn't 200
9
+ case status_code.to_i
10
+ when 401
11
+ raise Unauthorized.new("Authorization failed")
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,58 @@
1
+ module Outreach
2
+ class Prospect
3
+ attr_accessor :first_name, :last_name, :company, :contact, :tags
4
+
5
+ def initialize(attrs)
6
+ @first_name = attrs['attributes']['personal']['name']['first']
7
+ @last_name = attrs['attributes']['personal']['name']['last']
8
+ @company = to_ostruct(attrs['attributes']['company'])
9
+ @contact = to_ostruct(attrs['attributes']['contact'])
10
+ @tags = attrs['attributes']['metadata']['tags']
11
+ end
12
+
13
+ private
14
+
15
+ def to_ostruct(hash)
16
+ o = OpenStruct.new(hash)
17
+ hash.each.with_object(o) do |(k,v), o|
18
+ o.send(:"#{k}=", to_ostruct(v)) if v.is_a? Hash
19
+ end
20
+ o
21
+ end
22
+ end
23
+
24
+ class ProspectFinder
25
+ API_URL = "https://api.outreach.io/1.0/prospects"
26
+
27
+ def initialize(request)
28
+ @request = request
29
+ end
30
+
31
+ def find(id)
32
+ response = @request.get("#{API_URL}/#{id}")
33
+ Prospect.new(response)
34
+ end
35
+
36
+ def all(attrs={})
37
+ response = @request.get(API_URL, attribute_mapping(attrs))
38
+ response['data'].map {|attrs| Prospect.new(attrs)}
39
+ end
40
+
41
+ private
42
+
43
+ def attribute_mapping(attrs)
44
+ if attrs[:first_name]
45
+ attrs["filter[personal/name/first]"] = attrs.delete(:first_name)
46
+ end
47
+ if attrs[:last_name]
48
+ attrs["filter[personal/name/last]"] = attrs.delete(:last_name)
49
+ end
50
+ attrs["filter[contact/email]"] = attrs.delete(:email) if attrs[:email]
51
+ if attrs[:company_name]
52
+ attrs["filter[company/name]"] = attrs.delete(company_name)
53
+ end
54
+ attrs
55
+ end
56
+ end
57
+ end
58
+
@@ -0,0 +1,57 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Outreach
5
+
6
+ class Request
7
+
8
+ include HTTParty
9
+ include Errors
10
+
11
+ def initialize(access_token=nil)
12
+ @access_token = access_token
13
+ end
14
+
15
+ def get(url, query={})
16
+ response = HTTParty.get(url, query: query, headers: auth_header)
17
+ parse_response(response)
18
+ end
19
+
20
+ def post(url, params)
21
+ response_format = params.delete(:response_format) || :json
22
+ response = HTTParty.post(url, body: params.to_json, headers: auth_header)
23
+ parse_response(response, response_format)
24
+ end
25
+
26
+ def delete(url)
27
+ response = HTTParty.delete(url, headers: auth_header)
28
+ parse_response(response)
29
+ end
30
+
31
+ private
32
+
33
+ def parse_response(response, response_format=:json)
34
+ check_for_error(response.response.code)
35
+ display_debug(response.body)
36
+ if response_format == :json
37
+ JSON.parse(response.body.to_s)
38
+ else
39
+ response.body.to_s
40
+ end
41
+ end
42
+
43
+ def display_debug(response)
44
+ if Outreach.debug
45
+ puts "-" * 20 + " DEBUG " + "-" * 20
46
+ puts response
47
+ puts "-" * 18 + " END DEBUG " + "-" * 18
48
+ end
49
+ end
50
+
51
+ def auth_header
52
+ headers = { 'Content-Type' => 'application/json' }
53
+ headers["Authorization"] = "Bearer #{@access_token}" if @access_token
54
+ headers
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Outreach
2
+ VERSION = "0.0.1"
3
+ end
data/lib/outreach.rb ADDED
@@ -0,0 +1,16 @@
1
+ require "outreach/version"
2
+ require "outreach/errors"
3
+ require "outreach/request"
4
+ require "outreach/authorization"
5
+ require "outreach/client"
6
+ require "outreach/prospect"
7
+
8
+ module Outreach
9
+ class << self
10
+ attr_accessor :application_identifier
11
+ attr_accessor :application_secret
12
+ attr_accessor :scopes
13
+ attr_accessor :redirect_uri
14
+ attr_accessor :debug
15
+ end
16
+ end
data/outreach.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'outreach/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "outreach"
8
+ spec.version = Outreach::VERSION
9
+ spec.authors = ["Chris O'Sullivan"]
10
+ spec.email = ["thechrisoshow@gmail.com"]
11
+
12
+ spec.summary = %q{outreach is a wrapper for the outreach.io REST API}
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.9"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+
23
+ spec.add_development_dependency "rspec", "~> 3.4"
24
+ spec.add_development_dependency "webmock", "~> 1.24"
25
+
26
+ spec.add_dependency "httparty", "~> 0.13"
27
+ spec.add_dependency "json", "~> 1.8"
28
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: outreach
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chris O'Sullivan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-04 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.24'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.24'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.13'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.13'
83
+ - !ruby/object:Gem::Dependency
84
+ name: json
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.8'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.8'
97
+ description:
98
+ email:
99
+ - thechrisoshow@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/outreach.rb
112
+ - lib/outreach/authorization.rb
113
+ - lib/outreach/client.rb
114
+ - lib/outreach/errors.rb
115
+ - lib/outreach/prospect.rb
116
+ - lib/outreach/request.rb
117
+ - lib/outreach/version.rb
118
+ - outreach.gemspec
119
+ homepage:
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.5.1
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: outreach is a wrapper for the outreach.io REST API
143
+ test_files: []
144
+ has_rdoc: