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.
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
-
#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.
-
#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.
65 66 67 68 69 70 |
# File 'lib/createsend.rb', line 65 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 |
.delete(*args) ⇒ Object
109 |
# File 'lib/createsend.rb', line 109 def self.delete(*args); handle_response super end |
.get(*args) ⇒ Object
106 |
# File 'lib/createsend.rb', line 106 def self.get(*args); handle_response super end |
.handle_response(response) ⇒ Object
:nodoc:
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/createsend.rb', line 111 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
107 |
# File 'lib/createsend.rb', line 107 def self.post(*args); handle_response super end |
.put(*args) ⇒ Object
108 |
# File 'lib/createsend.rb', line 108 def self.put(*args); handle_response super end |
Instance Method Details
#apikey(site_url, username, password) ⇒ Object
Gets your CreateSend API key, given your site url, username and password.
73 74 75 76 77 78 79 80 |
# File 'lib/createsend.rb', line 73 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.
83 84 85 86 |
# File 'lib/createsend.rb', line 83 def clients response = CreateSend.get('/clients.json') response.map{|item| Hashie::Mash.new(item)} end |
#countries ⇒ Object
Gets valid countries.
89 90 91 92 |
# File 'lib/createsend.rb', line 89 def countries response = CreateSend.get('/countries.json') response.parsed_response end |
#systemdate ⇒ Object
Gets the current date in your account’s timezone.
95 96 97 98 |
# File 'lib/createsend.rb', line 95 def systemdate response = CreateSend.get('/systemdate.json') Hashie::Mash.new(response) end |
#timezones ⇒ Object
Gets valid timezones.
101 102 103 104 |
# File 'lib/createsend.rb', line 101 def timezones response = CreateSend.get('/timezones.json') response.parsed_response end |