faastruby 0.4.4 → 0.4.5

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
  SHA256:
3
- metadata.gz: 0403b639b196582ccd86e036dabd875cb97e91e0049ceaff95585aba1c106407
4
- data.tar.gz: 4d7af0e07cf350127ec659a74363576d924823f65578207215efe96976c64ef9
3
+ metadata.gz: 404957e8c7556650be4140ad86b4f566e272904d0381cb345be161620d09660d
4
+ data.tar.gz: 6543bd8471cd41b9139ab21f9d89f6eb004c0c1fbb082253eb9e96a20ae6ab57
5
5
  SHA512:
6
- metadata.gz: 3f2c6bf431d605338aeb6090a0870d53b4dbc8a04f8ca5daeed23cdb1812de65ef3c2860db9925699af455bb884728126ec012a53e4a95d846d8b82b7b42549e
7
- data.tar.gz: de5e092edd1506746525367c8b45c8eebbc1d65cb61b25d76ca4bf12360fb65ac31533f3cb8f21f68bd74d1ca02b070560676acbc0c5bd3a59b4321008becdfa
6
+ metadata.gz: 437bc09653b94ccf8745ae38288d01b89530bb8ec4cde8daa26bf0605a517aa4461609f45e5542f73dcfd9436b04b0caf6d261d2e9500750f75ee184e322653c
7
+ data.tar.gz: 3e016234385dda335740febe62f2a76dc436b8ac56b890424f04d379b9a7236a6e946bf360d34515cd108278da27b54943891801d562a240dbb1275421952313
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.5 - Jan 5 2019
4
+ - Change help terminal colors for better readability
5
+ - Add png, jpeg, css, svg, gif and icon mime-types to `render`
6
+
3
7
  ## 0.4.4 - Jan 3 2019
4
8
  - Update faastruby-rpc to 0.2.1
5
9
 
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- faastruby (0.4.3)
4
+ faastruby (0.4.4)
5
5
  colorize (~> 0.8)
6
- faastruby-rpc (~> 0.2.0)
6
+ faastruby-rpc (~> 0.2.1)
7
7
  oj (~> 3.6)
8
8
  puma (~> 3.12)
9
9
  rest-client (~> 2.0)
@@ -26,7 +26,7 @@ GEM
26
26
  domain_name (0.5.20180417)
27
27
  unf (>= 0.0.5, < 1.0.0)
28
28
  equatable (0.5.0)
29
- faastruby-rpc (0.2.0)
29
+ faastruby-rpc (0.2.1)
30
30
  oj (~> 3.6)
31
31
  hashdiff (0.3.7)
32
32
  http-cookie (1.0.3)
data/exe/faastruby-server CHANGED
@@ -5,6 +5,7 @@ require 'sinatra/multi_route'
5
5
  require 'yaml'
6
6
  require 'oj'
7
7
  require 'faastruby-rpc'
8
+ require 'base64'
8
9
 
9
10
  module FaaStRuby
10
11
  class DoubleRenderError < StandardError; end
@@ -41,15 +42,31 @@ module FaaStRuby
41
42
  @rendered
42
43
  end
43
44
 
44
- def respond_with(body, status: 200, headers: {})
45
+ def respond_with(body, status: 200, headers: {}, binary: false)
45
46
  raise FaaStRuby::DoubleRenderError.new("You called 'render' or 'respond_with' twice in your handler method") if rendered?
46
- response = FaaStRuby::Response.new(body: body, status: status, headers: headers)
47
+ response = FaaStRuby::Response.new(body: body, status: status, headers: headers, binary: binary)
47
48
  rendered!
48
49
  response
49
50
  end
50
51
 
51
- def render(js: nil, body: nil, inline: nil, html: nil, json: nil, yaml: nil, text: nil, status: 200, headers: {}, content_type: nil)
52
+ def render(
53
+ js: nil,
54
+ body: nil,
55
+ inline: nil,
56
+ html: nil,
57
+ json: nil,
58
+ yaml: nil,
59
+ text: nil,
60
+ data: nil,
61
+ png: nil,
62
+ svg: nil,
63
+ jpeg: nil,
64
+ gif: nil,
65
+ icon: nil,
66
+ status: 200, headers: {}, content_type: nil, binary: false
67
+ )
52
68
  headers["Content-Type"] = content_type if content_type
69
+ bin = false
53
70
  case
54
71
  when json
55
72
  headers["Content-Type"] ||= "application/json"
@@ -65,12 +82,36 @@ module FaaStRuby
65
82
  resp_body = yaml.is_a?(String) ? yaml : YAML.load(yaml)
66
83
  when body
67
84
  headers["Content-Type"] ||= "application/octet-stream"
68
- resp_body = raw
85
+ bin = binary
86
+ resp_body = bin ? Base64.urlsafe_encode64(body) : body
87
+ when data
88
+ headers["Content-Type"] ||= "application/octet-stream"
89
+ resp_body = Base64.urlsafe_encode64(data)
90
+ bin = true
69
91
  when js
70
92
  headers["Content-Type"] ||= "text/javascript"
71
93
  resp_body = js
94
+ when png
95
+ headers["Content-Type"] ||= "image/png"
96
+ resp_body = Base64.urlsafe_encode64(png)
97
+ bin = true
98
+ when svg
99
+ headers["Content-Type"] ||= "image/svg+xml"
100
+ resp_body = svg
101
+ when jpeg
102
+ headers["Content-Type"] ||= "image/jpeg"
103
+ resp_body = Base64.urlsafe_encode64(jpeg)
104
+ bin = true
105
+ when gif
106
+ headers["Content-Type"] ||= "image/gif"
107
+ resp_body = Base64.urlsafe_encode64(gif)
108
+ bin = true
109
+ when icon
110
+ headers["Content-Type"] ||= "image/x-icon"
111
+ resp_body = Base64.urlsafe_encode64(icon)
112
+ bin = true
72
113
  end
73
- respond_with(resp_body, status: status, headers: headers)
114
+ respond_with(resp_body, status: status, headers: headers, binary: bin)
74
115
  end
75
116
  end
76
117
 
@@ -78,11 +119,16 @@ module FaaStRuby
78
119
  end
79
120
 
80
121
  class Response
81
- attr_accessor :body, :status, :headers
82
- def initialize(body:, status: 200, headers: {})
122
+ attr_accessor :body, :status, :headers, :binary
123
+ def initialize(body:, status: 200, headers: {}, binary: false)
83
124
  @body = body
84
125
  @status = status
85
126
  @headers = headers
127
+ @binary = binary
128
+ end
129
+
130
+ def binary?
131
+ @binary
86
132
  end
87
133
  end
88
134
  end
@@ -117,7 +163,11 @@ class FaaStRubyServer < Sinatra::Application
117
163
  response = FaaStRuby::Runner.new.call(params[:workspace_name], params[:function_name], event, rpc_args)
118
164
  status response.status
119
165
  headers response.headers
120
- body response.body
166
+ if response.binary?
167
+ body Base64.urlsafe_decode64(response.body)
168
+ else
169
+ body response.body
170
+ end
121
171
  end
122
172
 
123
173
  def parse_body(body, content_type, method)
@@ -19,7 +19,7 @@ module FaaStRuby
19
19
  end
20
20
 
21
21
  def self.help
22
- "add-credentials".blue + " WORKSPACE_NAME -k API_KEY -s API_SECRET [-c CREDENTIALS_FILE]"
22
+ "add-credentials".light_cyan + " WORKSPACE_NAME -k API_KEY -s API_SECRET [-c CREDENTIALS_FILE]"
23
23
  end
24
24
 
25
25
  def usage
@@ -25,7 +25,7 @@ module FaaStRuby
25
25
  end
26
26
 
27
27
  def self.help
28
- "list-credentials".blue + " [-c CREDENTIALS_FILE]"
28
+ "list-credentials".light_cyan + " [-c CREDENTIALS_FILE]"
29
29
  end
30
30
 
31
31
  def usage
@@ -29,7 +29,7 @@ module FaaStRuby
29
29
  end
30
30
 
31
31
  def self.help
32
- "build".blue + " [-s, --source SOURCE_DIR] [-o, --output-file OUTPUT_FILE]"
32
+ "build".light_cyan + " [-s, --source SOURCE_DIR] [-o, --output-file OUTPUT_FILE]"
33
33
  end
34
34
 
35
35
  def usage
@@ -32,7 +32,7 @@ module FaaStRuby
32
32
  end
33
33
 
34
34
  def self.help
35
- "deploy-to".blue + " WORKSPACE_NAME"
35
+ "deploy-to".light_cyan + " WORKSPACE_NAME"
36
36
  end
37
37
 
38
38
  def usage
@@ -24,7 +24,7 @@ module FaaStRuby
24
24
  end
25
25
 
26
26
  def self.help
27
- "new".blue + " FUNCTION_NAME [--blank] [--force] [--runtime]" +
27
+ "new".light_cyan + " FUNCTION_NAME [--blank] [--force] [--runtime]" +
28
28
  <<-EOS
29
29
 
30
30
  --blank # Create a blank function
@@ -28,7 +28,7 @@ module FaaStRuby
28
28
  end
29
29
 
30
30
  def self.help
31
- "remove-from".blue + " WORKSPACE_NAME [-y, --yes]"
31
+ "remove-from".light_cyan + " WORKSPACE_NAME [-y, --yes]"
32
32
  end
33
33
 
34
34
  def usage
@@ -31,7 +31,7 @@ module FaaStRuby
31
31
  end
32
32
 
33
33
  def self.help
34
- 'run'.blue + ' WORKSPACE_NAME [OPTIONS]' +
34
+ 'run'.light_cyan + ' WORKSPACE_NAME [OPTIONS]' +
35
35
  <<-EOS
36
36
 
37
37
  Options:
@@ -20,7 +20,7 @@ module FaaStRuby
20
20
  end
21
21
 
22
22
  def self.help
23
- 'test'.blue
23
+ 'test'.light_cyan
24
24
  end
25
25
 
26
26
  def usage
@@ -26,7 +26,7 @@ module FaaStRuby
26
26
  end
27
27
 
28
28
  def self.help
29
- "update-context".blue + " WORKSPACE_NAME [-d, --data 'STRING'] [--stdin]"
29
+ "update-context".light_cyan + " WORKSPACE_NAME [-d, --data 'STRING'] [--stdin]"
30
30
  end
31
31
 
32
32
  def usage
@@ -57,7 +57,7 @@ module FaaStRuby
57
57
  end
58
58
 
59
59
  def self.help
60
- "upgrade".blue
60
+ "upgrade".light_cyan
61
61
  end
62
62
 
63
63
  def usage
@@ -12,8 +12,7 @@ module FaaStRuby
12
12
  puts
13
13
  puts 'help, -h, --help # Displays this help'
14
14
  puts '-v # Print version and exit'
15
- puts '--region tor1|sfo2 # Specify a region'
16
- puts
15
+ puts '--region tor1 # Specify a region. "tor1" (default) is the only region available'
17
16
  workspaces = ["Workspaces:"]
18
17
  functions = ["Functions:"]
19
18
  credentials = ["Credentials:"]
@@ -30,7 +30,7 @@ module FaaStRuby
30
30
  end
31
31
 
32
32
  def self.help
33
- "create-workspace".blue + " WORKSPACE_NAME [--stdout|-c, --credentials-file CREDENTIALS_FILE] [-e, --email YOUR_EMAIL_ADDRESS]"
33
+ "create-workspace".light_cyan + " WORKSPACE_NAME [--stdout|-c, --credentials-file CREDENTIALS_FILE] [-e, --email YOUR_EMAIL_ADDRESS]"
34
34
  end
35
35
 
36
36
  def usage
@@ -37,7 +37,7 @@ module FaaStRuby
37
37
  end
38
38
 
39
39
  def self.help
40
- "deploy".blue + " [WORKSPACE_FOLDER1] [WORKSPACE_FOLDER2]... # Deploy all workspaces in the current directory and their functions"
40
+ "deploy".light_cyan + " [WORKSPACE_FOLDER1] [WORKSPACE_FOLDER2]... # Deploy all workspaces in the current directory and their functions"
41
41
  end
42
42
 
43
43
  def usage
@@ -43,7 +43,7 @@ module FaaStRuby
43
43
  end
44
44
 
45
45
  def self.help
46
- "destroy-workspace".blue + " WORKSPACE_NAME [-y, --yes]"
46
+ "destroy-workspace".light_cyan + " WORKSPACE_NAME [-y, --yes]"
47
47
  end
48
48
 
49
49
  def usage
@@ -26,7 +26,7 @@ module FaaStRuby
26
26
  end
27
27
 
28
28
  def self.help
29
- "list-workspace".blue + " WORKSPACE_NAME"
29
+ "list-workspace".light_cyan + " WORKSPACE_NAME"
30
30
  end
31
31
 
32
32
  def usage
@@ -1,3 +1,3 @@
1
1
  module FaaStRuby
2
- VERSION = '0.4.4'
2
+ VERSION = '0.4.5'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faastruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Arruda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-03 00:00:00.000000000 Z
11
+ date: 2019-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client