panda 0.6.2 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -104,6 +104,17 @@ To do this, a method `signed_params()` is supported:
104
104
  # 'some_param' => 'some_value',
105
105
  # 'timestamp' => '2010-02-26T15:04:27.039620'}
106
106
 
107
+ ## Hash or JSON
108
+ Since Panda 0.6, PandaGem returns a Hash by default. If you want PandaGem to return JSON do the following:
109
+
110
+ Panda.connect!({
111
+ :cloud_id => 'cloud_id',
112
+ :access_key => 'access_key',
113
+ :secret_key => 'secret_key',
114
+ :format => 'json'
115
+ })
116
+
117
+
107
118
  Copyright
108
119
  ---------
109
120
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.2
1
+ 0.6.3
data/lib/panda/panda.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'restclient'
2
- require 'json'
2
+ require 'json' unless defined?(ActiveSupport::JSON)
3
3
 
4
4
  class Panda
5
5
 
@@ -56,10 +56,10 @@ class Panda
56
56
  @format = "hash"
57
57
 
58
58
  if auth_params.class == String
59
- self.format = options["format"]
59
+ self.format = options[:format] || options["format"]
60
60
  init_from_url(auth_params)
61
61
  else
62
- self.format = auth_params["format"]
62
+ self.format = auth_params[:format] || auth_params["format"]
63
63
  init_from_hash(auth_params)
64
64
  end
65
65
 
@@ -69,7 +69,7 @@ class Panda
69
69
  def format=(ret_format)
70
70
  if ret_format
71
71
  raise "Format unknown" if !["json", "hash"].include?(ret_format.to_s)
72
- @format = ret_format
72
+ @format = ret_format.to_s
73
73
  end
74
74
  end
75
75
 
@@ -147,7 +147,11 @@ class Panda
147
147
 
148
148
  def format_to(response)
149
149
  if self.format == "json"
150
- return response
150
+ response
151
+
152
+ elsif defined?(ActiveSupport::JSON)
153
+ ActiveSupport::JSON.decode(response)
154
+
151
155
  else
152
156
  JSON.parse(response)
153
157
  end
@@ -180,4 +184,4 @@ class Panda
180
184
  @prefix = params["prefix_url"] || "v#{@api_version}"
181
185
  end
182
186
  end
183
- end
187
+ end
data/panda.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{panda}
8
- s.version = "0.6.2"
8
+ s.version = "0.6.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["New Bamboo"]
12
- s.date = %q{2010-06-11}
12
+ s.date = %q{2010-07-01}
13
13
  s.description = %q{Panda Client}
14
14
  s.email = %q{info@pandastream.com}
15
15
  s.extra_rdoc_files = [
data/spec/panda_spec.rb CHANGED
@@ -116,6 +116,14 @@ describe Panda do
116
116
  it_should_behave_like "Connected"
117
117
  end
118
118
 
119
+ describe "Panda.connect with symbols" do
120
+ before(:each) do
121
+ @panda = Panda.connect!({:access_key => "my_access_key", :secret_key => "my_secret_key", :api_host => "myapihost", :api_port => 85, :cloud_id => 'my_cloud_id', :format => "json" })
122
+ end
123
+ it_should_behave_like "Connected"
124
+ end
125
+
126
+
119
127
  describe "Panda.connect with PANDASTREAM_URL" do
120
128
  before(:each) do
121
129
  Panda.connect!('http://my_access_key:my_secret_key@myapihost:85/my_cloud_id', "format" => "json")
@@ -134,8 +142,6 @@ describe Panda do
134
142
  describe "Using hash as a return format" do
135
143
 
136
144
  before(:each) do
137
- puts "here"
138
-
139
145
  @panda = Panda::Connection.new({"access_key" => "my_access_key", "secret_key" => "my_secret_key", "api_host" => "myapihost", "api_port" => 85, "cloud_id" => 'my_cloud_id' })
140
146
  end
141
147
 
@@ -145,6 +151,22 @@ describe Panda do
145
151
  end
146
152
 
147
153
  end
154
+
155
+ describe "ActiveSupport::JSON parsing" do
156
+
157
+ it "should use active support if it has been defined" do
158
+ @panda = Panda::Connection.new('http://my_access_key:my_secret_key@myapihost:85/my_cloud_id')
159
+ stub_http_request(:get, "myapihost:85/v2/videos?timestamp=2009-11-04T17%3A54%3A11%2B00%3A00&signature=CxSYPM65SeeWH4CE%2FLcq7Ny2NtwxlpS8QOXG2BKe4p8%3D&access_key=my_access_key&cloud_id=my_cloud_id").to_return(:body => "abc")
160
+
161
+
162
+ module ActiveSupport
163
+ class JSON; end
164
+ end
165
+
166
+ ActiveSupport::JSON.should_receive(:decode).with("abc").and_return("blah")
167
+ @panda.get("/videos").should == "blah"
168
+ end
169
+ end
148
170
 
149
171
 
150
172
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - New Bamboo
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-06-11 00:00:00 +01:00
12
+ date: 2010-07-01 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency