class Yesgraph::YesGraphAPI
Attributes
base_url[R]
Wrapper Class
secret_key[R]
Wrapper Class
Public Class Methods
new(secret_key, base_url = BASE_URL)
click to toggle source
# File lib/yesgraph.rb, line 15 def initialize(secret_key, base_url = BASE_URL) @secret_key = secret_key @base_url = base_url end
Public Instance Methods
build_url(endpoint, url_args = {})
click to toggle source
# File lib/yesgraph.rb, line 27 def build_url(endpoint, url_args = {}) base_url_cleaned = base_url.sub(%r{\/+$}, '') endpoint_cleaned = endpoint.sub(%r{^\/+}, '') url = [base_url_cleaned, endpoint_cleaned].join('/') url_args.delete_if { |_, v| v.to_s.strip.empty? } unless url_args.empty? args = URI.encode_www_form(url_args) url = "#{url}?#{args}" end url end
delete_address_book(user_id)
click to toggle source
# File lib/yesgraph.rb, line 140 def delete_address_book(user_id) # Wrapped method for DELETE /address-book/:user_id endpoint # # Documentation - https://docs.yesgraph.com/docs/address-book#section-delete-address-bookuser_id user_id = CGI.escape(user_id.to_s) endpoint = "/address-book/#{user_id}" request(:delete, endpoint) end
get_address_book(user_id, filter_suggested_seen: nil, filter_existing_users: nil, filter_invites_sent: nil, promote_existing_users: nil, promote_matching_domain: nil, filter_blank_names: nil, limit: nil)
click to toggle source
# File lib/yesgraph.rb, line 111 def get_address_book(user_id, filter_suggested_seen: nil, filter_existing_users: nil, filter_invites_sent: nil, promote_existing_users: nil, promote_matching_domain: nil, filter_blank_names: nil, limit: nil) # Wrapped method for GET of /address-book endpoint # # Documentation - https://docs.yesgraph.com/docs/address-book#section-get-address-bookuser_id raise('`limit` param is not an int') unless limit.nil? || (limit.is_a? Integer) urlargs = { 'filter_suggested_seen' => filter_suggested_seen, 'filter_existing_users' => filter_existing_users, 'filter_invites_sent' => filter_invites_sent, 'filter_blank_names' => filter_blank_names, 'promote_existing_users' => promote_existing_users, 'promote_matching_domain' => promote_matching_domain, 'limit' => limit } user_id = CGI.escape(user_id.to_s) endpoint = "/address-book/#{user_id}" request(:get, endpoint, {}, urlargs) end
get_client_key(user_id)
click to toggle source
# File lib/yesgraph.rb, line 62 def get_client_key(user_id) # Wrapped method for POST of /client-key endpoint # # Documentation - https://docs.yesgraph.com/docs/create-client-keys data = JSON.dump('user_id': user_id.to_s) result = request(:post, '/client-key', data) result['client_key'] end
get_domain_emails(domain, page: nil, batch_size: nil)
click to toggle source
# File lib/yesgraph.rb, line 192 def get_domain_emails(domain, page: nil, batch_size: nil) # Wrapped method for GET of /domain-emails/<domain> endpoint # # Documentation - https://docs.yesgraph.com/docs/domain-emails/ urlargs = { 'page' => page, 'batch_size' => batch_size } domain = CGI.escape(domain.to_s) endpoint = "/domain-emails/#{domain}" request(:get, endpoint, {}, urlargs) end
post_address_book(user_id, entries, source_type, source_name: nil, source_email: nil, filter_suggested_seen: nil, filter_existing_users: nil, filter_invites_sent: nil, filter_blank_names: nil, promote_existing_users: nil, promote_matching_domain: nil, backfill: nil, limit: nil)
click to toggle source
# File lib/yesgraph.rb, line 72 def post_address_book(user_id, entries, source_type, source_name: nil, source_email: nil, filter_suggested_seen: nil, filter_existing_users: nil, filter_invites_sent: nil, filter_blank_names: nil, promote_existing_users: nil, promote_matching_domain: nil, backfill: nil, limit: nil) # Wrapped method for POST of /address-book endpoint # # Documentation - https://docs.yesgraph.com/docs/address-book source = { 'type' => source_type } source['name'] = source_name if source_name source['email'] = source_email if source_email raise('`limit` param is not an int') unless limit.nil? || (limit.is_a? Integer) raise('`backfill` param is not an int') unless backfill.nil? || (backfill.is_a? Integer) data = { 'user_id' => user_id.to_s, 'filter_suggested_seen' => filter_suggested_seen, 'filter_existing_users' => filter_existing_users, 'filter_invites_sent' => filter_invites_sent, 'filter_blank_names' => filter_blank_names, 'promote_existing_users' => promote_existing_users, 'promote_matching_domain' => promote_matching_domain, 'source' => source, 'entries' => entries, 'limit' => limit, 'backfill' => backfill } data = JSON.dump(data) request(:post, '/address-book', data) end
post_invites_accepted(entries)
click to toggle source
# File lib/yesgraph.rb, line 150 def post_invites_accepted(entries) # Wrapped method for POST of /invites-accepted endpoint # # Documentation - https://docs.yesgraph.com/docs/invites-accepted raise('An entry list is required') unless entries && (entries.is_a? Array) data = { 'entries' => entries } data = JSON.dump(data) request(:post, '/invites-accepted', data) end
post_invites_sent(entries)
click to toggle source
# File lib/yesgraph.rb, line 161 def post_invites_sent(entries) # Wrapped method for POST of /invites-sent endpoint # # Documentation - https://docs.yesgraph.com/docs/invites-sent raise('An entry list is required') unless entries && (entries.is_a? Array) data = { 'entries' => entries } data = JSON.dump(data) request(:post, '/invites-sent', data) end
post_suggested_seen(entries)
click to toggle source
# File lib/yesgraph.rb, line 172 def post_suggested_seen(entries) # Wrapped method for POST of /suggested-seen endpoint # # Documentation - https://docs.yesgraph.com/docs/suggested-seen raise('An entry list is required') unless entries && (entries.is_a? Array) data = { 'entries' => entries } data = JSON.dump(data) request(:post, '/suggested-seen', data) end
post_users(users)
click to toggle source
# File lib/yesgraph.rb, line 183 def post_users(users) # Wrapped method for POST of users endpoint # # Documentation - https://docs.yesgraph.com/docs/users data = JSON.dump(users) request(:post, '/users', data) end
request(method, endpoint, data = {}, url_args = {})
click to toggle source
# File lib/yesgraph.rb, line 39 def request(method, endpoint, data = {}, url_args = {}) # Builds and sends the complete request. headers = { 'Authorization' => "Bearer #{secret_key}", 'Content-Type' => 'application/json', 'User-Agent' => user_agent } url = build_url(endpoint, url_args) resp = RestClient::Request.execute(method: method, url: url, payload: data.to_s, headers: headers) JSON.parse(resp.body) end
test()
click to toggle source
# File lib/yesgraph.rb, line 54 def test # Wrapped method for GET of /test endpoint # # Documentation - https://docs.yesgraph.com/docs/test request(:get, '/test') end
user_agent()
click to toggle source
# File lib/yesgraph.rb, line 20 def user_agent client_info = ['ruby-yesgraph', Yesgraph::VERSION].join('-') host_info = RbConfig::CONFIG['host'] language_info = RbConfig::CONFIG['RUBY_VERSION_NAME'] [client_info, host_info, language_info].join(' ') end