Class: ProximityBeacon::Client::Beacons
- Inherits:
-
Object
- Object
- ProximityBeacon::Client::Beacons
- Defined in:
- lib/proximity_beacon/client/beacons.rb
Constant Summary collapse
- BEACONS_URI =
URI(PROXIMITY_BEACON_ROOT + "beacons")
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
Instance Method Summary collapse
- #get(beacon_name, params = nil) ⇒ Object
-
#initialize(credentials) ⇒ Beacons
constructor
A new instance of Beacons.
- #list(params = {pageSize: 1000}) ⇒ Object
- #register(beacon, params = nil) ⇒ Object
- #update(beacon, params = nil) ⇒ Object
Constructor Details
#initialize(credentials) ⇒ Beacons
Returns a new instance of Beacons.
9 10 11 |
# File 'lib/proximity_beacon/client/beacons.rb', line 9 def initialize(credentials) self.credentials = credentials end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
7 8 9 |
# File 'lib/proximity_beacon/client/beacons.rb', line 7 def credentials @credentials end |
Instance Method Details
#get(beacon_name, params = nil) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/proximity_beacon/client/beacons.rb', line 20 def get(beacon_name, params = nil) uri = URI(Client::PROXIMITY_BEACON_ROOT + beacon_name) response = Request.get(uri, credentials, params) json = JSON.parse(response.body) Beacon.new(json) end |
#list(params = {pageSize: 1000}) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/proximity_beacon/client/beacons.rb', line 13 def list(params = {pageSize: 1000}) response = Request.get(BEACONS_URI, credentials, params) json = JSON.parse(response.body) beacons_json = json["beacons"] || [] beacons_json.map {|beacon_json| Beacon.new(beacon_json) } end |
#register(beacon, params = nil) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/proximity_beacon/client/beacons.rb', line 27 def register(beacon, params = nil) uri = URI(Client::PROXIMITY_BEACON_ROOT + "beacons:register") response = Request.post(uri, credentials, params) { |request| request.body = beacon.to_json request.add_field "Content-Type", "application/json" } Beacon.new(JSON.parse(response.body)) end |
#update(beacon, params = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/proximity_beacon/client/beacons.rb', line 36 def update(beacon, params = nil) uri = URI(Client::PROXIMITY_BEACON_ROOT + beacon.name) response = Request.put(uri, credentials, params) { |request| request.body = beacon.to_json request.add_field "Content-Type", "application/json" } json = JSON.parse(response.body) Beacon.new(json) end |