Module: Matroid
- Defined in:
- lib/matroid.rb,
lib/matroid/error.rb,
lib/matroid/version.rb,
lib/matroid/detector.rb,
lib/matroid/connection.rb
Defined Under Namespace
Modules: Error Classes: Detector, Token
Constant Summary collapse
- VERSION =
"1.0.0"
Class Attribute Summary collapse
-
.base_api_uri ⇒ Object
readonly
Returns the value of attribute base_api_uri.
-
.client ⇒ Object
readonly
Returns the value of attribute client.
-
.token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
-
.account_info ⇒ Object
Retrieves the authenticated user’s account information.
-
.authenticate(client_id = nil, client_secret = nil) ⇒ Boolean
Authenticates access for Matroid API.
-
.get_video_results(video_id, *args) ⇒ Object
Retrieves video classification data.
- .parse_response(response) ⇒ Object
-
.register_stream(stream_url, stream_name) ⇒ Object
Registers a new stream on Matroid.
-
.set_base_uri(uri) ⇒ Object
Changes the default base api uri.
-
.show_token ⇒ Object
Calls ::show on the current token (if it exists).
Class Attribute Details
.base_api_uri ⇒ Object (readonly)
Returns the value of attribute base_api_uri.
16 17 18 |
# File 'lib/matroid/connection.rb', line 16 def base_api_uri @base_api_uri end |
.client ⇒ Object (readonly)
Returns the value of attribute client.
16 17 18 |
# File 'lib/matroid/connection.rb', line 16 def client @client end |
.token ⇒ Object (readonly)
Returns the value of attribute token.
16 17 18 |
# File 'lib/matroid/connection.rb', line 16 def token @token end |
Class Method Details
.account_info ⇒ Object
Retrieves the authenticated user’s account information
64 65 66 |
# File 'lib/matroid.rb', line 64 def account_info get('account') end |
.authenticate(client_id = nil, client_secret = nil) ⇒ Boolean
Authenticates access for Matroid API
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/matroid.rb', line 19 def authenticate(client_id = nil, client_secret = nil) return true unless @token.nil? || @token.expired? if client_id && client_secret err_msg = 'problem using environment variables "MATROID_CLIENT_ID" and "MATROID_CLIENT_SECRET"' new_token = get_token(client_id, client_secret) raise Error::AuthorizationError.new(err_msg) if new_token.nil? @client_id, @client_secret = client_id, client_secret elsif (@client_id.nil? || @client_secret.nil?) && !environment_variables? err_msg = '"MATROID_CLIENT_ID" and "MATROID_CLIENT_SECRET" not found in environment' raise Error::AuthorizationError.new(err_msg) else err_msg = 'Problem using client variables provided' raise Error::AuthorizationError.new(err_msg) if get_token(@client_id, @client_secret).nil? end true end |
.get_video_results(video_id, *args) ⇒ Object
A “video_id” is needed to get the classification results
Retrieves video classification data. Requires a video_id from Matroid::Detector#classify_video_file or Matroid::Detector#classify_video_url format ‘json’/‘csv’
77 78 79 |
# File 'lib/matroid.rb', line 77 def get_video_results(video_id, *args) get("videos/#{video_id}", *args) end |
.parse_response(response) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/matroid/connection.rb', line 30 def parse_response(response) if valid_json?(response.body) status = response.status_code parsed_response = JSON.parse(response.body) if status != 200 err_msg = JSON.pretty_generate(parsed_response) raise Error::RateLimitError.new(err_msg) if status == 429 raise Error::InvalidQueryError.new(err_msg) if status == 422 raise Error::PaymentError.new(err_msg) if status == 402 raise Error::ServerError.new(err_msg) if status / 100 == 5 raise Error::APIError.new(err_msg) end parsed_response else p response raise Error::APIError.new(response.body) end end |
.register_stream(stream_url, stream_name) ⇒ Object
Registers a new stream on Matroid
85 86 87 88 89 |
# File 'lib/matroid.rb', line 85 def register_stream(stream_url, stream_name) register_err = "Must include a url and name for stream" raise Error::InvalidQueryError.new(register_err) unless stream_url && stream_name Matroid.post("feeds", name: stream_name, url: stream_url) end |
.set_base_uri(uri) ⇒ Object
Changes the default base api uri. This is used primarily for testing purposes.
20 21 22 |
# File 'lib/matroid/connection.rb', line 20 def set_base_uri(uri) @base_api_uri = uri end |
.show_token ⇒ Object
Calls ::show on the current token (if it exists).
38 39 40 41 42 |
# File 'lib/matroid.rb', line 38 def show_token if @token @token.show end end |