Sha256: 7de095c0f85293dd235eb5e191d214fa6eee1f7a2f1bc9c0a660b05bdfa41420

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 Bytes

Contents

require 'httparty'
require 'json'
require 'base64'
require 'forwardable'

module Rumour
  class Client
    include HTTParty
    base_uri 'rumour.herokuapp.com/api/v1'

    attr_accessor :access_token

    def initialize(access_token = nil)
      @access_token = access_token || Rumour.configuration.access_token
    end

    def send_text_message(sender, recipient, body)
      post('/text_messages', text_message: { from: sender, recipient: recipient, body: body })
    end

    def deliver_push_notification(platform, recipient, data)
      post('/push_notifications', platform: platform, recipient: recipient, data: data)
    end

    private

    def post(url, params = {}, headers = {})
      response = self.class.post(url, query: params, headers: headers.merge(auth_header))
      JSON.parse(response.body)
    end

    def auth_header
      { 'Authorization' => "Bearer #{credentials}" }
    end

    def credentials
      Base64.urlsafe_encode64(@access_token)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rumour-ruby-0.0.1 lib/rumour-ruby/client.rb