Module: SendCloud
- Defined in:
- lib/send-cloud.rb,
lib/send-cloud/mail.rb,
lib/send-cloud/label.rb,
lib/send-cloud/domain.rb,
lib/send-cloud/apiuser.rb,
lib/send-cloud/version.rb,
lib/send-cloud/template.rb,
lib/send-cloud/userinfo.rb,
lib/send-cloud/addresslist.rb,
lib/send-cloud/addressmember.rb
Defined Under Namespace
Modules: AddressList, AddressMember, ApiUser, Domain, Label, Mail, Template, UserInfo
Classes: DeliveryClass, Error
Constant Summary
collapse
- API_BASE =
'http://api.sendcloud.net/apiv2'
- VERSION =
'0.0.1'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.api_key ⇒ Object
Returns the value of attribute api_key.
56
57
58
|
# File 'lib/send-cloud.rb', line 56
def api_key
@api_key
end
|
.api_user ⇒ Object
Returns the value of attribute api_user.
56
57
58
|
# File 'lib/send-cloud.rb', line 56
def api_user
@api_user
end
|
Class Method Details
.get(path, params, necessary = []) ⇒ Object
59
60
61
62
63
|
# File 'lib/send-cloud.rb', line 59
def self.get(path, params, necessary = [])
request(path, params, necessary) do |url, options|
RestClient.get(url, {params: options})
end
end
|
.post(path, params, necessary = []) ⇒ Object
65
66
67
68
69
|
# File 'lib/send-cloud.rb', line 65
def self.post(path, params, necessary = [])
request(path, params, necessary) do |url, options|
RestClient.post(url, options)
end
end
|
.request(path, params, necessary, &block) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/send-cloud.rb', line 71
def self.request(path, params, necessary, &block)
params = { apiUser: SendCloud.api_user, apiKey: SendCloud.api_key }.merge(params)
needed_keys = necessary - params.keys
if needed_keys != []
return {
'result' => false,
'statusCode' => -1,
'message' => "缺少必填参数:#{needed_keys.join(',')}"
}
end
url = "#{API_BASE}/#{path}"
begin
return JSON.parse(yield(url, params))
rescue JSON::ParserError
raise SendCloud::Error.new('send-cloud response invalid')
end
end
|
.setup {|_self| ... } ⇒ Object
51
52
53
|
# File 'lib/send-cloud.rb', line 51
def self.setup
yield self
end
|