valikos / beeswaxapi

Ruby client for beeswax buzz api
MIT License
1 stars 2 forks source link

Cookie Auth Broken #17

Open jNicker opened 6 years ago

jNicker commented 6 years ago

Pardon my horrible markdown skills.

Couple of things shen using cookie auth:

  1. If the file referenced does not exist it should be created. I have been able to get around this with:

    BeeswaxAPI::App.configure do |config|
    ...
    require 'pathname'
    require 'fileutils'
    path = Pathname.new(File.join('tmp', 'beeswaxapi', 'cookie_file'))
    path.dirname.mkpath
    FileUtils::touch(path)
    config.cookie_file = path.to_s
    ...

    but it would be nice if this was automatic

  2. cookie_file is not flushed to disk since there is no wrapping around calling an api endpoint, it seems that a user first needs to call the authenticate endpoint first. BeeswaxAPI::Authenticate.create(body_params: {email: 'foo@bar.com', password: 'XXXX' }) You would think that on success, that the request would then write the correct cookies into the cookies file, but this is not the case. Typhoeus does not flush them to disk, and does not use them on the subsequent calls. Maybe a change is needed to BeeswaxAPI::Request

If I am incorrect in any of my assumptions above or am not using the gem as designed, then I would love some direction about where Im going wrong.

kunashir commented 2 years ago

Too much time has gone from this question but maybe my answer will be useful in the future. How I use the gem:

require "beeswaxapi"

BeeswaxAPI::App.configure do |config|
  config.auth_strategy = 'cookies'
  config.cookie_file   = './beeswax-cookie'
  config.base_uri      = 'https://demosbx.api.beeswax.com/rest'
  config.user_name     = 'email@address.com'
  config.password      = 'the_pass_to_beeswax_account'
end

credential = {
  email: 'email@address.com',
  password: "the_pass_to_beeswax_account",
  keep_logged_in: true
}
puts BeeswaxAPI::Authenticate.create(body_params: credential)
puts BeeswaxAPI::Campaign.retrieve(params:{ campaign_id: 204})