lib/createsend.rb in createsend-1.0.0 vs lib/createsend.rb in createsend-1.0.1
- old
+ new
@@ -2,17 +2,10 @@
require 'uri'
require 'httparty'
require 'hashie'
Hash.send :include, Hashie::HashExtensions
-CreateSendOptions = { 'api_key' => nil, 'base_uri' => "http://api.createsend.com/api/v3" } if not Object.const_defined? :CreateSendOptions # :nodoc:
-if File.exists?('config.yaml')
- config = YAML.load_file('config.yaml')
- CreateSendOptions['base_uri'] = config['base_uri']
- CreateSendOptions['api_key'] = config['api_key']
-end
-
libdir = File.dirname(__FILE__)
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
require 'createsend/version'
require 'createsend/client'
@@ -54,11 +47,11 @@
class Unavailable < StandardError; end
# Provides high level CreateSend functionality/data you'll probably need.
class CreateSend
include HTTParty
-
+
class Parser::DealWithCreateSendInvalidJson < HTTParty::Parser
# The createsend API returns an ID as a string when a 201 Created
# response is returned. Unfortunately this is invalid json.
def parse
begin
@@ -67,21 +60,21 @@
body[1..-2] # Strip surrounding quotes and return as is.
end
end
end
parser Parser::DealWithCreateSendInvalidJson
-
+ @@base_uri = "https://api.createsend.com/api/v3"
+ @@api_key = ""
headers({
'User-Agent' => "createsend-ruby-#{CreateSend::VERSION}",
'Content-Type' => 'application/json; charset=utf-8',
'Accept-Encoding' => 'gzip, deflate' })
- base_uri CreateSendOptions['base_uri']
- basic_auth CreateSendOptions['api_key'], 'x'
+ base_uri @@base_uri
+ basic_auth @@api_key, 'x'
# Sets the API key which will be used to make calls to the CreateSend API.
def self.api_key(api_key=nil)
return @@api_key unless api_key
- CreateSendOptions['api_key'] = api_key
@@api_key = api_key
basic_auth @@api_key, 'x'
end
# Gets your CreateSend API key, given your site url, username and password.
\ No newline at end of file