Class: Segment::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rest-segment.rb

Constant Summary collapse

@@api_endpoint =
"https://api.segment.io/v2/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ API

Returns a new instance of API.



13
14
15
# File 'lib/rest-segment.rb', line 13

def initialize(api_key)
  @api_key = api_key
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object (private)



24
25
26
27
# File 'lib/rest-segment.rb', line 24

def method_missing(m, *args, &block)
  args = args.unshift(m)
  send :post_with_api_key, *args
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



10
11
12
# File 'lib/rest-segment.rb', line 10

def api_key
  @api_key
end

Instance Method Details

#post_with_api_key(method, params = {}) ⇒ Object



17
18
19
20
21
# File 'lib/rest-segment.rb', line 17

def post_with_api_key(method, params = {})
  post api_endpoint(method), params.merge({
    apiKey: self.api_key
  })
end