lib/createsend/createsend.rb in createsend-3.2.0 vs lib/createsend/createsend.rb in createsend-3.3.0

- old
+ new

@@ -4,10 +4,12 @@ require 'hashie' require 'json' module CreateSend + USER_AGENT_STRING = "createsend-ruby-#{VERSION}-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}-#{RUBY_PLATFORM}" + # Represents a CreateSend API error. Contains specific data about the error. class CreateSendError < StandardError attr_reader :data def initialize(data) @data = data @@ -42,10 +44,20 @@ # Provides high level CreateSend functionality/data you'll probably need. class CreateSend include HTTParty attr_reader :auth_details + # Set a custom user agent string to be used when instances of + # CreateSend::CreateSend make API calls. + # + # user_agent - The user agent string to use in the User-Agent header when + # instances of this class make API calls. If set to nil, the + # default value of CreateSend::USER_AGENT_STRING will be used. + def self.user_agent(user_agent) + headers({'User-Agent' => user_agent || USER_AGENT_STRING}) + end + # Get the authorization URL for your application, given the application's # client_id, redirect_uri, scope, and optional state data. def self.authorize_url(client_id, redirect_uri, scope, state=nil) qs = "client_id=#{CGI.escape(client_id.to_s)}" qs << "&redirect_uri=#{CGI.escape(redirect_uri.to_s)}" @@ -96,10 +108,10 @@ @@base_uri = "https://api.createsend.com/api/v3" @@oauth_base_uri = "https://api.createsend.com/oauth" @@oauth_token_uri = "#{@@oauth_base_uri}/token" headers({ - 'User-Agent' => "createsend-ruby-#{VERSION}", + 'User-Agent' => USER_AGENT_STRING, 'Content-Type' => 'application/json; charset=utf-8', 'Accept-Encoding' => 'gzip, deflate' }) base_uri @@base_uri # Authenticate using either OAuth or an API key. \ No newline at end of file