zaeznet/realpush-ruby

View on GitHub
lib/realpush/resource.rb

Summary

Maintainability
A
0 mins
Test Coverage
module RealPush
  class Resource
    def initialize(client, path)
      @client = client
      @path = path
    end

    def get(params)
      create_request(:get, params).send_sync
    end

    def get_async(params)
      create_request(:get, params).send_async
    end

    def post(body)
      body = MultiJson.encode(body) unless body.is_a? String
      create_request(:post, {}, body).send_sync
    end

    def post_async(body)
      body = MultiJson.encode(body) unless body.is_a? String
      create_request(:post, {}, body).send_async
    end

    private

    def create_request(verb, params, body = nil)
      Request.new(@client, verb, url, params, body)
    end

    def url
      @_url ||= @client.url(@path)
    end
  end
end