360_services 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/360_services.gemspec +42 -0
  2. data/Manifest +48 -0
  3. data/Rakefile +30 -0
  4. data/fakeweb_cache +6650 -0
  5. data/features/manage_accounts.feature +32 -0
  6. data/features/manage_assets.feature +58 -0
  7. data/features/manage_categories.feature +87 -0
  8. data/features/manage_flags.feature +44 -0
  9. data/features/manage_group_assets.feature +33 -0
  10. data/features/manage_groups.feature +29 -0
  11. data/features/manage_metadata.feature +28 -0
  12. data/features/manage_metrics.feature +22 -0
  13. data/features/manage_sites.feature +17 -0
  14. data/features/manage_tags.feature +37 -0
  15. data/features/mange_rate_plan.feature +9 -0
  16. data/features/step_definitions/manage_accounts_steps.rb +19 -0
  17. data/features/step_definitions/manage_assets_steps.rb +62 -0
  18. data/features/step_definitions/manage_categories_steps.rb +56 -0
  19. data/features/step_definitions/manage_flags_steps.rb +19 -0
  20. data/features/step_definitions/manage_group_assets_steps.rb +15 -0
  21. data/features/step_definitions/manage_groups_steps.rb +27 -0
  22. data/features/step_definitions/manage_metadata_steps.rb +29 -0
  23. data/features/step_definitions/manage_metrics_steps.rb +15 -0
  24. data/features/step_definitions/manage_sites_steps.rb +15 -0
  25. data/features/step_definitions/manage_tags_steps.rb +23 -0
  26. data/features/step_definitions/mange_rate_plan_steps.rb +3 -0
  27. data/features/step_definitions/utility_steps.rb +33 -0
  28. data/features/step_definitions/web_steps.rb +259 -0
  29. data/features/support/document_steps.rb +46 -0
  30. data/features/support/env.rb +13 -0
  31. data/features/support/netrecorder.rb +20 -0
  32. data/features/support/paths.rb +27 -0
  33. data/lib/sorenson/services/account.rb +50 -0
  34. data/lib/sorenson/services/array.rb +5 -0
  35. data/lib/sorenson/services/asset.rb +155 -0
  36. data/lib/sorenson/services/base.rb +71 -0
  37. data/lib/sorenson/services/category.rb +52 -0
  38. data/lib/sorenson/services/core_ext/attribute_accessors.rb +40 -0
  39. data/lib/sorenson/services/core_ext/hash.rb +9 -0
  40. data/lib/sorenson/services/core_ext/object.rb +16 -0
  41. data/lib/sorenson/services/core_ext.rb +3 -0
  42. data/lib/sorenson/services/event.rb +28 -0
  43. data/lib/sorenson/services/flag.rb +14 -0
  44. data/lib/sorenson/services/group.rb +41 -0
  45. data/lib/sorenson/services/metric.rb +21 -0
  46. data/lib/sorenson/services/rate_plan.rb +30 -0
  47. data/lib/sorenson/services/site.rb +25 -0
  48. data/lib/sorenson/services/tag.rb +17 -0
  49. data/lib/sorenson/services.rb +18 -0
  50. metadata +161 -0
@@ -0,0 +1,71 @@
1
+ module Sorenson
2
+ module Services
3
+ class InvalidServerResponse < Exception
4
+ end
5
+
6
+ class Invalid360ServiceSetup < Exception
7
+ end
8
+
9
+ class InvalidSiteId < Exception
10
+ end
11
+
12
+ class Base
13
+ cattr_accessor :account_id, :account_token
14
+
15
+ def self.verify_account_settings
16
+ if @@account_id.blank? || @@account_token.blank?
17
+ raise Invalid360ServiceSetup.new("You must specify an account_id and account_token before using 360 services")
18
+ end
19
+ end
20
+
21
+ def self.login_no_resource(username, password)
22
+ RestClient.post(host + "/sessions", :username => username, :password => password)
23
+ end
24
+
25
+ def self.host
26
+ host = ENV['SORENSON_ENV'].eql?('cucumber') ? 'http://localhost:3001' : 'http://360services.sorensonmedia.com'
27
+ host
28
+ end
29
+
30
+ def self.post_to(url, payload = {})
31
+ verify_account_settings
32
+ post_to_url = host + url
33
+ client = RestClient::Resource.new(post_to_url, :user => account_id, :password => account_token)
34
+
35
+ parse_response(client.post(payload))
36
+ end
37
+
38
+ def self.get_from(url, payload = {})
39
+ verify_account_settings
40
+ get_from_url = host + url + "?#{payload.to_query}"
41
+ client = RestClient::Resource.new(get_from_url, :user => account_id, :password => account_token)
42
+
43
+ parse_response(client.get)
44
+ end
45
+
46
+ def self.put_to(url, payload = {})
47
+ verify_account_settings
48
+ put_to_url = host + url
49
+ client = RestClient::Resource.new(put_to_url, :user => account_id, :password => account_token)
50
+
51
+ parse_response(client.put(payload))
52
+ end
53
+
54
+ def self.delete_from(url)
55
+ verify_account_settings
56
+ delete_from_url = host + url
57
+ client = RestClient::Resource.new(delete_from_url, :user => account_id, :password => account_token)
58
+
59
+ parse_response(client.delete)
60
+ end
61
+
62
+ def self.parse_response(response)
63
+ begin
64
+ JSON.parse(response)
65
+ rescue JSON::ParserError => e
66
+ raise InvalidServerResponse.new("Sorenson::Services::InvalidServerResponse: #{e.message}")
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,52 @@
1
+ module Sorenson
2
+ module Services
3
+ class Category < Base
4
+ attr_accessor :description, :name, :parent_id, :parent, :id
5
+ def self.all
6
+ get_from("/categories").map{|c| c["name"]}
7
+ end
8
+
9
+ def self.find_by_name(name)
10
+ data = get_from("/categories/find_by_name", :category => {:name => name})
11
+ return new(data) unless data.blank?
12
+ nil
13
+ end
14
+
15
+ def self.find(id)
16
+ data = get_from("/categories/#{id}")
17
+ return new(data) unless data.blank?
18
+ end
19
+
20
+ def self.create(name, options = {})
21
+ new(post_to("/categories", :category => {:name => name}.merge(options)))
22
+ end
23
+
24
+ def save
25
+ Base.put_to("/categories/#{id}", :category => {:name => name, :description => description}, :parent_name => parent)
26
+ end
27
+
28
+ def destroy
29
+ Base.delete_from("/categories/#{id}")["status"]
30
+ end
31
+
32
+ def assets
33
+ Base.get_from("/categories/#{id}/assets")
34
+ end
35
+
36
+ def self.all_roots
37
+ Base.get_from("/categories/roots").map{|category| category['name']}
38
+ end
39
+
40
+ def parent
41
+ parent_id ? Sorenson::Services::Category.find(parent_id).name : @parent
42
+ end
43
+
44
+ def initialize(data)
45
+ self.description = data['description']
46
+ self.name = data['name']
47
+ self.parent_id = data["parent_id"]
48
+ self.id = data["id"]
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,40 @@
1
+ class Class
2
+ def cattr_reader(*syms)
3
+ syms.flatten.each do |sym|
4
+ next if sym.is_a?(Hash)
5
+ class_eval(<<-EOS, __FILE__, __LINE__)
6
+ unless defined? @@#{sym} # unless defined? @@hair_colors
7
+ @@#{sym} = nil # @@hair_colors = nil
8
+ end # end
9
+ #
10
+ def self.#{sym} # def self.hair_colors
11
+ @@#{sym} # @@hair_colors
12
+ end # end
13
+ #
14
+ def #{sym} # def hair_colors
15
+ @@#{sym} # @@hair_colors
16
+ end # end
17
+ EOS
18
+ end
19
+ end
20
+
21
+ def cattr_writer(*syms)
22
+ syms.flatten.each do |sym|
23
+ class_eval(<<-EOS, __FILE__, __LINE__)
24
+ unless defined? @@#{sym} # unless defined? @@hair_colors
25
+ @@#{sym} = nil # @@hair_colors = nil
26
+ end # end
27
+ #
28
+ def self.#{sym}=(obj) # def self.hair_colors=(obj)
29
+ @@#{sym} = obj # @@hair_colors = obj
30
+ end # end
31
+ #
32
+ EOS
33
+ end
34
+ end
35
+
36
+ def cattr_accessor(*syms)
37
+ cattr_reader(*syms)
38
+ cattr_writer(*syms)
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ class Hash
2
+ def to_param(namespace = nil)
3
+ collect do |key, value|
4
+ value.to_query(namespace ? "#{namespace}[#{key}]" : key)
5
+ end.sort * '&'
6
+ end
7
+
8
+ alias_method :to_query, :to_param
9
+ end
@@ -0,0 +1,16 @@
1
+ class Object
2
+ # Converts an object into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
3
+ # param name.
4
+ #
5
+ # Note: This method is defined as a default implementation for all Objects for Hash#to_query to work.
6
+ def to_query(key)
7
+ require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
8
+ "#{CGI.escape(key.to_s).gsub(/%(5B|5D)/n) { [$1].pack('H*') }}=#{CGI.escape(to_param.to_s)}"
9
+ end
10
+
11
+ # Alias of <tt>to_s</tt>.
12
+ def to_param
13
+ to_s
14
+ end
15
+
16
+ end
@@ -0,0 +1,3 @@
1
+ require(File.join(File.dirname(__FILE__), 'core_ext', 'attribute_accessors'))
2
+ require(File.join(File.dirname(__FILE__), 'core_ext', 'hash'))
3
+ require(File.join(File.dirname(__FILE__), 'core_ext', 'object'))
@@ -0,0 +1,28 @@
1
+ module Sorenson
2
+ module Services
3
+ class Event < Base
4
+ attr_accessor :date, :account_id, :value, :type, :day, :id, :last_modified, :retreived_on
5
+ def initialize(data)
6
+ @date = Date.parse(data['eventDate'])
7
+ @day = Date.parse(data['eventDay'])
8
+ @last_modified = Date.parse(data['dateLastModified'])
9
+ @retreived_on = Date.parse(data['dateRetrieved'])
10
+ @id = data['id']
11
+ @account_id = data['accountId']
12
+ @value = data['eventIntegerValue'] || data['eventDecimalValue'] || data['eventStringValue']
13
+ @type = data['eventType']
14
+
15
+ # {"eventDate"=>"2009-12-17 20:31:40",
16
+ # "accountId"=>"db786013-c786-4511-8a0d-73f1bacc2285",
17
+ # "eventIntegerValue"=>292684,
18
+ # "eventType"=>"storageAdd",
19
+ # "eventDay"=>"2009-12-17",
20
+ # "eventDecimalValue"=>nil,
21
+ # "id"=>"80437d46-f704-4fbc-8e61-0e9467a60b05",
22
+ # "dateLastModified"=>"2009-12-17 20:31:40",
23
+ # "eventStringValue"=>nil,
24
+ # "dateRetrieved"=>"2009-12-30 13:16:18"}
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,14 @@
1
+ module Sorenson
2
+ module Services
3
+ class Flag < Base
4
+ def self.all(order = nil)
5
+ url = "/flags#{"?order="+order if order}"
6
+ get_from(url)
7
+ end
8
+
9
+ def self.count
10
+ get_from("/accounts/#{account_id}/flags/count")["count"]
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,41 @@
1
+ module Sorenson
2
+ module Services
3
+ class Group < Base
4
+ attr_accessor :name, :description, :account_id, :id, :assets
5
+
6
+ def self.create(name, attributes={})
7
+ new(post_to("/groups", :group => attributes.merge(:name => name)))
8
+ end
9
+
10
+ def add_asset(asset)
11
+ self.assets = Base.put_to("/groups/#{id}/assets/#{asset.id}")
12
+ end
13
+
14
+ def self.all
15
+ Base.get_from("/groups")
16
+ end
17
+
18
+ def self.find(id)
19
+ data = Base.get_from("/groups/#{id}")
20
+ new(data) if data['group']
21
+ end
22
+
23
+ def self.find_by_name(name)
24
+ data = Base.get_from("/groups/find_by_name", :name => name)
25
+ new(data) if data['group']
26
+ end
27
+
28
+ def destroy
29
+ Base.delete_from("/groups/#{id}")
30
+ end
31
+
32
+ def initialize(attributes)
33
+ @name = attributes['group']["name"]
34
+ @description = attributes['group']["description"]
35
+ @account_id = attributes['group']["account_id"]
36
+ @id = attributes['group']["guid"]
37
+ @assets = attributes['group']["asset_ids"]
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ module Sorenson
2
+ module Services
3
+ class Metric < Base
4
+ def self.all(offset = nil, quantity = nil)
5
+ get_from("/metrics").collect do |event|
6
+ Event.new(event)
7
+ end
8
+ end
9
+
10
+ def self.total_plays
11
+ get_from("/metrics/total_plays")['total_plays'].to_i
12
+ end
13
+
14
+ def self.storage_used(start_date = nil, end_date = nil)
15
+ options = {}
16
+ options.merge(:start_date => start_date, :end_date => end_date) if start_date && end_date
17
+ get_from("/metrics/storage", options)['storage_used']
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,30 @@
1
+ module Sorenson
2
+ module Services
3
+ class RatePlan < Base
4
+ attr_accessor :display_name, :rate_plan_type, :max_thumbnails_per_video, :setup_cost, :monthly_cost, :annual_cost, :allowed_streams, :base_plan,
5
+ :date_last_modified, :date_retrieved, :streaming_overage_allowed, :storage_overage_allowed, :allowed_streaming_megabytes,
6
+ :allowed_storage_megabytes, :allowed_source_media_types, :allowed_output_media_types, :sorenson_sku, :data
7
+
8
+ def initialize(data)
9
+ @display_name = data['display_name']
10
+ @rate_plan_type = data['rate_plan_type']
11
+ @max_thumbnails_per_video = data['max_thumbnails_per_video']
12
+ @setup_cost = data['setup_cost']
13
+ @monthly_cost = data['monthly_cost']
14
+ @annual_cost = data['annual_cost']
15
+ @allowed_streams = data['allowed_streams']
16
+ @base_plan = data['base_plan']
17
+ @date_last_modified = data['date_last_modified']
18
+ @date_retrieved = data['date_retrieved']
19
+ @streaming_overage_allowed = data['streaming_overage_allowed']
20
+ @storage_overage_allowed = data['storage_overage_allowed']
21
+ @allowed_streaming_megabytes = data['allowed_streaming_megabytes']
22
+ @allowed_storage_megabytes = data['allowed_storage_megabytes']
23
+ @allowed_source_media_types = data['allowed_source_media_types'].collect {|e| e['mediaType']}
24
+ @allowed_output_media_types = data['allowed_output_media_types'].collect {|e| e['mediaType']}
25
+ @sorenson_sku = data['sorenson_sku']
26
+ @data = data
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,25 @@
1
+ module Sorenson
2
+ module Services
3
+ class Site < Base
4
+ attr_accessor :name, :account_id, :id, :description
5
+ def self.create(name, options = {})
6
+ new(post_to('/sites', {:site => {:name => name}.merge(options)}))
7
+ end
8
+
9
+ def self.all
10
+ get_from('/sites')
11
+ end
12
+
13
+ def Site.find_by_name(name)
14
+ new(get_from('/sites/find_by_name/', :name => name))
15
+ end
16
+
17
+ def initialize(data)
18
+ @name = data['name']
19
+ @account_id = data['account_id']
20
+ @id = data['id']
21
+ @description = data['description']
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ module Sorenson
2
+ module Services
3
+ class Tag < Base
4
+ def self.all(order = nil)
5
+ get_from("/tags#{"?order="+order if order}")
6
+ end
7
+
8
+ def self.find(tag_name)
9
+ get_from("/tags/#{tag_name}")
10
+ end
11
+
12
+ def self.count
13
+ get_from("/accounts/#{account_id}/tags/count")["count"]
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'rest_client'
3
+ require 'json'
4
+
5
+ require(File.join(File.dirname(__FILE__), 'services', 'core_ext'))
6
+ require(File.join(File.dirname(__FILE__), 'services', 'base'))
7
+ require(File.join(File.dirname(__FILE__), 'services', 'rate_plan'))
8
+ require(File.join(File.dirname(__FILE__), 'services', 'group'))
9
+ require(File.join(File.dirname(__FILE__), 'services', 'metric'))
10
+ require(File.join(File.dirname(__FILE__), 'services', 'category'))
11
+ require(File.join(File.dirname(__FILE__), 'services', 'flag'))
12
+ require(File.join(File.dirname(__FILE__), 'services', 'tag'))
13
+ require(File.join(File.dirname(__FILE__), 'services', 'event'))
14
+ require(File.join(File.dirname(__FILE__), 'services', 'account'))
15
+ require(File.join(File.dirname(__FILE__), 'services', 'asset'))
16
+ require(File.join(File.dirname(__FILE__), 'services', 'array'))
17
+ require(File.join(File.dirname(__FILE__), 'services', 'site'))
18
+ require(File.join(File.dirname(__FILE__), 'services', 'core_ext', 'object'))
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: 360_services
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sorenson Media
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-25 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: echoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: cucumber
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rspec
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: netrecorder
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ description: Ruby bindings for Sorenson 360
56
+ email: video@sorensonmedia.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - lib/sorenson/services.rb
63
+ - lib/sorenson/services/account.rb
64
+ - lib/sorenson/services/array.rb
65
+ - lib/sorenson/services/asset.rb
66
+ - lib/sorenson/services/base.rb
67
+ - lib/sorenson/services/category.rb
68
+ - lib/sorenson/services/core_ext.rb
69
+ - lib/sorenson/services/core_ext/attribute_accessors.rb
70
+ - lib/sorenson/services/core_ext/hash.rb
71
+ - lib/sorenson/services/core_ext/object.rb
72
+ - lib/sorenson/services/event.rb
73
+ - lib/sorenson/services/flag.rb
74
+ - lib/sorenson/services/group.rb
75
+ - lib/sorenson/services/metric.rb
76
+ - lib/sorenson/services/rate_plan.rb
77
+ - lib/sorenson/services/site.rb
78
+ - lib/sorenson/services/tag.rb
79
+ files:
80
+ - Manifest
81
+ - Rakefile
82
+ - fakeweb_cache
83
+ - features/manage_accounts.feature
84
+ - features/manage_assets.feature
85
+ - features/manage_categories.feature
86
+ - features/manage_flags.feature
87
+ - features/manage_group_assets.feature
88
+ - features/manage_groups.feature
89
+ - features/manage_metadata.feature
90
+ - features/manage_metrics.feature
91
+ - features/manage_sites.feature
92
+ - features/manage_tags.feature
93
+ - features/mange_rate_plan.feature
94
+ - features/step_definitions/manage_accounts_steps.rb
95
+ - features/step_definitions/manage_assets_steps.rb
96
+ - features/step_definitions/manage_categories_steps.rb
97
+ - features/step_definitions/manage_flags_steps.rb
98
+ - features/step_definitions/manage_group_assets_steps.rb
99
+ - features/step_definitions/manage_groups_steps.rb
100
+ - features/step_definitions/manage_metadata_steps.rb
101
+ - features/step_definitions/manage_metrics_steps.rb
102
+ - features/step_definitions/manage_sites_steps.rb
103
+ - features/step_definitions/manage_tags_steps.rb
104
+ - features/step_definitions/mange_rate_plan_steps.rb
105
+ - features/step_definitions/utility_steps.rb
106
+ - features/step_definitions/web_steps.rb
107
+ - features/support/document_steps.rb
108
+ - features/support/env.rb
109
+ - features/support/netrecorder.rb
110
+ - features/support/paths.rb
111
+ - lib/sorenson/services.rb
112
+ - lib/sorenson/services/account.rb
113
+ - lib/sorenson/services/array.rb
114
+ - lib/sorenson/services/asset.rb
115
+ - lib/sorenson/services/base.rb
116
+ - lib/sorenson/services/category.rb
117
+ - lib/sorenson/services/core_ext.rb
118
+ - lib/sorenson/services/core_ext/attribute_accessors.rb
119
+ - lib/sorenson/services/core_ext/hash.rb
120
+ - lib/sorenson/services/core_ext/object.rb
121
+ - lib/sorenson/services/event.rb
122
+ - lib/sorenson/services/flag.rb
123
+ - lib/sorenson/services/group.rb
124
+ - lib/sorenson/services/metric.rb
125
+ - lib/sorenson/services/rate_plan.rb
126
+ - lib/sorenson/services/site.rb
127
+ - lib/sorenson/services/tag.rb
128
+ - 360_services.gemspec
129
+ has_rdoc: true
130
+ homepage: http://github.com/sorensonmedia/360_services
131
+ licenses: []
132
+
133
+ post_install_message:
134
+ rdoc_options:
135
+ - --line-numbers
136
+ - --inline-source
137
+ - --title
138
+ - 360_services
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: "0"
146
+ version:
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: "1.2"
152
+ version:
153
+ requirements: []
154
+
155
+ rubyforge_project: 360_services
156
+ rubygems_version: 1.3.5
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: Ruby bindings for Sorenson 360
160
+ test_files: []
161
+