Class: CreateSend::CreateSend
- Inherits:
-
Object
- Object
- CreateSend::CreateSend
- Includes:
- HTTParty
- Defined in:
- lib/createsend.rb
Overview
Provides high level CreateSend functionality/data you’ll probably need.
Constant Summary collapse
- @@base_uri =
"https://api.createsend.com/api/v3"
- @@api_key =
""
Class Method Summary collapse
-
.api_key(api_key = nil) ⇒ Object
Sets the API key which will be used to make calls to the CreateSend API.
- .delete(*args) ⇒ Object
- .get(*args) ⇒ Object
-
.handle_response(response) ⇒ Object
:nodoc:.
- .post(*args) ⇒ Object
- .put(*args) ⇒ Object
Instance Method Summary collapse
-
#administrators ⇒ Object
Gets the administrators.
-
#apikey(site_url, username, password) ⇒ Object
Gets your CreateSend API key, given your site url, username and password.
-
#clients ⇒ Object
Gets your clients.
-
#countries ⇒ Object
Gets valid countries.
- #get_primary_contact ⇒ Object
- #set_primary_contact(email) ⇒ Object
-
#systemdate ⇒ Object
Gets the current date in your account’s timezone.
-
#timezones ⇒ Object
Gets valid timezones.
Class Method Details
.api_key(api_key = nil) ⇒ Object
Sets the API key which will be used to make calls to the CreateSend API.
83 84 85 86 87 |
# File 'lib/createsend.rb', line 83 def self.api_key(api_key=nil) return @@api_key unless api_key @@api_key = api_key basic_auth @@api_key, 'x' end |
.delete(*args) ⇒ Object
143 |
# File 'lib/createsend.rb', line 143 def self.delete(*args); handle_response super end |
.get(*args) ⇒ Object
140 |
# File 'lib/createsend.rb', line 140 def self.get(*args); handle_response super end |
.handle_response(response) ⇒ Object
:nodoc:
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/createsend.rb', line 145 def self.handle_response(response) # :nodoc: case response.code when 400 raise BadRequest.new(Hashie::Mash.new response) when 401 raise Unauthorized.new(Hashie::Mash.new response) when 404 raise NotFound.new when 400...500 raise ClientError.new when 500...600 raise ServerError.new else response end end |
.post(*args) ⇒ Object
141 |
# File 'lib/createsend.rb', line 141 def self.post(*args); handle_response super end |
.put(*args) ⇒ Object
142 |
# File 'lib/createsend.rb', line 142 def self.put(*args); handle_response super end |
Instance Method Details
#administrators ⇒ Object
Gets the administrators
124 125 126 127 |
# File 'lib/createsend.rb', line 124 def administrators response = CreateSend.get('/admins.json') response.map{|item| Hashie::Mash.new(item)} end |
#apikey(site_url, username, password) ⇒ Object
Gets your CreateSend API key, given your site url, username and password.
90 91 92 93 94 95 96 97 |
# File 'lib/createsend.rb', line 90 def apikey(site_url, username, password) site_url = CGI.escape(site_url) self.class.basic_auth username, password response = CreateSend.get("/apikey.json?SiteUrl=#{site_url}") # Revert basic_auth to use @@api_key, 'x' self.class.basic_auth @@api_key, 'x' Hashie::Mash.new(response) end |
#clients ⇒ Object
Gets your clients.
100 101 102 103 |
# File 'lib/createsend.rb', line 100 def clients response = CreateSend.get('/clients.json') response.map{|item| Hashie::Mash.new(item)} end |
#countries ⇒ Object
Gets valid countries.
106 107 108 109 |
# File 'lib/createsend.rb', line 106 def countries response = CreateSend.get('/countries.json') response.parsed_response end |
#get_primary_contact ⇒ Object
129 130 131 132 |
# File 'lib/createsend.rb', line 129 def get_primary_contact response = CreateSend.get('/primarycontact.json') Hashie::Mash.new(response) end |
#set_primary_contact(email) ⇒ Object
134 135 136 137 138 |
# File 'lib/createsend.rb', line 134 def set_primary_contact(email) = { :query => { :email => email } } response = CreateSend.put("/primarycontact.json", ) Hashie::Mash.new(response) end |
#systemdate ⇒ Object
Gets the current date in your account’s timezone.
112 113 114 115 |
# File 'lib/createsend.rb', line 112 def systemdate response = CreateSend.get('/systemdate.json') Hashie::Mash.new(response) end |
#timezones ⇒ Object
Gets valid timezones.
118 119 120 121 |
# File 'lib/createsend.rb', line 118 def timezones response = CreateSend.get('/timezones.json') response.parsed_response end |