stripe 1.6.2 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/stripe.rb +39 -2
  2. data/lib/stripe/version.rb +1 -1
  3. metadata +4 -4
@@ -96,6 +96,39 @@ module Stripe
96
96
  object
97
97
  end
98
98
  end
99
+
100
+ def self.encode_key(key)
101
+ URI.escape(key.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
102
+ end
103
+
104
+ def self.flatten_params(params, parent_key = nil)
105
+ result = []
106
+ params.each do |key, value|
107
+ calculated_key = parent_key ? "#{parent_key}[#{encode_key(key)}]" : encode_key(key)
108
+ if value.is_a? Hash
109
+ result += flatten_params(value, calculated_key)
110
+ elsif value.is_a? Array
111
+ result += flatten_params_array(value, calculated_key)
112
+ else
113
+ result << [calculated_key, value]
114
+ end
115
+ end
116
+ result
117
+ end
118
+
119
+ def self.flatten_params_array value, calculated_key
120
+ result = []
121
+ value.each do |elem|
122
+ if elem.is_a? Hash
123
+ result += flatten_params(elem, calculated_key)
124
+ elsif elem.is_a? Array
125
+ result += flatten_params_array(elem, calculated_key)
126
+ else
127
+ result << ["#{calculated_key}[]", elem]
128
+ end
129
+ end
130
+ result
131
+ end
99
132
  end
100
133
 
101
134
  module APIOperations
@@ -496,10 +529,14 @@ module Stripe
496
529
  }
497
530
 
498
531
  params = Util.objects_to_ids(params)
532
+ url = self.api_url(url)
499
533
  case method.to_s.downcase.to_sym
500
534
  when :get, :head, :delete
501
535
  # Make params into GET parameters
502
- headers = { :params => params }.merge(headers)
536
+ if params && params.count
537
+ query_string = Util.flatten_params(params).collect{|p| "#{p[0]}=#{p[1]}"}.join('&')
538
+ url += "?#{query_string}"
539
+ end
503
540
  payload = nil
504
541
  else
505
542
  payload = params
@@ -521,7 +558,7 @@ module Stripe
521
558
  }.merge(headers)
522
559
  opts = {
523
560
  :method => method,
524
- :url => self.api_url(url),
561
+ :url => url,
525
562
  :user => api_key,
526
563
  :headers => headers,
527
564
  :open_timeout => 30,
@@ -1,3 +1,3 @@
1
1
  module Stripe
2
- VERSION = '1.6.2'
2
+ VERSION = '1.6.3'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 6
9
- - 2
10
- version: 1.6.2
9
+ - 3
10
+ version: 1.6.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ross Boucher
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-02-24 00:00:00 Z
19
+ date: 2012-03-22 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: rest-client