tangerine 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -15,5 +15,6 @@ group :development do
15
15
  gem "vcr", "1.7.0"
16
16
  gem "fakeweb", "1.3.0"
17
17
  gem "timecop", "0.3.5"
18
+ gem "factory_girl", "1.3.3"
18
19
  gem "ruby-debug", "0.10.4"
19
20
  end
data/Gemfile.lock CHANGED
@@ -5,6 +5,7 @@ GEM
5
5
  columnize (0.3.2)
6
6
  crack (0.1.8)
7
7
  diff-lcs (1.1.2)
8
+ factory_girl (1.3.3)
8
9
  fakeweb (1.3.0)
9
10
  git (1.2.5)
10
11
  httparty (0.7.4)
@@ -40,6 +41,7 @@ PLATFORMS
40
41
  DEPENDENCIES
41
42
  activesupport (= 3.0.5)
42
43
  bundler (~> 1.0.0)
44
+ factory_girl (= 1.3.3)
43
45
  fakeweb (= 1.3.0)
44
46
  httparty (= 0.7.4)
45
47
  i18n (= 0.5.0)
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.summary = %Q{Ooyala Backlot API Wrapper}
18
18
  gem.description = %Q{Ooyala Backlot API Wrapper. Read more about the Ooyala Backlot API at http://www.ooyala.com/support/docs/backlot_api}
19
19
  gem.email = "anthony.navarre@factorylabs.com"
20
- gem.authors = ["Anthony Navarre"]
20
+ gem.authors = ["Anthony Navarre", "Craig Williams"]
21
21
 
22
22
  # Dependencies
23
23
  gem.add_dependency 'httparty'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
data/lib/tangerine.rb CHANGED
@@ -4,3 +4,5 @@ require 'tangerine/backlot/base'
4
4
  require 'tangerine/backlot/channel'
5
5
  require 'tangerine/backlot/channel_set'
6
6
  require 'tangerine/backlot/video'
7
+ require 'tangerine/backlot/player'
8
+
@@ -13,23 +13,14 @@ module Tangerine
13
13
  class API
14
14
 
15
15
  def self.authenticate!(credentials)
16
- @provider_code = credentials[:provider_code]
17
16
  @secret = credentials[:secret]
17
+ HTTP.default_params :pcode => credentials[:provider_code]
18
18
  end
19
19
 
20
20
  def self.get(request_type, params={})
21
- set_params(params)
22
- HTTP.get(request_type)
23
- end
24
-
25
- def self.set_params(params)
26
- HTTP.default_params.clear
27
-
28
21
  params['expires'] ||= (Time.now.to_i + 10).to_s
29
- HTTP.default_params params
30
-
31
- HTTP.default_params :pcode => @provider_code
32
- HTTP.default_params :signature => self.signature(params)
22
+ params['signature'] = self.signature(params)
23
+ HTTP.get(request_type, {:query => params})
33
24
  end
34
25
 
35
26
  def self.signature(params)
@@ -1,6 +1,6 @@
1
1
  class Tangerine::Base
2
2
 
3
- def initialize(options)
3
+ def initialize(options={})
4
4
  options.delete('content_type')
5
5
  options.each do |k,v|
6
6
  # TODO: Look into using Crack gem for reliably undercoring these
@@ -19,9 +19,14 @@ class Tangerine::Base
19
19
  end
20
20
 
21
21
  def self.find(embed_code)
22
- results = @finder.call
23
- results = self.prepare_items(results)
22
+ results = prepare_items @finder.call(embed_code)
24
23
  found_item = results.select { |item| item['embedCode'] == embed_code }.first
24
+ self.new(found_item)
25
+ end
26
+
27
+ def self.all
28
+ items = prepare_items @finder.call
29
+ items.collect { |item| self.new(item) }
25
30
  end
26
31
 
27
32
  end
@@ -2,7 +2,6 @@ class Tangerine::Channel < Tangerine::Base
2
2
 
3
3
  attr_accessor :size,
4
4
  :title,
5
- :content_type,
6
5
  :thumbnail,
7
6
  :updated_at,
8
7
  :embed_code,
@@ -11,4 +10,11 @@ class Tangerine::Channel < Tangerine::Base
11
10
  :status,
12
11
  :uploaded_at
13
12
 
13
+ def videos
14
+ channel = Tangerine::Backlot::API.get('/channels', 'mode' => 'list', 'channelEmbedCode' => embed_code)
15
+ items = channel.parsed_response['channel']['item']
16
+ items = Tangerine::Base.prepare_items(items)
17
+ embed_codes = items.collect { |item| item['embedCode'] }
18
+ Tangerine::Video.where(:embed_code => embed_codes)
19
+ end
14
20
  end
@@ -17,11 +17,6 @@ class Tangerine::ChannelSet < Tangerine::Base
17
17
  response.parsed_response['list']['item']
18
18
  end
19
19
 
20
- def self.find(embed_code)
21
- found = super(embed_code)
22
- Tangerine::ChannelSet.new(found)
23
- end
24
-
25
20
  def channels
26
21
  result = Tangerine::Backlot::API.get('/channel_sets', 'mode' => 'list', 'channelSetEmbedCode' => embed_code)
27
22
  items = result.parsed_response['channelSet']['channel']
@@ -0,0 +1,12 @@
1
+ class Tangerine::Player < Tangerine::Base
2
+ attr_accessor :width,
3
+ :height,
4
+ :embed_code,
5
+ :browser_placement,
6
+ :hide,
7
+ :autoplay
8
+
9
+ def render
10
+ "http://player.ooyala.com/player.js?width=#{width}&height=#{height}&embedCode=#{embed_code}"
11
+ end
12
+ end
@@ -1,6 +1,65 @@
1
- class Tangerine::Video
1
+ class Tangerine::Video < Tangerine::Base
2
+
3
+ attr_accessor :size,
4
+ :title,
5
+ :thumbnail,
6
+ :content,
7
+ :updated_at,
8
+ :embed_code,
9
+ :description,
10
+ :length,
11
+ :status,
12
+ :uploaded_at,
13
+ :flight_start_time,
14
+ :width,
15
+ :height,
16
+ :labels,
17
+ :metadata,
18
+ :stat
19
+
2
20
  def self.all
3
21
  Tangerine.query('contentType' => 'Video')
4
22
  end
23
+
24
+ def initialize(options={})
25
+ @options = options
26
+ add_metadata
27
+ add_labels
28
+
29
+ options.delete('metadata')
30
+ options.delete('labels')
31
+ super(options)
32
+ end
33
+
34
+ def player(options={})
35
+ options.merge!(:embed_code => embed_code, :width => width, :height => height)
36
+ Tangerine::Player.new(options)
37
+ end
38
+
39
+ def self.where(options)
40
+ embed_codes = options[:embed_code].join(',')
41
+ result = Tangerine.query('embedCode' => embed_codes, 'fields' => 'labels,metadata')
42
+ items = result.parsed_response['list']['item']
43
+ items = Tangerine::Base.prepare_items(items)
44
+ items.collect { |item| Tangerine::Video.new(item) }
45
+ end
46
+
47
+ protected
48
+
49
+ def add_labels
50
+ return unless @options['labels']
51
+ self.labels = Tangerine::Base.prepare_items(@options['labels']['label'])
52
+ end
53
+
54
+ def add_metadata
55
+ return unless @options['metadata']
56
+
57
+ self.metadata = {}
58
+ meta_data = @options['metadata']['metadataItem']
59
+ items = Tangerine::Base.prepare_items(meta_data)
60
+ items.each do |meta_item|
61
+ self.metadata[meta_item['name'].to_sym] = meta_item['value']
62
+ end
63
+ end
5
64
  end
6
65
 
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
4
  require 'timecop'
5
+ require 'factory_girl'
5
6
  require 'vcr'
6
7
  require 'tangerine'
7
8
 
@@ -1,53 +1,26 @@
1
- module TangerineGirl
2
-
3
- @@definitions = {}
4
-
5
- def self.create(template_name, overrides={})
6
- @@definitions[template_name].create(overrides)
7
- end
8
-
9
- def self.define(template_name)
10
- template = TangerineGirl::Template.new(template_name)
11
- yield template
12
- @@definitions[template_name] = template
13
- end
14
-
15
- class Template
16
-
17
- def initialize(name)
18
- @name = name
19
- @defaults = {}
20
- end
21
-
22
- def create(overrides)
23
- options = @defaults.dup.merge(overrides)
24
- subject = "Tangerine::#{@name.to_s.classify}".constantize
25
- subject.new(options)
26
- end
27
-
28
- def method_missing(method, *args, &block)
29
- if method.to_s =~ /=$/
30
- attr_name = method.to_s.gsub(/=$/, '').to_sym
31
- @defaults[attr_name] = *args
32
- else
33
- super(method, *args, &block)
34
- end
35
- end
36
- end
1
+ Factory.sequence :embed_code do |n|
2
+ "embed_code_#{n}"
3
+ end
37
4
 
5
+ Factory.define :channel_set, :class => Tangerine::ChannelSet do |cs|
6
+ cs.embed_code Factory.next(:embed_code)
7
+ cs.title "an ode to channelsets"
8
+ cs.description nil
9
+ cs.flight_start_time "1294087113"
10
+ cs.height "3"
11
+ cs.size nil
12
+ cs.stat nil
13
+ cs.status "live"
14
+ cs.updated_at "1294087113"
15
+ cs.uploaded_at "1294087113"
16
+ cs.width "4"
38
17
  end
39
18
 
40
- TangerineGirl.define(:channel_set) do |cs|
41
- cs.embed_code = "BLABLABLALBLABLABLBAHHH!!!!"
42
- cs.title = "an ode to channelsets"
43
- # cs.description = nil
44
- # cs.flight_start_time = "1294087113"
45
- # cs.height = "3"
46
- # cs.size = nil
47
- # cs.stat = nil
48
- # cs.status = "live"
49
- # cs.updated_at = "1294087113"
50
- # cs.uploaded_at = "1294087113"
51
- # cs.width = "4"
19
+ Factory.define :channel, :class => Tangerine::Channel do |ch|
20
+ ch.embed_code 'lorem ipsum embed'
52
21
  end
53
22
 
23
+ Factory.define :video, :class => Tangerine::Video do |v|
24
+ v.embed_code 'video embed code'
25
+ v.title ''
26
+ end
@@ -0,0 +1,59 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.ooyala.com:80/partner/channels?pcode=lsNTrbQBqCQbH-VA6ALCshAHLWrV&expires=1325437210&mode=list&signature=Xe%2B2%2B2TJc6bnWCOYpC33uHXEvVykP3fK5GQwYReXac4&channelEmbedCode=9haTdiMjoVHPey7H15JCroS9tJ25Xzw2
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ last-modified:
14
+ - Fri, 11 Mar 2011 17:32:20 GMT
15
+ content-type:
16
+ - application/xml; charset=utf-8
17
+ date:
18
+ - Fri, 11 Mar 2011 17:32:19 GMT
19
+ content-length:
20
+ - "1157"
21
+ set-cookie:
22
+ - ooyala-web-rails-session=BAh7CDoPdXBkYXRlZF9hdEl1OglUaW1lDXHJG4CI%2FD2BBjofQG1hcnNoYWxfd2l0aF91dGNfY29lcmNpb25UOg9zZXNzaW9uX2lkIiU0NjViMjY5NTJlYWQ4YWQ2YTllZGYzNDg1OThkYjc5NjoSY3JlYXRpb25fdGltZUAG--33416825151f4a1eead61415c279493e8788cdfa; path=/; HttpOnly
23
+ vary:
24
+ - Accept-Encoding,User-Agent
25
+ cache-control:
26
+ - private, max-age=0
27
+ body: |
28
+ <?xml version="1.0" encoding="UTF-8"?>
29
+ <channel>
30
+ <embedCode>9haTdiMjoVHPey7H15JCroS9tJ25Xzw2</embedCode>
31
+ <title>Snowboarding</title>
32
+ <status>live</status>
33
+ <item>
34
+ <embedCode>I3MHB2MTqP5zvA8dYvzbvGlPJdg7DxRK</embedCode>
35
+ <title><%= title %></title>
36
+ <description>TNF New Team Bio</description>
37
+ <status>live</status>
38
+ <content_type>Video</content_type>
39
+ <uploadedAt>1291860167</uploadedAt>
40
+ <length>218968</length>
41
+ <thumbnail>http://cdn.videos.thenorthface.com/I3MHB2MTqP5zvA8dYvzbvGlPJdg7DxRK/M_-lZjo5g2zgfr_H5hMDoxOjA0O88asB</thumbnail>
42
+ <size>146499024</size>
43
+ <updatedAt>1294868672</updatedAt>
44
+ </item>
45
+ <item>
46
+ <embedCode>Z3Y3l3MTqHOLU6LMeTNbP2O91Oq5ADxm</embedCode>
47
+ <title>TV SPOT KAITLYN-H.264.mov</title>
48
+ <description></description>
49
+ <status>live</status>
50
+ <content_type>Video</content_type>
51
+ <uploadedAt>1293037017</uploadedAt>
52
+ <length>39039</length>
53
+ <thumbnail>http://cdn.videos.thenorthface.com/Z3Y3l3MTqHOLU6LMeTNbP2O91Oq5ADxm/Ut_HKthATH4eww8X5hMDoxOjA0O88asB</thumbnail>
54
+ <size>24649650</size>
55
+ <updatedAt>1294868601</updatedAt>
56
+ </item>
57
+ </channel>
58
+
59
+ http_version: "1.1"
@@ -0,0 +1,47 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.ooyala.com:80/partner/query?pcode=lsNTrbQBqCQbH-VA6ALCshAHLWrV&expires=1325437210&signature=VAJNytKwToVNKastKoAoWArxXky58qE2B4CDGMQhJXY&contentType=MultiChannel
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ last-modified:
14
+ - Wed, 09 Mar 2011 22:17:59 GMT
15
+ content-type:
16
+ - application/xml; charset=utf-8
17
+ date:
18
+ - Wed, 09 Mar 2011 22:17:58 GMT
19
+ content-length:
20
+ - "2336"
21
+ set-cookie:
22
+ - ooyala-web-rails-session=BAh7CDoPdXBkYXRlZF9hdEl1OglUaW1lDTbJG4Bt76pHBjofQG1hcnNoYWxfd2l0aF91dGNfY29lcmNpb25UOg9zZXNzaW9uX2lkIiUzMzcyMTM4MjM4NTQyZTM0NTIxMTJmMjQ3NWU2YTZiOToSY3JlYXRpb25fdGltZUAG--ac51682d0ac32ee8a4f963e2dc7803e400ce56ad; path=/; HttpOnly
23
+ vary:
24
+ - Accept-Encoding,User-Agent
25
+ cache-control:
26
+ - private, max-age=0
27
+ body: |
28
+ <?xml version="1.0" encoding="UTF-8"?>
29
+ <list totalResults="5" size="5" pageID="0" statistics-as-of_text="Wed Mar 09 21:40:01 UTC 2011" limit="500" statistics-as-of="1299706801">
30
+ <% channel_sets.each do |channel_set| %>
31
+ <item>
32
+ <embedCode><%= channel_set.embed_code %></embedCode>
33
+ <title><%= channel_set.title %></title>
34
+ <description><%= channel_set.description %></description>
35
+ <status><%= channel_set.status %></status>
36
+ <content_type>MultiChannel</content_type>
37
+ <uploadedAt><%= channel_set.uploaded_at %></uploadedAt>
38
+ <size><%= channel_set.size %></size>
39
+ <updatedAt><%= channel_set.updated_at %></updatedAt>
40
+ <flightStartTime><%= channel_set.flight_start_time %></flightStartTime>
41
+ <width><%= channel_set.width %></width>
42
+ <height><%= channel_set.height %></height>
43
+ <stat><%= channel_set.stat %></stat>
44
+ </item>
45
+ <% end %>
46
+
47
+ http_version: "1.1"
@@ -0,0 +1,79 @@
1
+ ---
2
+ - !ruby/struct:VCR::HTTPInteraction
3
+ request: !ruby/struct:VCR::Request
4
+ method: :get
5
+ uri: http://api.ooyala.com:80/partner/query?expires=1325437210&signature=O%2B9kFOA4MbKGsw0N6mmUyrCiUApueJc04H5jWyHWMZM&fields=labels%2Cmetadata&pcode=lsNTrbQBqCQbH-VA6ALCshAHLWrV&embedCode=I3MHB2MTqP5zvA8dYvzbvGlPJdg7DxRK%2CZ3Y3l3MTqHOLU6LMeTNbP2O91Oq5ADxm
6
+ body:
7
+ headers:
8
+ response: !ruby/struct:VCR::Response
9
+ status: !ruby/struct:VCR::ResponseStatus
10
+ code: 200
11
+ message: OK
12
+ headers:
13
+ last-modified:
14
+ - Fri, 11 Mar 2011 22:09:13 GMT
15
+ content-type:
16
+ - application/xml; charset=utf-8
17
+ date:
18
+ - Fri, 11 Mar 2011 22:09:13 GMT
19
+ content-length:
20
+ - "1693"
21
+ set-cookie:
22
+ - ooyala-web-rails-session=BAh7CDoPdXBkYXRlZF9hdEl1OglUaW1lDXbJG4ACVNMkBjofQG1hcnNoYWxfd2l0aF91dGNfY29lcmNpb25UOg9zZXNzaW9uX2lkIiU0MTZmMDAxMTg3OWRiODE2OWU5NWYzNmQ0YzUzMTI4NToSY3JlYXRpb25fdGltZUAG--72a190cee40d77538ed4f6ec6a4d79319cde1396; path=/; HttpOnly
23
+ vary:
24
+ - Accept-Encoding,User-Agent
25
+ cache-control:
26
+ - private, max-age=0
27
+ body: |
28
+ <?xml version="1.0" encoding="UTF-8"?>
29
+ <list totalResults="2" size="2" pageID="0" statistics-as-of_text="Fri Mar 11 21:45:01 UTC 2011" limit="500" statistics-as-of="1299879901">
30
+ <item>
31
+ <embedCode>I3MHB2MTqP5zvA8dYvzbvGlPJdg7DxRK</embedCode>
32
+ <title><%= title1 %></title>
33
+ <description>TNF New Team Bio</description>
34
+ <status>live</status>
35
+ <content_type>Video</content_type>
36
+ <uploadedAt>1291860167</uploadedAt>
37
+ <length>218968</length>
38
+ <size>146499024</size>
39
+ <updatedAt>1294868672</updatedAt>
40
+ <flightStartTime>1291860167</flightStartTime>
41
+ <width>1280</width>
42
+ <height>720</height>
43
+ <labels>
44
+ <label>/YouTube</label>
45
+ <label>/testTube</label>
46
+ </labels>
47
+ <thumbnail height="72" width="128">http://cdn.videos.thenorthface.com/I3MHB2MTqP5zvA8dYvzbvGlPJdg7DxRK/M_-lZjo5g2zgfr_H5hMDoxOjA0O88asB</thumbnail>
48
+ <stat>
49
+ </stat>
50
+ <metadata>
51
+ <metadataItem value="Athlete" name="subtitle"/>
52
+ <metadataItem value="BigMeta!" name="bigmeta"/>
53
+ </metadata>
54
+ </item>
55
+ <item>
56
+ <embedCode>Z3Y3l3MTqHOLU6LMeTNbP2O91Oq5ADxm</embedCode>
57
+ <title><%= title2 %></title>
58
+ <description></description>
59
+ <status>live</status>
60
+ <content_type>Video</content_type>
61
+ <uploadedAt>1293037017</uploadedAt>
62
+ <length>39039</length>
63
+ <size>24649650</size>
64
+ <updatedAt>1294868601</updatedAt>
65
+ <flightStartTime>1293036960</flightStartTime>
66
+ <width>1280</width>
67
+ <height>720</height>
68
+ <labels>
69
+ <label>/YouTube</label>
70
+ </labels>
71
+ <thumbnail height="72" width="128">http://cdn.videos.thenorthface.com/Z3Y3l3MTqHOLU6LMeTNbP2O91Oq5ADxm/Ut_HKthATH4eww8X5hMDoxOjA0O88asB</thumbnail>
72
+ <stat>
73
+ </stat>
74
+ <metadata>
75
+ </metadata>
76
+ </item>
77
+ </list>
78
+
79
+ http_version: "1.1"