Module: Piped

Defined in:
lib/piped.rb,
lib/piped/version.rb

Constant Summary collapse

REQUEST_TIMEOUT =
60
OPEN_TIMEOUT =
5
VERSION =
"0.1.4"
@@api_key =
"SET_YOUR_API_KEY"
@@piped_host =

Optional

nil

Class Method Summary collapse

Class Method Details

.api_key=(key) ⇒ Object



12
13
14
# File 'lib/piped.rb', line 12

def self.api_key=(key)
  @@api_key = key
end

.pipeman_hostObject



20
21
22
# File 'lib/piped.rb', line 20

def self.pipeman_host
  @@pipeman_host ||= "https://pipeman.edmodo.com"
end

.pipeman_host=(host) ⇒ Object



16
17
18
# File 'lib/piped.rb', line 16

def self.pipeman_host=(host)
  @@pipeman_host = host
end

.push(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/piped.rb', line 25

def self.push(options={})
  api_key = options.delete(:api_key) || @@api_key
  host = options.delete(:pipeman_host) || self.pipeman_host

  response = RestClient::Request.execute(
    method: :post,
    url: "#{host}/events",
    payload: JSON.generate(options),
    headers: {"Authorization" => "Bearer #{api_key}", :content_type => :json, :accept => :json},
    timeout: REQUEST_TIMEOUT,
    open_timeout: OPEN_TIMEOUT
  )

  Hashie::Mash.new(JSON.parse(response))
end