pusher 0.8.4 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
1
- require 'crack/core_extensions' # Used for Hash#to_params
2
1
  require 'hmac-sha2'
3
2
  require 'multi_json'
4
3
 
@@ -4,6 +4,54 @@ require 'multi_json'
4
4
 
5
5
  module Pusher
6
6
  class Request
7
+ # Query string encoding extracted with thanks from em-http-request
8
+ module QueryEncoder
9
+ def encode_query(uri, query)
10
+ encoded_query = if query.kind_of?(Hash)
11
+ query.map { |k, v| encode_param(k, v) }.join('&')
12
+ else
13
+ query.to_s
14
+ end
15
+
16
+ if uri && !uri.query.to_s.empty?
17
+ encoded_query = [encoded_query, uri.query].reject {|part| part.empty?}.join("&")
18
+ end
19
+ encoded_query.to_s.empty? ? uri.path : "#{uri.path}?#{encoded_query}"
20
+ end
21
+
22
+ # URL encodes query parameters:
23
+ # single k=v, or a URL encoded array, if v is an array of values
24
+ def encode_param(k, v)
25
+ if v.is_a?(Array)
26
+ v.map { |e| escape(k) + "[]=" + escape(e) }.join("&")
27
+ else
28
+ escape(k) + "=" + escape(v)
29
+ end
30
+ end
31
+
32
+ def escape(s)
33
+ if defined?(EscapeUtils)
34
+ EscapeUtils.escape_url(s.to_s)
35
+ else
36
+ s.to_s.gsub(/([^a-zA-Z0-9_.-]+)/n) {
37
+ '%'+$1.unpack('H2'*bytesize($1)).join('%').upcase
38
+ }
39
+ end
40
+ end
41
+
42
+ if ''.respond_to?(:bytesize)
43
+ def bytesize(string)
44
+ string.bytesize
45
+ end
46
+ else
47
+ def bytesize(string)
48
+ string.size
49
+ end
50
+ end
51
+ end
52
+
53
+ include QueryEncoder
54
+
7
55
  def initialize(verb, uri, params, body = nil, token = nil)
8
56
  @verb = verb
9
57
  @uri = uri
@@ -32,11 +80,13 @@ module Pusher
32
80
  begin
33
81
  case @verb
34
82
  when :post
35
- response = @http_sync.post("#{@uri.path}?#{@params.to_params}",
36
- @body, { 'Content-Type'=> 'application/json' })
83
+ response = @http_sync.post(encode_query(@uri, @params), @body, {
84
+ 'Content-Type'=> 'application/json'
85
+ })
37
86
  when :get
38
- response = @http_sync.get("#{@uri.path}?#{@params.to_params}",
39
- { 'Content-Type'=> 'application/json' })
87
+ response = @http_sync.get(encode_query(@uri, @params), {
88
+ 'Content-Type'=> 'application/json'
89
+ })
40
90
  else
41
91
  raise "Unknown verb"
42
92
  end
data/pusher.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "pusher"
6
- s.version = "0.8.4"
6
+ s.version = "0.8.5"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Pusher"]
9
9
  s.email = ["support@pusher.com"]
@@ -12,7 +12,6 @@ Gem::Specification.new do |s|
12
12
  s.description = %q{Wrapper for pusher.com REST api}
13
13
 
14
14
  s.add_dependency "multi_json", "~> 1.0"
15
- s.add_dependency "crack", "~> 0.1.0"
16
15
  s.add_dependency "ruby-hmac", "~> 0.4.0"
17
16
  s.add_dependency 'signature', "~> 0.1.2"
18
17
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.4
4
+ version: 0.8.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-14 00:00:00.000000000Z
12
+ date: 2011-12-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
16
- requirement: &70240168472560 !ruby/object:Gem::Requirement
16
+ requirement: &70170954250900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,10 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70240168472560
25
- - !ruby/object:Gem::Dependency
26
- name: crack
27
- requirement: &70240168472100 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: 0.1.0
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *70240168472100
24
+ version_requirements: *70170954250900
36
25
  - !ruby/object:Gem::Dependency
37
26
  name: ruby-hmac
38
- requirement: &70240168471520 !ruby/object:Gem::Requirement
27
+ requirement: &70170954250400 !ruby/object:Gem::Requirement
39
28
  none: false
40
29
  requirements:
41
30
  - - ~>
@@ -43,10 +32,10 @@ dependencies:
43
32
  version: 0.4.0
44
33
  type: :runtime
45
34
  prerelease: false
46
- version_requirements: *70240168471520
35
+ version_requirements: *70170954250400
47
36
  - !ruby/object:Gem::Dependency
48
37
  name: signature
49
- requirement: &70240168470820 !ruby/object:Gem::Requirement
38
+ requirement: &70170954249520 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ~>
@@ -54,10 +43,10 @@ dependencies:
54
43
  version: 0.1.2
55
44
  type: :runtime
56
45
  prerelease: false
57
- version_requirements: *70240168470820
46
+ version_requirements: *70170954249520
58
47
  - !ruby/object:Gem::Dependency
59
48
  name: rspec
60
- requirement: &70240168470200 !ruby/object:Gem::Requirement
49
+ requirement: &70170954248040 !ruby/object:Gem::Requirement
61
50
  none: false
62
51
  requirements:
63
52
  - - ~>
@@ -65,10 +54,10 @@ dependencies:
65
54
  version: '2.0'
66
55
  type: :development
67
56
  prerelease: false
68
- version_requirements: *70240168470200
57
+ version_requirements: *70170954248040
69
58
  - !ruby/object:Gem::Dependency
70
59
  name: webmock
71
- requirement: &70240168469760 !ruby/object:Gem::Requirement
60
+ requirement: &70170954246460 !ruby/object:Gem::Requirement
72
61
  none: false
73
62
  requirements:
74
63
  - - ! '>='
@@ -76,10 +65,10 @@ dependencies:
76
65
  version: '0'
77
66
  type: :development
78
67
  prerelease: false
79
- version_requirements: *70240168469760
68
+ version_requirements: *70170954246460
80
69
  - !ruby/object:Gem::Dependency
81
70
  name: em-http-request
82
- requirement: &70240168468900 !ruby/object:Gem::Requirement
71
+ requirement: &70170954244800 !ruby/object:Gem::Requirement
83
72
  none: false
84
73
  requirements:
85
74
  - - ~>
@@ -87,10 +76,10 @@ dependencies:
87
76
  version: 1.0.0
88
77
  type: :development
89
78
  prerelease: false
90
- version_requirements: *70240168468900
79
+ version_requirements: *70170954244800
91
80
  - !ruby/object:Gem::Dependency
92
81
  name: rake
93
- requirement: &70240168467600 !ruby/object:Gem::Requirement
82
+ requirement: &70170954244120 !ruby/object:Gem::Requirement
94
83
  none: false
95
84
  requirements:
96
85
  - - ! '>='
@@ -98,7 +87,7 @@ dependencies:
98
87
  version: '0'
99
88
  type: :development
100
89
  prerelease: false
101
- version_requirements: *70240168467600
90
+ version_requirements: *70170954244120
102
91
  description: Wrapper for pusher.com REST api
103
92
  email:
104
93
  - support@pusher.com
@@ -142,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
131
  version: '0'
143
132
  requirements: []
144
133
  rubyforge_project:
145
- rubygems_version: 1.8.6
134
+ rubygems_version: 1.8.11
146
135
  signing_key:
147
136
  specification_version: 3
148
137
  summary: Pusher API client