Sha256: 6d8f744884a9dcf87e63a3a7d7a37d21db2ed74b6973181b5e0d7f889022d1f1

Contents?: true

Size: 1.91 KB

Versions: 5

Compression:

Stored size: 1.91 KB

Contents

require 'sendgrid-ruby'


sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])


##################################################
# Retrieve all recent access attempts #
# GET /access_settings/activity #

params = JSON.parse('{"limit": 1}')
response = sg.client.access_settings.activity.get(query_params: params)
puts response.status_code
puts response.body
puts response.headers

##################################################
# Add one or more IPs to the whitelist #
# POST /access_settings/whitelist #

data = JSON.parse('{
  "ips": [
    {
      "ip": "192.168.1.1"
    }, 
    {
      "ip": "192.*.*.*"
    }, 
    {
      "ip": "192.168.1.3/32"
    }
  ]
}')
response = sg.client.access_settings.whitelist.post(request_body: data)
puts response.status_code
puts response.body
puts response.headers

##################################################
# Retrieve a list of currently whitelisted IPs #
# GET /access_settings/whitelist #

response = sg.client.access_settings.whitelist.get()
puts response.status_code
puts response.body
puts response.headers

##################################################
# Remove one or more IPs from the whitelist #
# DELETE /access_settings/whitelist #

response = sg.client.access_settings.whitelist.delete(request_body: data)
puts response.status_code
puts response.body
puts response.headers

##################################################
# Retrieve a specific whitelisted IP #
# GET /access_settings/whitelist/{rule_id} #

rule_id = "test_url_param"
response = sg.client.access_settings.whitelist._(rule_id).get()
puts response.status_code
puts response.body
puts response.headers

##################################################
# Remove a specific IP from the whitelist #
# DELETE /access_settings/whitelist/{rule_id} #

rule_id = "test_url_param"
response = sg.client.access_settings.whitelist._(rule_id).delete()
puts response.status_code
puts response.body
puts response.headers

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sendgrid-ruby-4.0.1 examples/accesssettings/accesssettings.rb
sendgrid-ruby-4.0.0 examples/accesssettings/accesssettings.rb
sendgrid-ruby-3.0.7 examples/accesssettings/accesssettings.rb
sendgrid-ruby-3.0.6 examples/accesssettings/accesssettings.rb
sendgrid-ruby-3.0.5 examples/accesssettings/accesssettings.rb