Class: Picsou::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/picsou.rb

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, api_key) ⇒ Client

param [String] endpoint host to query, ie picsou.powerpanne.com param [String] api_key API key to log in



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

def initialize(endpoint, api_key)
  @endpoint = "http://#{endpoint}/api/notify/"
  @api_key = api_key
end

Instance Method Details

#query(feature_id, company_name) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/picsou.rb', line 14

def query(feature_id, company_name)
  url = URI.parse(@endpoint)
  url.query = URI.encode_www_form({token: @api_key, feature_id: feature_id, company_name: company_name})
  req = Net::HTTP::Get.new(url.to_s)
  res = Net::HTTP.start(url.host, url.port) do |http|
    http.request(req)
  end
end