botr 0.1.0

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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.document +3 -0
  3. data/.gitignore +31 -0
  4. data/.rspec +1 -0
  5. data/.yardopts +1 -0
  6. data/ChangeLog.md +4 -0
  7. data/LICENSE.txt +20 -0
  8. data/README.md +278 -0
  9. data/Rakefile +43 -0
  10. data/botr.gemspec +24 -0
  11. data/botr.watchr +3 -0
  12. data/certs/cacert.pem +3554 -0
  13. data/lib/botr.rb +34 -0
  14. data/lib/botr/api/api.rb +83 -0
  15. data/lib/botr/api/authentication.rb +24 -0
  16. data/lib/botr/channels/channel.rb +137 -0
  17. data/lib/botr/channels/channel_thumbnail.rb +88 -0
  18. data/lib/botr/channels/channel_video.rb +130 -0
  19. data/lib/botr/channels/channel_view.rb +88 -0
  20. data/lib/botr/common/logger.rb +31 -0
  21. data/lib/botr/configuration.rb +18 -0
  22. data/lib/botr/http/http.rb +88 -0
  23. data/lib/botr/http/http_backend.rb +66 -0
  24. data/lib/botr/http/http_response.rb +48 -0
  25. data/lib/botr/http/multipart.rb +84 -0
  26. data/lib/botr/http/uri_ext.rb +28 -0
  27. data/lib/botr/object.rb +20 -0
  28. data/lib/botr/players/player.rb +149 -0
  29. data/lib/botr/players/player_view.rb +88 -0
  30. data/lib/botr/version.rb +3 -0
  31. data/lib/botr/videos/video.rb +187 -0
  32. data/lib/botr/videos/video_caption.rb +154 -0
  33. data/lib/botr/videos/video_conversion.rb +114 -0
  34. data/lib/botr/videos/video_engagement.rb +51 -0
  35. data/lib/botr/videos/video_tag.rb +52 -0
  36. data/lib/botr/videos/video_thumbnail.rb +87 -0
  37. data/lib/botr/videos/video_view.rb +89 -0
  38. data/spec/authentication_spec.rb +31 -0
  39. data/spec/botr_spec.rb +8 -0
  40. data/spec/http_backend_spec.rb +93 -0
  41. data/spec/http_response_spec.rb +48 -0
  42. data/spec/multipart_spec.rb +35 -0
  43. data/spec/spec_helper.rb +5 -0
  44. data/spec/test.txt +1 -0
  45. metadata +150 -0
@@ -0,0 +1,20 @@
1
+ require 'json'
2
+
3
+ module BOTR
4
+ class Object
5
+
6
+ include BOTR::HTTP
7
+ include BOTR::API
8
+ include BOTR::Authentication
9
+
10
+ class << self
11
+
12
+ include BOTR::HTTP
13
+ include BOTR::API
14
+ include BOTR::Authentication
15
+
16
+ attr_accessor :threads
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,149 @@
1
+ module BOTR
2
+
3
+ class Player < BOTR::Object
4
+
5
+ class << self
6
+
7
+ attr_reader :last_status
8
+
9
+ def show(key)
10
+ json = get_request({:method => 'show',
11
+ :player_key => key})
12
+ res = JSON.parse(json.body)
13
+
14
+ if json.status == 200
15
+ params = process_show_response(res)
16
+ else
17
+ raise "HTTP Error #{json.status}: #{json.body}"
18
+ end
19
+
20
+ return new(params)
21
+ end
22
+
23
+ alias :find :show
24
+
25
+ def list(**options)
26
+ json = get_request(options.merge(:method => 'list'))
27
+ res = JSON.parse(json.body)
28
+
29
+ if json.status == 200
30
+ results = process_list_response(res)
31
+ else
32
+ raise "HTTP Error #{json.status}: #{json.body}"
33
+ end
34
+
35
+ return results
36
+ end
37
+
38
+ def all
39
+ list({})
40
+ end
41
+
42
+ private
43
+
44
+ def process_show_response(body)
45
+ @last_status = body["status"]
46
+
47
+ return body["player"]
48
+ end
49
+
50
+ def process_list_response(body)
51
+ res = []
52
+
53
+ body["players"].each do |player|
54
+ res << new(player)
55
+ end
56
+
57
+ return res
58
+ end
59
+
60
+ end
61
+
62
+ attr_reader :last_status, :key, :name, :width, :height, :template,
63
+ :ga_web_property_id, :controlbar, :playlist, :playlistsize,
64
+ :related_videos, :stretching, :aspectratio, :autostart,
65
+ :repeat, :responsive, :skin, :sharing, :sharing_player_key,
66
+ :sitecatalyst, :captions, :ltas_channel, :version, :views,
67
+ :watermark, :advertising
68
+
69
+ def initialize(params = {})
70
+ params.each do |key, val|
71
+ param = "@#{key.to_s}"
72
+ next unless methods.include? key.to_sym
73
+ instance_variable_set(param, val)
74
+ end
75
+ end
76
+
77
+ def create(name, sharing_player_key, **options)
78
+ json = get_request(options.merge(:method => 'create',
79
+ :name => name,
80
+ :sharing_player_key => sharing_player_key))
81
+ res = JSON.parse(json.body)
82
+
83
+ if json.status == 200
84
+ process_create_response(res, options)
85
+ else
86
+ raise "HTTP Error #{json.status}: #{json.body}"
87
+ end
88
+
89
+ return self
90
+ end
91
+
92
+ def update(**options)
93
+ json = put_request(options.merge(:player_key => @key,
94
+ :sharing_player_key => @sharing_player_key))
95
+ res = JSON.parse(json.body)
96
+
97
+ if json.status == 200
98
+ process_update_response(res, options)
99
+ else
100
+ raise "HTTP Error #{json.status}: #{json.body}"
101
+ end
102
+
103
+ return self
104
+ end
105
+
106
+ def delete
107
+ json = delete_request({:player_key => @key})
108
+ res = JSON.parse(json.body)
109
+
110
+ if json.status == 200
111
+ process_delete_response(res)
112
+ else
113
+ raise "HTTP Error #{json.status}: #{json.body}"
114
+ end
115
+
116
+ return self
117
+ end
118
+
119
+ private
120
+
121
+ def process_create_response(body, params)
122
+ @last_status = body["status"]
123
+ @key = body["media"]["key"]
124
+ params.each do |key, val|
125
+ param = "@#{key.to_s}"
126
+ next unless methods.include? key
127
+ instance_variable_set(param, val)
128
+ end
129
+ end
130
+
131
+ def process_update_response(body, updated_params)
132
+ @last_status = body["status"]
133
+ updated_params.each do |key, val|
134
+ param = "@#{key.to_s}"
135
+ next unless methods.include? key
136
+ instance_variable_set(param, val)
137
+ end
138
+ end
139
+
140
+ def process_delete_response(body)
141
+ @last_status = body["status"]
142
+ instance_variables.each do |param|
143
+ instance_variable_set(param, nil)
144
+ end
145
+ end
146
+
147
+ end
148
+
149
+ end
@@ -0,0 +1,88 @@
1
+ module BOTR
2
+
3
+ class PlayerView < BOTR::Object
4
+
5
+ class << self
6
+
7
+ attr_reader :last_status
8
+
9
+ def show(key, **options)
10
+ json = get_request(options.merge(:method => 'show',
11
+ :player_key => key))
12
+ res = JSON.parse(json.body)
13
+
14
+ if json.status == 200
15
+ params = process_show_response(res)
16
+ else
17
+ raise "HTTP Error #{json.status}: #{json.body}"
18
+ end
19
+
20
+ return new(params)
21
+ end
22
+
23
+ alias :find :show
24
+
25
+ def list(**options)
26
+ json = get_request(options.merge(:method => 'list'))
27
+ res = JSON.parse(json.body)
28
+
29
+ if json.status == 200
30
+ results = process_list_response(res)
31
+ else
32
+ raise "HTTP Error #{json.status}: #{json.body}"
33
+ end
34
+
35
+ return results
36
+ end
37
+
38
+ def all
39
+ list({})
40
+ end
41
+
42
+ private
43
+
44
+ def process_show_response(body)
45
+ @last_status = body["status"]
46
+
47
+ return body["player"]
48
+ end
49
+
50
+ def process_list_response(body)
51
+ @last_status = body["status"]
52
+ res = []
53
+
54
+ if body["players"]
55
+ body["players"].each do |player|
56
+ res << new(player)
57
+ end
58
+ elsif body["days"]
59
+ body["days"].each do |day|
60
+ res << new(day)
61
+ end
62
+ elsif body["years"]
63
+ body["years"].each do |year|
64
+ res << new(year)
65
+ end
66
+ else
67
+ res << new(body)
68
+ end
69
+
70
+ return res
71
+ end
72
+
73
+ end
74
+
75
+ attr_reader :last_status, :key, :name, :views, :date, :timestamp, :number,
76
+ :months, :years
77
+
78
+ def initialize(params = {})
79
+ params.each do |key, val|
80
+ param = "@#{key.to_s}"
81
+ next unless methods.include? key.to_sym
82
+ instance_variable_set(param, val)
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ end
@@ -0,0 +1,3 @@
1
+ module BOTR
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,187 @@
1
+ module BOTR
2
+
3
+ # The BOTR::Video class contains calls for creating (uploading) videos,
4
+ # searching for videos, editing video metadata (title, description,
5
+ # tags etc.) and deleting videos.
6
+ #
7
+ # A video object is a metadata container that actually contains multiple
8
+ # video files (conversions). It does _not_ reference the actual video file
9
+ # located on the content server.
10
+ #
11
+ class Video < BOTR::Object
12
+
13
+ class << self
14
+
15
+ attr_reader :last_status
16
+
17
+ # Show the properties of a given video.
18
+ #
19
+ # @param [String] video_key key of the video for which to show
20
+ # information
21
+ #
22
+ # @return [BOTR::Video] a new object with the properties of the
23
+ # video referenced by the video_key
24
+ def show(video_key)
25
+ json = get_request({:method => 'show', :video_key => video_key})
26
+ res = JSON.parse(json.body)
27
+
28
+ if json.status == 200
29
+ params = process_show_response(res)
30
+ else
31
+ raise "HTTP Error #{json.status}: #{json.body}"
32
+ end
33
+
34
+ return new(params)
35
+ end
36
+
37
+ alias :find :show
38
+
39
+ # Return a list of videos.
40
+ #
41
+ # @param [Hash] options search parameters
42
+ #
43
+ # @option options [String] tags restrict the search to videos tagged
44
+ # with these tags (multiple tags should be comma-separated)
45
+ # @option options [String] tags_mode tags search mode: "all" -- a
46
+ # video will only be listed if it has all tags specified in the
47
+ # tags parameter or "any" -- A video will be listed if it has at
48
+ # least one tag specified in the tags parameter
49
+ #
50
+ # @return [Array] a list of video object matching the search
51
+ # criteria
52
+ def list(**options)
53
+ json = get_request(options.merge(:method => 'list'))
54
+ res = JSON.parse(json.body)
55
+
56
+ if json.status == 200
57
+ results = process_list_response(res)
58
+ else
59
+ raise "HTTP Error #{json.status}: #{json.body}"
60
+ end
61
+
62
+ return results
63
+ end
64
+
65
+ # Return a list of all videos.
66
+ #
67
+ # @note Same as calling list with no arguments given.
68
+ def all
69
+ list({})
70
+ end
71
+
72
+ private
73
+
74
+ def process_show_response(body)
75
+ @last_status = body["status"]
76
+
77
+ return body["video"]
78
+ end
79
+
80
+ def process_list_response(body)
81
+ res = []
82
+
83
+ body["videos"].each do |video|
84
+ res << new(video)
85
+ end
86
+
87
+ return res
88
+ end
89
+
90
+ end
91
+
92
+ attr_reader :last_status, :key, :link, :file, :title, :tags, :md5, :size,
93
+ :description, :author, :date, :link, :download_url, :status,
94
+ :views, :error, :sourcetype, :duration, :mediatype
95
+
96
+ def initialize(params = {})
97
+ params.each do |key, val|
98
+ param = "@#{key.to_s}"
99
+ next unless methods.include? key.to_sym
100
+ instance_variable_set(param, val)
101
+ end
102
+ end
103
+
104
+ def create(**options)
105
+ json = get_request(options.merge(:method => 'create'))
106
+ res = JSON.parse(json.body)
107
+
108
+ if json.status == 200
109
+ process_create_response(res)
110
+ else
111
+ raise "HTTP Error #{json.status}: #{json.body}"
112
+ end
113
+
114
+ return self
115
+ end
116
+
117
+ def upload(data_path, **options)
118
+ json = post_request(options, data_path)
119
+ res = JSON.parse(json.body)
120
+
121
+ if json.status == 200
122
+ process_upload_response(res)
123
+ else
124
+ raise "HTTP Error #{json.status}: #{json.body}"
125
+ end
126
+
127
+ return self
128
+ end
129
+
130
+ def update(**options)
131
+ json = put_request(options.merge(:video_key => @key))
132
+ res = JSON.parse(json.body)
133
+
134
+ if json.status == 200
135
+ process_update_response(res, options)
136
+ else
137
+ raise "HTTP Error #{json.status}: #{json.body}"
138
+ end
139
+
140
+ return self
141
+ end
142
+
143
+ def delete
144
+ json = delete_request({:video_key => @key})
145
+ res = JSON.parse(json.body)
146
+
147
+ if json.status == 200
148
+ process_delete_response(res)
149
+ else
150
+ raise "HTTP Error #{json.status}: #{json.body}"
151
+ end
152
+
153
+ return self
154
+ end
155
+
156
+ private
157
+
158
+ def process_create_response(body)
159
+ @last_status = body["status"]
160
+ @key = body["media"]["key"]
161
+ @link = body["link"]
162
+ end
163
+
164
+ def process_upload_response(body)
165
+ @last_status = body["status"]
166
+ @file = body["file"]
167
+ end
168
+
169
+ def process_update_response(body, updated_params)
170
+ @last_status = body["status"]
171
+ updated_params.each do |key, val|
172
+ param = "@#{key.to_s}"
173
+ next unless methods.include? key
174
+ instance_variable_set(param, val)
175
+ end
176
+ end
177
+
178
+ def process_delete_response(body)
179
+ @last_status = body["status"]
180
+ instance_variables.each do |param|
181
+ instance_variable_set(param, nil)
182
+ end
183
+ end
184
+
185
+ end
186
+
187
+ end