Sha256: ffcf5da9b72a9d70eafaf37b7c038b38637f7b0b0f7704955a59557963b5978f

Contents?: true

Size: 818 Bytes

Versions: 1

Compression:

Stored size: 818 Bytes

Contents

require "rest-segment/version"
require "httparty"
require "active_support/core_ext"

module Segment
  class API
    include HTTParty
    
    @@api_endpoint = "https://api.segment.io/v2/"
    attr_accessor :api_key
    

    def initialize(api_key)
      @api_key = api_key
    end

    def post_with_api_key(method, params = {})
      post api_endpoint(method), params.merge({
        apiKey: self.api_key
      })
    end
        
  private
    def method_missing(m, *args, &block)
      args = args.unshift(m)
      send :post_with_api_key, *args
    end
    
    def api_endpoint(method)
      # add version if needed
      [@@api_endpoint, method.to_s].join
    end
    
    def post(url, params)
      self.class.post url, body: params.to_json, headers: {'Content-Type' => 'application/json'}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rest-segment-0.0.1 lib/rest-segment.rb