cine_io 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -2
- data/cine_io.gemspec +2 -0
- data/lib/cine_io.rb +4 -0
- data/lib/cine_io/resource_handler.rb +4 -2
- data/lib/cine_io/usage_handler.rb +22 -0
- data/lib/cine_io/version.rb +1 -1
- data/spec/cine_io/peer_spec.rb +1 -1
- data/spec/cine_io/usage_handler_spec.rb +41 -0
- data/spec/cine_io_spec.rb +5 -0
- data/spec/fixtures/vcr_cassettes/usage_project.yml +41 -0
- data/spec/fixtures/vcr_cassettes/usage_stream.yml +41 -0
- data/spec/spec_helper.rb +2 -0
- metadata +23 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 528e5a1955d49b0a66e7c72df42a6d2e4d9ab568
|
4
|
+
data.tar.gz: 99728496117f2929001f8d711620d843bc6c0f03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d8f1a68944bd0a590638f2b909eda3b58328a13c21d45c364bed5d1b16e7d79f46a208981ec7a033b3b4cc334b86ee989f7d0b5a0624be9d7fec7ef862d41e5
|
7
|
+
data.tar.gz: e6014ebf70ae7e1770d2055ea1f19caec3a28cc571f89878c554c4b4346eaee13da161fb0e92d0ede988ad4b9108d5fb40733dc52e66082ad221b3165d09605c
|
data/README.md
CHANGED
@@ -135,9 +135,33 @@ recordings = client.streams.recordings.delete('STREAM_ID', 'recordingName')
|
|
135
135
|
#### Identity Signature Generation
|
136
136
|
|
137
137
|
```ruby
|
138
|
-
|
138
|
+
identity = "Unique user name to your app"
|
139
139
|
response = client.peer.generate_identity_signature(identity)
|
140
|
-
|
140
|
+
# response looks like {signature: "sha1-hash", timestamp: 1420258111, identity: "Unique user name to your app"}
|
141
|
+
```
|
142
|
+
|
143
|
+
|
144
|
+
### Usage
|
145
|
+
|
146
|
+
Use these api endpoints to fetch the monthly usage for a project or a stream.
|
147
|
+
|
148
|
+
#### Project Usage
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
options = {:month => new Date, :report => ['bandwidth, 'peer']}
|
152
|
+
response = client.usage.project(options)
|
153
|
+
// response looks like {bandwidth: 12345, storage: 54321, month: "month (ISO 8601 format)", secretKey: "YOUR SECRET KEY"}
|
154
|
+
// bandwidth and storage are represented in bytes
|
155
|
+
```
|
156
|
+
|
157
|
+
#### Stream Usage
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
id = 'STREAM_ID'
|
161
|
+
options = {:month => new Date, :report => ['bandwidth, 'peer']}
|
162
|
+
response = client.usage.stream(id, options);
|
163
|
+
// response looks like {bandwidth: 12345, storage: 54321, month: "month (ISO 8601 format)", secretKey: "YOUR SECRET KEY", id: "STREAM_ID"}
|
164
|
+
// bandwidth and storage are represented in bytes
|
141
165
|
```
|
142
166
|
|
143
167
|
## Contributing
|
data/cine_io.gemspec
CHANGED
@@ -18,6 +18,8 @@ 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 "queryparams", "~> 0.0.3"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
24
|
spec.add_development_dependency "rake", '~> 10.3.0'
|
23
25
|
spec.add_development_dependency "rspec", '~> 3.0.0'
|
data/lib/cine_io.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require('queryparams')
|
2
|
+
|
1
3
|
class CineIo::ResourceHandler
|
2
4
|
|
3
5
|
protected
|
@@ -10,7 +12,7 @@ class CineIo::ResourceHandler
|
|
10
12
|
|
11
13
|
def get_resource(path, params={})
|
12
14
|
uri = URI.parse("#{CineIo::BASE_URL}#{path}")
|
13
|
-
uri.query =
|
15
|
+
uri.query = QueryParams.encode({:secretKey => @client.config.fetch(:secretKey)}.merge(params))
|
14
16
|
http = Net::HTTP.new(uri.host, uri.port)
|
15
17
|
http.use_ssl = (uri.scheme == "https")
|
16
18
|
|
@@ -23,7 +25,7 @@ class CineIo::ResourceHandler
|
|
23
25
|
|
24
26
|
def get_resource_with_master_key(path, params={})
|
25
27
|
uri = URI.parse("#{CineIo::BASE_URL}#{path}")
|
26
|
-
uri.query =
|
28
|
+
uri.query = QueryParams.encode({:masterKey => @client.config.fetch(:masterKey)}.merge(params))
|
27
29
|
http = Net::HTTP.new(uri.host, uri.port)
|
28
30
|
http.use_ssl = (uri.scheme == "https")
|
29
31
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
class CineIo::UsageHandler < CineIo::ResourceHandler
|
4
|
+
|
5
|
+
def project(options)
|
6
|
+
params = {
|
7
|
+
:month => options.fetch(:month).utc.iso8601,
|
8
|
+
:report => options.fetch(:report)
|
9
|
+
}
|
10
|
+
get_resource("/usage/project", params)
|
11
|
+
end
|
12
|
+
|
13
|
+
def stream(id, options)
|
14
|
+
params = {
|
15
|
+
:month => options.fetch(:month).utc.iso8601,
|
16
|
+
:report => options.fetch(:report),
|
17
|
+
:id => id
|
18
|
+
}
|
19
|
+
get_resource("/usage/stream", params)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/cine_io/version.rb
CHANGED
data/spec/cine_io/peer_spec.rb
CHANGED
@@ -12,7 +12,7 @@ describe CineIo::Peer do
|
|
12
12
|
time = Time.parse("Jan 2 2015")
|
13
13
|
allow(Time).to receive(:now) { time }
|
14
14
|
|
15
|
-
expect(subject.generate_identity_signature('Thomas')).to eq(identity: "Thomas", signature: "
|
15
|
+
expect(subject.generate_identity_signature('Thomas')).to eq(identity: "Thomas", signature: "604d94e08118b3539d12d9394fc5c0e27f9959dc", timestamp: 1420156800)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CineIo::UsageHandler do
|
4
|
+
|
5
|
+
let(:client) { CineIo::Client.new(:secretKey => "THE PROJECT SECRET KEY") }
|
6
|
+
|
7
|
+
subject { described_class.new(client) }
|
8
|
+
|
9
|
+
describe '#project' do
|
10
|
+
it "returns the project usage report" do
|
11
|
+
time = Time.parse("January 06 2015")
|
12
|
+
VCR.use_cassette('usage_project') do
|
13
|
+
options = {:month => time, :report => ['bandwidth', 'storage']}
|
14
|
+
result = subject.project(options)
|
15
|
+
|
16
|
+
expect(result["secretKey"]).to eq('THE PROJECT SECRET KEY')
|
17
|
+
expect(result["bandwidth"]).to eq(1073741824)
|
18
|
+
expect(result["storage"]).to eq(2147483648)
|
19
|
+
expect(result["month"]).to eq("2015-01-06T00:00:00.000Z")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#stream' do
|
25
|
+
it "returns the stream usage report" do
|
26
|
+
time = Time.parse("January 06 2015")
|
27
|
+
VCR.use_cassette('usage_stream') do
|
28
|
+
id = "THE STREAM ID"
|
29
|
+
options = {:month => time, :report => ['bandwidth', 'storage']}
|
30
|
+
result = subject.stream(id, options)
|
31
|
+
|
32
|
+
expect(result["id"]).to eq('THE STREAM ID')
|
33
|
+
expect(result["secretKey"]).to eq('THE PROJECT SECRET KEY')
|
34
|
+
expect(result["bandwidth"]).to eq(1073741824)
|
35
|
+
expect(result["storage"]).to eq(2147483648)
|
36
|
+
expect(result["month"]).to eq("2015-01-06T00:00:00.000Z")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/spec/cine_io_spec.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://www.cine.io/api/1/-/usage/project?month=2015-01-06T00:00:00Z&report%5B0%5D=bandwidth&report%5B1%5D=storage&secretKey=THE%20PROJECT%20SECRET%20KEY
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- ! '*/*'
|
12
|
+
User-Agent:
|
13
|
+
- Ruby
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Content-Type:
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
Date:
|
22
|
+
- Sun, 01 Jun 2014 07:27:53 GMT
|
23
|
+
Etag:
|
24
|
+
- ! '"-585713471"'
|
25
|
+
Set-Cookie:
|
26
|
+
- connect.sid=s%3ACxr5WVK6KEkFqdcFxxYTSTJ7.%2F7TTnVJK4mHsI%2FAIiKiebpUq5y5d5Fz8MmK7Azhad%2Bg;
|
27
|
+
Path=/; HttpOnly
|
28
|
+
Vary:
|
29
|
+
- Accept-Encoding
|
30
|
+
X-Powered-By:
|
31
|
+
- Express
|
32
|
+
Content-Length:
|
33
|
+
- '217'
|
34
|
+
Connection:
|
35
|
+
- keep-alive
|
36
|
+
body:
|
37
|
+
encoding: US-ASCII
|
38
|
+
string: ! '{"secretKey": "THE PROJECT SECRET KEY", "month": "2015-01-06T00:00:00.000Z", "bandwidth": 1073741824, "storage": 2147483648 }'
|
39
|
+
http_version:
|
40
|
+
recorded_at: Sun, 01 Jun 2014 07:27:53 GMT
|
41
|
+
recorded_with: VCR 2.3.0
|
@@ -0,0 +1,41 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://www.cine.io/api/1/-/usage/stream?id=THE%20STREAM%20ID&month=2015-01-06T00:00:00Z&report%5B0%5D=bandwidth&report%5B1%5D=storage&secretKey=THE%20PROJECT%20SECRET%20KEY
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- ! '*/*'
|
12
|
+
User-Agent:
|
13
|
+
- Ruby
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Content-Type:
|
20
|
+
- application/json; charset=utf-8
|
21
|
+
Date:
|
22
|
+
- Sun, 01 Jun 2014 07:27:53 GMT
|
23
|
+
Etag:
|
24
|
+
- ! '"-585713471"'
|
25
|
+
Set-Cookie:
|
26
|
+
- connect.sid=s%3ACxr5WVK6KEkFqdcFxxYTSTJ7.%2F7TTnVJK4mHsI%2FAIiKiebpUq5y5d5Fz8MmK7Azhad%2Bg;
|
27
|
+
Path=/; HttpOnly
|
28
|
+
Vary:
|
29
|
+
- Accept-Encoding
|
30
|
+
X-Powered-By:
|
31
|
+
- Express
|
32
|
+
Content-Length:
|
33
|
+
- '217'
|
34
|
+
Connection:
|
35
|
+
- keep-alive
|
36
|
+
body:
|
37
|
+
encoding: US-ASCII
|
38
|
+
string: ! '{"id": "THE STREAM ID", "secretKey": "THE PROJECT SECRET KEY", "month": "2015-01-06T00:00:00.000Z", "bandwidth": 1073741824, "storage": 2147483648 }'
|
39
|
+
http_version:
|
40
|
+
recorded_at: Sun, 01 Jun 2014 07:27:53 GMT
|
41
|
+
recorded_with: VCR 2.3.0
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cine_io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cine.io
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: queryparams
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.3
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,6 +119,7 @@ files:
|
|
105
119
|
- lib/cine_io/stream_recording.rb
|
106
120
|
- lib/cine_io/stream_recordings_handler.rb
|
107
121
|
- lib/cine_io/streams_handler.rb
|
122
|
+
- lib/cine_io/usage_handler.rb
|
108
123
|
- lib/cine_io/version.rb
|
109
124
|
- spec/cine_io/peer_spec.rb
|
110
125
|
- spec/cine_io/project_handler_spec.rb
|
@@ -114,6 +129,7 @@ files:
|
|
114
129
|
- spec/cine_io/stream_recordings_handler_spec.rb
|
115
130
|
- spec/cine_io/stream_spec.rb
|
116
131
|
- spec/cine_io/streams_handler_spec.rb
|
132
|
+
- spec/cine_io/usage_handler_spec.rb
|
117
133
|
- spec/cine_io_spec.rb
|
118
134
|
- spec/fixtures/vcr_cassettes/create_stream.yml
|
119
135
|
- spec/fixtures/vcr_cassettes/create_stream_error.yml
|
@@ -142,6 +158,8 @@ files:
|
|
142
158
|
- spec/fixtures/vcr_cassettes/update_project_error.yml
|
143
159
|
- spec/fixtures/vcr_cassettes/update_stream.yml
|
144
160
|
- spec/fixtures/vcr_cassettes/update_stream_error.yml
|
161
|
+
- spec/fixtures/vcr_cassettes/usage_project.yml
|
162
|
+
- spec/fixtures/vcr_cassettes/usage_stream.yml
|
145
163
|
- spec/spec_helper.rb
|
146
164
|
homepage: https://github.com/cine-io/cineio-ruby
|
147
165
|
licenses:
|
@@ -176,6 +194,7 @@ test_files:
|
|
176
194
|
- spec/cine_io/stream_recordings_handler_spec.rb
|
177
195
|
- spec/cine_io/stream_spec.rb
|
178
196
|
- spec/cine_io/streams_handler_spec.rb
|
197
|
+
- spec/cine_io/usage_handler_spec.rb
|
179
198
|
- spec/cine_io_spec.rb
|
180
199
|
- spec/fixtures/vcr_cassettes/create_stream.yml
|
181
200
|
- spec/fixtures/vcr_cassettes/create_stream_error.yml
|
@@ -204,4 +223,6 @@ test_files:
|
|
204
223
|
- spec/fixtures/vcr_cassettes/update_project_error.yml
|
205
224
|
- spec/fixtures/vcr_cassettes/update_stream.yml
|
206
225
|
- spec/fixtures/vcr_cassettes/update_stream_error.yml
|
226
|
+
- spec/fixtures/vcr_cassettes/usage_project.yml
|
227
|
+
- spec/fixtures/vcr_cassettes/usage_stream.yml
|
207
228
|
- spec/spec_helper.rb
|