panda 1.3.0 → 1.4.0

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.
@@ -4,12 +4,12 @@ describe Panda::Cloud do
4
4
 
5
5
  describe "region" do
6
6
  it "should tell the region" do
7
- Panda.configure do |c|
8
- c.access_key = "my_access_key"
9
- c.secret_key = "my_secret_key"
10
- c.api_host = "api.pandastream.com"
11
- c.cloud_id = 'my_cloud_id'
12
- c.api_port = 85
7
+ Panda.configure do
8
+ access_key "my_access_key"
9
+ secret_key "my_secret_key"
10
+ api_host "api.pandastream.com"
11
+ cloud_id 'my_cloud_id'
12
+ api_port 85
13
13
  end
14
14
 
15
15
  Panda.cloud.region.should == "us"
@@ -17,12 +17,12 @@ describe Panda::Cloud do
17
17
  end
18
18
 
19
19
  it "should tell the region" do
20
- Panda.configure do |c|
21
- c.access_key = "my_access_key"
22
- c.secret_key = "my_secret_key"
23
- c.api_host = "api.eu.pandastream.com"
24
- c.cloud_id = 'my_cloud_id'
25
- c.api_port = 85
20
+ Panda.configure do
21
+ access_key "my_access_key"
22
+ secret_key "my_secret_key"
23
+ api_host "api.eu.pandastream.com"
24
+ cloud_id 'my_cloud_id'
25
+ api_port 85
26
26
  end
27
27
 
28
28
  Panda.cloud.region.should == "eu"
@@ -31,14 +31,17 @@ describe Panda::Cloud do
31
31
 
32
32
  end
33
33
 
34
+
35
+
36
+
34
37
  describe "Using configure bloc" do
35
38
  before(:each) do
36
- Panda.configure do |c|
37
- c.access_key = "my_access_key"
38
- c.secret_key = "my_secret_key"
39
- c.api_host = "api.example.com"
40
- c.cloud_id = 'my_cloud_id'
41
- c.api_port = 85
39
+ Panda.configure do
40
+ access_key "my_access_key"
41
+ secret_key "my_secret_key"
42
+ api_host "api.example.com"
43
+ cloud_id 'my_cloud_id'
44
+ api_port 85
42
45
  end
43
46
  end
44
47
 
@@ -85,26 +88,32 @@ describe Panda::Cloud do
85
88
  to_return(:body => videos_json)
86
89
  @cloud.videos.create(:source_url => "my_source_url")
87
90
  end
88
- end
89
-
90
- describe "Using options on find" do
91
91
 
92
- it "should find a cloud" do
93
- cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\"}"
94
- stub_http_request(:get, /http:\/\/api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
95
- to_return(:body => cloud_json)
96
-
97
- @cloud = Panda::Cloud.find "my_cloud_id", {
98
- "access_key" => "my_access_key",
99
- "secret_key" => "my_secret_key",
100
- "api_host" => "api.example.com",
101
- "api_port" => 85,
102
- "format" => "json"
103
- }
104
-
105
- @cloud.s3_videos_bucket.should == "my_bucket"
92
+ it "should find return all cloud" do
93
+ clouds_json = "[{\"s3_videos_bucket\":\"my_bucket1\",\"id\":\"cloud1\"},{\"s3_videos_bucket\":\"my_bucket2\",\"id\":\"cloud2\"}]"
94
+
95
+ stub_http_request(:get, /api.example.com:85\/v2\/clouds.json/).to_return(:body => clouds_json)
96
+
97
+ cloud = Panda::Cloud.all
98
+ cloud.first.id.should == 'cloud1'
99
+ cloud.first.s3_videos_bucket.should == "my_bucket1"
100
+ cloud.size.should == 2
106
101
  end
107
102
  end
108
103
 
104
+
105
+ it "should create a cloud" do
106
+ cloud_json = "{\"s3_videos_bucket\":\"videobucket\",\"id\":\"my_cloud_id\"}"
107
+ stub_http_request(:post, /http:\/\/api.example.com:85\/v2\/clouds.json/).
108
+ with{|r| r.body =~ /s3_videos_bucket=videobucket/ && r.body =~ /user_aws_key=myaccesskey/ && r.body =~ /user_aws_secret=mysecretkey/ }.
109
+ to_return(:body => cloud_json)
110
+
111
+ @cloud = Panda::Cloud.create(:s3_videos_bucket => 'videobucket', :user_aws_key => 'myaccesskey', :user_aws_secret => 'mysecretkey')
112
+ @cloud.s3_videos_bucket.should == "videobucket"
113
+ end
114
+
109
115
  end
116
+
117
+
118
+
110
119
  end
@@ -3,12 +3,12 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe Panda::Encoding do
4
4
  before(:each) do
5
5
 
6
- Panda.configure do |c|
7
- c.access_key = "my_access_key"
8
- c.secret_key = "my_secret_key"
9
- c.api_host = "api.example.com"
10
- c.cloud_id = 'my_cloud_id'
11
- c.api_port = 85
6
+ Panda.configure do
7
+ access_key "my_access_key"
8
+ secret_key "my_secret_key"
9
+ api_host "api.example.com"
10
+ cloud_id 'my_cloud_id'
11
+ api_port 85
12
12
  end
13
13
 
14
14
  end
@@ -62,12 +62,12 @@ describe Panda::Encoding do
62
62
  encodings.first.id.should == "456"
63
63
  end
64
64
 
65
- it "should return the video_url" do
65
+ it "should return the encoding url" do
66
66
  cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\", \"url\":\"http://my_bucket.s3.amazonaws.com/\"}"
67
67
  stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
68
68
  to_return(:body => cloud_json)
69
69
 
70
- encoding = Panda::Encoding.new({:id => "456", :extname => ".ext", :path => "abc/panda"})
70
+ encoding = Panda::Encoding.new({:id => "456", :extname => ".ext", :path => "abc/panda", :status => 'success'})
71
71
  encoding.url.should == "http://my_bucket.s3.amazonaws.com/abc/panda.ext"
72
72
  end
73
73
 
@@ -104,6 +104,25 @@ describe Panda::Encoding do
104
104
  encoding.profile_id.should == "901"
105
105
  end
106
106
 
107
+ it "should create an encoding through the association" do
108
+ video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
109
+ encoding_json = "{\"abc\":\"efg\",\"id\":\"456\", \"video_id\":\"123\", \"profile_id\":\"901\"}"
110
+
111
+ stub_http_request(:get, /api.example.com:85\/v2\/videos\/123.json/).
112
+ to_return(:body => video_json)
113
+
114
+ stub_http_request(:post, /api.example.com:85\/v2\/encodings.json/).
115
+ with{|r| r.body =~ /video_id=123/ && r.body =~ /profile_id=901/}.
116
+ to_return(:body => encoding_json)
117
+
118
+ video = Panda::Video.find("123")
119
+
120
+ encoding = video.encodings.create!(:profile_id => "901")
121
+ encoding.id.should == "456"
122
+ encoding.profile_id.should == "901"
123
+ end
124
+
125
+
107
126
  it "should filter the profile name after triggering the request" do
108
127
  video_json = "{\"source_url\":\"my_source_url\",\"id\":\"123\"}"
109
128
  encodings_1_json = "[{\"id\":\"456\", \"video_id\":\"123\", \"profile_name\":\"h264\"}]"
@@ -195,7 +214,7 @@ describe Panda::Encoding do
195
214
  stub_http_request(:get, /api.example.com:85\/v2\/encodings\/456.json/).
196
215
  to_return(:body => encoding_json)
197
216
 
198
- Panda::Encoding.id("456")
217
+ Panda::Encoding.find("456")
199
218
  end
200
219
 
201
220
  it "should tell if the encoding is success" do
@@ -3,20 +3,30 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe Panda::Video do
4
4
  before(:each) do
5
5
  cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\"}"
6
- stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
6
+ stub_http_request(:get, /api.example.com:443\/v2\/clouds\/my_cloud_id.json/).
7
7
  to_return(:body => cloud_json)
8
8
 
9
9
  my_heroku_url = "http://access_key:secret_key@api.example.com:85/my_cloud_id"
10
- Panda.configure do |c|
11
- c.heroku = my_heroku_url
12
- end
10
+ ENV['PANDASTREAM_URL']= my_heroku_url
13
11
  end
14
12
 
15
13
  it "should get all videos" do
14
+ Panda.configure_heroku
15
+
16
16
  videos_json = "[]"
17
- stub_http_request(:get, /api.example.com:85\/v2\/videos.json/).to_return(:body => videos_json)
17
+ stub_http_request(:get, /api.example.com:443\/v2\/videos.json/).to_return(:body => videos_json)
18
18
 
19
19
  Panda::Video.all.should be_empty
20
20
  end
21
21
 
22
+ it "should get all videos" do
23
+ Panda.configure ENV['PANDASTREAM_URL']
24
+
25
+ videos_json = "[]"
26
+ stub_http_request(:get, /api.example.com:443\/v2\/videos.json/).to_return(:body => videos_json)
27
+
28
+ Panda::Video.all.should be_empty
29
+ end
30
+
31
+
22
32
  end
@@ -1,7 +1,10 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'timecop'
2
3
 
3
4
  describe Panda do
4
5
  before(:each) do
6
+ new_time = Time.local(20010, 1, 12, 1, 0, 0)
7
+ Timecop.freeze(new_time)
5
8
  end
6
9
 
7
10
  describe "when not connected" do
@@ -10,17 +13,17 @@ describe Panda do
10
13
  it "should raise error for #{method}" do
11
14
  lambda {
12
15
  Panda.send(method, nil, nil)
13
- }.should raise_error("Not connected. Please connect! first.")
16
+ }.should raise_error("Panda is not configured!")
14
17
  end
15
18
  end
16
19
 
17
20
  end
18
21
 
19
- describe "Connected", :shared => true do
22
+ shared_examples_for "Connected" do
20
23
 
21
24
  it "should make get request with signed request to panda server" do
22
- 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")
23
- @panda.get("/videos").should == "abc"
25
+ stub_http_request(:get, "http://myapihost:85/v2/videos?access_key=my_access_key&cloud_id=my_cloud_id&signature=DYpg2K6d7kGo%2FuWPO%2FaQgtQmY3BPtFEtQgdQhVe8teM%3D&timestamp=20010-01-12T01%3A00%3A00.000000Z").to_return(:body => "{\"abc\":\"d\"}")
26
+ @panda.get("/videos").should == {'abc' => 'd'}
24
27
  end
25
28
 
26
29
  it "should create a signed version of the parameters" do
@@ -30,9 +33,9 @@ describe Panda do
30
33
  )
31
34
  signed_params.should == {
32
35
  'access_key' => "my_access_key",
33
- 'timestamp' => "2009-11-04T17:54:11+00:00",
36
+ 'timestamp' => "20010-01-12T01:00:00.000000Z",
34
37
  'cloud_id' => 'my_cloud_id',
35
- 'signature' => 'w66goW6Ve5CT9Ibbx3ryvq4XM8OfIfSZe5oapgZBaUs=',
38
+ 'signature' => 'aTgBGPeMrRk2Pnc13RxhK/ctWjDsL33vOFEC9qKLWV0=',
36
39
  'param1' => 'one',
37
40
  'param2' => 'two'
38
41
  }
@@ -41,9 +44,9 @@ describe Panda do
41
44
  it "should create a signed version of the parameters without additional arguments" do
42
45
  @panda.signed_params('POST', '/videos.json').should == {
43
46
  'access_key' => "my_access_key",
44
- 'timestamp' => "2009-11-04T17:54:11+00:00",
47
+ 'timestamp' => "20010-01-12T01:00:00.000000Z",
45
48
  'cloud_id' => 'my_cloud_id',
46
- 'signature' => 'TI2n/dsSllxFhxcEShRGKWtDSqxu+kuJUPs335NavMo='
49
+ 'signature' => 'g5lAh0cPC/qyUyTQb125vosvZwubQ+HgB04ORt+iw7o='
47
50
  }
48
51
  end
49
52
 
@@ -55,9 +58,9 @@ describe Panda do
55
58
  )
56
59
  signed_params.should == {
57
60
  'access_key' => "my_access_key",
58
- 'timestamp' => "2009-11-04T17:54:11+00:00",
61
+ 'timestamp' => "20010-01-12T01:00:00.000000Z",
59
62
  'cloud_id' => 'my_cloud_id',
60
- 'signature' => 'w5P9+xPpQpRlweTh0guFYqQOmF+ZuTKXCmaKpUP3sH0=',
63
+ 'signature' => 'G6LUFGIseRyDrqnj55t+CDrAGdRWtUWSqZwMmIsuW40=',
61
64
  'tilde' => '~',
62
65
  'space' => ' '
63
66
  }
@@ -67,9 +70,9 @@ describe Panda do
67
70
  it "should not include file inside the signature" do
68
71
  @panda.signed_params('POST', '/videos.json', { "file" => "my_file" }).should == {
69
72
  'access_key' => "my_access_key",
70
- 'timestamp' => "2009-11-04T17:54:11+00:00",
73
+ 'timestamp' => "20010-01-12T01:00:00.000000Z",
71
74
  'cloud_id' => 'my_cloud_id',
72
- 'signature' => 'TI2n/dsSllxFhxcEShRGKWtDSqxu+kuJUPs335NavMo=',
75
+ 'signature' => 'g5lAh0cPC/qyUyTQb125vosvZwubQ+HgB04ORt+iw7o=',
73
76
  'file' => "my_file"
74
77
  }
75
78
  end
@@ -77,63 +80,32 @@ describe Panda do
77
80
  it "should stringify keys" do
78
81
  @panda.signed_params('POST', '/videos.json', { :file => "symbol_key" }).should == {
79
82
  'access_key' => "my_access_key",
80
- 'timestamp' => "2009-11-04T17:54:11+00:00",
83
+ 'timestamp' => "20010-01-12T01:00:00.000000Z",
81
84
  'cloud_id' => 'my_cloud_id',
82
- 'signature' => 'TI2n/dsSllxFhxcEShRGKWtDSqxu+kuJUPs335NavMo=',
85
+ 'signature' => 'g5lAh0cPC/qyUyTQb125vosvZwubQ+HgB04ORt+iw7o=',
83
86
  'file' => "symbol_key"
84
87
  }
85
88
  end
86
-
87
- it "should return a json file for every http code" do
88
- stub_http_request(:get, "http://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")
89
-
90
- resource = RestClient::Resource.new("http://myapihost:85/v2")
91
- RestClient::Resource.stub!(:new).and_return(resource)
92
-
93
- e = RestClient::Exception.new({:body => "abc", :code => 400})
94
- e.stub!(:http_body).and_return("abc")
95
-
96
- resource.stub!(:get).and_raise(e)
97
-
98
- 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', "format" => "json" })
99
- panda.get("/videos").should == "abc"
100
- end
101
89
  end
102
-
103
- describe "Connected with a string url" do
104
- before(:each) do
105
- @panda = Panda::Connection.new('http://my_access_key:my_secret_key@myapihost:85/my_cloud_id', "format" => "json")
106
- end
107
90
 
108
- it_should_behave_like "Connected"
109
- end
110
-
111
91
  describe "Panda.connect " do
112
92
  before(:each) do
113
- @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" })
93
+ @panda = Panda.connect!({"access_key" => "my_access_key", "secret_key" => "my_secret_key", "api_host" => "myapihost", "api_port" => 85, "cloud_id" => 'my_cloud_id'})
114
94
  end
115
95
  it_should_behave_like "Connected"
116
96
  end
117
97
 
118
98
  describe "Panda.connect with symbols" do
119
99
  before(:each) do
120
- @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" })
100
+ @panda = Panda.connect!({:access_key => "my_access_key", :secret_key => "my_secret_key", :api_host => "myapihost", :api_port => 85, :cloud_id => 'my_cloud_id'})
121
101
  end
122
102
 
123
103
  it_should_behave_like "Connected"
124
104
  end
125
-
126
-
127
- describe "Panda.connect with PANDASTREAM_URL" do
128
- before(:each) do
129
- @panda = Panda.connect!('http://my_access_key:my_secret_key@myapihost:85/my_cloud_id', "format" => "json")
130
- end
131
- it_should_behave_like "Connected"
132
- end
133
105
 
134
106
  describe "Panda::Connection.new" do
135
107
  before(:each) do
136
- @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', "format" => "json" })
108
+ @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'})
137
109
  end
138
110
  it_should_behave_like "Connected"
139
111
  end
@@ -145,34 +117,35 @@ describe Panda do
145
117
  end
146
118
 
147
119
  it "should make get request" do
148
- 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 => "{\"key\":\"value\"}")
120
+ stub_http_request(:get, "http://myapihost:85/v2/videos?access_key=my_access_key&cloud_id=my_cloud_id&signature=DYpg2K6d7kGo%2FuWPO%2FaQgtQmY3BPtFEtQgdQhVe8teM%3D&timestamp=20010-01-12T01%3A00%3A00.000000Z").to_return(:body => "{\"key\":\"value\"}")
149
121
  @panda.get("/videos").should == {'key' => 'value'}
150
122
  end
151
123
 
152
124
  end
153
-
154
- describe "ActiveSupport::JSON parsing" do
155
-
156
- it "should use active support if it has been defined" do
157
- @panda = Panda::Connection.new('http://my_access_key:my_secret_key@myapihost:85/my_cloud_id')
158
- 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")
159
-
160
-
161
- module ActiveSupport
162
- class JSON; end
163
- end
164
-
165
- ActiveSupport::JSON.should_receive(:decode).with("abc").and_return("blah")
166
- @panda.get("/videos").should == "blah"
167
-
168
- Object.send :remove_const, :ActiveSupport
169
- end
170
- end
125
+
126
+ # describe "ActiveSupport::JSON parsing" do
127
+ #
128
+ # it "should use active support if it has been defined and if restclient is used " do
129
+ # @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' })
130
+ # Panda.adapter = 'restclient'
131
+ #
132
+ # stub_http_request(:get, "http://myapihost:85/v2/videos?access_key=my_access_key&cloud_id=my_cloud_id&signature=DYpg2K6d7kGo%2FuWPO%2FaQgtQmY3BPtFEtQgdQhVe8teM%3D&timestamp=20010-01-12T01%3A00%3A00.000000Z").to_return(:body => "abc")
133
+ #
134
+ #
135
+ # module ActiveSupport
136
+ # class JSON; end
137
+ # end
138
+ #
139
+ # ActiveSupport::JSON.should_receive(:decode).with("abc").and_return("blah")
140
+ # @panda.get("/videos").should == "blah"
141
+ #
142
+ # Object.send :remove_const, :ActiveSupport
143
+ # end
144
+ # end
171
145
 
172
146
  describe "parsing" do
173
147
  it "should raise an error if the response is not JSON parsable" do
174
148
  @connection = Panda::Connection.new({"access_key" => "my_access_key", "secret_key" => "my_secret_key", "api_host" => "myapihost", "api_port" => 85, "cloud_id" => 'my_cloud_id' })
175
- @connection.raise_error=true
176
149
 
177
150
  stub_http_request(:get, //).to_return(:body => "blahblah")
178
151
 
@@ -6,12 +6,12 @@ describe Panda::Profile do
6
6
  stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
7
7
  to_return(:body => cloud_json)
8
8
 
9
- Panda.configure do |c|
10
- c.access_key = "my_access_key"
11
- c.secret_key = "my_secret_key"
12
- c.api_host = "api.example.com"
13
- c.cloud_id = 'my_cloud_id'
14
- c.api_port = 85
9
+ Panda.configure do
10
+ access_key "my_access_key"
11
+ secret_key "my_secret_key"
12
+ api_host "api.example.com"
13
+ cloud_id 'my_cloud_id'
14
+ api_port 85
15
15
  end
16
16
 
17
17
  end
@@ -1,8 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'panda'
4
- require 'spec'
5
- require 'spec/autorun'
4
+ require 'rspec'
6
5
 
7
6
  require 'webmock/rspec'
8
7
  include WebMock::API
@@ -11,10 +10,10 @@ def hputs(*args)
11
10
  puts ERB::Util.html_escape(args.join("\n")).gsub(/\r?\n/, '<br/>') + '<br/>'
12
11
  end
13
12
 
14
- Spec::Runner.configure do |config|
13
+ RSpec.configure do |config|
15
14
  config.before(:each) do
16
15
  Panda.instance_variable_set("@connection", nil)
17
16
  Panda.instance_variable_set("@cloud", nil)
18
- Time.stub!(:now).and_return(mock("time", :iso8601 => "2009-11-04T17:54:11+00:00"))
17
+ Time.now.stub!(:utc).and_return(mock("time", :iso8601 => "2009-11-04T17:54:11+00:00"))
19
18
  end
20
19
  end