Class: CreateSend::Client

Inherits:
CreateSend show all
Defined in:
lib/createsend/client.rb

Overview

Represents a client and associated functionality.

Constant Summary

Constants included from CreateSend

USER_AGENT_STRING, VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(auth, client_id) ⇒ Client

Returns a new instance of Client.



6
7
8
9
# File 'lib/createsend/client.rb', line 6

def initialize(auth, client_id)
  @client_id = client_id
  super
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



4
5
6
# File 'lib/createsend/client.rb', line 4

def client_id
  @client_id
end

Class Method Details

.create(auth, company, timezone, country) ⇒ Object

Creates a client.



12
13
14
15
16
17
18
19
# File 'lib/createsend/client.rb', line 12

def self.create(auth, company, timezone, country)
  options = { :body => {
    :CompanyName => company,
    :TimeZone => timezone,
    :Country => country }.to_json }
  cs = CreateSend.new auth
  cs.post "/clients.json", options
end

Instance Method Details

#campaigns(page = 1, page_size = 1000, order_direction = "desc", sent_from_date = '', sent_to_date = '', tags = '') ⇒ Object

Gets the sent campaigns belonging to this client.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/createsend/client.rb', line 28

def campaigns(page=1, page_size=1000, order_direction="desc",
  sent_from_date='', sent_to_date='', tags='')
  options = { :query => {
    :page => page,
    :pagesize => page_size,
    :orderdirection => order_direction,
    :sentfromdate => sent_from_date,
    :senttodate => sent_to_date,
    :tags => tags
  }}

  response = get 'campaigns', options
  Hashie::Mash.new(response)
end

#deleteObject

Deletes this client.



196
197
198
# File 'lib/createsend/client.rb', line 196

def delete
  super "/clients/#{client_id}.json", {}
end

#detailsObject

Gets the details of this client.



22
23
24
25
# File 'lib/createsend/client.rb', line 22

def details
  response = cs_get "/clients/#{client_id}.json", {}
  Hashie::Mash.new(response)
end

#draftsObject

Gets the draft campaigns belonging to this client.



50
51
52
53
# File 'lib/createsend/client.rb', line 50

def drafts
  response = get 'drafts'
  response.map{|item| Hashie::Mash.new(item)}
end

#get_primary_contactObject



88
89
90
91
# File 'lib/createsend/client.rb', line 88

def get_primary_contact
  response = get "primarycontact"
  Hashie::Mash.new(response)
end

#journeysObject

Gets the journeys belonging to this client.



201
202
203
204
# File 'lib/createsend/client.rb', line 201

def journeys
  response = get 'journeys'
  response.map{|item| Hashie::Mash.new(item)}
end

#listsObject

Gets the subscriber lists belonging to this client.



62
63
64
65
# File 'lib/createsend/client.rb', line 62

def lists
  response = get 'lists'
  response.map{|item| Hashie::Mash.new(item)}
end

#lists_for_email(email_address) ⇒ Object

Gets the lists across a client, to which a subscriber with a particular email address belongs. email_address - A String representing the subcriber’s email address



70
71
72
73
74
# File 'lib/createsend/client.rb', line 70

def lists_for_email(email_address)
  options = { :query => { :email => email_address } }
  response = get 'listsforemail', options
  response.map{|item| Hashie::Mash.new(item)}
end

#peopleObject

Gets the people associated with this client



83
84
85
86
# File 'lib/createsend/client.rb', line 83

def people
  response = get "people"
  response.map{|item| Hashie::Mash.new(item)}
end

#scheduledObject

Gets the currently scheduled campaigns belonging to this client.



44
45
46
47
# File 'lib/createsend/client.rb', line 44

def scheduled
  response = get 'scheduled'
  response.map{|item| Hashie::Mash.new(item)}
end

#segmentsObject

Gets the segments belonging to this client.



77
78
79
80
# File 'lib/createsend/client.rb', line 77

def segments
  response = get 'segments'
  response.map{|item| Hashie::Mash.new(item)}
end

#set_basics(company, timezone, country) ⇒ Object

Sets the basic details for this client.



133
134
135
136
137
138
139
# File 'lib/createsend/client.rb', line 133

def set_basics(company, timezone, country)
  options = { :body => {
    :CompanyName => company,
    :TimeZone => timezone,
    :Country => country }.to_json }
  put 'setbasics', options
end

#set_monthly_billing(currency, client_pays, markup_percentage, monthly_scheme = nil) ⇒ Object

Sets the monthly billing settings for this client. monthly_scheme must be nil, Basic or Unlimited



158
159
160
161
162
163
164
165
166
# File 'lib/createsend/client.rb', line 158

def set_monthly_billing(currency, client_pays, markup_percentage,
  monthly_scheme = nil)
  options = { :body => {
    :Currency => currency,
    :ClientPays => client_pays,
    :MarkupPercentage => markup_percentage,
    :MonthlyScheme => monthly_scheme }.to_json }
  put 'setmonthlybilling', options
end

#set_payg_billing(currency, can_purchase_credits, client_pays, markup_percentage, markup_on_delivery = 0, markup_per_recipient = 0, markup_on_design_spam_test = 0) ⇒ Object

Sets the PAYG billing settings for this client.



142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/createsend/client.rb', line 142

def set_payg_billing(currency, can_purchase_credits, client_pays,
  markup_percentage, markup_on_delivery=0, markup_per_recipient=0,
  markup_on_design_spam_test=0)
  options = { :body => {
    :Currency => currency,
    :CanPurchaseCredits => can_purchase_credits,
    :ClientPays => client_pays,
    :MarkupPercentage => markup_percentage,
    :MarkupOnDelivery => markup_on_delivery,
    :MarkupPerRecipient => markup_per_recipient,
    :MarkupOnDesignSpamTest => markup_on_design_spam_test }.to_json }
  put 'setpaygbilling', options
end

#set_primary_contact(email) ⇒ Object



93
94
95
96
97
# File 'lib/createsend/client.rb', line 93

def set_primary_contact(email)
  options = { :query => { :email => email } }
  response = put "primarycontact", options
  Hashie::Mash.new(response)
end

#suppress(emails) ⇒ Object

Adds email addresses to a client’s suppression list



112
113
114
115
116
117
# File 'lib/createsend/client.rb', line 112

def suppress(emails)
  options = { :body => {
    :EmailAddresses => emails.kind_of?(String) ?
      [ emails ] : emails }.to_json }
  post "suppress", options
end

#suppressionlist(page = 1, page_size = 1000, order_field = "email", order_direction = "asc") ⇒ Object

Gets this client’s suppression list.



100
101
102
103
104
105
106
107
108
109
# File 'lib/createsend/client.rb', line 100

def suppressionlist(page=1, page_size=1000, order_field="email",
  order_direction="asc")
  options = { :query => {
    :page => page,
    :pagesize => page_size,
    :orderfield => order_field,
    :orderdirection => order_direction } }
  response = get 'suppressionlist', options
  Hashie::Mash.new(response)
end

#tagsObject

Gets all the tags belonging to this client.



56
57
58
59
# File 'lib/createsend/client.rb', line 56

def tags
  response = get 'tags'
  response.map{|item| Hashie::Mash.new(item)}
end

#templatesObject

Gets the templates belonging to this client.



127
128
129
130
# File 'lib/createsend/client.rb', line 127

def templates
  response = get 'templates'
  response.map{|item| Hashie::Mash.new(item)}
end

#transfer_credits(credits, can_use_my_credits_when_they_run_out) ⇒ Object

Transfer credits to or from this client.

credits - An Integer representing the number of credits to transfer.

This value may be either positive if you want to allocate credits from
your account to the client, or negative if you want to deduct credits
from the client back into your account.

can_use_my_credits_when_they_run_out - A Boolean value representing

which, if set to true, will allow the client to continue sending using
your credits or payment details once they run out of credits, and if
set to false, will prevent the client from using your credits to
continue sending until you allocate more credits to them.

Returns an object of the following form representing the result:

AccountCredits # Integer representing credits in your account now
ClientCredits # Integer representing credits in this client's
   now



186
187
188
189
190
191
192
193
# File 'lib/createsend/client.rb', line 186

def transfer_credits(credits, can_use_my_credits_when_they_run_out)
  options = { :body => {
    :Credits => credits,
    :CanUseMyCreditsWhenTheyRunOut => can_use_my_credits_when_they_run_out
  }.to_json }
  response = post 'credits', options
  Hashie::Mash.new(response)
end

#unsuppress(email) ⇒ Object

Unsuppresses an email address by removing it from the the client’s suppression list



121
122
123
124
# File 'lib/createsend/client.rb', line 121

def unsuppress(email)
  options = { :query => { :email => email }, :body => '' }
  put "unsuppress", options
end