sg 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec2b677360953e28edaed315f7c132cf094ccc4c
4
- data.tar.gz: b3102d281a5d4446f483356a6d1f9731f4d57fcd
3
+ metadata.gz: df4695ad6999bf76e18e1328d8f9fb9a26df6765
4
+ data.tar.gz: 95c35d2e4d1af122ac3757ce3e3a8c11b8ed32dc
5
5
  SHA512:
6
- metadata.gz: 8d09e70c8a3fc014f9bff54225a024a22109fd69c86601c9a0d29880b98f9297b3f17d552957373d03da6b4bc4ba0920a4c184b6fed9a284624bf0a500191844
7
- data.tar.gz: 456c07a21fad3693a8fd584061e8154ed6c6a91457e90e5f933b6dc6d9f5c9f37b3b1476715efb42c54e37cb4548ee19affbf8b6ec99ac87f4ba37e561923a83
6
+ metadata.gz: 89767ab66a09c07fbc4140ef8b4717b5ed2a4622a79824f351a36f57425a819dcf7b07a2b6bb2b0e3ea1681bd159a6e1925dd49b782fd024eabe70512cba8288
7
+ data.tar.gz: 3ce9b33eb10ce70c36988fa19d1daefebde40ec9e5d92a0012fb67014f6ff2d5c9b53c602e794c6042e320608ed36ec67dae19a2af3e4b569afb7822fb3756ae
data/.rubocop.yml CHANGED
@@ -1,34 +1,12 @@
1
- # # Let prefix of method name set_ and get_
2
- # AccessorMethodName:
3
- # Enabled: false
4
- #
5
1
  # Change limitation of method length
6
2
  MethodLength:
7
3
  CountComments: true # count full line comments?
8
4
  Max: 20
9
5
 
10
- # # Change limitation of module length
11
- # ModuleLength:
12
- # Max: 600
13
- #
14
- # # Change limitation of the number of params
15
- # ParameterLists:
16
- # Max: 8
17
- # CountKeywordArgs: false
18
- #
19
6
  # Change limitation of AbcSize
20
7
  AbcSize:
21
8
  Max: 27
22
9
 
23
- # # Change numeric literals
24
- # NumericLiterals:
25
- # MinDigits: 20
26
- #
27
- # # Disable force module and class style
28
- # ClassAndModuleChildren:
29
- # Enabled: false
30
- #
31
- # # Change limitation of the class length
32
- # ClassLength:
33
- # CountComments: false # count full line comments?
34
- # Max: 180
10
+ # Change Line length
11
+ LineLength:
12
+ Max: 250
data/.travis.yml CHANGED
@@ -1,4 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
+ - 2.2
3
4
  - 2.3.0
4
- before_install: gem install bundler -v 1.11.2
5
+ before_script:
6
+ - bundle install
7
+ before_install:
8
+ - gem install bundler -v 1.11.2
9
+ script:
10
+ - rubocop --fail-level=W
11
+ - rake
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # sg
2
2
 
3
+ [![Build Status](https://travis-ci.org/awwa/sg.svg?branch=master)](https://travis-ci.org/awwa/sg)
4
+ [![Gem Version](https://badge.fury.io/rb/sg.svg)](https://badge.fury.io/rb/sg)
5
+
3
6
  `sg` gem allows you to access SendGrid API v3 endpoints from command line interface.
4
7
 
5
8
  ## Installation
data/lib/sg.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'base64'
1
2
  require 'thor'
2
3
  require 'sendgrid-ruby'
3
4
  require 'sg/version'
@@ -41,21 +42,35 @@ module Sg
41
42
  option(
42
43
  :apikey,
43
44
  aliases: '-k',
44
- desc: 'API Key. Use env variable "SENDGRID_API_KEY" if not specified.'
45
+ desc: 'API Key. Load env variable "SENDGRID_API_KEY" if not specified.'
45
46
  )
47
+ option :user, aliases: '-u', desc: 'Username for Basic Auth.'
48
+ option :pass, aliases: '-p', desc: 'Password for Basic Auth.'
46
49
  option :request_body, aliases: '-b', desc: 'Request Body'
47
- option :query_params, aliases: '-q', desc: 'Query String of the request'
48
- option :response_header, aliases: '-h', desc: 'Output response header'
49
- option :response_status, aliases: '-s', desc: 'Output reponse status code'
50
- option :version, aliases: '-v', desc: 'Output gem version'
50
+ option(
51
+ :query_params,
52
+ aliases: '-q',
53
+ desc: 'Query String of the request',
54
+ banner: 'JSON_STRING'
55
+ )
56
+ option(
57
+ :response_header,
58
+ aliases: '-h',
59
+ desc: 'Output response header',
60
+ banner: ''
61
+ )
62
+ option(
63
+ :response_status,
64
+ aliases: '-s',
65
+ desc: 'Output reponse status code',
66
+ banner: ''
67
+ )
68
+ option :version, aliases: '-v', desc: 'Output gem version', banner: ''
51
69
  def client(*args)
52
70
  return puts Sg::VERSION if options[:version]
53
- api_key = options[:apikey]
54
- api_key ||= ENV['SENDGRID_API_KEY']
55
- sg = SendGrid::API.new(api_key: api_key)
56
71
  idx = 0
57
72
  params = CLI.parameterise(options)
58
- response = args.inject(sg.client) do |c, arg|
73
+ response = args.inject(CLI.get_client(options)) do |c, arg|
59
74
  idx += 1
60
75
  (args.length == idx) ? c.send(arg, params) : c.send('_', arg)
61
76
  end
@@ -71,5 +86,18 @@ module Sg
71
86
  end
72
87
  end
73
88
  end
89
+
90
+ def self.get_client(options)
91
+ if options[:user] && options[:pass]
92
+ up = "#{options[:user]}:#{options[:pass]}"
93
+ headers = {}
94
+ headers['Authorization'] = "Basic #{Base64.urlsafe_encode64(up)}"
95
+ SendGrid::API.new(api_key: '', request_headers: headers).client
96
+ else
97
+ api_key = options[:apikey]
98
+ api_key ||= ENV['SENDGRID_API_KEY']
99
+ SendGrid::API.new(api_key: api_key).client
100
+ end
101
+ end
74
102
  end
75
103
  end
data/lib/sg/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # SendGrid Command Line Interface
3
3
  #
4
4
  module Sg
5
- VERSION = '0.1.4'
5
+ VERSION = '0.2.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - awwa500@gmail.com
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-06 00:00:00.000000000 Z
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor