yesgraph 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e72432bc882ad0a203aaf7284f4e8117844250c8
4
+ data.tar.gz: 1441278b7a133a192f41061684f58c22677dd13a
5
+ SHA512:
6
+ metadata.gz: 5d8a5ed713be9f690de2865e001cdc60b2aa3cc0a42de1a506b5ce4220bb394cd31c1781a9d6c02b8826520af06ba8c44486ab3aa5d1fa3b4d6c20f55d3adbc0
7
+ data.tar.gz: d95dbffc6e093c8031a865795fbe2d0ed20366a954ca558c96e4a5a998450500a5a54299c440d927f547e855863cb922c8d70caf7d12fa89270d1e88afee07ba
@@ -0,0 +1,2 @@
1
+ .ruby-version
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yesgraph.gemspec
4
+ gemspec
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2017 YesGraph, Inc.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
20
+ OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ # Ruby YesGraph
2
+
3
+ Ruby wrapper for the YesGraph API.
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yesgraph"
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
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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,204 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yesgraph/version'
4
+ require 'uri'
5
+ require 'rest-client'
6
+ require 'json'
7
+ require 'cgi'
8
+
9
+ BASE_URL = 'https://api.yesgraph.com/v0/'
10
+
11
+ module Yesgraph
12
+ class YesGraphAPI
13
+ # Wrapper Class
14
+ attr_reader :secret_key, :base_url
15
+ def initialize(secret_key, base_url = BASE_URL)
16
+ @secret_key = secret_key
17
+ @base_url = base_url
18
+ end
19
+
20
+ def user_agent
21
+ client_info = ['ruby-yesgraph', Yesgraph::VERSION].join('-')
22
+ host_info = RbConfig::CONFIG['host']
23
+ language_info = RbConfig::CONFIG['RUBY_VERSION_NAME']
24
+ [client_info, host_info, language_info].join(' ')
25
+ end
26
+
27
+ def build_url(endpoint, url_args = {})
28
+ base_url_cleaned = base_url.sub(%r{\/+$}, '')
29
+ endpoint_cleaned = endpoint.sub(%r{^\/+}, '')
30
+ url = [base_url_cleaned, endpoint_cleaned].join('/')
31
+ url_args.delete_if { |_, v| v.to_s.strip.empty? }
32
+ unless url_args.empty?
33
+ args = URI.encode_www_form(url_args)
34
+ url = "#{url}?#{args}"
35
+ end
36
+ url
37
+ end
38
+
39
+ def request(method, endpoint, data = {}, url_args = {})
40
+ # Builds and sends the complete request.
41
+ headers = {
42
+ 'Authorization' => "Bearer #{secret_key}",
43
+ 'Content-Type' => 'application/json',
44
+ 'User-Agent' => user_agent
45
+ }
46
+
47
+ url = build_url(endpoint, url_args)
48
+ resp = RestClient::Request.execute(method: method, url: url,
49
+ payload: data.to_s,
50
+ headers: headers)
51
+ JSON.parse(resp.body)
52
+ end
53
+
54
+ def test
55
+ # Wrapped method for GET of /test endpoint
56
+ #
57
+ # Documentation - https://docs.yesgraph.com/docs/test
58
+
59
+ request(:get, '/test')
60
+ end
61
+
62
+ def get_client_key(user_id)
63
+ # Wrapped method for POST of /client-key endpoint
64
+ #
65
+ # Documentation - https://docs.yesgraph.com/docs/create-client-keys
66
+
67
+ data = JSON.dump('user_id': user_id.to_s)
68
+ result = request(:post, '/client-key', data)
69
+ result['client_key']
70
+ end
71
+
72
+ def post_address_book(user_id, entries, source_type, source_name: nil,
73
+ source_email: nil, filter_suggested_seen: nil,
74
+ filter_existing_users: nil,
75
+ filter_invites_sent: nil,
76
+ filter_blank_names: nil,
77
+ promote_existing_users: nil,
78
+ promote_matching_domain: nil,
79
+ backfill: nil,
80
+ limit: nil)
81
+ # Wrapped method for POST of /address-book endpoint
82
+ #
83
+ # Documentation - https://docs.yesgraph.com/docs/address-book
84
+
85
+ source = { 'type' => source_type }
86
+ source['name'] = source_name if source_name
87
+ source['email'] = source_email if source_email
88
+
89
+ raise('`limit` param is not an int') unless limit.nil? ||
90
+ (limit.is_a? Integer)
91
+ raise('`backfill` param is not an int') unless backfill.nil? ||
92
+ (backfill.is_a? Integer)
93
+
94
+ data = {
95
+ 'user_id' => user_id.to_s,
96
+ 'filter_suggested_seen' => filter_suggested_seen,
97
+ 'filter_existing_users' => filter_existing_users,
98
+ 'filter_invites_sent' => filter_invites_sent,
99
+ 'filter_blank_names' => filter_blank_names,
100
+ 'promote_existing_users' => promote_existing_users,
101
+ 'promote_matching_domain' => promote_matching_domain,
102
+ 'source' => source,
103
+ 'entries' => entries,
104
+ 'limit' => limit,
105
+ 'backfill' => backfill
106
+ }
107
+ data = JSON.dump(data)
108
+ request(:post, '/address-book', data)
109
+ end
110
+
111
+ def get_address_book(user_id, filter_suggested_seen: nil,
112
+ filter_existing_users: nil,
113
+ filter_invites_sent: nil,
114
+ promote_existing_users: nil,
115
+ promote_matching_domain: nil,
116
+ filter_blank_names: nil,
117
+ limit: nil)
118
+ # Wrapped method for GET of /address-book endpoint
119
+ #
120
+ # Documentation - https://docs.yesgraph.com/docs/address-book#section-get-address-bookuser_id
121
+
122
+ raise('`limit` param is not an int') unless limit.nil? ||
123
+ (limit.is_a? Integer)
124
+
125
+ urlargs = {
126
+ 'filter_suggested_seen' => filter_suggested_seen,
127
+ 'filter_existing_users' => filter_existing_users,
128
+ 'filter_invites_sent' => filter_invites_sent,
129
+ 'filter_blank_names' => filter_blank_names,
130
+ 'promote_existing_users' => promote_existing_users,
131
+ 'promote_matching_domain' => promote_matching_domain,
132
+ 'limit' => limit
133
+ }
134
+
135
+ user_id = CGI.escape(user_id.to_s)
136
+ endpoint = "/address-book/#{user_id}"
137
+ request(:get, endpoint, {}, urlargs)
138
+ end
139
+
140
+ def delete_address_book(user_id)
141
+ # Wrapped method for DELETE /address-book/:user_id endpoint
142
+ #
143
+ # Documentation - https://docs.yesgraph.com/docs/address-book#section-delete-address-bookuser_id
144
+
145
+ user_id = CGI.escape(user_id.to_s)
146
+ endpoint = "/address-book/#{user_id}"
147
+ request(:delete, endpoint)
148
+ end
149
+
150
+ def post_invites_accepted(entries)
151
+ # Wrapped method for POST of /invites-accepted endpoint
152
+ #
153
+ # Documentation - https://docs.yesgraph.com/docs/invites-accepted
154
+
155
+ raise('An entry list is required') unless entries && (entries.is_a? Array)
156
+ data = { 'entries' => entries }
157
+ data = JSON.dump(data)
158
+ request(:post, '/invites-accepted', data)
159
+ end
160
+
161
+ def post_invites_sent(entries)
162
+ # Wrapped method for POST of /invites-sent endpoint
163
+ #
164
+ # Documentation - https://docs.yesgraph.com/docs/invites-sent
165
+
166
+ raise('An entry list is required') unless entries && (entries.is_a? Array)
167
+ data = { 'entries' => entries }
168
+ data = JSON.dump(data)
169
+ request(:post, '/invites-sent', data)
170
+ end
171
+
172
+ def post_suggested_seen(entries)
173
+ # Wrapped method for POST of /suggested-seen endpoint
174
+ #
175
+ # Documentation - https://docs.yesgraph.com/docs/suggested-seen
176
+
177
+ raise('An entry list is required') unless entries && (entries.is_a? Array)
178
+ data = { 'entries' => entries }
179
+ data = JSON.dump(data)
180
+ request(:post, '/suggested-seen', data)
181
+ end
182
+
183
+ def post_users(users)
184
+ # Wrapped method for POST of users endpoint
185
+ #
186
+ # Documentation - https://docs.yesgraph.com/docs/users
187
+
188
+ data = JSON.dump(users)
189
+ request(:post, '/users', data)
190
+ end
191
+
192
+ def get_domain_emails(domain, page: nil, batch_size: nil)
193
+ # Wrapped method for GET of /domain-emails/<domain> endpoint
194
+ #
195
+ # Documentation - https://docs.yesgraph.com/docs/domain-emails/
196
+
197
+ urlargs = { 'page' => page, 'batch_size' => batch_size }
198
+
199
+ domain = CGI.escape(domain.to_s)
200
+ endpoint = "/domain-emails/#{domain}"
201
+ request(:get, endpoint, {}, urlargs)
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,3 @@
1
+ module Yesgraph
2
+ VERSION = "0.1.0"
3
+ end
data/test.rb ADDED
@@ -0,0 +1,82 @@
1
+ require 'yesgraph'
2
+ require 'json'
3
+
4
+ yg = Yesgraph::YesGraphAPI.new(SECRET_KEY)
5
+
6
+ entries = [
7
+ {'name'=> 'Ivan Kirigin', 'email'=> 'ivan@yesgraph.com'},
8
+ {'name'=> 'Bar', 'email'=> 'bar@example.org'}
9
+ ]
10
+
11
+ res = yg.post_address_book(1, entries, 'gmail', source_name: 'Mayank Juneja', source_email: 'mayank@yesgraph.com')
12
+ puts JSON.pretty_generate(res)
13
+ puts('===')
14
+
15
+ res=yg.post_address_book(1, entries, 'gmail', source_name: 'Mayank Juneja', source_email: 'mayank@yesgraph.com', backfill: 1)
16
+ puts JSON.pretty_generate(res)
17
+ puts('===')
18
+
19
+ res = yg.get_address_book(1 )
20
+ puts JSON.pretty_generate(res)
21
+ puts('===')
22
+
23
+ # res = yg.delete_address_book(1 )
24
+ # puts JSON.pretty_generate(res)
25
+ # puts('===')
26
+
27
+ entries = [
28
+ {
29
+ 'user_id'=> '1111',
30
+ 'invitee_name'=> 'Carolyn',
31
+ 'email'=> 'carolyn@yesgraph.com',
32
+ 'phone'=> '2223332222',
33
+ 'sent_at'=> '2017-02-28T20:16:12+00:00'
34
+ }
35
+ ]
36
+
37
+ res = yg.post_invites_sent(entries)
38
+ puts JSON.pretty_generate(res)
39
+ puts('===')
40
+
41
+
42
+ entries = [{'new_user_id'=> '1111',
43
+ 'name':'Carolyn',
44
+ 'email':'carolyn@yesgraph.com',
45
+ 'phone'=> '4442223333',
46
+ 'accepted_at'=> '2017-02-28T20:16:12+00:00'
47
+ }]
48
+
49
+ res = yg.post_invites_accepted(entries)
50
+ puts JSON.pretty_generate(res)
51
+ puts('===')
52
+
53
+ entries = [{'user_id'=> '1111',
54
+ 'name':'Carolyn',
55
+ 'emails'=> ['carolyn@yesgraph.com'],
56
+ 'seen_at'=> '2017-02-28T20:16:12+00:00'
57
+ }]
58
+
59
+ res = yg.post_suggested_seen(entries)
60
+ puts JSON.pretty_generate(res)
61
+ puts('===')
62
+
63
+
64
+ users = [
65
+ {
66
+ 'username'=> 'mayank',
67
+ 'name'=> 'Mayank Juneja',
68
+ 'email'=> 'mayank@yesgraph.com'
69
+ },
70
+ {
71
+ 'id'=> '1234',
72
+ 'email'=> 'ivan@yesgraph.com'
73
+ }
74
+ ]
75
+
76
+ res = yg.post_users(users)
77
+ puts JSON.pretty_generate(res)
78
+ puts('===')
79
+
80
+ res = yg.get_domain_emails('yesgraph.com')
81
+ puts JSON.pretty_generate(res)
82
+ puts('===')
@@ -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 'yesgraph/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yesgraph"
8
+ spec.version = Yesgraph::VERSION
9
+ spec.authors = ["Mayank Juneja"]
10
+ spec.email = ["mayank@yesgraph.com"]
11
+
12
+ spec.summary = %q{Ruby wrapper for YesGraph API}
13
+ spec.description = %q{Ruby wrapper for YesGraph API}
14
+ spec.homepage = "https://github.com/YesGraph/ruby-yesgraph"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.2"
27
+ spec.add_development_dependency "rest-client", "~> 2.0"
28
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yesgraph
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mayank Juneja
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-27 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.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
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.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ description: Ruby wrapper for YesGraph API
70
+ email:
71
+ - mayank@yesgraph.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - lib/yesgraph.rb
84
+ - lib/yesgraph/version.rb
85
+ - test.rb
86
+ - yesgraph.gemspec
87
+ homepage: https://github.com/YesGraph/ruby-yesgraph
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.6.8
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Ruby wrapper for YesGraph API
111
+ test_files: []