Sha256: c73972e5b14f59df4864e5128c8bef9ca4b57effa514bb7cda716e0d49446454

Contents?: true

Size: 1.05 KB

Versions: 4

Compression:

Stored size: 1.05 KB

Contents

module GlobalSMS
  class REPORT
    def initialize(args)
      @api_key = args[:api_key]
      @api_secret = args[:api_secret]
    end

    def message(message_id, limit=250)
      uri = "/sms/report/#{message_id}?key=#{@api_key}&secret=#{@api_secret}&limit=#{limit}"
      get_request(uri)
    end

    def last_n(limit=1)
      uri = "/sms/report/sent?limit=#{limit}&key=#{@api_key}&secret=#{@api_secret}"
      get_request(uri)
    end

    def between(argv)
      argv = {
        start_time: '00:00:00',
        end_time: '23:59:59',
        limit: '200',
        start: '0'
      }.merge(argv)

      uri = "/sms/report/sent?between_start=#{argv[:start_date]} #{argv[:start_time]}&between_end=#{argv[:end_date]} #{argv[:end_time]}&limit=#{argv[:limit]}&start=#{argv[:start]}&key=#{@api_key}&secret=#{@api_secret}"
      safe_uri = URI.parse(URI.encode(uri))
      get_request(safe_uri)
    end

    private

    def get_request(uri)
      client = HTTPClient.new
      response = client.get("#{API_BASE_URL}#{uri}")
      JSON.parse(response.body)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
globalsms-1.0.7 lib/globalsms/report.rb
globalsms-1.0.6 lib/globalsms/report.rb
globalsms-1.0.5 lib/globalsms/report.rb
globalsms-1.0.4 lib/globalsms/report.rb