Skip to content

Instantly share code, notes, and snippets.

@olvap
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save olvap/755a6a3a18c86fda867a to your computer and use it in GitHub Desktop.

Select an option

Save olvap/755a6a3a18c86fda867a to your computer and use it in GitHub Desktop.
Cliente para Xively
def create_on_xively
client = XivelyClient.new({ service: params[:service],
domain: params[:domain] })
response = client.post devise.json_for_xively
response["devices"].first
end
class XivelyClient
attr_accessor :serial, :domain, :service
def initialize args = nil
self.service = args[:service] || ENV['TI_MQTT_INSTANCE']
self.domain = args[:domain] || ENV['TI_MQTT_DOMAIN']
self.serial = args[:serial]
end
def post body
HTTParty.post(url_to_post,
:body => body,
:headers => header)
end
def delete
HTTParty.delete(url_to_delete,
:headers => header )
end
private
def url_to_post
"https://v3api.xively.com/v3/service_instances/#{ service }/domains/#{ domain }/devices"
end
def url_to_delete
"https://v3api.xively.com/v3/service_instances/#{ service }/domains/#{ domain }/devices/#{ serial }"
end
def header
{ 'Content-Type' => 'application/json',
'Authorization' => ENV['XIVELY_AUTHORIZATION']
}
# ENV['XIVELY_AUTHORIZATION'] = BASIC YV8xemczZDczdXc3Y2R4X2R1Nmh4MzkycnhranVyODNzZjN5dnRvNDoyaHNkbWJ1M21icHZo
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment