phant_rb 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +36 -2
- data/lib/phant_rb/version.rb +1 -1
- data/lib/phant_rb.rb +31 -10
- data/spec/phant_rb_spec.rb +20 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17838ed9df5576d26e9c8ce00811e647f5edc3d5
|
4
|
+
data.tar.gz: 2f61e56fb9dc21398b4d98cacaca28a31a249c47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 351f3e77f750359d37bab877344284ddb828c9070422f79d18e7353b50b330262387b22b27118aa52633e80cce195e345f9f33ed8d7aebe38aaeaae23a39a3a5
|
7
|
+
data.tar.gz: dde8cd909d22e1da291b7edace160fdb2f2621d2dd69c19aad4a16d213e66b5f635a3f0292f5987f9c7a0cccbfa103e9b6b738a03d221362a7c272e2eeed543f
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A Ruby client for Phant. See [data.sparkfun.com](https://data.sparkfun.com/) for more information.
|
4
4
|
|
5
|
-
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/phant_rb.png)](http://badge.fury.io/rb/phant_rb)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -22,19 +22,53 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
client = PhantRb::Client.new "PUBLIC_KEY", %w(humidity temp), private_key: 'PRIVATE_KEY'
|
25
|
+
|
26
|
+
# log data, http://phant.io/docs/input/http/
|
25
27
|
client.log(22.7, 17.8)
|
26
28
|
|
29
|
+
# retrieve your data, http://phant.io/docs/output/http/
|
27
30
|
data = client.get()
|
28
31
|
puts data
|
32
|
+
|
33
|
+
# retrieve info about the current state of your stream, http://phant.io/docs/output/stats/
|
34
|
+
stats = client.stats()
|
35
|
+
puts stats.pageCount
|
36
|
+
puts stats.remaining
|
37
|
+
|
38
|
+
# retrieve rate limit for the current stream, http://phant.io/docs/input/limit/
|
39
|
+
# must be called only after PhantRb::Client#log is called
|
40
|
+
limits = client.rate_limits()
|
41
|
+
puts limits.x_rate_limit_remaining
|
42
|
+
|
43
|
+
# clear all logged data from a stream, http://phant.io/docs/management/clear/
|
44
|
+
client.clear()
|
45
|
+
|
46
|
+
```
|
47
|
+
|
48
|
+
To use different Phant server
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
client = PhantRb::Client.new "PUBLIC_KEY", %w(humidity temp), {private_key: 'PRIVATE_KEY', base_url: 'http://127.0.0.1/'}
|
29
52
|
```
|
30
53
|
|
54
|
+
## TODO
|
55
|
+
* delete a stream
|
56
|
+
* paginate data
|
57
|
+
* use local server in specs
|
58
|
+
|
31
59
|
## Contributing
|
32
60
|
|
33
|
-
1. Fork it ( https://github.com/
|
61
|
+
1. Fork it ( https://github.com/girishso/phant_rb/fork )
|
34
62
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
63
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
64
|
4. Push to the branch (`git push origin my-new-feature`)
|
37
65
|
5. Create a new Pull Request
|
38
66
|
|
67
|
+
## Licence
|
68
|
+
|
69
|
+
MIT License
|
70
|
+
|
71
|
+
This software is provided as is, use it your own risk.
|
39
72
|
|
73
|
+
Brought to you by: [Cube Root Software](http://www.cuberoot.in) (c) 2014
|
40
74
|
|
data/lib/phant_rb/version.rb
CHANGED
data/lib/phant_rb.rb
CHANGED
@@ -14,23 +14,44 @@ module PhantRb
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def log(*data)
|
17
|
-
|
17
|
+
conn = rest_conn 'input'
|
18
|
+
@last_response = conn.post URI.encode_www_form(@fields.zip(data))
|
18
19
|
Hashie::Mash.new(JSON.parse(@last_response.body))
|
19
20
|
end
|
20
21
|
|
21
22
|
def get
|
22
|
-
|
23
|
-
|
24
|
-
JSON.parse
|
23
|
+
conn = rest_conn 'output'
|
24
|
+
response = conn.get
|
25
|
+
JSON.parse response.body
|
26
|
+
end
|
27
|
+
|
28
|
+
def stats
|
29
|
+
conn = rest_conn 'stats'
|
30
|
+
response = conn.get
|
31
|
+
Hashie::Mash.new(JSON.parse(response.body))
|
32
|
+
end
|
33
|
+
|
34
|
+
def clear
|
35
|
+
conn = rest_conn 'input'
|
36
|
+
response = conn.delete
|
37
|
+
Hashie::Mash.new(JSON.parse(response.body))
|
38
|
+
end
|
39
|
+
|
40
|
+
def rate_limits
|
41
|
+
unless !@last_response.nil? && @last_response.headers.has_key?(:x_rate_limit_remaining)
|
42
|
+
raise "No rate limit headers found. PhantRb::Client#log must be called before this."
|
43
|
+
end
|
44
|
+
Hashie::Mash.new(@last_response.headers)
|
25
45
|
end
|
26
46
|
|
27
47
|
private
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
48
|
+
def rest_conn(type)
|
49
|
+
url = case type
|
50
|
+
when 'stats' then URI.join @opts[:base_url], "/output/", "#{@public_key}/stats.json"
|
51
|
+
else URI.join @opts[:base_url], "/#{type}/", "#{@public_key}.json"
|
52
|
+
end
|
53
|
+
RestClient::Resource.new url.to_s,
|
54
|
+
{:headers => {'Phant-Private-Key' => @opts[:private_key]}}
|
34
55
|
end
|
35
56
|
end
|
36
57
|
end
|
data/spec/phant_rb_spec.rb
CHANGED
@@ -10,12 +10,28 @@ describe PhantRb do
|
|
10
10
|
expect(resp.success).to be true
|
11
11
|
end
|
12
12
|
|
13
|
-
it '
|
13
|
+
it 'returns rate limits' do
|
14
|
+
resp = @client.log(12.0, 23)
|
14
15
|
@client.get
|
16
|
+
resp = @client.rate_limits
|
17
|
+
expect(resp.has_key?(:x_rate_limit_remaining)).to be true
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'reads data' do
|
21
|
+
resp = @client.get
|
22
|
+
expect(resp).to be_an(Array)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'returns stats for a stream' do
|
26
|
+
resp = @client.stats
|
27
|
+
expect(resp.has_key?(:remaining)).to be true
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
it 'clears a stream' do
|
32
|
+
resp = @client.clear
|
33
|
+
expect(resp.success).to be true
|
15
34
|
end
|
16
35
|
|
17
36
|
it 'completely deletes a stream'
|
18
|
-
it 'clears a stream'
|
19
|
-
it 'returns stats for a stream'
|
20
|
-
it 'returns rate limits'
|
21
37
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phant_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Girish S
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|