class Benchwarmer::API
Constants
- BENCHMARK_API_VERSION
Benchmark Email
API
Documentation: www.benchmarkemail.com/API/Library- DEFAULTS
Public Class Methods
Token management methods
Each time you “login”, a new token is generated with access to the B.E. API
. This means that you should store a single token and use it over and over, preventing a build-up of tokens.
Our hope is that in the future B.E. will make the following changes with regard to API
access tokens:
-
Provide an interface for account holders to manage their
API
tokens. -
Remove the ability to login with username, password.
-
Add OAuth2 so that the “access_token” can be used in the same way that “API tokens” are currently used.
In other words, make it more like Mailchimp.
# File lib/benchwarmer/api.rb, line 52 def self.login(username, password, config = {}) api_client(config) @api_client.call('login', username, password) end
Initialize with an API
token and config options
# File lib/benchwarmer/api.rb, line 17 def initialize(api_token, config = {}) opts = DEFAULTS.merge(config).freeze @api_client = XMLRPC::Client.new2("#{opts[:secure] ? 'https' : 'http'}://api.benchmarkemail.com/#{opts[:api_version]}/", nil, opts[:timeout]) @api_token = api_token end
Add a new token (generated randomly)
# File lib/benchwarmer/api.rb, line 64 def self.token_add(username, password, config = {}) api_client(config) @api_client.call("tokenAdd", username, password, SecureRandom.urlsafe_base64(20)) end
Delete an existing token
# File lib/benchwarmer/api.rb, line 70 def self.token_delete(username, password, token, config = {}) api_client(config) @api_client.call("tokenDelete", username, password, token) end
Get a list of the tokens
# File lib/benchwarmer/api.rb, line 58 def self.token_get(username, password, config = {}) api_client(config) @api_client.call("tokenGet", username, password) end
Private Class Methods
# File lib/benchwarmer/api.rb, line 77 def self.api_client(options) opts = DEFAULTS.merge(options).freeze @api_client = XMLRPC::Client.new2("#{opts[:secure] ? 'https' : 'http'}://api.benchmarkemail.com/#{opts[:api_version]}/", nil, opts[:timeout]) end
Private Instance Methods
# File lib/benchwarmer/api.rb, line 82 def camelize_api_method_name(str) str.to_s[0].chr.downcase + str.gsub(/(?:^|_)(.)/) { $1.upcase }[1..str.size] end