Class: ProximityBeacon::Client::Attachments

Inherits:
Object
  • Object
show all
Defined in:
lib/proximity_beacon/client/attachments.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials) ⇒ Attachments

Returns a new instance of Attachments.



7
8
9
# File 'lib/proximity_beacon/client/attachments.rb', line 7

def initialize(credentials)
  self.credentials = credentials
end

Instance Attribute Details

#credentialsObject

Returns the value of attribute credentials.



5
6
7
# File 'lib/proximity_beacon/client/attachments.rb', line 5

def credentials
  @credentials
end

Instance Method Details

#batch_delete(beacon_name, params = nil) ⇒ Object



34
35
36
37
38
# File 'lib/proximity_beacon/client/attachments.rb', line 34

def batch_delete(beacon_name, params = nil)
  uri = URI(PROXIMITY_BEACON_ROOT + beacon_name + "/attachments:batchDelete")
  response = Request.post(uri, credentials, params)
  JSON.parse(response.body)
end

#create(attachment, beacon_name, params = nil) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/proximity_beacon/client/attachments.rb', line 19

def create(attachment, beacon_name, params = nil)
  uri = URI(PROXIMITY_BEACON_ROOT + beacon_name + "/attachments")
  response = Request.post(uri, credentials, params) { |request|
    request.body = attachment.to_json
    request.add_field "Content-Type", "application/json"
  }
  Attachment.new(JSON.parse(response.body))
end

#delete(attachment_name, params = nil) ⇒ Object



28
29
30
31
32
# File 'lib/proximity_beacon/client/attachments.rb', line 28

def delete(attachment_name, params = nil)
  uri = URI(PROXIMITY_BEACON_ROOT + attachment_name)
  response = Request.delete(uri, credentials, params)
  JSON.parse(response.body)
end

#list(beacon_name, params = nil) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/proximity_beacon/client/attachments.rb', line 11

def list(beacon_name, params = nil)
  uri = URI(PROXIMITY_BEACON_ROOT + beacon_name + "/attachments")
  response = Request.get(uri, credentials, params)
  json = JSON.parse(response.body)
  attachments_json = json["attachments"] || []
  attachments_json.map {|attachment_json| Attachment.new(attachment_json) }
end