Sha256: ba1aca7563e77559b25cb7897a9004176eb7a2e2d64dfbbb61b89df7ace30dfc

Contents?: true

Size: 918 Bytes

Versions: 2

Compression:

Stored size: 918 Bytes

Contents

require 'rest_client'

module RestPack::Activity::Proxies
  class Api < RestPack::BaseProxy
    def self.get(id)
      http(:get, "/api/v1/activities/#{id}.json")
    end

    def self.list(params = {})
      http(:get, "/api/v1/activities.json", params)
    end

    def self.create(params)
      http(:post, "/api/v1/activities.json", params)
    end

    def self.update(params)
      http(:put, "/api/v1/activities/#{params[:id]}.json", params)
    end

    def self.destroy(id)
      http(:delete, "/api/v1/activities/#{id}.json")
    end

    private

    def self.http(method, path, params = {})
      params = { params: params } if method == :get

      RestClient.send(method, "#{RestPack::Activity.config.api_domain}#{path}", params) do |rest_response|
        response = RestPack::Response.from_rest(rest_response)
        raise_exceptions_if_required(response)
        response
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
restpack_activity-0.0.3 lib/restpack_activity/proxies/activity/api.rb
restpack_activity-0.0.2 lib/restpack_activity/proxies/activity/api.rb