Module: Sendcloud

Defined in:
lib/sendcloud.rb,
lib/sendcloud/mail.rb,
lib/sendcloud/stats.rb,
lib/sendcloud/bounces.rb,
lib/sendcloud/version.rb,
lib/sendcloud/template.rb,
lib/sendcloud/mail_list.rb,
lib/sendcloud/unsubscribes.rb

Defined Under Namespace

Modules: Bounces, Mail, MailList, Stats, Template, Unsubscribes Classes: Error

Constant Summary collapse

API_BASE =
'https://sendcloud.sohu.com/webapi'
VERSION =
'0.2.1'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_keyObject

Returns the value of attribute api_key.



21
22
23
# File 'lib/sendcloud.rb', line 21

def api_key
  @api_key
end

.api_userObject

Returns the value of attribute api_user.



21
22
23
# File 'lib/sendcloud.rb', line 21

def api_user
  @api_user
end

.formatObject

Returns the value of attribute format.



21
22
23
# File 'lib/sendcloud.rb', line 21

def format
  @format
end

Class Method Details

.get(path, params) ⇒ Object



24
25
26
27
28
29
# File 'lib/sendcloud.rb', line 24

def self.get(path, params)

  request(path, params) do |url, options|
    RestClient.get(url, {:params => options})
  end
end

.post(path, params) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/sendcloud.rb', line 31

def self.post(path, params)

  request(path, params) do |url, options|
    RestClient.post(url, options)
  end

end

.request(path, params, &block) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sendcloud.rb', line 39

def self.request(path, params, &block)
  params = {
      :api_user => Sendcloud.api_user,
      :api_key => Sendcloud.api_key,
  }.merge(params)

  format = params.delete(:format) || 'json'
  url = "#{API_BASE}/#{path}.#{format}"
  begin
    return JSON.parse(yield(url, params))
  rescue JSON::ParserError
    raise Sendcloud::Error.new('sendcloud response invalid')
  end

end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Sendcloud)

    the object that the method was called on



16
17
18
# File 'lib/sendcloud.rb', line 16

def self.setup
  yield self
end