Sha256: ef0643e6515cd7ed328598ffe0489401a772a1c078ce5722dd80cbc88cf5ab45

Contents?: true

Size: 788 Bytes

Versions: 1

Compression:

Stored size: 788 Bytes

Contents

require 'active_support'
require 'rest_client'
require 'json'

module Moonshado
  class Keywords
    def self.config
      Moonshado::Sms.config
    end

    def self.url
      @url ||= URI.parse(Moonshado::Sms.config[:sms_api_url])
      "#{@url.scheme}://#{@url.user}:#{@url.password}@#{@url.host}:#{@url.port}/keywords"
    end

    def self.list
      response = RestClient.get(url)

      JSON.parse(response.body)
    end

    def self.register_keywords
      unless Moonshado::Sms.config[:keywords].nil?
        response = RestClient.post(url, {:keywords => Moonshado::Sms.config[:keywords]})
        JSON.parse(response.body)
      end
    end

    def self.destory(keyword)
      response = RestClient.delete("#{url}/#{keyword}")
      JSON.parse(response.body)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
moonshado-sms-0.2.0 lib/moonshado/keywords.rb