chespirito 0.0.3 → 0.0.4

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: 8c4d6e5d80eb4af70ff671777425f063aa79ea43125e68c453ddb1be96f14abd
4
- data.tar.gz: 0bb3fcbd997da246fa75b009517a8b53c8e57dffd2cd539db9c925179c5ba33f
3
+ metadata.gz: c26d5cfd95f22fdb7fa89e0f16c36cc551f757c4009c42dbd36c95798f27c252
4
+ data.tar.gz: '09c340a8e1776bf4d33e578ba6475110d84703d2c5a0fc79b3bfff6f45859a75'
5
5
  SHA512:
6
- metadata.gz: ed1632d57adc92b16534f172e79de97003a3a97bb1698d330d0517de467722cb495993b563a9ae203f51000d2a58ccd8f64514a86b02d5a2d882effce6ea2852
7
- data.tar.gz: 1f850630a40f3da4f642d30f3ce4ee0b81143889ecd47ee3cad57aa11b587cce30c6e8c119305f3e638403cbdfae6238739dd135b80295c2636381397a918beb
6
+ metadata.gz: 75895b71b94768410da2bae31f1969dc7fde2b374c6d45ca9128049b97d7b3571163fe56ebb3f54a36f0f6c0b38cd178d9157dbba71abe403a30e8eeeb9c24d7
7
+ data.tar.gz: 21684e74e4478c61fe5f56b85c4a31d72e95489fb5a3ebb68a19cada1e46dca52b89e1aac2502632d15b85494cb66e6cc57b769196fe1b01f5649bfb2ea98617
data/README.md CHANGED
@@ -8,12 +8,13 @@
8
8
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
9
9
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-community-brightgreen.svg)](https://rubystyle.guide)
10
10
  ```
11
- ______ __ __ _______ _______..______ __ .______ __ .___________. ______
12
- / || | | | | ____| / || _ \ | | | _ \ | | | | / __ \
13
- | ,----'| |__| | | |__ | (----`| |_) | | | | |_) | | | `---| |----`| | | |
14
- | | | __ | | __| \ \ | ___/ | | | / | | | | | | | |
15
- | `----.| | | | | |____.----) | | | | | | |\ \----.| | | | | `--' |
16
- \______||__| |__| |_______|_______/ | _| |__| | _| `._____||__| |__| \______/
11
+ ( ) _ _ ( )_
12
+ ___ | |__ __ ___ _ _ (_) _ __ (_)| ,_) _
13
+ /'___)| _ `\ /'__`\/',__)( '_`\ | |( '__)| || | /'_`\
14
+ ( (___ | | | |( ___/\__, \| (_) )| || | | || |_ ( (_) )
15
+ `\____)(_) (_)`\____)(____/| ,__/'(_)(_) (_)`\__)`\___/'
16
+ | |
17
+ (_)
17
18
  ```
18
19
 
19
20
  [chespirito](https://rubygems.org/gems/chespirito) is a dead simple, yet Rack-compatible, web framework written in Ruby.
@@ -54,6 +55,7 @@ Usage: make <target>
54
55
  ## Boostrapping an application using Chespirito and Adelnor
55
56
 
56
57
  1. Install the gems:
58
+
57
59
  ```bash
58
60
  $ gem install chespirito adelnor
59
61
  ```
@@ -89,7 +91,7 @@ class HelloController < Chespirito::Controller
89
91
  end
90
92
  ```
91
93
 
92
- 4. Run the app using Adelnor (or you can choose other web server like Puma, Unicorn, etc):
94
+ 4. Run the app using Adelnor (or you can choose another web server like Puma, Unicorn, etc):
93
95
 
94
96
  ```ruby
95
97
  Adelnor::Server.run MyApp.application, 3000
@@ -99,4 +101,4 @@ Adelnor::Server.run MyApp.application, 3000
99
101
 
100
102
  ----
101
103
 
102
- [ASCII art generator](http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20)
104
+ [ASCII art generator](http://www.network-science.de/ascii/)
data/chespirito.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'chespirito'
5
- spec.version = '0.0.3'
5
+ spec.version = '0.0.4'
6
6
  spec.summary = 'Chespirito Ruby web framework'
7
7
  spec.description = 'A dead simple, yet Rack-compatible, web framework written in Ruby'
8
8
  spec.authors = ['Leandro Proença']
@@ -26,14 +26,14 @@ module Chespirito
26
26
  def dispatch(request) = @router.dispatch(request)
27
27
 
28
28
  def call(env)
29
- request = ::Chespirito::Request.build(env)
30
- response = dispatch(request)
31
-
32
- [
33
- response.status,
34
- response.headers,
35
- [response.body]
36
- ]
29
+ request = ::Chespirito::Request.build(env)
30
+ response = dispatch(request)
31
+
32
+ [
33
+ response.status,
34
+ response.headers,
35
+ [response.body]
36
+ ]
37
37
  end
38
38
  end
39
39
 
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'rack'
4
4
  require 'json'
5
+ require 'cgi'
5
6
 
6
7
  module Chespirito
7
8
  class Request
@@ -19,7 +20,9 @@ module Chespirito
19
20
  def self.build(env)
20
21
  rack_request = Rack::Request.new(env)
21
22
 
22
- body_params = rack_request.post? ? (JSON.parse(rack_request.body.read) rescue {}) : {}
23
+ body_params = rack_request.post? ? parse_body_params(rack_request.body.read,
24
+ rack_request.env['Content-Type']) : {}
25
+
23
26
  params = rack_request.params.merge(body_params)
24
27
 
25
28
  new(
@@ -31,6 +34,18 @@ module Chespirito
31
34
  )
32
35
  end
33
36
 
37
+ def self.parse_body_params(body_data, content_type)
38
+ case content_type
39
+ in 'application/json'; JSON.parse(body_data)
40
+ in 'application/x-www-form-urlencoded'
41
+ CGI.unescape(body_data).split('&').each_with_object({}) do |param, hash|
42
+ key, value = param.split('=')
43
+ hash[key] = value
44
+ end
45
+ else {}
46
+ end
47
+ end
48
+
34
49
  def add_param!(name, value)
35
50
  @params ||= {}
36
51
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chespirito
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Proença
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-24 00:00:00.000000000 Z
11
+ date: 2023-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -61,7 +61,7 @@ homepage: https://github.com/leandronsp/chespirito
61
61
  licenses:
62
62
  - MIT
63
63
  metadata: {}
64
- post_install_message:
64
+ post_install_message:
65
65
  rdoc_options: []
66
66
  require_paths:
67
67
  - lib
@@ -76,8 +76,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
78
  requirements: []
79
- rubygems_version: 3.3.3
80
- signing_key:
79
+ rubygems_version: 3.4.10
80
+ signing_key:
81
81
  specification_version: 4
82
82
  summary: Chespirito Ruby web framework
83
83
  test_files: []