brightcove_cms_api 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e98f7568e63d644e25a0871b7e9b4c8210069c4
4
+ data.tar.gz: 79ccecc43f76c37344be5abc7a326c6feec580f5
5
+ SHA512:
6
+ metadata.gz: 4a69d67b6962c1fed80519ac3e6a1f06eadd71852b1d7f875b462d9ed65196d6d1daec372fad965f42b0d7d30096419cc5a6216d1537973422dec34bc46c8576
7
+ data.tar.gz: b876f827aa23dcb82ce649af212c8d0187c65fd791cb4cb67c8c9faf4cfaf854e8e4fe3b0ed03a50671309e4090fe718f088fcd8811c382220144f556915c56d
@@ -0,0 +1,8 @@
1
+ module BrightcoveCmsApi
2
+ class CmsapiError < StandardError
3
+ end
4
+
5
+ # AuthenticationError is raised when the Oauth authentication fails
6
+ class AuthenticationError < CmsapiError
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module BrightcoveCmsApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,117 @@
1
+ require "http"
2
+ require_relative "errors"
3
+
4
+ API_URL = "https://cms.api.brightcove.com/v1/accounts"
5
+ OAUTH_ENDPOINT = "https://oauth.brightcove.com/v4/access_token"
6
+
7
+ module BrightcoveCmsApi
8
+ class Video
9
+
10
+ def initialize(account_id:, client_id:, client_secret:)
11
+ @account_id = account_id
12
+ @client_id = client_id
13
+ @client_secret = client_secret
14
+ set_authtoken
15
+ end
16
+
17
+ # Get Videos
18
+ def find_all
19
+ check_token_expires
20
+ @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/videos")
21
+ send_response
22
+ end
23
+
24
+ # Create Videos
25
+ def create(params = {})
26
+ check_token_expires
27
+ @response = HTTP.auth("Bearer #{@token}").post("#{API_URL}/#{@account_id}/videos", { json: params })
28
+ send_response
29
+ end
30
+
31
+ # Get Video count
32
+ def count
33
+ check_token_expires
34
+ @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/counts/videos")
35
+ send_response
36
+ end
37
+
38
+ # Get Video by id and reference_id
39
+ def get_by_reference_id(video_id)
40
+ check_token_expires
41
+ @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/videos/#{video_id}")
42
+ send_response
43
+ end
44
+
45
+ # delete video
46
+ def delete(video_id)
47
+ check_token_expires
48
+ @response = HTTP.auth("Bearer #{@token}").delete("#{API_URL}/#{@account_id}/videos/#{video_id}")
49
+ send_response
50
+ end
51
+
52
+ # update video
53
+ def update(video_id, params = {})
54
+ check_token_expires
55
+ @response = HTTP.auth("Bearer #{@token}").patch("#{API_URL}/#{@account_id}/videos/#{video_id}", { json: params })
56
+ send_response
57
+ end
58
+
59
+ # Get video images
60
+ def images(video_id)
61
+ check_token_expires
62
+ @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/videos/#{video_id}/images")
63
+ send_response
64
+ end
65
+
66
+ # get playlists for video
67
+ def playlists(video_id)
68
+ check_token_expires
69
+ @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/videos/#{video_id}/references")
70
+ send_response
71
+ end
72
+
73
+ # remove video from all playlists
74
+ def remove_from_playlists(video_id)
75
+ check_token_expires
76
+ @response = HTTP.auth("Bearer #{@token}").delete("#{API_URL}/#{@account_id}/videos/#{video_id}/references")
77
+ send_response
78
+ end
79
+
80
+ # Get custom fields
81
+ def custom_fields
82
+ check_token_expires
83
+ @response = HTTP.auth("Bearer #{@token}").get("#{API_URL}/#{@account_id}/video_fields")
84
+ send_response
85
+ end
86
+
87
+ private
88
+
89
+ def set_authtoken
90
+ response = HTTP.basic_auth(user: @client_id, pass: @client_secret)
91
+ .post(OAUTH_ENDPOINT,
92
+ form: { grant_type: "client_credentials" })
93
+ token_response = response.parse
94
+
95
+ if response.status == 200
96
+ @token = token_response.fetch("access_token")
97
+ @token_expires = Time.now + token_response.fetch("expires_in")
98
+ else
99
+ raise AuthenticationError, token_response.fetch("error_description")
100
+ end
101
+ end
102
+
103
+ def check_token_expires
104
+ set_authtoken if @token_expires < Time.now
105
+ end
106
+
107
+ def send_response
108
+ case @response.code
109
+ when 200, 201, 204
110
+ @response.parse
111
+ else
112
+ raise CmsapiError, @response
113
+ end
114
+ end
115
+
116
+ end
117
+ end
@@ -0,0 +1,3 @@
1
+ require_relative "brightcove_cms_api/version"
2
+ require_relative "brightcove_cms_api/video"
3
+ require_relative "brightcove_cms_api/errors"
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brightcove_cms_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dilkhush Soni
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.2.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.2
41
+ description:
42
+ email:
43
+ - dilkhushsoni2010@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/brightcove_cms_api.rb
49
+ - lib/brightcove_cms_api/errors.rb
50
+ - lib/brightcove_cms_api/version.rb
51
+ - lib/brightcove_cms_api/video.rb
52
+ homepage: https://github.com/nhsuk/brightcove-cmsapi
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 2.2.6
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.6.12
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: A simple wrapper around Brightcove's CMS API
76
+ test_files: []