plezi 0.12.1 → 0.12.2

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: bb98dd3b32e4204480007a592bdd9e7d7b55fa08
4
- data.tar.gz: b5b670f66538b2a98d7306176528ddfd45e6a878
3
+ metadata.gz: 57622e2bc4d95fe0c0902460b9d181632276064f
4
+ data.tar.gz: 2c5b4ea394f9984cd72c7707a423099402a323de
5
5
  SHA512:
6
- metadata.gz: 78e46c96f20cc3955000f0cb32a2ebf7c5cd1d472176bdba6990b3f4f840271a6cb3426bd0774eb96d9493e90e44ad22c68164ce4fa7bf2a4be4ef869ef12fe0
7
- data.tar.gz: 90fe75d999ab81c05ea98249907c368858eaf0c4bab5145630e23428cf3549a5c96eef0fc78abb53ae7b3341ddd34818723da8fd4b20fd28803da005bf25d5f6
6
+ metadata.gz: 54bfd6e45045a268a2980618e220976bfc92a8d1ad31312e1a1f9ebc276ecb6ad0e7f442841076ef8a554fc501e525647c39666ab360c02fb4bc67ddd648078e
7
+ data.tar.gz: bc7f627f2f9b9f068d72e22a4535ee4dafef8eec4363d49b39b53c4742a0b3fa0b3bb2dbd176ff463b39b3edbab7e3bd7b913e7905eed7ec6b8c989a112942ae
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  ***
4
4
 
5
+ Change log v.0.12.2
6
+
7
+ **Update**: Plezi now leverages Iodine's support for a File response body, allowing for a smaller memory footpring when sending large files.
8
+
9
+ **Fix**: fixed an issue where host aliases wouldn't initiate, causing host initiation to fail, due to a typo in the HTTPRouter.
10
+
11
+ **Fix**: fixed an issue with the plezi OAuth2 extention, which caused OAuth to fail when encoding URL data before initiating the OAuth process. OAuth2 should now work as expected. Plezi's OAuth2 has built-in support for both Google and Facebook authentication, as well as an API that allows implemnting more OAuth2 complient services (i.e. GitHub).
12
+
13
+ ***
14
+
5
15
  Change log v.0.12.1
6
16
 
7
17
  **Fix**: fixed an issue with the app template, where a typo (an extra comma sign ',') caused the `host` command to fail.
@@ -83,7 +83,7 @@ module Plezi
83
83
  url = "#{request.base_url}/#{url.to_s.gsub('_', '/')}" if url.is_a?(Symbol) || ( url.is_a?(String) && url.empty? ) || url.nil?
84
84
  # redirect
85
85
  response.status = options.delete(:status) || 302
86
- response['Location'] = url
86
+ response['location'] = url
87
87
  response['content-length'] ||= 0
88
88
  flash.update options
89
89
  true
@@ -119,7 +119,7 @@ module Plezi
119
119
  # this is also usful for offering a file name for the browser to "save as".
120
120
  #
121
121
  # it accepts:
122
- # data:: the data to be sent
122
+ # data:: the data to be sent - this could be a String or an open File handle.
123
123
  # options:: a hash of any of the options listed furtheron.
124
124
  #
125
125
  # the :symbol=>value options are:
@@ -129,15 +129,17 @@ module Plezi
129
129
  #
130
130
  def send_data data, options = {}
131
131
  raise 'Cannot use "send_data" after headers were sent' if response.headers_sent?
132
- Plezi.warn 'HTTP response buffer is cleared by `#send_data`' if response.body && response.body.any? && response.body.clear
133
- response << data
132
+ if response.body && response.body.any?
133
+ Plezi.warn 'existing response body was cleared by `#send_data`!'
134
+ response.body.close if response.body.respond_to? :close
135
+ end
136
+ response = data
134
137
 
135
138
  # set headers
136
139
  content_disposition = options[:inline] ? 'inline' : 'attachment'
137
- content_disposition << "; filename=#{options[:filename]}" if options[:filename]
140
+ content_disposition << "; filename=#{::File.basename(options[:filename])}" if options[:filename]
138
141
 
139
142
  response['content-type'] = (options[:type] ||= MimeTypeHelper::MIME_DICTIONARY[::File.extname(options[:filename])])
140
- response['content-length'] = data.bytesize rescue true
141
143
  response['content-disposition'] = content_disposition
142
144
  true
143
145
  end
@@ -47,13 +47,13 @@ module Plezi
47
47
  params[:public] ||= params[:root] # backwards compatability
48
48
  host_name = (host_name.is_a?(String) ? host_name.to_s.downcase : (host_name.is_a?(Regexp) ? host_name : :default))
49
49
  @active_host = get_host(host_name) || ( @hosts[host_name] = Host.new(params) )
50
- add_alias host_name, *params[:alias] if params[:alias]
50
+ add_alias host_name, *params[:alias] if params[:alias] # && host_name != :default
51
51
  @active_host
52
52
  end
53
53
  # adds an alias to an existing host name (normally through the :alias parameter in the `add_host` method).
54
54
  def add_alias host_name, *aliases
55
55
  host = get_host host_name
56
- raise "Couldn't find requested host to add alias." unless host.
56
+ raise "Couldn't find requested host to add alias." unless host
57
57
  aliases.each {|a| @hosts[a.to_s.downcase] = host}
58
58
  true
59
59
  end
@@ -120,7 +120,11 @@ module Plezi
120
120
 
121
121
  # send the file if it exists (no render needed)
122
122
  if File.exists?(source_file)
123
- data = Plezi.cache_needs_update?(source_file) ? Plezi.save_file(target_file, Plezi.reload_file(source_file), (params[:public] && params[:save_assets])) : Plezi.load_file(source_file)
123
+ data = if ::Plezi::Cache::CACHABLE.include?(::File.extname(source_file)[1..-1])
124
+ Plezi.cache_needs_update?(source_file) ? Plezi.save_file(target_file, Plezi.reload_file(source_file), (params[:public] && params[:save_assets])) : Plezi.load_file(source_file)
125
+ else
126
+ ::File.new source_file, 'rb'
127
+ end
124
128
  return (data ? Base::HTTPSender.send_raw_data(request, response, data, MimeTypeHelper::MIME_DICTIONARY[::File.extname(source_file)]) : false)
125
129
  end
126
130
 
@@ -49,7 +49,12 @@ module Plezi
49
49
  # sends a file/cacheed data if it exists. otherwise returns false.
50
50
  def send_file request, response, filename, status_code = 200, headers = {}
51
51
  if Plezi.file_exists?(filename) && !::File.directory?(filename)
52
- return send_raw_data request, response, Plezi.load_file(filename), MimeTypeHelper::MIME_DICTIONARY[::File.extname(filename)], status_code, headers
52
+ data = if Plezi::Cache::CACHABLE.include?(::File.extname(filename)[1..-1])
53
+ Plezi.load_file(filename)
54
+ else
55
+ ::File.new filename, 'rb'
56
+ end
57
+ return send_raw_data request, response, data , MimeTypeHelper::MIME_DICTIONARY[::File.extname(filename)], status_code, headers
53
58
  end
54
59
  return false
55
60
  end
@@ -59,8 +64,8 @@ module Plezi
59
64
  response.status = status_code
60
65
  response['content-type'] = mime
61
66
  response['cache-control'] ||= 'public, max-age=86400'
62
- response << data
63
- response['content-length'] = data.bytesize
67
+ response.body = data
68
+ # response['content-length'] = data.bytesize #this one is automated by the server and should be avoided to support Range requests.
64
69
  true
65
70
  end##########
66
71
 
@@ -88,8 +88,8 @@ module Plezi
88
88
  # options:: a Hash of options, some of which are required.
89
89
  #
90
90
  # The options are:
91
- # app_id:: Required. The aplication's unique ID registered with the service. i.e. ENV [FB_APP_ID] (storing these in environment variables is safer then hardcoding them)
92
- # app_secret:: Required. The aplication's unique secret registered with the service.
91
+ # app_id:: Required. The aplication's unique ID (sometimes called `client_id`) registered with the service. i.e. ENV [FB_APP_ID] (storing these in environment variables is safer then hardcoding them)
92
+ # app_secret:: Required. The aplication's unique secret registered with the service (sometimes called `client_secret`).
93
93
  # auth_url:: Required. The authentication URL. This is the url to which the user is redirected. i.e.: "https://www.facebook.com/dialog/oauth"
94
94
  # token_url:: Required. The token request URL. This is the url used to switch the single-use code into a persistant authentication token. i.e.: "https://www.googleapis.com/oauth2/v3/token"
95
95
  # profile_url:: Required. The URL used to ask the service for the user's profile (the service's API url). i.e.: "https://graph.facebook.com/v2.3/me"
@@ -110,7 +110,7 @@ module Plezi
110
110
  # * google token_url: "https://www.googleapis.com/oauth2/v3/token"
111
111
  # * google profile_url: "https://www.googleapis.com/plus/v1/people/me"
112
112
  #
113
- # to change the default url's for Facebook or Google, simpley re-register the service using this method.
113
+ # to change the default scope or url's for Facebook or Google, simpley re-register the service using this method.
114
114
  #
115
115
  def self.register_service service_name, options
116
116
  raise "Cannot register service, missing required information." unless service_name && options[:auth_url] && options[:token_url] && options[:profile_url] && options[:app_id] && options[:app_secret]
@@ -190,7 +190,7 @@ module Plezi
190
190
  def _auth_url_for service_name
191
191
  service = SERVICES[service_name]
192
192
  return nil unless service
193
- redirect_uri = Plezi::Base::Helpers.encode_url "#{request.base_url}/auth/#{service_name.to_s}", :url #response_type
193
+ redirect_uri = Plezi::Base::Helpers.encode_url "#{request.base_url}/auth/#{service_name.to_s}" #response_type
194
194
  return "#{service[:auth_url]}?client_id=#{service[:app_id]}&redirect_uri=#{redirect_uri}&scope=#{service[:scope]}&response_type=code"
195
195
  end
196
196
 
data/lib/plezi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Plezi
2
- VERSION = "0.12.1"
2
+ VERSION = "0.12.2"
3
3
  end
data/plezi.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "iodine", "~> 0.1.2"
21
+ spec.add_dependency "iodine", "~> 0.1.5"
22
22
  spec.add_development_dependency "bundler", "~> 1.7"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
 
@@ -29,7 +29,7 @@
29
29
  # flash:: a hash used for one-time cookies (get and set). any added values will be available for the same client for this and the next connection, after which they are removed.
30
30
  #
31
31
  # redirect_to:: easily set up redirection.
32
- # send_data:: easily send data, setting the content-type and content-length headers.
32
+ # send_data:: easily send data, setting the content-type header.
33
33
  # render:: easily render Slim, Haml and IRB files into String text.
34
34
  #
35
35
  class SampleController
@@ -73,8 +73,8 @@ host host: :default,
73
73
  # route "/:locale{#{I18n.available_locales.join "|"}}/*" , false if defined? I18n
74
74
  #
75
75
  # # OAuth2 - Facebook / Google authentication
76
- # require 'plezi/oauth'
77
76
  # ENV["FB_APP_ID"] ||= "app id"; ENV["FB_APP_SECRET"] ||= "secret"; ENV['GOOGLE_APP_ID'] = "app id"; ENV['GOOGLE_APP_SECRET'] = "secret"
77
+ # require 'plezi/oauth' # do this AFTER setting ENV variables.
78
78
  # create_auth_shared_route do |service_name, auth_token, remote_user_id, remote_user_email, remote_response|
79
79
  # # ...callback for authentication.
80
80
  # # This callback should return the app user object or false
@@ -10,7 +10,8 @@ var websocket = NaN
10
10
  var websocket_fail_count = 0
11
11
  // to limit failed reconnection attempts, set this to a number.
12
12
  var websocket_fail_limit = NaN
13
-
13
+ // to offer some space between reconnection attempts, set this interval in miliseconds.
14
+ var websocket_reconnect_interval = 250
14
15
 
15
16
  function init_websocket()
16
17
  {
@@ -33,12 +34,12 @@ function init_websocket()
33
34
  // update the count
34
35
  websocket_fail_count += 1;
35
36
  // try to reconect
36
- init_websocket();
37
+ setTimeout( init_websocket, websocket_reconnect_interval);
37
38
  };
38
39
  };
39
40
  websocket.onerror = function(e) {
40
41
  // update the count.
41
- websocket_fail_limit += 1
42
+ websocket_fail_count += 1
42
43
  // what do you want to do now?
43
44
  };
44
45
  websocket.onmessage = function(e) {
@@ -67,11 +67,13 @@ require 'pathname'
67
67
  Root = Pathname.new(File.dirname(__FILE__)).expand_path
68
68
  ```
69
69
 
70
- Then, we set up the Plezi service's parameters - parameters which Plezi will use to create our main service and host.
70
+ Then, we set up Plezi's Http Host parameters.
71
71
 
72
- A service, in this case, is realy just a nice word for the Plezi server (which might have a number of services or hosts). We will have only one service and one host, so it's very easy to set up.
72
+ A host, in this case, refers to the domain name that the request belongs to. The default domain name is a catch-all (answers requests with any domain name). Setting up hosts is a great way to manage sub-domains (i.e. serving two different home pages for `www.example.com` and `admin.example.com`).
73
73
 
74
- As you can see, some options are there for later, but are disabled for now.
74
+ We will have only one one host for this application, so it's very easy to set up.
75
+
76
+ As you can see, some options are there for later, but are disabled for now. here are some of the common options:
75
77
 
76
78
  - **public**: this option defines the folder from which Plezi should serve public static files (html files, images etc'). We will not be serving any static files at the moment, so this option is disabled.
77
79
 
@@ -81,17 +83,14 @@ As you can see, some options are there for later, but are disabled for now.
81
83
 
82
84
  - **_templates_**: this option tells Plezi where to look for template files (.haml / .erb files). Since we will use a template file for our HTML, let's go ahead and create a subfolder called `views` and set that as our templates source folder.
83
85
 
84
- - **ssl**: this option, if set to true, will make our service into an SSL/TSL encrypted service (as well as our websocket service)... we can leave this off for now - it's actually hardly ever used since it's usually better to leave that to our production server.
85
-
86
- - **port**: Hardcoding a port would override the default port (which is either 3000 or the default port specified using the `-p <port>`). For this demo, as in most cases, it's best to a avoid setting up a port and preffer the default preferance.
86
+ - **host**: a host name, if we need one (can also be a Regexp object).
87
87
 
88
88
  ```ruby
89
- service_options = {
89
+ host_options = {
90
90
  # public: Root.join('public').to_s,
91
91
  # assets: Root.join('assets').to_s,
92
92
  # assets_public: '/assets',
93
- templates: Root.join('views').to_s,
94
- ssl: false
93
+ templates: Root.join('views').to_s
95
94
  }
96
95
  ```
97
96
 
@@ -100,7 +99,7 @@ Next we call the `host` command - this command sets up some of the host options
100
99
  The port plezi uses by default is either 3000 [http://localhost:3000/](http://localhost:3000/) or the port defined when calling the script (i.e. `./mychat.rb -p 8080`).
101
100
 
102
101
  ```ruby
103
- host :default, service_options
102
+ host host_options
104
103
  ```
105
104
 
106
105
  Last, but not least, we tell Plezi to connect the root of our web application to our ChatController - in other words, make sure the root _path_ ('/') is connected to the ChatController class.
@@ -476,15 +475,14 @@ require 'pathname'
476
475
  Root = Pathname.new(File.dirname(__FILE__)).expand_path
477
476
 
478
477
  # set up the Plezi service options
479
- service_options = {
478
+ host_options = {
480
479
  # root: Root.join('public').to_s,
481
480
  # assets: Root.join('assets').to_s,
482
481
  # assets_public: '/',
483
- templates: Root.join('views').to_s,
484
- ssl: false
482
+ templates: Root.join('views').to_s
485
483
  }
486
484
 
487
- host :default, service_options
485
+ host host_options
488
486
 
489
487
  # this routes the root of the application ('/') to our ChatController
490
488
  route '/:id', ChatController
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plezi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.12.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Boaz Segev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-25 00:00:00.000000000 Z
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: iodine
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.2
19
+ version: 0.1.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.2
26
+ version: 0.1.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement