Class: XivelyApiClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/xively_api_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
# File 'lib/xively_api_client.rb', line 9

def initialize args = {}
  @instance = args[:instance] || ENV['XIVELY_INSTANCE']
  @domain = args[:domain] || ENV['XIVELY_DOMAIN']
  @user = args[:user] || ENV['XIVELY_USER']
  @pass = args[:pass] || ENV['XIVELY_PASS']
end

Instance Attribute Details

#domainObject

Returns the value of attribute domain.



7
8
9
# File 'lib/xively_api_client.rb', line 7

def domain
  @domain
end

#instanceObject

Returns the value of attribute instance.



7
8
9
# File 'lib/xively_api_client.rb', line 7

def instance
  @instance
end

#passObject

Returns the value of attribute pass.



7
8
9
# File 'lib/xively_api_client.rb', line 7

def pass
  @pass
end

#userObject

Returns the value of attribute user.



7
8
9
# File 'lib/xively_api_client.rb', line 7

def user
  @user
end

Instance Method Details

#create_device(serial_id, options = {}) ⇒ Object



25
26
27
# File 'lib/xively_api_client.rb', line 25

def create_device serial_id, options = {}
  json_parse(post(build_json serial_id, options)).first
end

#destroy_device(serial) ⇒ Object

def put body

HTTParty.put device_url,
              :body => body,
              :basic_auth => credentials,
              :headers => {'Content-Type' => 'application/json'}

end



45
46
47
# File 'lib/xively_api_client.rb', line 45

def destroy_device serial
  delete device_url(serial)
end

#index_devicesObject



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

def index_devices
  json_parse(get device_url)
end

#show_device(serial_id) ⇒ Object



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

def show_device serial_id
  response = get device_url serial_id
  json_parse(response).first
end