Module: Flix::Default

Defined in:
lib/flix/default.rb

Constant Summary collapse

ENDPOINT =
'http://api.netflix.com'
CONNECTION_OPTIONS =

MEDIA_ENDPOINT = ‘upload.flix.com’ unless defined? MEDIA_ENDPOINT SEARCH_ENDPOINT = ‘search.flix.com’ unless defined? SEARCH_ENDPOINT

{
  :headers => {
    :accept => 'application/json',
    :user_agent => "Flix Ruby Gem #{Flix::VERSION}"
  },
  :open_timeout => 5,
  :raw => true,
  :ssl => {:verify => false},
  :timeout => 10,
}
IDENTITY_MAP =
Flix::IdentityMap
MIDDLEWARE =
Faraday::Builder.new(
  &Proc.new do |builder|
    # # Convert file uploads to Faraday::UploadIO objects
    # builder.use Flix::Request::MultipartWithFile
    # # Checks for files in the payload
    # builder.use Faraday::Request::Multipart
    
    builder.use Faraday::Request::OAuth, Flix::Default.options
    # Convert request params to "www-form-urlencoded"
    builder.use Faraday::Request::UrlEncoded
    # Handle 4xx server responses
    # builder.use Flix::Response::RaiseError, Flix::Error::ClientError
    # # Parse JSON response bodies using MultiJson
    # builder.use Flix::Response::ParseJson
    # # Handle 5xx server responses
    # builder.use Flix::Response::RaiseError, Flix::Error::ServerError
    # Set Faraday's HTTP adapter
    builder.adapter Faraday.default_adapter
  end
)

Class Method Summary collapse

Class Method Details

.connection_optionsHash

Returns:

  • (Hash)


96
97
98
# File 'lib/flix/default.rb', line 96

def connection_options
  CONNECTION_OPTIONS
end

.consumer_keyString

Returns:

  • (String)


56
57
58
# File 'lib/flix/default.rb', line 56

def consumer_key
  ENV['NETFLIX_CONSUMER_KEY']
end

.consumer_secretString

Returns:

  • (String)


61
62
63
# File 'lib/flix/default.rb', line 61

def consumer_secret
  ENV['NETFLIX_CONSUMER_SECRET']
end

.endpointString

Note:

This is configurable in case you want to use HTTP instead of HTTPS or use a Netflix-compatible endpoint.



81
82
83
# File 'lib/flix/default.rb', line 81

def endpoint
  ENDPOINT
end

.identity_mapFlix::IdentityMap

Returns:



101
102
103
# File 'lib/flix/default.rb', line 101

def identity_map
  IDENTITY_MAP
end

.middlewareFaraday::Builder

Note:

Faraday’s middleware stack implementation is comparable to that of Rack middleware. The order of middleware is important: the first middleware on the list wraps all others, while the last middleware is the innermost one.



109
110
111
# File 'lib/flix/default.rb', line 109

def middleware
  MIDDLEWARE
end

.oauth_tokenString

Returns:

  • (String)


66
67
68
# File 'lib/flix/default.rb', line 66

def oauth_token
  ENV['NETFLIX_OAUTH_TOKEN']
end

.oauth_token_secretString

Returns:

  • (String)


71
72
73
# File 'lib/flix/default.rb', line 71

def oauth_token_secret
  ENV['NETFLIX_OAUTH_TOKEN_SECRET']
end

.optionsHash

Returns:

  • (Hash)


51
52
53
# File 'lib/flix/default.rb', line 51

def options
  Hash[Flix::Configurable.keys.map{|key| [key, send(key)]}]
end