helix 0.0.1.8.pre → 0.0.1.9.pre

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Helix
1
+ # Helix [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/Twistage/helix)
2
2
 
3
3
  The Helix gem allows developers to easily connect to and manipulate the Twistage API.
4
4
 
data/lib/helix/config.rb CHANGED
@@ -76,6 +76,7 @@ module Helix
76
76
  def get_base_url(opts)
77
77
  creds = credentials
78
78
  base_url = creds[:site]
79
+ return base_url if opts[:guid]
79
80
  reseller, company, library = SCOPES.map { |scope| creds[scope] }
80
81
  base_url += "/resellers/#{reseller}" if reseller
81
82
  if company
@@ -17,7 +17,7 @@ module Helix
17
17
  #
18
18
  # @return [Array of Hashes] Statistics information.
19
19
  def self.album_delivery(opts={})
20
- self.image_delivery(opts)
20
+ image_delivery(opts)
21
21
  end
22
22
 
23
23
  # @example
@@ -25,7 +25,7 @@ module Helix
25
25
  #
26
26
  # @return [Array of Hashes] Statistics information.
27
27
  def self.album_storage(opts={})
28
- self.image_storage(opts)
28
+ image_storage(opts)
29
29
  end
30
30
 
31
31
  # @example
@@ -33,7 +33,7 @@ module Helix
33
33
  #
34
34
  # @return [Array of Hashes] Statistics information.
35
35
  def self.audio_delivery(opts={})
36
- self.delivery(:track, opts)
36
+ delivery(:track, opts)
37
37
  end
38
38
 
39
39
  # @example
@@ -43,8 +43,7 @@ module Helix
43
43
  #
44
44
  # @return [Array of Hashes] Statistics information.
45
45
  def self.audio_ingest(opts={})
46
- opts[:action] ||= :breakdown
47
- self.storage(:track, opts.merge(action: :"track_ingest/#{opts[:action]}"))
46
+ ingest(:track, opts)
48
47
  end
49
48
 
50
49
  # @example
@@ -52,7 +51,7 @@ module Helix
52
51
  #
53
52
  # @return [Array of Hashes] Statistics information.
54
53
  def self.audio_storage(opts={})
55
- self.storage(:track, opts)
54
+ storage(:track, opts)
56
55
  end
57
56
 
58
57
  # @example
@@ -60,7 +59,7 @@ module Helix
60
59
  #
61
60
  # @return [Array of Hashes] Statistics information.
62
61
  def self.image_delivery(opts={})
63
- self.delivery(:image, opts)
62
+ delivery(:image, opts)
64
63
  end
65
64
 
66
65
  # @example
@@ -68,7 +67,7 @@ module Helix
68
67
  #
69
68
  # @return [Array of Hashes] Statistics information.
70
69
  def self.image_storage(opts={})
71
- self.storage(:image, opts)
70
+ storage(:image, opts)
72
71
  end
73
72
 
74
73
  # @example
@@ -76,7 +75,7 @@ module Helix
76
75
  #
77
76
  # @return [Array of Hashes] Statistics information.
78
77
  def self.track_delivery(opts={})
79
- self.audio_delivery(opts)
78
+ audio_delivery(opts)
80
79
  end
81
80
 
82
81
  # @example
@@ -86,7 +85,7 @@ module Helix
86
85
  #
87
86
  # @return [Array of Hashes] Statistics information.
88
87
  def self.track_ingest(opts={})
89
- self.audio_ingest(opts)
88
+ audio_ingest(opts)
90
89
  end
91
90
 
92
91
  # @example
@@ -94,7 +93,7 @@ module Helix
94
93
  #
95
94
  # @return [Array of Hashes] Statistics information.
96
95
  def self.track_storage(opts={})
97
- self.audio_storage(opts)
96
+ audio_storage(opts)
98
97
  end
99
98
 
100
99
  # @example
@@ -102,7 +101,7 @@ module Helix
102
101
  #
103
102
  # @return [Array of Hashes] Statistics information.
104
103
  def self.video_delivery(opts={})
105
- self.delivery(:video, opts)
104
+ delivery(:video, opts)
106
105
  end
107
106
 
108
107
  # @example
@@ -112,8 +111,7 @@ module Helix
112
111
  #
113
112
  # @return [Array of Hashes] Statistics information.
114
113
  def self.video_ingest(opts={})
115
- opts[:action] ||= :breakdown
116
- self.storage(:video, opts.merge(action: :"video_publish/#{opts[:action]}"))
114
+ ingest(:video, opts)
117
115
  end
118
116
 
119
117
  # @example
@@ -121,7 +119,7 @@ module Helix
121
119
  #
122
120
  # @return [Array of Hashes] Statistics information.
123
121
  def self.video_storage(opts={})
124
- self.storage(:video, opts)
122
+ storage(:video, opts)
125
123
  end
126
124
 
127
125
  private
@@ -139,6 +137,12 @@ module Helix
139
137
  memo_cfg.get_response(url, {sig_type: :view}.merge(opts))
140
138
  end
141
139
 
140
+ def self.ingest(media_type, opts)
141
+ opts[:action] ||= :breakdown
142
+ action_prefix = ingest_action_prefix_for(media_type)
143
+ storage(media_type, opts.merge(action: :"#{action_prefix}/#{opts[:action]}"))
144
+ end
145
+
142
146
  def self.storage(media_type, opts)
143
147
  memo_cfg = Helix::Config.instance
144
148
  format = opts.delete(:format)
@@ -150,6 +154,10 @@ module Helix
150
154
  memo_cfg.get_response(url, {sig_type: :view}.merge(opts))
151
155
  end
152
156
 
157
+ def self.ingest_action_prefix_for(media_type)
158
+ STORAGE_ACTION_FOR[media_type].split('/').first
159
+ end
160
+
153
161
  def self.storage_action_for(media_type)
154
162
  STORAGE_ACTION_FOR[media_type].to_sym
155
163
  end
data/spec/config_spec.rb CHANGED
@@ -103,18 +103,27 @@ describe Helix::Config do
103
103
  end
104
104
  end
105
105
 
106
+ def build_test_url(site, sub_url, guid, action, media_type, format)
107
+ expected_url = site
108
+ expected_url += sub_url unless guid
109
+ expected_url += "/#{media_type}"
110
+ expected_url += "/the_guid" if guid
111
+ expected_url += "/#{action}" if action
112
+ expected_url += ".#{format}"
113
+ end
114
+
106
115
  describe "#build_url" do
107
116
  site = 'http://example.com'
108
117
  let(:meth) { :build_url }
109
118
  subject { obj.method(meth) }
110
119
  its(:arity) { should be(-1) }
111
- before(:each) do
112
- obj.credentials = {site: site}
113
- end
120
+ before(:each) do obj.credentials = { site: site } end
114
121
  shared_examples_for "reads scope from credentials for build_url" do |media_type,format,more_opts|
115
- more_opts ||= {}
116
- guid = more_opts[:guid]
117
- action = more_opts[:action]
122
+ let(:opts) { more_opts || {} }
123
+ let(:action) { opts[:action] }
124
+ let(:guid) { opts[:guid] }
125
+ let(:url_pieces) { [site, sub_url, guid, action, media_type, format] }
126
+ let(:expected_url) { build_test_url(*url_pieces) }
118
127
  before(:each) do obj.credentials = {site: 'http://example.com'} end
119
128
  context "and credentials has a key for :reseller" do
120
129
  before(:each) do obj.credentials.merge!(reseller: 're_id') end
@@ -122,27 +131,18 @@ describe Helix::Config do
122
131
  before(:each) do obj.credentials.merge!(company: 'co_id') end
123
132
  context "and credentials has a key for :library" do
124
133
  before(:each) do obj.credentials.merge!(library: 'lib_id') end
125
- expected_url = "#{site}/resellers/re_id/companies/co_id/libraries/lib_id/#{media_type}"
126
- expected_url += "/the_guid" if guid
127
- expected_url += "/#{action}" if action
128
- expected_url += ".#{format}"
134
+ let(:sub_url) { "/resellers/re_id/companies/co_id/libraries/lib_id" }
129
135
  it { should eq(expected_url) }
130
136
  end
131
137
  context "and credentials does NOT have a key for :library" do
132
138
  before(:each) do obj.credentials.delete(:library) end
133
- expected_url = "#{site}/resellers/re_id/companies/co_id/#{media_type}"
134
- expected_url += "/the_guid" if guid
135
- expected_url += "/#{action}" if action
136
- expected_url += ".#{format}"
139
+ let(:sub_url) { "/resellers/re_id/companies/co_id" }
137
140
  it { should eq(expected_url) }
138
141
  end
139
142
  end
140
143
  context "and credentials does NOT have a key for :company" do
141
144
  before(:each) do obj.credentials.delete(:company) end
142
- expected_url = "#{site}/resellers/re_id/#{media_type}"
143
- expected_url += "/the_guid" if guid
144
- expected_url += "/#{action}" if action
145
- expected_url += ".#{format}"
145
+ let(:sub_url) { "/resellers/re_id" }
146
146
  it { should eq(expected_url) }
147
147
  end
148
148
  end
@@ -152,10 +152,7 @@ describe Helix::Config do
152
152
  before(:each) do obj.credentials[:company] = 'co_id' end
153
153
  context "and credentials has a key for 'library'" do
154
154
  before(:each) do obj.credentials[:library] = 'lib_id' end
155
- expected_url = "#{site}/companies/co_id/libraries/lib_id/#{media_type}"
156
- expected_url += "/the_guid" if guid
157
- expected_url += "/#{action}" if action
158
- expected_url += ".#{format}"
155
+ let(:sub_url) { "/companies/co_id/libraries/lib_id" }
159
156
  it { should eq(expected_url) }
160
157
  end
161
158
  end
@@ -165,7 +162,6 @@ describe Helix::Config do
165
162
  subject { obj.send(meth) }
166
163
  it_behaves_like "reads scope from credentials for build_url", :videos, :json
167
164
  end
168
- =begin
169
165
  context "when given opts of {}" do
170
166
  subject { obj.send(meth, {}) }
171
167
  it_behaves_like "reads scope from credentials for build_url", :videos, :json
@@ -236,7 +232,6 @@ describe Helix::Config do
236
232
  end
237
233
  end
238
234
  end
239
- =end
240
235
  end
241
236
 
242
237
  describe "#clear_signatures!" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.8.pre
4
+ version: 0.0.1.9.pre
5
5
  prerelease: 8
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-02 00:00:00.000000000 Z
12
+ date: 2013-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json