Class: Plotlyrb::ApiV2

Inherits:
Object
  • Object
show all
Defined in:
lib/plotlyrb/api_v2.rb

Constant Summary collapse

PROTOCOL =
'https'
HOSTNAME =
'api.plot.ly'
BASE_PATH =
'v2'
BASE_URI =
"#{PROTOCOL}://#{HOSTNAME}/#{BASE_PATH}"
IMAGES =
mk_endpoint('images')
GRIDS =
mk_endpoint('grids')
PLOTS =
mk_endpoint('plots')
COMMON_HEADERS =
{
  'plotly-client-platform' => "Ruby #{Plotlyrb::VERSION}",
  'content-type' => 'application/json'
}

Class Method Summary collapse

Class Method Details

.auth_plotly(username, api_key) ⇒ Object



28
29
30
31
32
# File 'lib/plotlyrb/api_v2.rb', line 28

def self.auth_plotly(username, api_key)
  encoded_auth = Base64.encode64("#{username}:#{api_key}")
  headers_hash = COMMON_HEADERS.merge({ 'authorization' => "Basic #{encoded_auth}" })
  Plotly.new(headers_hash)
end

.mk_endpoint(path) ⇒ Object



12
13
14
# File 'lib/plotlyrb/api_v2.rb', line 12

def self.mk_endpoint(path)
  URI.parse("#{BASE_URI}/#{path}")
end

.plotlyObject



24
25
26
# File 'lib/plotlyrb/api_v2.rb', line 24

def self.plotly
  Plotly.new(COMMON_HEADERS)
end