Class: Sg::CLI
- Inherits:
-
Thor
- Object
- Thor
- Sg::CLI
- Defined in:
- lib/sg.rb
Overview
SendGrid Command Line Interface Class
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.get_client(options) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/sg.rb', line 90 def self.get_client() if [:user] && [:pass] up = "#{options[:user]}:#{options[:pass]}" headers = {} headers['Authorization'] = "Basic #{Base64.urlsafe_encode64(up)}" SendGrid::API.new(api_key: '', request_headers: headers).client else api_key = [:apikey] api_key ||= ENV['SENDGRID_API_KEY'] SendGrid::API.new(api_key: api_key).client end end |
.parameterise(options) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/sg.rb', line 82 def self.parameterise() .each_with_object({}) do |(k, v), memo| if k.to_s == 'request_body' || k.to_s == 'query_params' memo[k.to_s.to_sym] = JSON.parse(v) unless v.nil? end end end |
Instance Method Details
#client(*args) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sg.rb', line 69 def client(*args) return puts Sg::VERSION if [:version] idx = 0 params = CLI.parameterise() response = args.inject(CLI.get_client()) do |c, arg| idx += 1 args.length == idx ? c.send(arg, params) : c.send('_', arg) end puts response.status_code if [:response_status] puts response.headers if [:response_header] puts response.body end |