Class: Beacon

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-beaconpush.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, secret_key, options = {}) ⇒ Beacon

Returns a new instance of Beacon.



9
10
11
12
13
14
15
16
# File 'lib/ruby-beaconpush.rb', line 9

def initialize(api_key, secret_key, options = {})
  @api_key    = api_key
  @secret_key = secret_key
  
  @host    = options[:host]    || 'api.beaconpush.com'
  @headers = options[:headers] || {}
  @version = options[:version] || '1.0.0'
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



6
7
8
# File 'lib/ruby-beaconpush.rb', line 6

def api_key
  @api_key
end

#hostObject

Returns the value of attribute host.



6
7
8
# File 'lib/ruby-beaconpush.rb', line 6

def host
  @host
end

#secret_keyObject

Returns the value of attribute secret_key.



6
7
8
# File 'lib/ruby-beaconpush.rb', line 6

def secret_key
  @secret_key
end

#versionObject

Returns the value of attribute version.



6
7
8
# File 'lib/ruby-beaconpush.rb', line 6

def version
  @version
end

Instance Method Details

#logout(username) ⇒ Object



37
38
39
40
# File 'lib/ruby-beaconpush.rb', line 37

def logout(username)
  RestClient.delete("#{base_url}/users/#{username}", headers)
  username
end

#online?(username) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/ruby-beaconpush.rb', line 31

def online?(username)
  response = RestClient.get("#{base_url}/users/#{username}", headers)
  JSON.load(response)['status'] == 200
end

#publish(channel, data) ⇒ Object



19
20
21
22
# File 'lib/ruby-beaconpush.rb', line 19

def publish(channel, data)
  RestClient.post("#{base_url}/channels/#{channel}", JSON.dump(data), headers)
  data
end

#users(channel) ⇒ Object



43
44
45
46
# File 'lib/ruby-beaconpush.rb', line 43

def users(channel)
  response = RestClient.get("#{base_url}/channels/#{channel}", headers)
  JSON.load(response)['users']
end

#users_countObject



25
26
27
28
# File 'lib/ruby-beaconpush.rb', line 25

def users_count
  response = RestClient.get("#{base_url}/users", headers)
  JSON.load(response)['online']
end

#whisper(username, data) ⇒ Object



49
50
51
52
# File 'lib/ruby-beaconpush.rb', line 49

def whisper(username, data)
  RestClient.post("#{base_url}/users/#{username}", JSON.dump(data), headers)
  data
end