7d 0.0.1.pre → 0.0.1.pre.2
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.
- checksums.yaml +4 -4
- data/bin/7d +3 -12
- data/lib/7d/cli/app.rb +63 -5
- data/lib/7d/cli/signature_generator_factory.rb +26 -0
- data/lib/7d/endpoints/clip.rb +4 -6
- data/lib/7d/endpoints/helpers/require_consumer_key.rb +7 -3
- data/lib/7d/endpoints/helpers/require_signing.rb +12 -5
- data/lib/7d/endpoints/helpers/require_signing_with_user.rb +14 -5
- data/lib/7d/endpoints/release_details.rb +6 -3
- data/lib/7d/endpoints/stream_catalogue.rb +5 -3
- data/lib/7d/endpoints/stream_subscription.rb +6 -6
- data/lib/7d/endpoints/track_details.rb +6 -3
- data/spec/bin/7d_spec.rb +23 -0
- data/spec/cli/app_spec.rb +169 -0
- data/spec/cli/signature_generator_factory_spec.rb +27 -0
- data/spec/endpoints/clip_spec.rb +29 -0
- data/spec/endpoints/release_details_spec.rb +27 -0
- data/spec/endpoints/stream_catalogue_spec.rb +33 -0
- data/spec/endpoints/stream_subscription_spec.rb +41 -0
- data/spec/endpoints/track_details_spec.rb +27 -0
- data/spec/spec_helper.rb +17 -67
- metadata +55 -13
- data/lib/7d/cli/subcommands/sign.rb +0 -52
- data/spec/integration/bin/7d_spec.rb +0 -77
- data/spec/unit/endpoints/clip_spec.rb +0 -19
- data/spec/unit/endpoints/release_details_spec.rb +0 -17
- data/spec/unit/endpoints/stream_catalogue_spec.rb +0 -19
- data/spec/unit/endpoints/stream_subscription_spec.rb +0 -20
- data/spec/unit/endpoints/track_details_spec.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85bb5d853373dd397e655ebb71b200868a859759
|
4
|
+
data.tar.gz: 6772aedbca22d9961745479e08db50650483730d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05a55f41cfb52b49ac4c9aa6bd8f31290d95f248bc5f8a5f8622fc897999932ca84c90fa790bf6afb56ac3ea6d7e8dd1e2a9d2e3c2fb33e378a8c51c2b7a46ce
|
7
|
+
data.tar.gz: 177131681d5419292d68ecbddf6f5f7716e62f79220b8d61e956f06592cbc1b12984d44614157c7fe1051494ab94ccd2c0fe324e259cd57459728f69115a160b
|
data/bin/7d
CHANGED
@@ -2,16 +2,7 @@
|
|
2
2
|
|
3
3
|
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
|
4
4
|
|
5
|
-
missing_environment_variables = false
|
6
|
-
|
7
|
-
%w(SEVENDIGITAL_CONSUMER_KEY SEVENDIGITAL_CONSUMER_SECRET).each do |variable|
|
8
|
-
if ENV[variable].nil?
|
9
|
-
STDERR.puts "#{variable} is not defined"
|
10
|
-
missing_environment_variables = true
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
exit if missing_environment_variables
|
15
|
-
|
16
5
|
require '7d/cli/app'
|
17
|
-
|
6
|
+
require '7d/cli/signature_generator_factory'
|
7
|
+
|
8
|
+
puts ::SevenDigital::CLI::App.new(::SevenDigital::CLI::SignatureGeneratorFactory.new).run(ARGV)
|
data/lib/7d/cli/app.rb
CHANGED
@@ -1,11 +1,69 @@
|
|
1
|
-
require '
|
2
|
-
require '7d/cli/subcommands/sign'
|
1
|
+
require 'trollop'
|
3
2
|
|
4
3
|
module SevenDigital
|
5
4
|
module CLI
|
6
|
-
class App
|
7
|
-
|
8
|
-
|
5
|
+
class App
|
6
|
+
def initialize(signature_generator_factory)
|
7
|
+
@signature_generator_factory = signature_generator_factory
|
8
|
+
end
|
9
|
+
|
10
|
+
def run(args)
|
11
|
+
parse(args)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def parse(args)
|
17
|
+
subcommand = args.shift
|
18
|
+
|
19
|
+
case subcommand
|
20
|
+
when 'sign'
|
21
|
+
return sign_subcommand(args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def sign_subcommand(args)
|
26
|
+
endpoint = args.shift
|
27
|
+
|
28
|
+
case endpoint
|
29
|
+
when 'track/details'
|
30
|
+
opts = Trollop.options args do
|
31
|
+
opt :trackid, 'Track ID', type: :integer, required: true
|
32
|
+
opt :country, 'Country', type: :string, default: 'GB'
|
33
|
+
end
|
34
|
+
@signature_generator_factory.find(endpoint).generate_url(opts[:trackid], opts[:country])
|
35
|
+
|
36
|
+
when 'release/details'
|
37
|
+
opts = Trollop.options args do
|
38
|
+
opt :releaseid, 'Release ID', type: :integer, required: true
|
39
|
+
opt :country, 'Country', type: :string, default: 'GB'
|
40
|
+
end
|
41
|
+
@signature_generator_factory.find(endpoint).generate_url(opts[:releaseid], opts[:country])
|
42
|
+
|
43
|
+
when 'clip'
|
44
|
+
opts = Trollop.options args do
|
45
|
+
opt :trackid, 'Track ID', type: :integer, required: true
|
46
|
+
opt :country, 'Country', type: :string, default: 'GB'
|
47
|
+
end
|
48
|
+
@signature_generator_factory.find(endpoint).generate_url(opts[:trackid], opts[:country])
|
49
|
+
|
50
|
+
when 'stream/subscription'
|
51
|
+
opts = Trollop.options args do
|
52
|
+
opt :trackid, 'Track ID', type: :integer, required: true
|
53
|
+
opt :formatid, 'Format ID', type: :integer, default: 26
|
54
|
+
opt :country, 'Country', type: :string, default: 'GB'
|
55
|
+
end
|
56
|
+
@signature_generator_factory.find(endpoint).generate_url(opts[:trackid], opts[:formatid], opts[:country])
|
57
|
+
|
58
|
+
when 'stream/catalogue'
|
59
|
+
opts = Trollop.options args do
|
60
|
+
opt :trackid, 'Track ID', type: :integer, required: true
|
61
|
+
opt :formatid, 'Format ID', type: :integer, default: 26
|
62
|
+
opt :country, 'Country', type: :string, default: 'GB'
|
63
|
+
end
|
64
|
+
@signature_generator_factory.find(endpoint).generate_url(opts[:trackid], opts[:formatid], opts[:country])
|
65
|
+
end
|
66
|
+
end
|
9
67
|
end
|
10
68
|
end
|
11
69
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require '7d/endpoints/clip'
|
2
|
+
require '7d/endpoints/track_details'
|
3
|
+
require '7d/endpoints/release_details'
|
4
|
+
require '7d/endpoints/stream_catalogue'
|
5
|
+
require '7d/endpoints/stream_subscription'
|
6
|
+
|
7
|
+
module SevenDigital
|
8
|
+
module CLI
|
9
|
+
class SignatureGeneratorFactory
|
10
|
+
def find(endpoint)
|
11
|
+
case endpoint
|
12
|
+
when 'track/details'
|
13
|
+
::SevenDigital::Endpoints::TrackDetails.new ENV['SEVENDIGITAL_CONSUMER_KEY']
|
14
|
+
when 'release/details'
|
15
|
+
::SevenDigital::Endpoints::ReleaseDetails.new ENV['SEVENDIGITAL_CONSUMER_KEY']
|
16
|
+
when 'clip'
|
17
|
+
::SevenDigital::Endpoints::Clip.new ENV['SEVENDIGITAL_CONSUMER_KEY'], ENV['SEVENDIGITAL_CONSUMER_SECRET']
|
18
|
+
when 'stream/catalogue'
|
19
|
+
::SevenDigital::Endpoints::StreamCatalogue.new ENV['SEVENDIGITAL_CONSUMER_KEY'], ENV['SEVENDIGITAL_CONSUMER_SECRET']
|
20
|
+
when 'stream/subscription'
|
21
|
+
::SevenDigital::Endpoints::StreamSubscription.new ENV['SEVENDIGITAL_CONSUMER_KEY'], ENV['SEVENDIGITAL_CONSUMER_SECRET'], ENV['SEVENDIGITAL_TOKEN'], ENV['SEVENDIGITAL_TOKEN_SECRET']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/7d/endpoints/clip.rb
CHANGED
@@ -5,14 +5,12 @@ module SevenDigital
|
|
5
5
|
class Clip
|
6
6
|
include Helpers::RequireSigning
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
@consumer_secret = consumer_secret
|
8
|
+
def url(parameters = nil)
|
9
|
+
"https://previews.7digital.com/clip/#{parameters[:track_id]}"
|
11
10
|
end
|
12
11
|
|
13
|
-
def generate_url(
|
14
|
-
|
15
|
-
super(parameters)
|
12
|
+
def generate_url(track_id, country)
|
13
|
+
sign track_id: track_id, country: country
|
16
14
|
end
|
17
15
|
end
|
18
16
|
end
|
@@ -2,12 +2,16 @@ module SevenDigital
|
|
2
2
|
module Endpoints
|
3
3
|
module Helpers
|
4
4
|
module RequireConsumerKey
|
5
|
-
def
|
5
|
+
def initialize(consumer_key)
|
6
|
+
@consumer_key = consumer_key
|
7
|
+
end
|
8
|
+
|
9
|
+
def sign(parameters)
|
6
10
|
qs = parameters.reduce('') do |memo, (key, val)|
|
7
|
-
memo + "&#{key
|
11
|
+
memo + "&#{key}=#{val}"
|
8
12
|
end
|
9
13
|
|
10
|
-
"#{
|
14
|
+
"#{url(parameters)}?oauth_consumer_key=#{@consumer_key}#{qs}"
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
@@ -4,10 +4,17 @@ module SevenDigital
|
|
4
4
|
module Endpoints
|
5
5
|
module Helpers
|
6
6
|
module RequireSigning
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def initialize(consumer_key, consumer_secret)
|
8
|
+
@consumer_key = consumer_key
|
9
|
+
@consumer_secret = consumer_secret
|
10
|
+
end
|
11
|
+
|
12
|
+
def sign(parameters)
|
13
|
+
user_params = {}
|
14
|
+
|
15
|
+
parameters.each do |key, val|
|
16
|
+
user_params[key.to_s] = val
|
17
|
+
end
|
11
18
|
|
12
19
|
all_params = {
|
13
20
|
'oauth_consumer_key' => @consumer_key,
|
@@ -17,7 +24,7 @@ module SevenDigital
|
|
17
24
|
'oauth_version' => '1.0'
|
18
25
|
}.merge(user_params)
|
19
26
|
|
20
|
-
request = OAuth::RequestProxy.proxy('method' => :GET, 'uri' =>
|
27
|
+
request = OAuth::RequestProxy.proxy('method' => :GET, 'uri' => url(parameters), 'parameters' => all_params)
|
21
28
|
|
22
29
|
request.sign! consumer_secret: @consumer_secret
|
23
30
|
request.signed_uri
|
@@ -4,10 +4,19 @@ module SevenDigital
|
|
4
4
|
module Endpoints
|
5
5
|
module Helpers
|
6
6
|
module RequireSigningWithUser
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
def initialize(consumer_key, consumer_secret, token_key, token_secret)
|
8
|
+
@consumer_key = consumer_key
|
9
|
+
@consumer_secret = consumer_secret
|
10
|
+
@token_key = token_key
|
11
|
+
@token_secret = token_secret
|
12
|
+
end
|
13
|
+
|
14
|
+
def sign(parameters)
|
15
|
+
user_params = {}
|
16
|
+
|
17
|
+
parameters.each do |key, val|
|
18
|
+
user_params[key.to_s] = val
|
19
|
+
end
|
11
20
|
|
12
21
|
all_params = {
|
13
22
|
'oauth_consumer_key' => @consumer_key,
|
@@ -18,7 +27,7 @@ module SevenDigital
|
|
18
27
|
'oauth_version' => '1.0'
|
19
28
|
}.merge(user_params)
|
20
29
|
|
21
|
-
request = OAuth::RequestProxy.proxy('method' => :GET, 'uri' =>
|
30
|
+
request = OAuth::RequestProxy.proxy('method' => :GET, 'uri' => url(parameters), 'parameters' => all_params)
|
22
31
|
|
23
32
|
request.sign! consumer_secret: @consumer_secret, token_secret: @token_secret
|
24
33
|
request.signed_uri
|
@@ -5,9 +5,12 @@ module SevenDigital
|
|
5
5
|
class ReleaseDetails
|
6
6
|
include Helpers::RequireConsumerKey
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
8
|
+
def url(_ = nil)
|
9
|
+
'https://api.7digital.com/1.2/release/details'
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_url(release_id, country)
|
13
|
+
sign releaseid: release_id, country: country
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
@@ -5,11 +5,13 @@ module SevenDigital
|
|
5
5
|
class StreamCatalogue
|
6
6
|
include Helpers::RequireSigning
|
7
7
|
|
8
|
-
def
|
9
|
-
@consumer_key = consumer_key
|
10
|
-
@consumer_secret = consumer_secret
|
8
|
+
def url(_ = nil)
|
11
9
|
@url = 'https://stream.svc.7digital.net/stream/catalogue'
|
12
10
|
end
|
11
|
+
|
12
|
+
def generate_url(track_id, format_id, country)
|
13
|
+
sign trackid: track_id, formatid: format_id, country: country
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -5,12 +5,12 @@ module SevenDigital
|
|
5
5
|
class StreamSubscription
|
6
6
|
include Helpers::RequireSigningWithUser
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
def url(_ = nil)
|
9
|
+
'https://stream.svc.7digital.net/stream/subscription'
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_url(track_id, format_id, country)
|
13
|
+
sign trackid: track_id, formatid: format_id, country: country
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -5,9 +5,12 @@ module SevenDigital
|
|
5
5
|
class TrackDetails
|
6
6
|
include Helpers::RequireConsumerKey
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
8
|
+
def url(_ = nil)
|
9
|
+
'https://api.7digital.com/1.2/track/details'
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate_url(track_id, country)
|
13
|
+
sign trackid: track_id, country: country
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
data/spec/bin/7d_spec.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'bin/7d' do
|
4
|
+
it 'should be able to generate a URI for track/details' do
|
5
|
+
expect(`bin/7d sign track/details --trackid=1234`).to start_with('https')
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should be able to generate a URI for release/details' do
|
9
|
+
expect(`bin/7d sign release/details --releaseid=12345`).to start_with('https')
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should be able to able to generate a preview clip' do
|
13
|
+
expect(`bin/7d sign clip --trackid=1234`).to start_with('https')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should be able to generate a URI for stream/catalogue' do
|
17
|
+
expect(`bin/7d sign stream/catalogue --trackid=1234`).to start_with('https')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should be able to generate a URI for stream/subscription' do
|
21
|
+
expect(`bin/7d sign stream/subscription --trackid=1234`).to start_with('https')
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::SevenDigital::CLI::App do
|
4
|
+
let(:factory) { double('endpoint_factory') }
|
5
|
+
let(:signature_generator) { double('signature_generator') }
|
6
|
+
subject { ::SevenDigital::CLI::App.new(factory) }
|
7
|
+
|
8
|
+
context 'sign' do
|
9
|
+
context 'track/details' do
|
10
|
+
describe '#run' do
|
11
|
+
before(:each) do
|
12
|
+
allow(factory).to receive(:find).with('track/details').and_return(signature_generator)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should pass the correct arguments to the endpoint handler' do
|
16
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 'GB')
|
17
|
+
|
18
|
+
subject.run(%w(sign track/details --trackid=1234))
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should allow country to be overridden' do
|
22
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 'US')
|
23
|
+
|
24
|
+
subject.run(%w(sign track/details --trackid=1234 --country=US))
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should not allow someone to specify a non-integer track id' do
|
28
|
+
expect { subject.run(%w(sign track/details --trackid=invalid)) }.to raise_error(SystemExit)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should require a track id' do
|
32
|
+
expect { subject.run(%w(sign track/details)) }.to raise_error(SystemExit)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'release/details' do
|
38
|
+
describe '#run' do
|
39
|
+
before(:each) do
|
40
|
+
allow(factory).to receive(:find).with('release/details').and_return(signature_generator)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should pass the correct arguments to the endpoint handler' do
|
44
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 'GB')
|
45
|
+
|
46
|
+
subject.run(%w(sign release/details --releaseid=1234))
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should allow country to be overridden' do
|
50
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 'US')
|
51
|
+
|
52
|
+
subject.run(%w(sign release/details --releaseid=1234 --country=US))
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should not allow someone to specify a non-integer release id' do
|
56
|
+
expect { subject.run(%w(sign release/details --releaseid=invalid)) }.to raise_error(SystemExit)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should require a release id' do
|
60
|
+
expect { subject.run(%w(sign release/details)) }.to raise_error(SystemExit)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'clip' do
|
66
|
+
describe '#run' do
|
67
|
+
before(:each) do
|
68
|
+
allow(factory).to receive(:find).with('clip').and_return(signature_generator)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should pass the correct arguments to the endpoint handler' do
|
72
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 'GB')
|
73
|
+
|
74
|
+
subject.run(%w(sign clip --trackid=1234))
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should allow country to be overridden' do
|
78
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 'US')
|
79
|
+
|
80
|
+
subject.run(%w(sign clip --trackid=1234 --country=US))
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should not allow someone to specify a non-integer track id' do
|
84
|
+
expect { subject.run(%w(sign clip --trackid=invalid)) }.to raise_error(SystemExit)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should require a track id' do
|
88
|
+
expect { subject.run(%w(sign clip)) }.to raise_error(SystemExit)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'stream/subscription' do
|
94
|
+
describe '#run' do
|
95
|
+
before(:each) do
|
96
|
+
allow(factory).to receive(:find).with('stream/subscription').and_return(signature_generator)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should pass the correct arguments to the endpoint handler' do
|
100
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 26, 'GB')
|
101
|
+
|
102
|
+
subject.run(%w(sign stream/subscription --trackid=1234))
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should allow country to be overridden' do
|
106
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 26, 'US')
|
107
|
+
|
108
|
+
subject.run(%w(sign stream/subscription --trackid=1234 --country=US))
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'should allow format id to be overridden' do
|
112
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 55, 'GB')
|
113
|
+
|
114
|
+
subject.run(%w(sign stream/subscription --trackid=1234 --formatid=55))
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'should not allow someone to specify a non-integer format id' do
|
118
|
+
expect { subject.run(%w(sign stream/subscription --trackid=1234 --formatid=invalid)) }.to raise_error(SystemExit)
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should not allow someone to specify a non-integer track id' do
|
122
|
+
expect { subject.run(%w(sign stream/subscription --trackid=invalid)) }.to raise_error(SystemExit)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'should require a track id' do
|
126
|
+
expect { subject.run(%w(sign stream/subscription)) }.to raise_error(SystemExit)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'stream/catalogue' do
|
132
|
+
describe '#run' do
|
133
|
+
before(:each) do
|
134
|
+
allow(factory).to receive(:find).with('stream/catalogue').and_return(signature_generator)
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should pass the correct arguments to the endpoint handler' do
|
138
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 26, 'GB')
|
139
|
+
|
140
|
+
subject.run(%w(sign stream/catalogue --trackid=1234))
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should allow country to be overridden' do
|
144
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 26, 'US')
|
145
|
+
|
146
|
+
subject.run(%w(sign stream/catalogue --trackid=1234 --country=US))
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'should allow format id to be overridden' do
|
150
|
+
expect(signature_generator).to receive(:generate_url).with(1234, 55, 'GB')
|
151
|
+
|
152
|
+
subject.run(%w(sign stream/catalogue --trackid=1234 --formatid=55))
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'should not allow someone to specify a non-integer format id' do
|
156
|
+
expect { subject.run(%w(sign stream/catalogue --trackid=1234 --formatid=invalid)) }.to raise_error(SystemExit)
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'should not allow someone to specify a non-integer track id' do
|
160
|
+
expect { subject.run(%w(sign stream/catalogue --trackid=invalid)) }.to raise_error(SystemExit)
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should require a track id' do
|
164
|
+
expect { subject.run(%w(sign stream/catalogue)) }.to raise_error(SystemExit)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::SevenDigital::CLI::SignatureGeneratorFactory do
|
4
|
+
subject { ::SevenDigital::CLI::SignatureGeneratorFactory.new }
|
5
|
+
|
6
|
+
describe '#find' do
|
7
|
+
it 'should return TrackDetails' do
|
8
|
+
expect(subject.find('track/details')).to be_an_instance_of(::SevenDigital::Endpoints::TrackDetails)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should return Clip' do
|
12
|
+
expect(subject.find('clip')).to be_an_instance_of(::SevenDigital::Endpoints::Clip)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return ReleaseDetails' do
|
16
|
+
expect(subject.find('release/details')).to be_an_instance_of(::SevenDigital::Endpoints::ReleaseDetails)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should return StreamCatalogue' do
|
20
|
+
expect(subject.find('stream/catalogue')).to be_an_instance_of(::SevenDigital::Endpoints::StreamCatalogue)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should return StreamSubscription' do
|
24
|
+
expect(subject.find('stream/subscription')).to be_an_instance_of(::SevenDigital::Endpoints::StreamSubscription)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::SevenDigital::Endpoints::Clip do
|
4
|
+
context 'with dummy authorization configuration' do
|
5
|
+
subject { ::SevenDigital::Endpoints::Clip.new(ENV['SEVENDIGITAL_CONSUMER_KEY'], ENV['SEVENDIGITAL_CONSUMER_SECRET']) }
|
6
|
+
|
7
|
+
describe '#generate_url' do
|
8
|
+
it 'should return a signed url' do
|
9
|
+
actual = subject.generate_url(1234, 'GB')
|
10
|
+
|
11
|
+
expect(actual).to start_with('https://previews.7digital.com/clip/1234')
|
12
|
+
expect(actual).to include('country=GB')
|
13
|
+
expect(actual).to include('oauth_signature=')
|
14
|
+
expect(actual).to include('oauth_consumer_key=')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'with real authorization configuration' do
|
19
|
+
describe '#generate_url' do
|
20
|
+
it 'should be requestable' do
|
21
|
+
res = Faraday.get(subject.generate_url(1234, 'GB'))
|
22
|
+
|
23
|
+
expect(res.status).to eq(200)
|
24
|
+
expect(res.headers['Content-Type']).to eq('audio/mpeg')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::SevenDigital::Endpoints::ReleaseDetails do
|
4
|
+
context 'with dummy authorization configuration' do
|
5
|
+
subject { ::SevenDigital::Endpoints::ReleaseDetails.new('foo') }
|
6
|
+
|
7
|
+
describe '#generate_url' do
|
8
|
+
it 'should return a signed url' do
|
9
|
+
expect(subject.generate_url(1234, 'GB')).to eq('https://api.7digital.com/1.2/release/details?oauth_consumer_key=foo&releaseid=1234&country=GB')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with real authorization configuration' do
|
15
|
+
subject { ::SevenDigital::Endpoints::ReleaseDetails.new(ENV['SEVENDIGITAL_CONSUMER_KEY']) }
|
16
|
+
|
17
|
+
describe '#generate_url' do
|
18
|
+
it 'should be requestable' do
|
19
|
+
res = Faraday.get(subject.generate_url(2345, 'GB'))
|
20
|
+
|
21
|
+
expect(res.status).to eq(200)
|
22
|
+
expect(res.headers['Content-Type']).to eq('application/xml; charset=utf-8')
|
23
|
+
expect(res.body).to include('Sound Affects')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::SevenDigital::Endpoints::StreamCatalogue do
|
4
|
+
subject { ::SevenDigital::Endpoints::StreamCatalogue.new('foo', 'bar') }
|
5
|
+
|
6
|
+
context 'with dummy authorization configuration' do
|
7
|
+
describe '#generate_url' do
|
8
|
+
it 'should return a signed url' do
|
9
|
+
actual = subject.generate_url(1234, 26, 'GB')
|
10
|
+
|
11
|
+
expect(actual).to start_with('https://stream.svc.7digital.net/stream/catalogue')
|
12
|
+
expect(actual).to include('oauth_signature=')
|
13
|
+
expect(actual).to include('oauth_consumer_key=foo')
|
14
|
+
expect(actual).to include('trackid=1234')
|
15
|
+
expect(actual).to include('formatid=26')
|
16
|
+
expect(actual).to include('country=GB')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with real authorization configuration', skip: using_demo_key? do
|
22
|
+
subject { ::SevenDigital::Endpoints::StreamCatalogue.new(ENV['SEVENDIGITAL_CONSUMER_KEY'], ENV['SEVENDIGITAL_CONSUMER_SECRET']) }
|
23
|
+
|
24
|
+
describe '#generate_url' do
|
25
|
+
it 'should return a signed url' do
|
26
|
+
res = Faraday.get(subject.generate_url(1234, 26, 'GB'))
|
27
|
+
|
28
|
+
expect(res.status).to eq(200)
|
29
|
+
expect(res.headers['Content-Type']).to eq('audio/mpeg')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::SevenDigital::Endpoints::StreamSubscription do
|
4
|
+
context 'with dummy authorization configuration' do
|
5
|
+
describe '#generate_url' do
|
6
|
+
subject { ::SevenDigital::Endpoints::StreamSubscription.new('foo', 'bar', 'baz', 'qux') }
|
7
|
+
|
8
|
+
it 'should return a signed url' do
|
9
|
+
actual = subject.generate_url(1234, 26, 'GB')
|
10
|
+
|
11
|
+
expect(actual).to start_with('https://stream.svc.7digital.net/stream/subscription')
|
12
|
+
expect(actual).to include('trackid=1234')
|
13
|
+
expect(actual).to include('formatid=26')
|
14
|
+
expect(actual).to include('country=GB')
|
15
|
+
expect(actual).to include('oauth_consumer_key=foo')
|
16
|
+
expect(actual).to include('oauth_token=baz')
|
17
|
+
expect(actual).to include('oauth_signature=')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'with real authorization configuration', skip: using_demo_key? do
|
23
|
+
subject do
|
24
|
+
::SevenDigital::Endpoints::StreamSubscription.new(
|
25
|
+
ENV['SEVENDIGITAL_CONSUMER_KEY'],
|
26
|
+
ENV['SEVENDIGITAL_CONSUMER_SECRET'],
|
27
|
+
ENV['SEVENDIGITAL_TOKEN'],
|
28
|
+
ENV['SEVENDIGITAL_TOKEN_SECRET']
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#generate_url' do
|
33
|
+
it 'should be requestable' do
|
34
|
+
res = Faraday.get(subject.generate_url(1234, 26, 'GB'))
|
35
|
+
|
36
|
+
expect(res.status).to eq(200)
|
37
|
+
expect(res.headers['Content-Type']).to eq('audio/mpeg')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ::SevenDigital::Endpoints::TrackDetails do
|
4
|
+
context 'with dummy authorization configuration' do
|
5
|
+
subject { ::SevenDigital::Endpoints::TrackDetails.new('foo') }
|
6
|
+
|
7
|
+
describe '#generate_url' do
|
8
|
+
it 'should return a signed url' do
|
9
|
+
expect(subject.generate_url(1234, 'GB')).to eq('https://api.7digital.com/1.2/track/details?oauth_consumer_key=foo&trackid=1234&country=GB')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with real authorization configuration' do
|
15
|
+
subject { ::SevenDigital::Endpoints::TrackDetails.new(ENV['SEVENDIGITAL_CONSUMER_KEY']) }
|
16
|
+
|
17
|
+
describe '#generate_url' do
|
18
|
+
it 'should requestable' do
|
19
|
+
res = Faraday.get(subject.generate_url(1234, 'GB'))
|
20
|
+
|
21
|
+
expect(res.status).to eq(200)
|
22
|
+
expect(res.headers['Content-Type']).to eq('application/xml; charset=utf-8')
|
23
|
+
expect(res.body).to include('Everyday Struggle')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,89 +1,39 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# users commonly want.
|
17
|
-
#
|
18
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
require '7d/cli/app'
|
4
|
+
require '7d/cli/signature_generator_factory'
|
5
|
+
|
6
|
+
require '7d/endpoints/clip'
|
7
|
+
require '7d/endpoints/track_details'
|
8
|
+
require '7d/endpoints/release_details'
|
9
|
+
require '7d/endpoints/stream_catalogue'
|
10
|
+
require '7d/endpoints/stream_subscription'
|
11
|
+
|
12
|
+
def using_demo_key?
|
13
|
+
ENV['SEVENDIGITAL_CONSUMER_KEY'].nil? || ENV['SEVENDIGITAL_CONSUMER_KEY'] == 'YOUR_KEY_HERE'
|
14
|
+
end
|
15
|
+
|
19
16
|
RSpec.configure do |config|
|
20
|
-
# rspec-expectations config goes here. You can use an alternate
|
21
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
-
# assertions if you prefer.
|
23
17
|
config.expect_with :rspec do |expectations|
|
24
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
-
# and `failure_message` of custom matchers include text for helper methods
|
26
|
-
# defined using `chain`, e.g.:
|
27
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
-
# # => "be bigger than 2 and smaller than 4"
|
29
|
-
# ...rather than:
|
30
|
-
# # => "be bigger than 2"
|
31
18
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
19
|
+
expectations.syntax = :expect
|
32
20
|
end
|
33
21
|
|
34
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
22
|
config.mock_with :rspec do |mocks|
|
37
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
-
# a real object. This is generally recommended, and will default to
|
39
|
-
# `true` in RSpec 4.
|
40
23
|
mocks.verify_partial_doubles = true
|
41
24
|
end
|
42
25
|
|
43
26
|
begin
|
44
|
-
# These two settings work together to allow you to limit a spec run
|
45
|
-
# to individual examples or groups you care about by tagging them with
|
46
|
-
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
47
|
-
# get run.
|
48
27
|
config.filter_run :focus
|
49
28
|
config.run_all_when_everything_filtered = true
|
29
|
+
config.warnings = false
|
50
30
|
|
51
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
52
|
-
# recommended. For more details, see:
|
53
|
-
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
54
|
-
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
55
|
-
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
56
|
-
config.disable_monkey_patching!
|
57
|
-
|
58
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
59
|
-
# be too noisy due to issues in dependencies.
|
60
|
-
config.warnings = true
|
61
|
-
|
62
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
63
|
-
# file, and it's useful to allow more verbose output when running an
|
64
|
-
# individual spec file.
|
65
31
|
if config.files_to_run.one?
|
66
|
-
# Use the documentation formatter for detailed output,
|
67
|
-
# unless a formatter has already been configured
|
68
|
-
# (e.g. via a command-line flag).
|
69
32
|
config.default_formatter = 'doc'
|
70
33
|
end
|
71
34
|
|
72
|
-
# Print the 10 slowest examples and example groups at the
|
73
|
-
# end of the spec run, to help surface which specs are running
|
74
|
-
# particularly slow.
|
75
|
-
config.profile_examples = 10
|
76
|
-
|
77
|
-
# Run specs in random order to surface order dependencies. If you find an
|
78
|
-
# order dependency and want to debug it, you can fix the order by providing
|
79
|
-
# the seed, which is printed after each run.
|
80
|
-
# --seed 1234
|
81
35
|
config.order = :random
|
82
36
|
|
83
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
84
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
85
|
-
# test failures related to randomization by passing the same `--seed` value
|
86
|
-
# as the one that triggered the failure.
|
87
37
|
Kernel.srand config.seed
|
88
38
|
end
|
89
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 7d
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.pre
|
4
|
+
version: 0.0.1.pre.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Crang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth
|
@@ -25,19 +25,45 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.4.7
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: trollop
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '2.1'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.1.2
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
41
|
- - "~>"
|
39
42
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
43
|
+
version: '2.1'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.1.2
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.4'
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 10.4.2
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '10.4'
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 10.4.2
|
41
67
|
- !ruby/object:Gem::Dependency
|
42
68
|
name: rspec
|
43
69
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,6 +98,20 @@ dependencies:
|
|
72
98
|
- - "~>"
|
73
99
|
- !ruby/object:Gem::Version
|
74
100
|
version: 0.29.1
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: faraday
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - "~>"
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: 0.9.1
|
108
|
+
type: :development
|
109
|
+
prerelease: false
|
110
|
+
version_requirements: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - "~>"
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: 0.9.1
|
75
115
|
description: |2
|
76
116
|
Generates signed URLs for the 7digital API. Useful for piping between
|
77
117
|
various other command line tools.
|
@@ -83,7 +123,7 @@ extra_rdoc_files: []
|
|
83
123
|
files:
|
84
124
|
- bin/7d
|
85
125
|
- lib/7d/cli/app.rb
|
86
|
-
- lib/7d/cli/
|
126
|
+
- lib/7d/cli/signature_generator_factory.rb
|
87
127
|
- lib/7d/endpoints/clip.rb
|
88
128
|
- lib/7d/endpoints/helpers/require_consumer_key.rb
|
89
129
|
- lib/7d/endpoints/helpers/require_signing.rb
|
@@ -92,13 +132,15 @@ files:
|
|
92
132
|
- lib/7d/endpoints/stream_catalogue.rb
|
93
133
|
- lib/7d/endpoints/stream_subscription.rb
|
94
134
|
- lib/7d/endpoints/track_details.rb
|
95
|
-
- spec/
|
135
|
+
- spec/bin/7d_spec.rb
|
136
|
+
- spec/cli/app_spec.rb
|
137
|
+
- spec/cli/signature_generator_factory_spec.rb
|
138
|
+
- spec/endpoints/clip_spec.rb
|
139
|
+
- spec/endpoints/release_details_spec.rb
|
140
|
+
- spec/endpoints/stream_catalogue_spec.rb
|
141
|
+
- spec/endpoints/stream_subscription_spec.rb
|
142
|
+
- spec/endpoints/track_details_spec.rb
|
96
143
|
- spec/spec_helper.rb
|
97
|
-
- spec/unit/endpoints/clip_spec.rb
|
98
|
-
- spec/unit/endpoints/release_details_spec.rb
|
99
|
-
- spec/unit/endpoints/stream_catalogue_spec.rb
|
100
|
-
- spec/unit/endpoints/stream_subscription_spec.rb
|
101
|
-
- spec/unit/endpoints/track_details_spec.rb
|
102
144
|
homepage: https://github.com/samcrang/7digital-cli
|
103
145
|
licenses:
|
104
146
|
- MIT
|
@@ -111,7 +153,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
153
|
requirements:
|
112
154
|
- - ">="
|
113
155
|
- !ruby/object:Gem::Version
|
114
|
-
version: '
|
156
|
+
version: '1.9'
|
115
157
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
158
|
requirements:
|
117
159
|
- - ">"
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'thor'
|
2
|
-
require '7d/endpoints/track_details'
|
3
|
-
require '7d/endpoints/release_details'
|
4
|
-
require '7d/endpoints/clip'
|
5
|
-
require '7d/endpoints/stream_catalogue'
|
6
|
-
require '7d/endpoints/stream_subscription'
|
7
|
-
|
8
|
-
module SevenDigital
|
9
|
-
module CLI
|
10
|
-
class Sign < Thor
|
11
|
-
desc 'track_details', 'track/details'
|
12
|
-
def track_details(track_id)
|
13
|
-
puts ::SevenDigital::Endpoints::TrackDetails.new(
|
14
|
-
ENV['SEVENDIGITAL_CONSUMER_KEY']
|
15
|
-
).generate_url(track_id: track_id)
|
16
|
-
end
|
17
|
-
|
18
|
-
desc 'release_details', 'release/details'
|
19
|
-
def release_details(release_id)
|
20
|
-
puts ::SevenDigital::Endpoints::ReleaseDetails.new(
|
21
|
-
ENV['SEVENDIGITAL_CONSUMER_KEY']
|
22
|
-
).generate_url(release_id: release_id)
|
23
|
-
end
|
24
|
-
|
25
|
-
desc 'clip', 'clip'
|
26
|
-
def clip(track_id)
|
27
|
-
puts ::SevenDigital::Endpoints::Clip.new(
|
28
|
-
ENV['SEVENDIGITAL_CONSUMER_KEY'],
|
29
|
-
ENV['SEVENDIGITAL_CONSUMER_SECRET']
|
30
|
-
).generate_url(track_id: track_id, country: 'GB')
|
31
|
-
end
|
32
|
-
|
33
|
-
desc 'stream_catalogue', 'stream/catalogue'
|
34
|
-
def stream_catalogue(track_id)
|
35
|
-
puts ::SevenDigital::Endpoints::StreamCatalogue.new(
|
36
|
-
ENV['SEVENDIGITAL_CONSUMER_KEY'],
|
37
|
-
ENV['SEVENDIGITAL_CONSUMER_SECRET']
|
38
|
-
).generate_url(track_id: track_id)
|
39
|
-
end
|
40
|
-
|
41
|
-
desc 'stream_subscription', 'stream/subscription'
|
42
|
-
def stream_subscription(track_id)
|
43
|
-
puts ::SevenDigital::Endpoints::StreamSubscription.new(
|
44
|
-
ENV['SEVENDIGITAL_CONSUMER_KEY'],
|
45
|
-
ENV['SEVENDIGITAL_CONSUMER_SECRET'],
|
46
|
-
ENV['SEVENDIGITAL_TOKEN'],
|
47
|
-
ENV['SEVENDIGITAL_TOKEN_SECRET']
|
48
|
-
).generate_url(track_id: track_id)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,77 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'open3'
|
3
|
-
require 'open-uri'
|
4
|
-
|
5
|
-
def valid_environment?
|
6
|
-
!ENV['SEVENDIGITAL_CONSUMER_KEY'].nil? && !ENV['SEVENDIGITAL_CONSUMER_SECRET'].nil?
|
7
|
-
end
|
8
|
-
|
9
|
-
module SevenDigital
|
10
|
-
RSpec.describe 'bin/7d' do
|
11
|
-
context 'with an incorrectly configured environment' do
|
12
|
-
it 'should fail with error message' do
|
13
|
-
skip 'TODO'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'with correctly configured environment', skip: !valid_environment? do
|
18
|
-
it 'should invoke thor' do
|
19
|
-
_, stdout, _ = Open3.popen3('bin/7d')
|
20
|
-
|
21
|
-
expect(stdout.gets).to match(/Commands/)
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'should be able to fetch track/details' do
|
25
|
-
_, stdout, _ = Open3.popen3('bin/7d sign track_details 1234')
|
26
|
-
|
27
|
-
uri = stdout.gets
|
28
|
-
|
29
|
-
open(uri) do |r|
|
30
|
-
expect(r.status[0]).to eq('200')
|
31
|
-
expect(r.read).to match(/Everyday Struggle/)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should be able to fetch release/details' do
|
36
|
-
_, stdout, _ = Open3.popen3('bin/7d sign release_details 12345')
|
37
|
-
|
38
|
-
uri = stdout.gets
|
39
|
-
|
40
|
-
open(uri) do |r|
|
41
|
-
expect(r.status[0]).to eq('200')
|
42
|
-
expect(r.read).to match(/Extremoduro/)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should be able to fetch a preview clip' do
|
47
|
-
_, stdout, _ = Open3.popen3('bin/7d sign clip 1234')
|
48
|
-
|
49
|
-
uri = stdout.gets
|
50
|
-
|
51
|
-
open(uri) do |r|
|
52
|
-
expect(r.status[0]).to eq('200')
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should be able to fetch stream/catalogue' do
|
57
|
-
_, stdout, _ = Open3.popen3('bin/7d sign stream_catalogue 1234')
|
58
|
-
|
59
|
-
uri = stdout.gets
|
60
|
-
|
61
|
-
open(uri) do |r|
|
62
|
-
expect(r.status[0]).to eq('200')
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'should be able to fetch stream/subscription' do
|
67
|
-
_, stdout, _ = Open3.popen3('bin/7d sign stream_subscription 1234')
|
68
|
-
|
69
|
-
uri = stdout.gets
|
70
|
-
|
71
|
-
open(uri) do |r|
|
72
|
-
expect(r.status[0]).to eq('200')
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require '7d/endpoints/clip'
|
3
|
-
|
4
|
-
module SevenDigital
|
5
|
-
module Endpoints
|
6
|
-
RSpec.describe 'Clip' do
|
7
|
-
describe '#generate_url' do
|
8
|
-
it 'should return a signed url' do
|
9
|
-
subject = Clip.new('foo', 'bar')
|
10
|
-
actual = subject.generate_url(track_id: 1234, country: 'GB')
|
11
|
-
|
12
|
-
expect(actual).to start_with('https://previews.7digital.com/clip/1234')
|
13
|
-
expect(actual).to include('oauth_signature=')
|
14
|
-
expect(actual).to include('country=GB')
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require '7d/endpoints/release_details'
|
3
|
-
|
4
|
-
module SevenDigital
|
5
|
-
module Endpoints
|
6
|
-
RSpec.describe 'ReleaseDetails' do
|
7
|
-
describe '#generate_url' do
|
8
|
-
it 'should return a signed url' do
|
9
|
-
subject = ReleaseDetails.new('foo')
|
10
|
-
actual = subject.generate_url(release_id: 1234)
|
11
|
-
|
12
|
-
expect(actual).to eq('https://api.7digital.com/1.2/release/details?oauth_consumer_key=foo&releaseid=1234')
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require '7d/endpoints/stream_catalogue'
|
3
|
-
|
4
|
-
module SevenDigital
|
5
|
-
module Endpoints
|
6
|
-
RSpec.describe 'StreamCatalogue' do
|
7
|
-
describe '#generate_url' do
|
8
|
-
it 'should return a signed url' do
|
9
|
-
subject = StreamCatalogue.new('foo', 'bar')
|
10
|
-
actual = subject.generate_url(track_id: 1234)
|
11
|
-
|
12
|
-
expect(actual).to start_with('https://stream.svc.7digital.net/stream/catalogue')
|
13
|
-
expect(actual).to include('trackid=1234')
|
14
|
-
expect(actual).to include('&oauth_signature=')
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require '7d/endpoints/stream_subscription'
|
3
|
-
|
4
|
-
module SevenDigital
|
5
|
-
module Endpoints
|
6
|
-
RSpec.describe 'StreamSubscription' do
|
7
|
-
describe '#generate_url' do
|
8
|
-
it 'should return a signed url' do
|
9
|
-
subject = StreamSubscription.new('foo', 'bar', 'baz', 'qux')
|
10
|
-
actual = subject.generate_url(track_id: 1234)
|
11
|
-
|
12
|
-
expect(actual).to start_with('https://stream.svc.7digital.net/stream/subscription')
|
13
|
-
expect(actual).to include('trackid=1234')
|
14
|
-
expect(actual).to include('oauth_token=baz')
|
15
|
-
expect(actual).to include('&oauth_signature=')
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require '7d/endpoints/track_details'
|
3
|
-
|
4
|
-
module SevenDigital
|
5
|
-
module Endpoints
|
6
|
-
RSpec.describe 'TrackDetails' do
|
7
|
-
describe '#generate_url' do
|
8
|
-
it 'should return a signed url' do
|
9
|
-
subject = TrackDetails.new('foo')
|
10
|
-
|
11
|
-
expect(subject.generate_url(track_id: 1234)).to eq('https://api.7digital.com/1.2/track/details?oauth_consumer_key=foo&trackid=1234')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|