Sha256: 7477ac906faf1e40085857a41f5c42e599d460ce3c8d38869bbc89b93ba09e79

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require 'rop/version'
require 'httparty'

# 通道编码: http://open.rongcapital.cn/dashboard/isv/SmsBalanceList
# API调用Doc: http://open.rongcapital.cn/welcome/document/1109a17a-5873-420e-a590-c4ce6c5a2d59

module Rop
  API_BASE = 'https://api.open.ruixuesoft.com:30005/ropapi'

  class Error < StandardError; end

  def self.setup
    yield self
  end

  class << self
    attr_accessor :channel_code, :access_token
  end

  def self.post(method, body = {})
    begin
      body.merge!({
        method: method,
        channel_code: Rop.channel_code,
        access_token: Rop.access_token,
        format: 'json'
      })
      query = URI.encode_www_form(body)
      res = HTTParty.post("#{API_BASE}?#{query}", verify: false, body: body.to_json)
      return JSON.parse(res.body)
    rescue JSON::ParserError
      raise Sendcloud::Error.new('rop response invalid')
    end
  end

  def self.get_balance
    post('ruixue.sms.balance.get', {
      channel_code: Rop.channel_code
    })
  end

  def self.send_sms(mobile, content, append_code)
    post("ruixue.sms.note.send", {
      mobile: mobile,
      content: content,
      append_code: append_code
    })
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rop-0.1.1 lib/rop.rb