Class: CreateSend::Client

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

Overview

Represents a client and associated functionality.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/createsend/client.rb', line 9

def initialize(client_id)
  @client_id = client_id
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



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

def client_id
  @client_id
end

Class Method Details

.create(company, timezone, country) ⇒ Object

Creates a client.



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

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

Instance Method Details

#campaignsObject

Gets the sent campaigns belonging to this client.



29
30
31
32
# File 'lib/createsend/client.rb', line 29

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

#deleteObject

Deletes this client.



154
155
156
# File 'lib/createsend/client.rb', line 154

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

#detailsObject

Gets the details of this client.



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

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

#draftsObject

Gets the draft campaigns belonging to this client.



41
42
43
44
# File 'lib/createsend/client.rb', line 41

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

#get_primary_contactObject



73
74
75
76
# File 'lib/createsend/client.rb', line 73

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

#listsObject

Gets the subscriber lists belonging to this client.



47
48
49
50
# File 'lib/createsend/client.rb', line 47

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



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

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



68
69
70
71
# File 'lib/createsend/client.rb', line 68

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

#scheduledObject

Gets the currently scheduled campaigns belonging to this client.



35
36
37
38
# File 'lib/createsend/client.rb', line 35

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

#segmentsObject

Gets the segments belonging to this client.



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

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.



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

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



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

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.



127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/createsend/client.rb', line 127

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



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

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



97
98
99
100
101
102
# File 'lib/createsend/client.rb', line 97

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

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

Gets this client’s suppression list.



85
86
87
88
89
90
91
92
93
94
# File 'lib/createsend/client.rb', line 85

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

#templatesObject

Gets the templates belonging to this client.



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

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

#unsuppress(email) ⇒ Object

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



106
107
108
109
# File 'lib/createsend/client.rb', line 106

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