sg 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -25
- data/.travis.yml +8 -1
- data/README.md +3 -0
- data/lib/sg.rb +37 -9
- data/lib/sg/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df4695ad6999bf76e18e1328d8f9fb9a26df6765
|
4
|
+
data.tar.gz: 95c35d2e4d1af122ac3757ce3e3a8c11b8ed32dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
#
|
24
|
-
|
25
|
-
|
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
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# sg
|
2
2
|
|
3
|
+
[](https://travis-ci.org/awwa/sg)
|
4
|
+
[](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.
|
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
|
48
|
-
|
49
|
-
|
50
|
-
|
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(
|
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
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.
|
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-
|
11
|
+
date: 2016-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|