Class: CG::API

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

Constant Summary collapse

ROOT_URL =
"http://api.codegears.co"
PUSHER_URL =
"#{ROOT_URL}:9292/stream"

Class Method Summary collapse

Class Method Details

.attach_auth(secret_id, secret_token) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/cg/api.rb', line 24

def self.attach_auth(secret_id, secret_token)
  if secret_id && secret_token
    "secret_id=#{secret_id}&secret_token=#{secret_token}"
  else
    ""
  end
end

.create_app_request(email) ⇒ Object



9
10
11
# File 'lib/cg/api.rb', line 9

def self.create_app_request(email)
  JSON.parse(self.post("#{ROOT_URL}/apps", :body => { :application => { :email => email } }).body)
end

.push_message_request(channel, message) ⇒ Object



17
18
19
20
21
22
# File 'lib/cg/api.rb', line 17

def self.push_message_request(channel, message)
  message = { :channel => channel,
              :message => message,
              :ext => { :secret_id => CG::APP.secret_id, :secret_token => CG::APP.secret_token } }.to_json
  JSON.parse(Net::HTTP.post_form(URI.parse(PUSHER_URL), :message => message).body)
end

.show_app_request(id, secret_id = nil, secret_token = nil) ⇒ Object



13
14
15
# File 'lib/cg/api.rb', line 13

def self.show_app_request(id, secret_id = nil, secret_token = nil)
  JSON.parse(self.get("#{ROOT_URL}/apps/#{id}?#{self.attach_auth(secret_id, secret_token)}").body)
end