Sha256: 20b6ff5a064605aa5f97f6527e3ea81a00684d4296e425c42ba9c8b8292360f0

Contents?: true

Size: 1.54 KB

Versions: 6

Compression:

Stored size: 1.54 KB

Contents

# -*- encoding: utf-8 -*-

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
      )

      Account = Struct.new(:type, :reputation)

      def self.url(path)
        url = "#{BASE_URL}/user/#{path}"
        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 self.create_account(resp)
        return resp if resp.nil?
        Account.new(
          resp['type'],
          resp['reputation']
        )
      end

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

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

      def get_user_account(&block)
        resp = get(@auth, SendGrid4r::REST::Users.url('account'), nil, &block)
        SendGrid4r::REST::Users.create_account(resp)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sendgrid4r-1.8.1 lib/sendgrid4r/rest/users.rb
sendgrid4r-1.8.0 lib/sendgrid4r/rest/users.rb
sendgrid4r-1.7.1 lib/sendgrid4r/rest/users.rb
sendgrid4r-1.7.0 lib/sendgrid4r/rest/users.rb
sendgrid4r-1.6.0 lib/sendgrid4r/rest/users.rb
sendgrid4r-1.5.1 lib/sendgrid4r/rest/users.rb