euclid 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.DS_Store +0 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.html +21 -0
- data/README.md +114 -0
- data/Rakefile +2 -0
- data/euclid.gemspec +20 -0
- data/lib/euclid.rb +11 -0
- data/lib/euclid/alert.rb +15 -0
- data/lib/euclid/client.rb +33 -0
- data/lib/euclid/shopper.rb +40 -0
- data/lib/euclid/version.rb +3 -0
- metadata +80 -0
data/.DS_Store
ADDED
|
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Scott Woody
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.html
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!DOCTYPE html PUBLIC
|
|
3
|
+
"-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
|
|
4
|
+
"http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
|
|
5
|
+
<html xml:lang='en' xmlns:svg='http://www.w3.org/2000/svg' xmlns='http://www.w3.org/1999/xhtml'>
|
|
6
|
+
<head><meta content='application/xhtml+xml;charset=utf-8' http-equiv='Content-type' /><title></title></head>
|
|
7
|
+
<body>
|
|
8
|
+
<h1 id='euclid_gem'>Euclid Gem</h1>
|
|
9
|
+
|
|
10
|
+
<p>Ruby wrapper for the <a href='http://www.euclidelements.com/hack/api'>Euclid Hackathon API</a>. The Euclid gem provides an easy to user wrapper for Euclid’s JSON API. It uses <a href='https://github.com/archiloque/rest-client'>RestClient</a> to simplify communication with Euclid’s servers.</p>
|
|
11
|
+
|
|
12
|
+
<h2 id='installation'>Installation</h2>
|
|
13
|
+
|
|
14
|
+
<p>gem install euclid</p>
|
|
15
|
+
|
|
16
|
+
<h1 id='usage'>Usage</h1>
|
|
17
|
+
|
|
18
|
+
<h3 id='authenticate'>Authenticate</h3>
|
|
19
|
+
|
|
20
|
+
<p>In order to talk to the appropriate sensor you must provide a credential to the server. To simplify this process I’ve created a client object to store the credential, all calls are made through the client.</p>
|
|
21
|
+
</body></html>
|
data/README.md
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Euclid Gem
|
|
2
|
+
==========
|
|
3
|
+
Ruby wrapper for the [Euclid Hackathon API](http://www.euclidelements.com/hack/api). The Euclid gem provides an easy to user wrapper for Euclid's JSON API. It uses [RestClient](https://github.com/archiloque/rest-client) to simplify communication with Euclid's servers.
|
|
4
|
+
|
|
5
|
+
Installation
|
|
6
|
+
------------
|
|
7
|
+
[sudo] gem install euclid
|
|
8
|
+
|
|
9
|
+
Usage
|
|
10
|
+
=====
|
|
11
|
+
|
|
12
|
+
### Authentication
|
|
13
|
+
|
|
14
|
+
In order to talk to the appropriate sensor you must provide a credential to the server. To simplify this process I've created a client object to store the credential, all calls are made through the client.
|
|
15
|
+
|
|
16
|
+
require 'rubygems'
|
|
17
|
+
require 'euclid'
|
|
18
|
+
|
|
19
|
+
# credential is the id of the sensor
|
|
20
|
+
client = Euclid::Client.new('credential')
|
|
21
|
+
|
|
22
|
+
### Register Shopper
|
|
23
|
+
|
|
24
|
+
Using a properly credentialed client you can register a shopper with Euclid. A shopper with a previously registered mac address will return the shopper_id already stored with Euclid.
|
|
25
|
+
|
|
26
|
+
# Create a client, optionally include a name identifier for the shopper
|
|
27
|
+
# mac should be the mac address of the user's wireless device without colons. E.g. 00:AA:11:22:33:44 should be 00AA11223344
|
|
28
|
+
# name is an optional parameter
|
|
29
|
+
client.create_shopper("AABBCCFFFFFF", "Jeff Brown")
|
|
30
|
+
# Return Value
|
|
31
|
+
{
|
|
32
|
+
"shopper_id": 183,
|
|
33
|
+
"name": "Jeff Brown",
|
|
34
|
+
"mac": "AABBCCFFFFFF",
|
|
35
|
+
"registered_at": 1338577684
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
### Fetch Shopper
|
|
39
|
+
|
|
40
|
+
Using a properly credentialed client you can fetch a shopper by shopper_id.
|
|
41
|
+
|
|
42
|
+
# Fetch a shopper by shopper_id
|
|
43
|
+
client.get_shopper(183)
|
|
44
|
+
# Return Value
|
|
45
|
+
{
|
|
46
|
+
"shopper_id": 183,
|
|
47
|
+
"name": "Jeff Brown",
|
|
48
|
+
"mac": "AABBCCFFFFFF",
|
|
49
|
+
"registered_at": 1338577684
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
### Fetch Shoppers
|
|
53
|
+
|
|
54
|
+
Using a properly credentialed client you can fetch shoppers registered with the sensor.
|
|
55
|
+
|
|
56
|
+
# fetch all shoppers registered with this credential, with an optional proximity parameter
|
|
57
|
+
# get registerd shoppers close to the sensor
|
|
58
|
+
client.get_shoppers('close')
|
|
59
|
+
# get registerd shoppers detected by sensor
|
|
60
|
+
client.get_shoppers('detected')
|
|
61
|
+
# get registerd shoppers not detected by the sensor
|
|
62
|
+
client.get_shoppers('away')
|
|
63
|
+
# get all registered shoppers for this sensor
|
|
64
|
+
client.get_shoppers()
|
|
65
|
+
|
|
66
|
+
# Return Values
|
|
67
|
+
[
|
|
68
|
+
{
|
|
69
|
+
"detected_at": 1338577743,
|
|
70
|
+
"id": 161,
|
|
71
|
+
"mac": "AABBCCDDEEEE",
|
|
72
|
+
"name": "Macbook Ken",
|
|
73
|
+
"registered_at": 1338491556
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"detected_at": 1338577719,
|
|
77
|
+
"id": 157,
|
|
78
|
+
"mac": "9022E454333F",
|
|
79
|
+
"name": "iPhone 4 Steve",
|
|
80
|
+
"registered_at": 1338491553
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
### Fetch Alerts
|
|
84
|
+
|
|
85
|
+
You can also fetch alerts for a sensor, scoped by proximity and shopper_id (optional).
|
|
86
|
+
|
|
87
|
+
# fetch all shoppers registered with this credential, with an optional proximity parameter
|
|
88
|
+
# get recent alerts for all shoppers
|
|
89
|
+
client.get_alerts()
|
|
90
|
+
# get alerts for close shoppers
|
|
91
|
+
client.get_alerts({"proximity" => "close"})
|
|
92
|
+
# get alerts scoped by shopper_id
|
|
93
|
+
client.get_alerts({"proximity" => "close", "shopper_id" => 183})
|
|
94
|
+
client.get_alerts({"shopper_id" => 183})
|
|
95
|
+
|
|
96
|
+
# Return Values
|
|
97
|
+
[
|
|
98
|
+
{
|
|
99
|
+
"detected_at": 1338578069,
|
|
100
|
+
"id": 13274,
|
|
101
|
+
"proximity": "close",
|
|
102
|
+
"shopper_id": 174,
|
|
103
|
+
"shopper_mac": "00260890500B",
|
|
104
|
+
"shopper_name": "iPhone 3GS Roy"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"detected_at": 1338578060,
|
|
108
|
+
"id": 13273,
|
|
109
|
+
"proximity": "close",
|
|
110
|
+
"shopper_id": 165,
|
|
111
|
+
"shopper_mac": "CC08E0763CF6",
|
|
112
|
+
"shopper_name": "Jane Doe"
|
|
113
|
+
}
|
|
114
|
+
]
|
data/Rakefile
ADDED
data/euclid.gemspec
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../lib/euclid/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = ["Scott Woody"]
|
|
6
|
+
gem.email = ["swoody92@gmail.com"]
|
|
7
|
+
gem.description = %q{This gem wraps the Euclid Elements API}
|
|
8
|
+
gem.summary = %q{Wraps basic API commands in Ruby}
|
|
9
|
+
gem.homepage = ""
|
|
10
|
+
|
|
11
|
+
gem.add_development_dependency "rest-client"
|
|
12
|
+
gem.add_development_dependency "json"
|
|
13
|
+
|
|
14
|
+
gem.files = `git ls-files`.split($\)
|
|
15
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
17
|
+
gem.name = "euclid"
|
|
18
|
+
gem.require_paths = ["lib"]
|
|
19
|
+
gem.version = Euclid::VERSION
|
|
20
|
+
end
|
data/lib/euclid.rb
ADDED
data/lib/euclid/alert.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Euclid
|
|
2
|
+
class Alert
|
|
3
|
+
|
|
4
|
+
def self.get_alerts(credential, args)
|
|
5
|
+
url = "https://store.euclidelements.com/shoppers.json?&credential=" + credential
|
|
6
|
+
if args.length > 0
|
|
7
|
+
args.each do |k,v|
|
|
8
|
+
url += "&#{k}=#{v}"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
p url
|
|
12
|
+
JSON.parse(RestClient.get(url))
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Euclid
|
|
2
|
+
class Client
|
|
3
|
+
def initialize(credential)
|
|
4
|
+
@credential = credential
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def create_shopper(mac, name=nil)
|
|
8
|
+
name = Digest::SHA2.hexdigest(mac.to_s) if name.nil?
|
|
9
|
+
shopper = Euclid::Shopper.new(@credential, mac, name)
|
|
10
|
+
response = shopper.register()
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# proximity = detected || away || close
|
|
14
|
+
def get_shoppers(proximity=nil)
|
|
15
|
+
Euclid::Shopper.get_shoppers(@credential, proximity)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# gets the shopper information by shopper_id
|
|
19
|
+
def get_shopper(id=nil)
|
|
20
|
+
Euclid::Shopper.get_shopper(id)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# gets the alerts associated with this sensor, optional params shopper_id, proximity
|
|
24
|
+
def get_alerts(opts={})
|
|
25
|
+
args = {}
|
|
26
|
+
args[:shopper_id] = opts["shopper_id"] if opts["shopper_id"]
|
|
27
|
+
args[:proximity] = opts["proximity"] if opts["proximity"] && ["close", "detected", "away"].include?(opts["proximity"])
|
|
28
|
+
p opts
|
|
29
|
+
p opts["proximity"]
|
|
30
|
+
Euclid::Alert.get_alerts(@credential, args)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Euclid
|
|
2
|
+
class Shopper
|
|
3
|
+
|
|
4
|
+
def self.get_shoppers(credential, proximity=nil)
|
|
5
|
+
url = "https://store.euclidelements.com/shoppers.json?credential=" + credential
|
|
6
|
+
url += "&proximity=#{proximity}" if ["close", "detected", "away"].include? proximity
|
|
7
|
+
JSON.parse(RestClient.get(url))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.get_shopper(id=nil)
|
|
11
|
+
raise "Shopper ID required" if id.nil?
|
|
12
|
+
url = "https://store.euclidelements.com/shoppers/#{id}.json?credential=hackathon"
|
|
13
|
+
JSON.parse(RestClient.get(url))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def initialize(credential, mac, name)
|
|
17
|
+
@mac = mac
|
|
18
|
+
@name = name
|
|
19
|
+
@credential = credential
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def register
|
|
23
|
+
url = "https://store.euclidelements.com/shoppers.json?credential=" + @credential
|
|
24
|
+
response = RestClient.post(
|
|
25
|
+
url,
|
|
26
|
+
{
|
|
27
|
+
mac: @mac,
|
|
28
|
+
name: @name
|
|
29
|
+
}
|
|
30
|
+
)
|
|
31
|
+
json_response = JSON.parse(response)
|
|
32
|
+
if json_response["shopper_id"]
|
|
33
|
+
@shopper_id = json_response["shopper_id"]
|
|
34
|
+
self
|
|
35
|
+
else
|
|
36
|
+
raise "could not create shopper"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: euclid
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Scott Woody
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2012-06-04 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rest-client
|
|
16
|
+
requirement: &70167385760320 !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: *70167385760320
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: json
|
|
27
|
+
requirement: &70167385759660 !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: *70167385759660
|
|
36
|
+
description: This gem wraps the Euclid Elements API
|
|
37
|
+
email:
|
|
38
|
+
- swoody92@gmail.com
|
|
39
|
+
executables: []
|
|
40
|
+
extensions: []
|
|
41
|
+
extra_rdoc_files: []
|
|
42
|
+
files:
|
|
43
|
+
- .DS_Store
|
|
44
|
+
- .gitignore
|
|
45
|
+
- Gemfile
|
|
46
|
+
- LICENSE
|
|
47
|
+
- README.html
|
|
48
|
+
- README.md
|
|
49
|
+
- Rakefile
|
|
50
|
+
- euclid.gemspec
|
|
51
|
+
- lib/euclid.rb
|
|
52
|
+
- lib/euclid/alert.rb
|
|
53
|
+
- lib/euclid/client.rb
|
|
54
|
+
- lib/euclid/shopper.rb
|
|
55
|
+
- lib/euclid/version.rb
|
|
56
|
+
homepage: ''
|
|
57
|
+
licenses: []
|
|
58
|
+
post_install_message:
|
|
59
|
+
rdoc_options: []
|
|
60
|
+
require_paths:
|
|
61
|
+
- lib
|
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
|
+
none: false
|
|
64
|
+
requirements:
|
|
65
|
+
- - ! '>='
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
none: false
|
|
70
|
+
requirements:
|
|
71
|
+
- - ! '>='
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
requirements: []
|
|
75
|
+
rubyforge_project:
|
|
76
|
+
rubygems_version: 1.8.10
|
|
77
|
+
signing_key:
|
|
78
|
+
specification_version: 3
|
|
79
|
+
summary: Wraps basic API commands in Ruby
|
|
80
|
+
test_files: []
|