Class: ComboClient

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/comboclient.rb

Instance Method Summary collapse

Constructor Details

#initialize(host, topic) ⇒ ComboClient

Returns a new instance of ComboClient.



6
7
8
# File 'lib/comboclient.rb', line 6

def initialize(host, topic)
  self.class.base_uri "#{host}/topics/#{topic}"
end

Instance Method Details

#add(fact) ⇒ Object



14
15
16
# File 'lib/comboclient.rb', line 14

def add(fact)
  self.class.post("/facts", body: fact.to_json, headers: {'Content-Type' => 'application/json'})
end

#factsObject



10
11
12
# File 'lib/comboclient.rb', line 10

def facts
  self.class.get("/facts")
end

#subscribeObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/comboclient.rb', line 18

def subscribe
  response = self.class.post("/subscriptions")
  poll_url = response.parsed_response["retrieval_url"]
  manager = ComboClientSubscriptionManager.new
  while manager.is_active? do
    newdata = self.class.get(poll_url)
    if newdata.code == 200
      yield newdata.parsed_response, manager
    end
  end
end