sendgrid_webapi 0.0.4 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +132 -0
  3. data/.circleci/setup-rubygems.sh +5 -0
  4. data/.gitignore +27 -1
  5. data/.rspec +2 -2
  6. data/.ruby-version +1 -0
  7. data/.tool-versions +1 -0
  8. data/Gemfile +1 -0
  9. data/README.rdoc +27 -2
  10. data/lib/api_key/management.rb +33 -0
  11. data/lib/api_key/modules.rb +10 -0
  12. data/lib/apikey_client.rb +11 -0
  13. data/lib/base.rb +43 -12
  14. data/lib/helper.rb +8 -8
  15. data/lib/sendgrid_webapi.rb +1 -0
  16. data/lib/sub_user/modules.rb +15 -15
  17. data/lib/version.rb +2 -2
  18. data/lib/web_api/modules.rb +15 -11
  19. data/lib/web_api/version.rb +1 -1
  20. data/sendgrid_webapi.gemspec +10 -15
  21. data/spec/cassettes/client/_modules/_block/should_get_block_emails.yml +1 -1
  22. data/spec/cassettes/client/_modules/_block/should_get_totals_blocks.yml +1 -1
  23. data/spec/cassettes/client/_modules/_block/should_try_delete_not_existing_block_email.yml +1 -1
  24. data/spec/cassettes/client/_modules/_bounce/should_get_bounce_emails.yml +1 -1
  25. data/spec/cassettes/client/_modules/_bounce/should_get_totals_bounces.yml +1 -1
  26. data/spec/cassettes/client/_modules/_bounce/should_try_delete_not_existing_bounce_email.yml +1 -1
  27. data/spec/cassettes/client/_modules/_event_notification/should_delete_event_notification_url.yml +1 -1
  28. data/spec/cassettes/client/_modules/_event_notification/should_get_event_notification_url.yml +1 -1
  29. data/spec/cassettes/client/_modules/_event_notification/should_set_event_notification_url.yml +1 -1
  30. data/spec/cassettes/client/_modules/_invalid_email/should_get_invalid_emails.yml +1 -1
  31. data/spec/cassettes/client/_modules/_invalid_email/should_try_delete_not_existing_invalid_emails.yml +1 -1
  32. data/spec/cassettes/client/_modules/_parse_email/should_delete_parse_email.yml +2 -2
  33. data/spec/cassettes/client/_modules/_parse_email/should_get_parse_email.yml +1 -1
  34. data/spec/cassettes/client/_modules/_parse_email/should_set_parse_email.yml +1 -1
  35. data/spec/cassettes/client/_modules/_profile/should_get_profile.yml +1 -1
  36. data/spec/cassettes/client/_modules/_profile/should_set_first_name.yml +3 -3
  37. data/spec/cassettes/client/_modules/_spam/should_get_spam_emails.yml +1 -1
  38. data/spec/cassettes/client/_modules/_spam/should_try_delete_not_existing_spam_emails.yml +1 -1
  39. data/spec/cassettes/client/_modules/_unsubscribe/should_add_unsubscribe_emails.yml +1 -1
  40. data/spec/cassettes/client/_modules/_unsubscribe/should_delete_unsubscribe_email.yml +1 -1
  41. data/spec/cassettes/client/_modules/_unsubscribe/should_get_unsubscribe_emails.yml +1 -1
  42. data/spec/cassettes/client/_modules/_unsubscribe/should_try_delete_not_existing_unsubscribe_emails.yml +1 -1
  43. data/spec/cassettes/helper/_create_sub_user_account/should_create_sub_user_account.yml +6 -6
  44. data/spec/cassettes/helper/_run_sendgrid_query/should_raise_with_unsucessfull_request.yml +1 -1
  45. data/spec/cassettes/helper/_run_sendgrid_query/should_run_sendgrid_request.yml +1 -1
  46. data/spec/cassettes/sub_user/_apps/should_activate_app.yml +1 -1
  47. data/spec/cassettes/sub_user/_apps/should_deactivate_app.yml +1 -1
  48. data/spec/cassettes/sub_user/_apps/should_get_current_setting_from_one_app.yml +1 -1
  49. data/spec/cassettes/sub_user/_apps/should_return_available_apps.yml +1 -1
  50. data/spec/cassettes/sub_user/_apps/should_set_current_app.yml +1 -1
  51. data/spec/cassettes/sub_user/_authentication/should_auth_a_sub_user.yml +1 -1
  52. data/spec/cassettes/sub_user/_authentication/should_return_error_with_a_bad_sub_user.yml +1 -1
  53. data/spec/cassettes/sub_user/_bounces/should_returns_bounce_emails.yml +1 -1
  54. data/spec/cassettes/sub_user/_bounces/should_tries_to_delete_unexisting_bounce_emails.yml +1 -1
  55. data/spec/cassettes/sub_user/_event_notification/should_add_event_notification_url.yml +1 -1
  56. data/spec/cassettes/sub_user/_event_notification/should_delete_event_notification_url.yml +1 -1
  57. data/spec/cassettes/sub_user/_event_notification/should_get_event_notification_url.yml +1 -1
  58. data/spec/cassettes/sub_user/_invalid_emails/should_return_invalid_emails.yml +1 -1
  59. data/spec/cassettes/sub_user/_invalid_emails/should_tries_to_delete_unexisting_invalid_mail.yml +1 -1
  60. data/spec/cassettes/sub_user/_ip_management/should_return_all_ips_available.yml +1 -1
  61. data/spec/cassettes/sub_user/_ip_management/should_show_ip_subuser.yml +1 -1
  62. data/spec/cassettes/sub_user/_limits/should_decrements_credits_for_a_sub_user.yml +2 -2
  63. data/spec/cassettes/sub_user/_limits/should_delete_all_limits_for_a_sub_user.yml +2 -2
  64. data/spec/cassettes/sub_user/_limits/should_increments_credits_for_a_sub_user.yml +2 -2
  65. data/spec/cassettes/sub_user/_limits/should_list_the_limits_for_a_sub_user.yml +1 -1
  66. data/spec/cassettes/sub_user/_limits/should_reset_all_limits_for_a_sub_user.yml +2 -2
  67. data/spec/cassettes/sub_user/_limits/should_returns_limits_for_a_sub_user.yml +1 -1
  68. data/spec/cassettes/sub_user/_limits/should_set_total_credits.yml +1 -1
  69. data/spec/cassettes/sub_user/_management/should_add_new_subuser.yml +1 -1
  70. data/spec/cassettes/sub_user/_management/should_disable_sub_user_for_send_email.yml +1 -1
  71. data/spec/cassettes/sub_user/_management/should_enable_sub_user_for_access_to_website.yml +1 -1
  72. data/spec/cassettes/sub_user/_management/should_enable_sub_user_for_send_email.yml +1 -1
  73. data/spec/cassettes/sub_user/_management/should_update_sub_user.yml +1 -1
  74. data/spec/cassettes/sub_user/_monitor_records/should_add_existing_sub_user_to_monitor_record.yml +2 -2
  75. data/spec/cassettes/sub_user/_monitor_records/should_create_a_new_monitor_record.yml +2 -2
  76. data/spec/cassettes/sub_user/_monitor_records/should_delete_a_monitor_record.yml +2 -2
  77. data/spec/cassettes/sub_user/_monitor_records/should_edit_a_monitor_record.yml +2 -2
  78. data/spec/cassettes/sub_user/_monitor_records/should_remove_existing_sub_user_from_monitor_record.yml +2 -2
  79. data/spec/cassettes/sub_user/_parse_email/should_delete_parse_email.yml +2 -2
  80. data/spec/cassettes/sub_user/_parse_email/should_get_parse_email.yml +1 -1
  81. data/spec/cassettes/sub_user/_parse_email/should_set_parse_email.yml +1 -1
  82. data/spec/cassettes/sub_user/_spam/should_return_spam_mails.yml +1 -1
  83. data/spec/cassettes/sub_user/_spam/should_tries_to_delete_unexisting_spam_mail.yml +1 -1
  84. data/spec/cassettes/sub_user/_unsubscribes/should_add_bounce_email.yml +1 -1
  85. data/spec/cassettes/sub_user/_unsubscribes/should_delete_existing_bounce_email.yml +1 -1
  86. data/spec/cassettes/sub_user/_unsubscribes/should_delete_unexisting_bounce_email.yml +1 -1
  87. data/spec/cassettes/sub_user/_unsubscribes/should_returns_bounce_emails.yml +1 -1
  88. data/spec/client_spec.rb +2 -2
  89. data/spec/helper_spec.rb +4 -4
  90. data/spec/sub_user_spec.rb +1 -1
  91. data/test.rb +1 -1
  92. metadata +73 -48
  93. data/.travis.yml +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 03c0e04a19c4c46b8246a823efb74d88f58c5d58
4
- data.tar.gz: 97451052fae8ae90cbbc710507141375bad8dfc0
2
+ SHA256:
3
+ metadata.gz: ff233662151a27ee1fc9a7b97b76ca8a94c31dce74a1bf2a1cf9988ac8bc7b91
4
+ data.tar.gz: 0b3726d98a4eb9addceeeea27beabafd89a2cabaab00c3ced99e0ff0086448bd
5
5
  SHA512:
6
- metadata.gz: 6763e1f42e356e172bcd595aa96747729af4c3c9963fd4fd9f4f16ddcd1995322faac3f1320f155d631dc2217600b616e76b46bd826d433e8a5a451e68c51ff3
7
- data.tar.gz: fd5cae50b5c1f7f8245a4962fc2201b291156d51960f960816e51bb26eb49102373a8e735c91655db604df9d449b9bc4c313237cf61b58840c07a2eaa1ea30e7
6
+ metadata.gz: a2f836e58f0fca1c0d413e9d0f32a78d1c9b3cea13286b5e0e0801db5be02124cded1ba17a98d784a1bfc98e5a5ca55d09d6d73b90055a5906c7e41ac566706c
7
+ data.tar.gz: 67531dc60c343fa706200db2ae2de1468483bcbd06833a73dd5a69d8a9f01b11867bdd36b1e876ca5c0ba0e576deb81b0e9d0a50541b73748f77ca606a58d316
@@ -0,0 +1,132 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ defaults: &defaults
6
+ working_directory: ~/repo
7
+ docker:
8
+ - image: circleci/ruby:2.3.6-stretch-node
9
+ environment:
10
+ # - DBHOST: localhost
11
+ # - DBNAME: sendgrid_webapi_test
12
+ # - DBPASSWORD: Vdm9omJt8Z3MCV4N
13
+ # - DBUSER: test_user
14
+ - RACK_ENV: test
15
+ - RAILS_ENV: test
16
+ # - image: circleci/postgres:10.3-alpine-ram
17
+ # environment:
18
+ # - POSTGRES_DB: sendgrid_webapi_test
19
+ # - POSTGRES_USER: test_user
20
+ # - POSTGRES_PASSWORD: Vdm9omJt8Z3MCV4N
21
+
22
+ version: 2
23
+ jobs:
24
+ run_specs:
25
+ <<: *defaults
26
+
27
+ steps:
28
+ - run:
29
+ name: Set up environment
30
+ command: |
31
+ sudo apt-get update && sudo apt-get install -y apt-transport-https apt-utils
32
+
33
+ - checkout
34
+
35
+ - restore_cache:
36
+ keys:
37
+ - sendgrid_webapi-dependencies-v1-{{ checksum "sendgrid_webapi.gemspec" }}
38
+ - sendgrid_webapi-dependencies-v1-
39
+
40
+ - run:
41
+ name: Install dependencies
42
+ command: |
43
+ # curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
44
+ # echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
45
+ # sudo apt-get update && sudo apt-get install postgresql-client-10
46
+ bundle check --path=./vendor/bundle || bundle install --path=./vendor/bundle --jobs=4 --retry=3
47
+
48
+ - save_cache:
49
+ key: sendgrid_webapi-dependencies-v1-{{ checksum "sendgrid_webapi.gemspec" }}
50
+ paths:
51
+ - ./vendor/bundle
52
+
53
+ # - run:
54
+ # name: Set up database
55
+ # command: |
56
+ # cp spec/internal/config/database.docker.yml spec/internal/config/database.yml
57
+
58
+ - run:
59
+ name: Run tests
60
+ command: |
61
+ mkdir /tmp/test-results
62
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
63
+ bundle exec rspec --format progress --format RspecJunitFormatter --out /tmp/test-results/rspec.xml $TEST_FILES
64
+
65
+ - store_test_results:
66
+ path: /tmp/test-results
67
+
68
+ - store_artifacts:
69
+ path: /tmp/test-results
70
+ destination: test-results
71
+
72
+ build_gem:
73
+ <<: *defaults
74
+
75
+ steps:
76
+ - run:
77
+ name: Set up environment
78
+ command: |
79
+ sudo apt-get update && sudo apt-get install -y apt-transport-https apt-utils
80
+
81
+ - checkout
82
+
83
+ - restore_cache:
84
+ keys:
85
+ - sendgrid_webapi-dependencies-v1-{{ checksum "sendgrid_webapi.gemspec" }}
86
+ - sendgrid_webapi-dependencies-v1-
87
+
88
+ - run:
89
+ name: Install dependencies
90
+ command: |
91
+ gem install gemfury
92
+ bundle check --path=./vendor/bundle || bundle install --path=./vendor/bundle --jobs=4 --retry=3
93
+
94
+ - save_cache:
95
+ key: sendgrid_webapi-dependencies-v1-{{ checksum "sendgrid_webapi.gemspec" }}
96
+ paths:
97
+ - ./vendor/bundle
98
+
99
+ - run:
100
+ name: Build gem
101
+ command: |
102
+ gem build sendgrid_webapi.gemspec
103
+
104
+ - run:
105
+ name: Push gem
106
+ command: |
107
+ if [[ "${CIRCLE_PROJECT_USERNAME}" == "OneHQ" && "${CIRCLE_BRANCH}" == "master" && -n "${RUBYGEMS_API_KEY}" ]]; then
108
+ bash .circleci/setup-rubygems.sh
109
+ version=$(ruby -e 'load "lib/version.rb"; puts SendGridWebApi::VERSION')
110
+ grep -q "${version}" <(gem search sendgrid_api) || EXIT_CODE=$? && true
111
+ if [[ $EXIT_CODE == 1 ]]; then
112
+ gem push sendgrid_webapi-${version}.gem
113
+ git tag ${version}
114
+ git push --tags
115
+
116
+ [[ -n "$SLACK_TOKEN" ]] && curl -s -d "sendgrid_webapi ($version) released." "https://onehq.slack.com/services/hooks/slackbot?token=${SLACK_TOKEN}&channel=%23machines"
117
+ fi
118
+ fi
119
+
120
+ workflows:
121
+ version: 2
122
+ build-deploy:
123
+ jobs:
124
+ - run_specs
125
+ - build_gem:
126
+ requires:
127
+ - run_specs
128
+ filters:
129
+ branches:
130
+ only:
131
+ - master
132
+ - staging
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ mkdir -p ~/.gem
4
+ echo -e "---\r\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
5
+ chmod 0600 /home/circleci/.gem/credentials
data/.gitignore CHANGED
@@ -1,5 +1,31 @@
1
1
  *.gem
2
+ *.pgz
3
+ *.tmproj
2
4
  .bundle
5
+ .DS_Store
6
+ .gitconfig
7
+ .idea
3
8
  .rvmrc
9
+ .sass-cache
10
+ /.ey_local_data
11
+ /.ruby-gemset
12
+ /.vagrant
13
+ bin/*
14
+ config/*.sphinx.conf
15
+ config/database.yml
16
+ config/sphinx.yml
17
+ db/sphinx/
18
+ Gemfile.lock
19
+ log
20
+ log/*.log
21
+ project.rvmrc
22
+ public/assets
23
+ public/flash/*.swf
24
+ public/javascripts/packaged/*.js
25
+ public/packages/*
26
+ public/stylesheets/packaged/*.css
27
+ spec/internal/config/database.yml
28
+ sphinx/**/*
29
+ tmp
30
+ tmp/**/*
4
31
  Gemfile.lock
5
- pkg/*
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --colour
2
- --format nested
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.0
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.3.6
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in send_grid.gemspec
4
+
4
5
  gemspec
data/README.rdoc CHANGED
@@ -19,7 +19,7 @@ for sendgrid v2 support
19
19
 
20
20
  === Creating client object:
21
21
 
22
- client = SendGridWebApi::Client.new("user_name", "password")
22
+ client = SendGridWebApi::Client.new("apikey")
23
23
 
24
24
  == Modules
25
25
 
@@ -131,7 +131,7 @@ This module allows you to send email.
131
131
 
132
132
  === Creating client object:
133
133
 
134
- client = SendGridWebApi::Client.new("user_name", "password")
134
+ client = SendGridWebApi::Client.new("apikey")
135
135
 
136
136
  client.sub_user
137
137
 
@@ -340,6 +340,31 @@ This module allows you to setup subusers app settings.
340
340
  * options are available here: http://sendgrid.com/docs/API_Reference/Customer_Subuser_API/apps.html
341
341
 
342
342
 
343
+ === Apikey
344
+ This module allows you to manage apikeys
345
+
346
+ client.apikey.management.get
347
+
348
+ client.apikey.management.get({ on_behalf_of: "SUB_USERNAME" })
349
+
350
+ client.apikey.management.get({ apikey_id: "APIKEY_ID" })
351
+
352
+ client.apikey.management.get({ on_behalf_of: "SUB_USERNAME" })
353
+
354
+ client.apikey.management.create({ "name" => "APIKEY NAME", "scopes" => ["mail.send"] })
355
+
356
+ client.apikey.management.create({ on_behalf_of: "SUB_USERNAME", "name" => "APIKEY NAME", "scopes" => ["mail.send"] })
357
+
358
+ client.apikey.management.update("APIKEY_ID", { "name" => "NEW APIKEY NAME"})
359
+
360
+ client.apikey.management.update("APIKEY_ID", { on_behalf_of: "SUB_USERNAME", "name" => "NEW APIKEY NAME"})
361
+
362
+ client.apikey.management.delete("APIKEY_ID")
363
+
364
+ client.apikey.management.delete("APIKEY_ID", { on_behalf_of: "SUB_USERNAME" })
365
+
366
+ * options are available here: https://sendgrid.com/docs/api-reference/
367
+
343
368
  == Helper
344
369
 
345
370
  === Create Sub User
@@ -0,0 +1,33 @@
1
+ module SendGridWebApi::ApiKeyModules
2
+ class Management < SendGridWebApi::ApiKey
3
+ APIKEY_URL = "api_keys"
4
+
5
+ def get options = {}
6
+ management_get_url = APIKEY_URL
7
+ if options.key?(:apikey_id)
8
+ management_get_url += "/#{options[:apikey_id]}"
9
+ options.delete(:apikey_id)
10
+ end
11
+ query_api(management_get_url, process_header_options(options))
12
+ end
13
+
14
+ def create options = {}
15
+ query_post_json_api(APIKEY_URL, process_header_options(options))
16
+ end
17
+
18
+ def delete apikey_id, options = {}
19
+ query_delete_api(APIKEY_URL+"/#{apikey_id}", process_header_options(options))
20
+ end
21
+
22
+ def update apikey_id, options = {}
23
+ query_patch_api(APIKEY_URL+"/#{apikey_id}", process_header_options(options))
24
+ end
25
+
26
+ private
27
+ def process_header_options options
28
+ on_behalf_of = options.delete(:on_behalf_of)
29
+ options.merge!({ headers: { "on-behalf-of" => on_behalf_of } }) unless on_behalf_of.nil?
30
+ options
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ #loading modules
2
+ %w(management).each do |mod|
3
+ require "api_key/" + mod
4
+ end
5
+
6
+ module SendGridWebApi::ApiKeyModules
7
+ def management
8
+ @management_instance ||= Management.new(@api_key)
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ module SendGridWebApi
2
+ autoload :ApiKeyModules, 'api_key/modules'
3
+
4
+ class ApiKey < Base
5
+ include SendGridWebApi::ApiKeyModules
6
+
7
+ def base_url
8
+ "https://api.sendgrid.com/v3/"
9
+ end
10
+ end
11
+ end
data/lib/base.rb CHANGED
@@ -1,41 +1,72 @@
1
1
  require 'faraday_middleware'
2
2
 
3
- module SendGridWebApi
3
+ module SendGridWebApi
4
4
  class Base
5
- attr_accessor :api_user, :api_key
5
+ attr_accessor :api_key
6
6
 
7
- def initialize api_user, api_key
8
- @api_user = api_user
7
+ def initialize api_key
9
8
  @api_key = api_key
10
9
  end
11
-
10
+
12
11
  def make_request_url url, options
13
12
  "#{url}?#{builder_options(options)}"
14
13
  end
15
14
 
16
15
  def builder_options options
17
- options.merge!(:api_user => @api_user, :api_key => @api_key)
18
16
  to_query(options)
19
17
  end
20
18
 
21
19
  def query_api url, options
22
- session.get(make_request_url(url, options)).body
20
+ headers = options.delete(:headers)
21
+ (session.get(make_request_url(url, options)) do |req|
22
+ req.headers.merge!(headers) unless headers.nil?
23
+ end).body
23
24
  end
24
25
 
25
26
  def query_post_api url, options
26
- builder_options(options)
27
- session.post(url, builder_options(options)).body
27
+ headers = options.delete(:headers)
28
+ (session.post(url, builder_options(options)) do |req|
29
+ req.headers.merge!(headers) unless headers.nil?
30
+ end).body
31
+ end
32
+
33
+ def query_post_json_api url, options
34
+ headers = options.delete(:headers)
35
+ (session.post(url) do |req|
36
+ req.headers[:content_type] = 'application/json'
37
+ req.headers.merge!(headers) unless headers.nil?
38
+ req.body = options.to_json
39
+ end).body
40
+ end
41
+
42
+ def query_patch_api url, options
43
+ headers = options.delete(:headers)
44
+ (session.patch(url) do |req|
45
+ req.headers[:content_type] = 'application/json'
46
+ req.headers.merge!(headers) unless headers.nil?
47
+ req.body = options.to_json
48
+ end).body
49
+ end
50
+
51
+ def query_delete_api url, options
52
+ headers = options.delete(:headers)
53
+ (session.delete(make_request_url(url, options)) do |req|
54
+ req.headers.merge!(headers) unless headers.nil?
55
+ end).body
28
56
  end
29
-
57
+
30
58
  def to_query(options)
31
59
  Faraday::Utils.build_nested_query(options)
32
60
  end
33
61
 
34
62
  def session
35
- @connection ||= ::Faraday.new base_url do |conn|
63
+ @connection ||= ::Faraday.new(
64
+ url: base_url,
65
+ headers: {"Authorization" => "Bearer #{@api_key}"}
66
+ ) do |conn|
36
67
  # Forces the connection request and response to be JSON even though
37
68
  # Sendgrids API headers do not specify the content type is JSON
38
- conn.request :json
69
+ conn.request :url_encoded
39
70
  conn.response :json #, :content_type => /\bjson$/
40
71
  conn.adapter Faraday.default_adapter
41
72
  end
data/lib/helper.rb CHANGED
@@ -1,33 +1,33 @@
1
1
  module SendGridWebApi::Helper
2
2
  extend self
3
3
 
4
- def run_sendgrid_query(username, password)
5
- @client = SendGridWebApi::Client.new(username, password)
4
+ def run_sendgrid_query(apikey)
5
+ @client = SendGridWebApi::Client.new(apikey)
6
6
  result = yield
7
7
  raise "it returns the following errors: #{result}" unless result.eql?({"message"=>"success"})
8
8
  end
9
9
 
10
10
  ###this accepts subuser array
11
- def create_sub_user_account(username, password, users)
11
+ def create_sub_user_account(apikey, users)
12
12
  users.each do |user, data|
13
13
  #load users
14
- run_sendgrid_query(username, password) do
14
+ run_sendgrid_query(apikey) do
15
15
  @client.sub_user.management.add(data[:account].merge!(:username => user))
16
16
  end
17
17
 
18
18
  #active user for send email
19
- run_sendgrid_query(username, password){@client.sub_user.management.enable(:user => user)}
19
+ run_sendgrid_query(apikey){@client.sub_user.management.enable(:user => user)}
20
20
 
21
21
  #assign ip
22
22
  unless data[:assigned_ips].empty?
23
- run_sendgrid_query(username, password){@client.sub_user.ip_management.assign_ip :user => user, :ip => data[:assigned_ips]}
23
+ run_sendgrid_query(apikey){@client.sub_user.ip_management.assign_ip :user => user, :ip => data[:assigned_ips]}
24
24
  end
25
25
  #load apps
26
26
  unless data[:applications].empty?
27
27
  data[:applications].each do |app_name, options|
28
- run_sendgrid_query(username, password){@client.sub_user.apps.activate(:user => user, :name => app_name)}
28
+ run_sendgrid_query(apikey){@client.sub_user.apps.activate(:user => user, :name => app_name)}
29
29
  unless options.empty?
30
- run_sendgrid_query(username, password){@client.sub_user.apps.customize(options.merge!(:user => user, :name => app_name))}
30
+ run_sendgrid_query(apikey){@client.sub_user.apps.customize(options.merge!(:user => user, :name => app_name))}
31
31
  end
32
32
  end
33
33
  end
@@ -3,3 +3,4 @@ require 'base'
3
3
  require 'helper'
4
4
  require 'webapi_client'
5
5
  require 'subuser_client'
6
+ require 'apikey_client'