Sha256: 0445299bd0930f3accd1457d52e2675421ff093b1e92d236ecbd835347fbed17

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

# -*- encoding: utf-8 -*-
$LOAD_PATH.unshift File.dirname(__FILE__)

require 'sendgrid4r/rest/request'

module SendGrid4r
  module REST
    #
    # SendGrid Web API v3 Users
    #
    module Users
      include SendGrid4r::REST::Request

      Profile = Struct.new(
        :address, :city, :company, :country, :first_name, :last_name,
        :phone, :state, :website, :zip
      )

      def self.url
        url = "#{BASE_URL}/user/profile"
        url
      end

      def self.create_profile(resp)
        return resp if resp.nil?
        Profile.new(
          resp['address'],
          resp['city'],
          resp['company'],
          resp['country'],
          resp['first_name'],
          resp['last_name'],
          resp['phone'],
          resp['state'],
          resp['website'],
          resp['zip']
        )
      end

      def get_user_profile(&block)
        resp = get(@auth, SendGrid4r::REST::Users.url, nil, &block)
        SendGrid4r::REST::Users.create_profile(resp)
      end

      def patch_user_profile(params: nil, &block)
        endpoint = SendGrid4r::REST::Users.url
        resp = patch(@auth, endpoint, params, &block)
        SendGrid4r::REST::Users.create_profile(resp)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sendgrid4r-1.2.1 lib/sendgrid4r/rest/users/users.rb