Module: Ohanakapa::Default

Defined in:
lib/ohanakapa/default.rb

Overview

Default configuration options for Client

Constant Summary collapse

API_ENDPOINT =

Default API endpoint

"http://ohana-api-demo.herokuapp.com/api".freeze
USER_AGENT =

Default User Agent header string

"Ohanakapa Ruby Gem #{Ohanakapa::VERSION}".freeze
MEDIA_TYPE =

Default media type

"application/vnd.ohanapi-v1+json"
RACK_BUILDER_CLASS =

In Faraday 0.9, Faraday::Builder was renamed to Faraday::RackBuilder

defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder
MIDDLEWARE =

Default Faraday middleware stack

RACK_BUILDER_CLASS.new do |builder|
  builder.use Ohanakapa::Response::RaiseError
  builder.adapter Faraday.default_adapter
end

Class Method Summary collapse

Class Method Details

.api_endpointString

Default API endpoint from ENV or API_ENDPOINT



37
38
39
# File 'lib/ohanakapa/default.rb', line 37

def api_endpoint
  ENV['OHANA_API_ENDPOINT'] || API_ENDPOINT
end

.api_tokenString

Default api token for Ohana API



87
88
89
# File 'lib/ohanakapa/default.rb', line 87

def api_token
  ENV['OHANAKAPA_API_TOKEN']
end

.auto_paginateString

Default pagination preference from ENV



43
44
45
# File 'lib/ohanakapa/default.rb', line 43

def auto_paginate
  ENV['OHANAKAPA_AUTO_PAGINATE']
end

.connection_optionsHash

Default options for Faraday::Connection



57
58
59
60
61
62
63
64
# File 'lib/ohanakapa/default.rb', line 57

def connection_options
  {
    :headers => {
      :accept => default_media_type,
      :user_agent => user_agent
    }
  }
end

.default_media_typeString

Default media type from ENV or MEDIA_TYPE



68
69
70
# File 'lib/ohanakapa/default.rb', line 68

def default_media_type
  ENV['OHANAKAPA_DEFAULT_MEDIA_TYPE'] || MEDIA_TYPE
end

.middlewareString

Default middleware stack for Faraday::Connection from MIDDLEWARE



75
76
77
# File 'lib/ohanakapa/default.rb', line 75

def middleware
  MIDDLEWARE
end

.optionsHash

Configuration options



31
32
33
# File 'lib/ohanakapa/default.rb', line 31

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

.per_pageFixnum

Default pagination page size from ENV



49
50
51
52
53
# File 'lib/ohanakapa/default.rb', line 49

def per_page
  page_size = ENV['OCTOKIT_PER_PAGE']

  page_size.to_i if page_size
end

.proxyString

Default proxy server URI for Faraday connection from ENV



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

def proxy
  ENV['OHANAKAPA_PROXY']
end

.user_agentString

Default User-Agent header string from ENV or USER_AGENT



93
94
95
# File 'lib/ohanakapa/default.rb', line 93

def user_agent
  ENV['OHANAKAPA_USER_AGENT'] || USER_AGENT
end