Class: JWPlayer::API::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/jwplayer/api/client.rb,
lib/jwplayer/api/client/version.rb

Constant Summary collapse

ALLOWED_KEYS =
[:format, :key, :nonce, :timestamp]
IGNORED_KEYS =
[:host, :scheme, :secret, :signature, :version]
ESCAPE_REGEX =
/[^a-z0-9\-\.\_\~]/i
VERSION =
'0.1.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jwplayer/api/client.rb', line 16

def initialize(args = {})
  @options = {
      host:    'api.jwplatform.com',
      scheme:  'https',
      version: :v1,
      key:     ENV['JWPLAYER_API_KEY'],
      secret:  ENV['JWPLAYER_API_SECRET'],
      format:  :json
  }.merge(args)

  [:key, :secret].each do |key|
    if options[key].nil? || options[key].empty?
      raise ArgumentError, "Missing :#{key} parameter or 'JWPLAYER_API_#{key.upcase}' ENV variable"
    end
  end
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



14
15
16
# File 'lib/jwplayer/api/client.rb', line 14

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



14
15
16
# File 'lib/jwplayer/api/client.rb', line 14

def params
  @params
end

Instance Method Details

#signed_uri(path, params = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/jwplayer/api/client.rb', line 33

def signed_uri(path, params = {})
  @params              = params
  @options[:nonce]     = rand.to_s[2..9]
  @options[:timestamp] = Time.now.to_i.to_s
  @uri                 = URI.join(URI::Generic.build(@options), [@options[:version], '/'].join, path)
  @uri.query           = signed_attributes
  @uri.normalize!
  @uri
end

#signed_url(path, params = {}) ⇒ Object



43
44
45
# File 'lib/jwplayer/api/client.rb', line 43

def signed_url(path, params = {})
  signed_uri(path, params).to_s
end