Module: Aliyun::Dysms

Defined in:
lib/aliyun/dysms.rb,
lib/aliyun/dysms/version.rb

Defined Under Namespace

Classes: Configuration

Constant Summary collapse

VERSION =
"0.0.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject


25
26
27
# File 'lib/aliyun/dysms.rb', line 25

def configuration
  @configuration ||= Configuration.new
end

.responseObject (readonly)

Returns the value of attribute response


61
62
63
# File 'lib/aliyun/dysms.rb', line 61

def response
  @response
end

Class Method Details

.clientObject


52
53
54
55
56
57
58
59
# File 'lib/aliyun/dysms.rb', line 52

def client
  @client ||= RPCClient.new(
    access_key_id:     configuration.access_key_id,
    access_key_secret: configuration.access_key_secret,
    api_version:       configuration.api_version,
    endpoint:          "https://dysmsapi.aliyuncs.com"
  )
end

.configure {|configuration| ... } ⇒ Object

Yields:


29
30
31
# File 'lib/aliyun/dysms.rb', line 29

def configure
  yield(configuration)
end

.send(phone_numbers, template_code, template_param, out_id = "") ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/aliyun/dysms.rb', line 33

def send(phone_numbers, template_code, template_param, out_id = "")
  @response = client.request(
    action: configuration.action,
    params: {
      "RegionId": configuration.region_id,
      "SignName": configuration.sign_name,
      "PhoneNumbers": phone_numbers,
      "TemplateCode": template_code,
      "TemplateParam": template_param,
      "OutId": out_id
  },
    opts: {
      method: "POST"
    }
  )
rescue StandardError => e
  { Code: "BadRequest", Message: "Request failed: #<#{e.class}: #{e.message}>" }
end